From ace6d94f93a55351327f6f03b1373f9b9c0be90c Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Mon, 25 Nov 2024 23:37:29 +0800 Subject: [PATCH] Remove useless default constructor of ShardingSphereTable (#33806) * Refactor ShardingSphereTable * Remove useless default constructor of ShardingSphereTable --- .../sharding/merge/dql/orderby/OrderByValueTest.java | 3 ++- .../database/schema/model/ShardingSphereTable.java | 5 ----- .../database/schema/manager/GenericSchemaManagerTest.java | 7 +++++-- .../infra/yaml/schema/swapper/YamlTableSwapperTest.java | 3 ++- .../ddl/SingleDropSchemaMetaDataValidatorTest.java | 3 ++- .../StandaloneMetaDataManagerPersistServiceTest.java | 5 +++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java index 1e7067a61a432..c2dd776ba01ae 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; @@ -148,7 +149,7 @@ private void assertCompareToForDesc(final SelectStatement selectStatement) throw SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME, Collections.emptyList()); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); - when(schema.getTable("table")).thenReturn(new ShardingSphereTable()); + when(schema.getTable("foo_tbl")).thenReturn(new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE)); QueryResult queryResult1 = createQueryResult("1", "2"); OrderByValue orderByValue1 = new OrderByValue(queryResult1, Arrays.asList( createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderType.FIRST)), diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java index 1ecc8332a64c6..bfd15c84d365b 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTable.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -62,10 +61,6 @@ public final class ShardingSphereTable { private final TableType type; - public ShardingSphereTable() { - this("", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE); - } - public ShardingSphereTable(final String name, final Collection columns, final Collection indexes, final Collection constraints) { this(name, columns, indexes, constraints, TableType.TABLE); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManagerTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManagerTest.java index c2c89105c3b98..23330df3cdc87 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManagerTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManagerTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.metadata.database.schema.manager; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.junit.jupiter.api.Test; @@ -57,14 +58,16 @@ void assertGetToBeDroppedTablesBySchemas() { @Test void assertGetToBeAddedTables() { - Map actual = GenericSchemaManager.getToBeAddedTables(Collections.singletonMap("foo_table", new ShardingSphereTable()), Collections.emptyMap()); + Map actual = GenericSchemaManager.getToBeAddedTables(Collections.singletonMap("foo_table", + new ShardingSphereTable("", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE)), Collections.emptyMap()); assertThat(actual.size(), is(1)); assertTrue(actual.containsKey("foo_table")); } @Test void assertGetToBeDroppedTables() { - Map actual = GenericSchemaManager.getToBeDroppedTables(Collections.emptyMap(), Collections.singletonMap("foo_table", new ShardingSphereTable())); + Map actual = GenericSchemaManager.getToBeDroppedTables(Collections.emptyMap(), Collections.singletonMap("foo_table", + new ShardingSphereTable("", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE))); assertThat(actual.size(), is(1)); assertTrue(actual.containsKey("foo_table")); } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java index 19fe8d2664d17..959e31b09203f 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.infra.yaml.schema.swapper; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereConstraint; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex; @@ -57,7 +58,7 @@ void assertSwapToObject() { @Test void assertSwapToObjectWithEmptySchema() { ShardingSphereTable actual = swapper.swapToObject(YamlEngine.unmarshal(ConfigurationFileUtils.readFile(EMPTY_YAML_FILE), YamlShardingSphereTable.class)); - ShardingSphereTable expected = new ShardingSphereTable(); + ShardingSphereTable expected = new ShardingSphereTable("", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE); assertThat(actual, deepEqual(expected)); } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java index b014c9f9a101f..66b36335fdcb7 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.UnknownSQLStatementContext; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType; import org.apache.shardingsphere.infra.exception.kernel.metadata.SchemaNotFoundException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -61,7 +62,7 @@ void assertValidate() { private ShardingSphereDatabase mockDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME); - schema.putTable("foo_table", new ShardingSphereTable()); + schema.putTable("foo_tbl", new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE)); when(result.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", schema)); return result; } diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistServiceTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistServiceTest.java index 0ff1a6d6513f4..059bafaf5f84f 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistServiceTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistServiceTest.java @@ -21,6 +21,7 @@ import org.apache.groovy.util.Maps; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; @@ -229,9 +230,9 @@ void assertAlterProperties() { @Test void assertCreateTable() { - ShardingSphereTable table = new ShardingSphereTable(); + ShardingSphereTable table = new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE); metaDataManagerPersistService.createTable("foo_db", "foo_schema", table, "foo_ds"); - verify(metaDataPersistService.getDatabaseMetaDataFacade().getTable()).persist("foo_db", "foo_schema", Maps.of("", table)); + verify(metaDataPersistService.getDatabaseMetaDataFacade().getTable()).persist("foo_db", "foo_schema", Maps.of("foo_tbl", table)); } @Test