From 71814406e3e5ece6c1a2ce256d91ec71d8643ed3 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 10 Dec 2024 23:13:42 +0800 Subject: [PATCH] Remove useless codes on ColumnReviseEngine (#33999) --- .../schema/reviser/MetaDataReviseEngine.java | 10 ++-------- .../schema/reviser/column/ColumnReviseEngine.java | 6 ------ .../reviser/schema/SchemaMetaDataReviseEngine.java | 12 +++--------- .../reviser/table/TableMetaDataReviseEngine.java | 8 +------- .../schema/SchemaMetaDataReviseEngineTest.java | 6 ++---- .../reviser/table/TableMetadataReviseEngineTest.java | 12 ++---------- 6 files changed, 10 insertions(+), 44 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/MetaDataReviseEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/MetaDataReviseEngine.java index 6ddf574a133d8..798922e32b89f 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/MetaDataReviseEngine.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/MetaDataReviseEngine.java @@ -18,14 +18,11 @@ package org.apache.shardingsphere.infra.metadata.database.schema.reviser; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; -import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial; import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData; +import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.schema.SchemaMetaDataReviseEngine; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import javax.sql.DataSource; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; @@ -49,10 +46,7 @@ public final class MetaDataReviseEngine { public Map revise(final Map schemaMetaDataMap, final GenericSchemaBuilderMaterial material) { Map result = new LinkedHashMap<>(schemaMetaDataMap.size(), 1F); for (Entry entry : schemaMetaDataMap.entrySet()) { - // TODO establish a corresponding relationship between tables and data sources - DatabaseType databaseType = material.getStorageUnits().values().stream().map(StorageUnit::getStorageType).findFirst().orElse(null); - DataSource dataSource = material.getStorageUnits().values().stream().map(StorageUnit::getDataSource).findFirst().orElse(null); - result.put(entry.getKey(), new SchemaMetaDataReviseEngine(rules, material.getProps(), databaseType, dataSource).revise(entry.getValue())); + result.put(entry.getKey(), new SchemaMetaDataReviseEngine(rules, material.getProps()).revise(entry.getValue())); } return result; } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/column/ColumnReviseEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/column/ColumnReviseEngine.java index ba7355f7743c9..dc744ef076b19 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/column/ColumnReviseEngine.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/column/ColumnReviseEngine.java @@ -19,11 +19,9 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.database.core.metadata.data.model.ColumnMetaData; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import javax.sql.DataSource; import java.util.Collection; import java.util.LinkedHashSet; import java.util.Optional; @@ -38,10 +36,6 @@ public final class ColumnReviseEngine { private final T rule; - private final DatabaseType databaseType; - - private final DataSource dataSource; - private final MetaDataReviseEntry reviseEntry; /** diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngine.java index cacecc6145ba1..03bf9842152f9 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngine.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngine.java @@ -19,15 +19,13 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.database.schema.reviser.table.TableMetaDataReviseEngine; -import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry; import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData; import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData; +import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry; +import org.apache.shardingsphere.infra.metadata.database.schema.reviser.table.TableMetaDataReviseEngine; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; -import javax.sql.DataSource; import java.util.Collection; import java.util.Map.Entry; import java.util.Optional; @@ -43,10 +41,6 @@ public final class SchemaMetaDataReviseEngine { private final ConfigurationProperties props; - private final DatabaseType databaseType; - - private final DataSource dataSource; - /** * Revise schema meta data. * @@ -63,7 +57,7 @@ public SchemaMetaData revise(final SchemaMetaData originalMetaData) { } private SchemaMetaData revise(final SchemaMetaData originalMetaData, final T rule, final MetaDataReviseEntry reviseEntry) { - TableMetaDataReviseEngine tableMetaDataReviseEngine = new TableMetaDataReviseEngine<>(rule, databaseType, dataSource, reviseEntry); + TableMetaDataReviseEngine tableMetaDataReviseEngine = new TableMetaDataReviseEngine<>(rule, reviseEntry); Optional> aggregationReviser = reviseEntry.getSchemaTableAggregationReviser(props); if (!aggregationReviser.isPresent()) { return new SchemaMetaData(originalMetaData.getName(), originalMetaData.getTables().stream().map(tableMetaDataReviseEngine::revise).collect(Collectors.toList())); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetaDataReviseEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetaDataReviseEngine.java index f29c355b44b4c..3822599555ebc 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetaDataReviseEngine.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetaDataReviseEngine.java @@ -18,7 +18,6 @@ package org.apache.shardingsphere.infra.metadata.database.schema.reviser.table; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.column.ColumnReviseEngine; @@ -26,7 +25,6 @@ import org.apache.shardingsphere.infra.metadata.database.schema.reviser.index.IndexReviseEngine; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import javax.sql.DataSource; import java.util.Optional; /** @@ -39,10 +37,6 @@ public final class TableMetaDataReviseEngine { private final T rule; - private final DatabaseType databaseType; - - private final DataSource dataSource; - private final MetaDataReviseEntry reviseEntry; /** @@ -54,7 +48,7 @@ public final class TableMetaDataReviseEngine { public TableMetaData revise(final TableMetaData originalMetaData) { Optional> tableNameReviser = reviseEntry.getTableNameReviser(); String revisedTableName = tableNameReviser.map(optional -> optional.revise(originalMetaData.getName(), rule)).orElse(originalMetaData.getName()); - return new TableMetaData(revisedTableName, new ColumnReviseEngine<>(rule, databaseType, dataSource, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getColumns()), + return new TableMetaData(revisedTableName, new ColumnReviseEngine<>(rule, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getColumns()), new IndexReviseEngine<>(rule, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getIndexes()), new ConstraintReviseEngine<>(rule, reviseEntry).revise(originalMetaData.getName(), originalMetaData.getConstraints()), originalMetaData.getType()); } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngineTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngineTest.java index f1b0d8c0b1155..b9b2f4e6efc72 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngineTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/schema/SchemaMetaDataReviseEngineTest.java @@ -23,11 +23,9 @@ import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData; import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData; import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRule; import org.junit.jupiter.api.Test; -import javax.sql.DataSource; import java.sql.Types; import java.util.Arrays; import java.util.Collection; @@ -45,7 +43,7 @@ class SchemaMetaDataReviseEngineTest { void assertReviseWithoutMetaDataReviseEntry() { SchemaMetaData schemaMetaData = new SchemaMetaData("expected", Collections.singleton(mock(TableMetaData.class))); SchemaMetaData actual = new SchemaMetaDataReviseEngine( - Collections.emptyList(), new ConfigurationProperties(new Properties()), mock(DatabaseType.class), mock(DataSource.class)).revise(schemaMetaData); + Collections.emptyList(), new ConfigurationProperties(new Properties())).revise(schemaMetaData); assertThat(actual.getName(), is(schemaMetaData.getName())); assertThat(actual.getTables(), is(schemaMetaData.getTables())); } @@ -54,7 +52,7 @@ void assertReviseWithoutMetaDataReviseEntry() { void assertReviseWithMetaDataReviseEntry() { SchemaMetaData schemaMetaData = new SchemaMetaData("expected", Collections.singletonList(createTableMetaData())); SchemaMetaData actual = new SchemaMetaDataReviseEngine( - Collections.singleton(new FixtureGlobalRule()), new ConfigurationProperties(new Properties()), mock(DatabaseType.class), mock(DataSource.class)).revise(schemaMetaData); + Collections.singleton(new FixtureGlobalRule()), new ConfigurationProperties(new Properties())).revise(schemaMetaData); assertThat(actual.getName(), is(schemaMetaData.getName())); assertThat(actual.getTables(), is(schemaMetaData.getTables())); } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetadataReviseEngineTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetadataReviseEngineTest.java index 1d632b0ec0993..e304796c914e3 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetadataReviseEngineTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/table/TableMetadataReviseEngineTest.java @@ -20,7 +20,6 @@ import org.apache.shardingsphere.infra.database.core.metadata.data.model.ColumnMetaData; import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData; import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.test.mock.AutoMockExtension; @@ -31,7 +30,6 @@ import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; -import javax.sql.DataSource; import java.util.Collection; import java.util.LinkedList; import java.util.Optional; @@ -52,12 +50,6 @@ class TableMetadataReviseEngineTest { @Mock private T rule; - @Mock - private DatabaseType databaseType; - - @Mock - private DataSource dataSource; - @SuppressWarnings("rawtypes") @Mock private MetaDataReviseEntry metaDataReviseEntry; @@ -67,7 +59,7 @@ class TableMetadataReviseEngineTest { void assertGetRevisedTableName() { TableNameReviser tableNameReviser = mock(TableNameReviser.class); TableMetaData originalMetaData = new TableMetaData("originalTableName", new LinkedList<>(), null, null); - TableMetaDataReviseEngine tableMetaDataReviseEngine = new TableMetaDataReviseEngine(rule, databaseType, dataSource, metaDataReviseEntry); + TableMetaDataReviseEngine tableMetaDataReviseEngine = new TableMetaDataReviseEngine(rule, metaDataReviseEntry); doReturn(Optional.of(tableNameReviser)).when(metaDataReviseEntry).getTableNameReviser(); when(tableNameReviser.revise(anyString(), eq(rule))).thenReturn("revisedTableName"); TableMetaData revisedMetaData = tableMetaDataReviseEngine.revise(originalMetaData); @@ -82,7 +74,7 @@ void assertGetOriginalTableName() { Collection indexes = new LinkedList<>(); indexes.add(new IndexMetaData("index1")); TableMetaData tableMetaData = new TableMetaData("originalTableName", columns, indexes, null); - TableMetaDataReviseEngine tableMetaDataReviseEngine = new TableMetaDataReviseEngine(rule, databaseType, dataSource, metaDataReviseEntry); + TableMetaDataReviseEngine tableMetaDataReviseEngine = new TableMetaDataReviseEngine(rule, metaDataReviseEntry); when(metaDataReviseEntry.getTableNameReviser()).thenReturn(Optional.empty()); TableMetaData revisedMetaData = tableMetaDataReviseEngine.revise(tableMetaData); assertThat(revisedMetaData.getName(), is("originalTableName"));