diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java index 00d997e47a12d..3904d1c4620c1 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; @@ -119,7 +120,7 @@ private TimestampServiceRule createTimeServiceRule() { } private ShardingSphereDatabase createDatabase(final ShardingRule shardingRule, final TimestampServiceRule timestampServiceRule) { - ShardingSphereSchema schema = new ShardingSphereSchema(); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME); schema.getTables().put("t_warehouse", new ShardingSphereTable("t_warehouse", Arrays.asList( new ShardingSphereColumn("id", Types.INTEGER, true, false, false, true, false, false), new ShardingSphereColumn("warehouse_name", Types.VARCHAR, false, false, false, true, false, false)), diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java index 43c3bcc4e0f22..37c6088b2b0a8 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java @@ -19,6 +19,7 @@ import org.apache.groovy.util.Maps; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereConstraint; @@ -68,7 +69,7 @@ private ShardingSphereSchema createSchema() { tables.put("t_order", new ShardingSphereTable("t_order", Collections.emptyList(), Collections.emptyList(), Collections.singleton(new ShardingSphereConstraint("t_order_foreign_key", "t_user")))); tables.put("t_user", new ShardingSphereTable("t_user", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); - return new ShardingSphereSchema(tables, Collections.emptyMap()); + return new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()); } @Test diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java index 77eccb0ca96dc..499cfe0f320e4 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java @@ -19,6 +19,7 @@ import org.apache.groovy.util.Maps; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.merge.result.MergedResult; @@ -57,7 +58,7 @@ class ShowTableStatusMergedResultTest { @BeforeEach void setUp() { shardingRule = buildShardingRule(); - schema = new ShardingSphereSchema(Collections.singletonMap("table", + schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("table", new ShardingSphereTable("table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())), Collections.emptyMap()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java index a6494f2e66a5a..0c6fc470ea164 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java @@ -19,6 +19,7 @@ import org.apache.groovy.util.Maps; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -48,7 +49,7 @@ class ShowTablesMergedResultTest { @BeforeEach void setUp() { shardingRule = createShardingRule(); - schema = new ShardingSphereSchema(Collections.singletonMap("table", + schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("table", new ShardingSphereTable("table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())), Collections.emptyMap()); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java index 2722a32e9a7a1..05e69694440c2 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java @@ -513,7 +513,7 @@ private ShardingSphereDatabase createDatabase() { ShardingSphereColumn column2 = new ShardingSphereColumn("col2", 0, false, false, false, true, false, false); ShardingSphereColumn column3 = new ShardingSphereColumn("col3", 0, false, false, false, true, false, false); ShardingSphereTable table = new ShardingSphereTable("tbl", Arrays.asList(column1, column2, column3), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()); return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, TypedSPILoader.getService(DatabaseType.class, "MySQL"), mock(ResourceMetaData.class), mock(RuleMetaData.class), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema)); } @@ -523,7 +523,7 @@ private ShardingSphereDatabase createSQLServerDatabase() { ShardingSphereColumn column2 = new ShardingSphereColumn("col2", 0, false, false, false, true, false, false); ShardingSphereColumn column3 = new ShardingSphereColumn("col3", 0, false, false, false, true, false, false); ShardingSphereTable table = new ShardingSphereTable("tbl", Arrays.asList(column1, column2, column3), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()); return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, TypedSPILoader.getService(DatabaseType.class, "SQLServer"), mock(ResourceMetaData.class), mock(RuleMetaData.class), Collections.singletonMap("dbo", schema)); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java index 14edaf0e16ab2..f9ed7a3a2c5c3 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java @@ -187,7 +187,7 @@ private ShardingSphereDatabase createDatabase() { ShardingSphereColumn column2 = new ShardingSphereColumn("col2", 0, false, false, false, true, false, false); ShardingSphereColumn column3 = new ShardingSphereColumn("col3", 0, false, false, false, true, false, false); ShardingSphereTable table = new ShardingSphereTable("tbl", Arrays.asList(column1, column2, column3), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()); return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, TypedSPILoader.getService(DatabaseType.class, "MySQL"), mock(ResourceMetaData.class), mock(RuleMetaData.class), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema)); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java index 4e5f957a09989..cd3e5add266b7 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java @@ -206,7 +206,7 @@ private ShardingSphereDatabase createDatabase() { ShardingSphereColumn column1 = new ShardingSphereColumn("col1", 0, false, false, true, true, false, false); ShardingSphereColumn column2 = new ShardingSphereColumn("col2", 0, false, false, false, true, false, false); ShardingSphereTable table = new ShardingSphereTable("tbl", Arrays.asList(column1, column2), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()); return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, TypedSPILoader.getService(DatabaseType.class, "MySQL"), mock(ResourceMetaData.class), mock(RuleMetaData.class), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema)); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/assertion/ShardingRouteAssert.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/assertion/ShardingRouteAssert.java index d87cedf28db88..23354399256cf 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/assertion/ShardingRouteAssert.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/assertion/ShardingRouteAssert.java @@ -114,6 +114,6 @@ private static Map buildSchemas() { Collections.emptyList(), Collections.emptyList())); tables.put("t_hint_test", new ShardingSphereTable("t_hint_test", Collections.singleton(new ShardingSphereColumn("user_id", Types.INTEGER, true, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList())); - return Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new ShardingSphereSchema(tables, Collections.emptyMap())); + return Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap())); } } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java index b4f1a2b1cf7b9..659070cb4b039 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap; import org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; @@ -64,7 +65,7 @@ void setUp() { "tbl", Collections.singletonList(new ShardingSphereColumn("id", Types.INTEGER, true, true, false, true, false, false)), Collections.emptyList(), Collections.emptyList()); ShardingSphereTable table2 = new ShardingSphereTable( "tbl2", Collections.singletonList(new ShardingSphereColumn("ID", Types.INTEGER, true, true, false, true, false, false)), Collections.emptyList(), Collections.emptyList()); - schema = new ShardingSphereSchema(ImmutableMap.of(table.getName(), table, table2.getName(), table2), Collections.emptyMap()); + schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, ImmutableMap.of(table.getName(), table, table2.getName(), table2), Collections.emptyMap()); } @Test diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java index 683df09f72fa2..b9cff285b59ea 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java @@ -116,7 +116,8 @@ void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsCol SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", "TBL_2"); ShardingSphereTable table = new ShardingSphereTable("TABLE_1", Collections.singletonList(new ShardingSphereColumn("COL", 0, false, false, true, true, false, false)), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(Stream.of(table).collect(Collectors.toMap(ShardingSphereTable::getName, value -> value)), Collections.emptyMap()); + ShardingSphereSchema schema = + new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Stream.of(table).collect(Collectors.toMap(ShardingSphereTable::getName, value -> value)), Collections.emptyMap()); ColumnSegment columnSegment = createColumnSegment(null, "COL"); Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), DefaultDatabase.LOGIC_NAME).findTableNames(Collections.singletonList(columnSegment), schema); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java index 1b706d06251d9..a34f732c7ea50 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java @@ -119,12 +119,12 @@ private static Map revise(final Map convertToSchemaMap(final Map schemaMetaDataMap, final GenericSchemaBuilderMaterial material) { if (schemaMetaDataMap.isEmpty()) { - return Collections.singletonMap(material.getDefaultSchemaName(), new ShardingSphereSchema()); + return Collections.singletonMap(material.getDefaultSchemaName(), new ShardingSphereSchema(material.getDefaultSchemaName())); } Map result = new ConcurrentHashMap<>(schemaMetaDataMap.size(), 1F); for (Entry entry : schemaMetaDataMap.entrySet()) { Map tables = convertToTableMap(entry.getValue().getTables()); - result.put(entry.getKey().toLowerCase(), new ShardingSphereSchema(tables, new LinkedHashMap<>())); + result.put(entry.getKey().toLowerCase(), new ShardingSphereSchema(entry.getKey(), tables, new LinkedHashMap<>())); } return result; } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java index c8addf96ab0fd..e779cefdce9b2 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilder.java @@ -84,6 +84,6 @@ private static ShardingSphereSchema createSchema(final String schemaName, final tables.put(metaData.getName(), swapper.swapToObject(metaData)); } } - return new ShardingSphereSchema(tables, Collections.emptyMap()); + return new ShardingSphereSchema(schemaName, tables, Collections.emptyMap()); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManager.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManager.java index 4429f0d4087ad..68c7fa88a57de 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManager.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/GenericSchemaManager.java @@ -49,7 +49,7 @@ public static Map getToBeAddedTablesBySchemas(fina } private static ShardingSphereSchema getToBeAddedTablesBySchema(final ShardingSphereSchema reloadSchema, final ShardingSphereSchema currentSchema) { - return new ShardingSphereSchema(getToBeAddedTables(reloadSchema.getTables(), currentSchema.getTables()), new LinkedHashMap<>()); + return new ShardingSphereSchema(currentSchema.getName(), getToBeAddedTables(reloadSchema.getTables(), currentSchema.getTables()), new LinkedHashMap<>()); } /** @@ -78,7 +78,7 @@ public static Map getToBeDeletedTablesBySchemas(fi } private static ShardingSphereSchema getToBeDeletedTablesBySchema(final ShardingSphereSchema reloadSchema, final ShardingSphereSchema currentSchema) { - return new ShardingSphereSchema(getToBeDeletedTables(reloadSchema.getTables(), currentSchema.getTables()), new LinkedHashMap<>()); + return new ShardingSphereSchema(currentSchema.getName(), getToBeDeletedTables(reloadSchema.getTables(), currentSchema.getTables()), new LinkedHashMap<>()); } /** diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java index 0f997f27083e3..d19254dee172a 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java @@ -32,17 +32,21 @@ @Getter public final class ShardingSphereSchema { + private final String name; + private final Map tables; private final Map views; @SuppressWarnings("CollectionWithoutInitialCapacity") - public ShardingSphereSchema() { + public ShardingSphereSchema(final String name) { + this.name = name; tables = new ConcurrentHashMap<>(); views = new ConcurrentHashMap<>(); } - public ShardingSphereSchema(final Map tables, final Map views) { + public ShardingSphereSchema(final String name, final Map tables, final Map views) { + this.name = name; this.tables = new ConcurrentHashMap<>(tables.size(), 1F); this.views = new ConcurrentHashMap<>(views.size(), 1F); tables.forEach((key, value) -> this.tables.put(key.toLowerCase(), value)); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/pojo/YamlShardingSphereSchema.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/pojo/YamlShardingSphereSchema.java index 5223b03ff6cea..9e6c3c4846cb7 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/pojo/YamlShardingSphereSchema.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/pojo/YamlShardingSphereSchema.java @@ -30,6 +30,8 @@ @Setter public final class YamlShardingSphereSchema implements YamlConfiguration { + private String name; + private Map tables; private Map views; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapper.java index 357b77c043b97..0d5bee46f566f 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapper.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapper.java @@ -43,6 +43,7 @@ public YamlShardingSphereSchema swapToYamlConfiguration(final ShardingSphereSche Map views = schema.getAllViewNames().stream() .collect(Collectors.toMap(each -> each, each -> swapYamlView(schema.getView(each)), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); YamlShardingSphereSchema result = new YamlShardingSphereSchema(); + result.setName(schema.getName()); result.setTables(tables); result.setViews(views); return result; @@ -50,7 +51,7 @@ public YamlShardingSphereSchema swapToYamlConfiguration(final ShardingSphereSche @Override public ShardingSphereSchema swapToObject(final YamlShardingSphereSchema yamlConfig) { - return Optional.ofNullable(yamlConfig).map(this::swapSchema).orElseGet(ShardingSphereSchema::new); + return Optional.ofNullable(yamlConfig).map(this::swapSchema).orElseGet(() -> new ShardingSphereSchema(yamlConfig.getName())); } private ShardingSphereSchema swapSchema(final YamlShardingSphereSchema schema) { @@ -58,7 +59,7 @@ private ShardingSphereSchema swapSchema(final YamlShardingSphereSchema schema) { : schema.getTables().entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> swapTable(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); Map views = null == schema.getViews() || schema.getViews().isEmpty() ? new LinkedHashMap<>() : schema.getViews().entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> swapView(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); - return new ShardingSphereSchema(tables, views); + return new ShardingSphereSchema(schema.getName(), tables, views); } private ShardingSphereTable swapTable(final YamlShardingSphereTable table) { diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/GenericSchemaManagerTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/GenericSchemaManagerTest.java index 4d7c5263f5f8c..b460ad91611fc 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/GenericSchemaManagerTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/GenericSchemaManagerTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.infra.metadata.database.schema; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.manager.GenericSchemaManager; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; @@ -34,9 +35,9 @@ class GenericSchemaManagerTest { @Test void assertGetToBeAddedTablesBySchemas() { Map reloadSchemas = Collections.singletonMap("foo_schema", - new ShardingSphereSchema(Collections.singletonMap("foo_table", new ShardingSphereTable("foo_table", + new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("foo_table", new ShardingSphereTable("foo_table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())), Collections.emptyMap())); - Map currentSchemas = Collections.singletonMap("foo_schema", new ShardingSphereSchema(Collections.emptyMap(), Collections.emptyMap())); + Map currentSchemas = Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.emptyMap(), Collections.emptyMap())); Map actual = GenericSchemaManager.getToBeAddedTablesBySchemas(reloadSchemas, currentSchemas); assertThat(actual.size(), is(1)); assertThat(actual.get("foo_schema").getTables().size(), is(1)); @@ -46,9 +47,9 @@ void assertGetToBeAddedTablesBySchemas() { @Test void assertGetToBeDeletedTablesBySchemas() { Map currentSchemas = Collections.singletonMap("foo_schema", - new ShardingSphereSchema(Collections.singletonMap("foo_table", new ShardingSphereTable("foo_table", + new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("foo_table", new ShardingSphereTable("foo_table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())), Collections.emptyMap())); - Map reloadSchemas = Collections.singletonMap("foo_schema", new ShardingSphereSchema(Collections.emptyMap(), Collections.emptyMap())); + Map reloadSchemas = Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.emptyMap(), Collections.emptyMap())); Map actual = GenericSchemaManager.getToBeDeletedTablesBySchemas(reloadSchemas, currentSchemas); assertThat(actual.size(), is(1)); assertThat(actual.get("foo_schema").getTables().size(), is(1)); @@ -71,7 +72,8 @@ void assertGetToBeDeletedTables() { @Test void assertGetToBeDeletedSchemaNames() { - Map actual = GenericSchemaManager.getToBeDeletedSchemaNames(Collections.emptyMap(), Collections.singletonMap("foo_schema", new ShardingSphereSchema())); + Map actual = + GenericSchemaManager.getToBeDeletedSchemaNames(Collections.emptyMap(), Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME))); assertThat(actual.size(), is(1)); assertTrue(actual.containsKey("foo_schema")); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/ShardingSphereSchemaTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/ShardingSphereSchemaTest.java index 8cb17cdf3c036..1e7426954f9c1 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/ShardingSphereSchemaTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/ShardingSphereSchemaTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.infra.metadata.database.schema; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -37,31 +38,33 @@ class ShardingSphereSchemaTest { @Test void assertGetAllTableNames() { - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.emptyMap()).getAllTableNames(), + assertThat(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.emptyMap()).getAllTableNames(), is(new HashSet<>(Collections.singleton("tbl")))); } @Test void assertGetAllViewNames() { - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), + assertThat(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.singletonMap("tbl_view", mock(ShardingSphereView.class))).getAllViewNames(), is(new HashSet<>(Collections.singleton("tbl_view")))); } @Test void assertGetTable() { ShardingSphereTable table = mock(ShardingSphereTable.class); - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()).getTable("tbl"), is(table)); + assertThat(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()).getTable("tbl"), is(table)); } @Test void assertGetView() { ShardingSphereView view = mock(ShardingSphereView.class); - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.singletonMap("tbl_view", view)).getView("tbl_view"), is(view)); + assertThat( + new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.singletonMap("tbl_view", view)).getView("tbl_view"), + is(view)); } @Test void assertPutTable() { - ShardingSphereSchema actual = new ShardingSphereSchema(Collections.emptyMap(), Collections.emptyMap()); + ShardingSphereSchema actual = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.emptyMap(), Collections.emptyMap()); ShardingSphereTable table = mock(ShardingSphereTable.class); actual.putTable("tbl", table); assertThat(actual.getTable("tbl"), is(table)); @@ -69,54 +72,56 @@ void assertPutTable() { @Test void assertRemoveTable() { - ShardingSphereSchema actual = new ShardingSphereSchema(Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.emptyMap()); + ShardingSphereSchema actual = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.emptyMap()); actual.removeTable("tbl"); assertNull(actual.getTable("tbl")); } @Test void assertContainsTable() { - assertTrue(new ShardingSphereSchema(Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.emptyMap()).containsTable("tbl")); + assertTrue(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", mock(ShardingSphereTable.class)), Collections.emptyMap()).containsTable("tbl")); } @Test void assertContainsColumn() { ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.singletonList( new ShardingSphereColumn("col", 0, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList()); - assertTrue(new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()).containsColumn("tbl", "col")); + assertTrue(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()).containsColumn("tbl", "col")); } @Test void assertGetAllColumnNamesWhenContainsKey() { ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.singletonList( new ShardingSphereColumn("col", 0, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList()); - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()).getAllColumnNames("tbl"), is(Collections.singletonList("col"))); + assertThat(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()).getAllColumnNames("tbl"), is(Collections.singletonList("col"))); } @Test void assertGetAllColumnNamesWhenNotContainsKey() { ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.singletonList( new ShardingSphereColumn("col", 0, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList()); - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl1", table), Collections.emptyMap()).getAllColumnNames("tbl2"), is(Collections.emptyList())); + assertThat(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl1", table), Collections.emptyMap()).getAllColumnNames("tbl2"), + is(Collections.emptyList())); } @Test void assertContainsIndex() { ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.emptyList(), Collections.singletonList(new ShardingSphereIndex("col_idx")), Collections.emptyList()); - assertTrue(new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()).containsIndex("tbl", "col_idx")); + assertTrue(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()).containsIndex("tbl", "col_idx")); } @Test void assertGetVisibleColumnNamesWhenContainsKey() { ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.singletonList( new ShardingSphereColumn("col", 0, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList()); - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()).getVisibleColumnNames("tbl"), is(Collections.singletonList("col"))); + assertThat(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()).getVisibleColumnNames("tbl"), + is(Collections.singletonList("col"))); } @Test void assertGetVisibleColumnNamesWhenNotContainsKey() { ShardingSphereTable table = new ShardingSphereTable("tbl", Collections.singletonList( new ShardingSphereColumn("col", 0, false, false, false, false, true, false)), Collections.emptyList(), Collections.emptyList()); - assertThat(new ShardingSphereSchema(Collections.singletonMap("tbl", table), Collections.emptyMap()).getVisibleColumnNames("tbl"), is(Collections.emptyList())); + assertThat(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tbl", table), Collections.emptyMap()).getVisibleColumnNames("tbl"), is(Collections.emptyList())); } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java index 3a49c73337657..de6f97a7ad0c9 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java @@ -91,7 +91,7 @@ void assertLoadAllTables() throws SQLException { when(MetaDataLoader.load(any())).thenReturn(createSchemaMetaDataMap(tableNames, material)); Map actual = GenericSchemaBuilder.build(tableNames, material); assertThat(actual.size(), is(1)); - assertTables(new ShardingSphereSchema(actual.values().iterator().next().getTables(), Collections.emptyMap()).getTables()); + assertTables(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, actual.values().iterator().next().getTables(), Collections.emptyMap()).getTables()); } private Map createSchemaMetaDataMap(final Collection tableNames, final GenericSchemaBuilderMaterial material) { diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/IndexMetaDataUtilsTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/IndexMetaDataUtilsTest.java index 0bdf9f0a48782..6ca840133e058 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/IndexMetaDataUtilsTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/IndexMetaDataUtilsTest.java @@ -92,7 +92,7 @@ void assertGetTableNames() { private ShardingSphereDatabase buildDatabase() { ShardingSphereTable table = new ShardingSphereTable(TABLE_NAME, Collections.emptyList(), Collections.singleton(new ShardingSphereIndex(INDEX_NAME)), Collections.emptyList()); Map tables = Collections.singletonMap(TABLE_NAME, table); - Map schemas = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new ShardingSphereSchema(tables, Collections.emptyMap())); + Map schemas = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap())); return new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ResourceMetaData.class), mock(RuleMetaData.class), schemas); } } diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java index 0c7fdcbe73011..f6dc10dbe970b 100644 --- a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java +++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java @@ -104,7 +104,7 @@ private Map buildDatabaseWithoutPrimaryKey() { new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)), Collections.emptySet(), Collections.emptyList())); tables.put("t_other", new ShardingSphereTable("t_other", Collections.singletonList( new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false)), Collections.emptySet(), Collections.emptyList())); - return Collections.singletonMap("name", new ShardingSphereSchema(tables, Collections.emptyMap())); + return Collections.singletonMap("name", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap())); } private Map buildDatabase() { @@ -119,6 +119,6 @@ private Map buildDatabase() { new ShardingSphereColumn("c_date", Types.TIMESTAMP, false, false, false, true, false, false)), Collections.emptySet(), Collections.emptyList())); tables.put("t_other", new ShardingSphereTable("t_other", Collections.singletonList( new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false, false)), Collections.emptySet(), Collections.emptyList())); - return Collections.singletonMap("name", new ShardingSphereSchema(tables, Collections.emptyMap())); + return Collections.singletonMap("name", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap())); } } diff --git a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java index 09ae021e0d7f5..02174b6ae9dd6 100644 --- a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java +++ b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.data.pipeline.cdc.util; import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -67,14 +68,14 @@ private ShardingSphereSchema mockedPublicSchema() { Map tables = new HashMap<>(2, 1F); tables.put("t_order", mock(ShardingSphereTable.class)); tables.put("t_order2", mock(ShardingSphereTable.class)); - return new ShardingSphereSchema(tables, Collections.emptyMap()); + return new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()); } private ShardingSphereSchema mockedTestSchema() { Map tables = new HashMap<>(2, 1F); tables.put("t_order_item", mock(ShardingSphereTable.class)); tables.put("t_order_item2", mock(ShardingSphereTable.class)); - return new ShardingSphereSchema(tables, Collections.emptyMap()); + return new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()); } @Test diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/database/DatabaseMetaDataPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/database/DatabaseMetaDataPersistService.java index ce39647d3bf35..1ebf6e0495a3c 100644 --- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/database/DatabaseMetaDataPersistService.java +++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/database/DatabaseMetaDataPersistService.java @@ -136,7 +136,7 @@ public Map loadSchemas(final String databaseName) Collection schemaNames = loadAllSchemaNames(databaseName); Map result = new LinkedHashMap<>(schemaNames.size(), 1F); schemaNames.forEach(each -> result.put(each.toLowerCase(), - new ShardingSphereSchema(tableMetaDataPersistService.load(databaseName, each), viewMetaDataPersistService.load(databaseName, each)))); + new ShardingSphereSchema(each, tableMetaDataPersistService.load(databaseName, each), viewMetaDataPersistService.load(databaseName, each)))); return result; } 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 585cf3eba0693..b014c9f9a101f 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 @@ -19,6 +19,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.exception.kernel.metadata.SchemaNotFoundException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -59,7 +60,7 @@ void assertValidate() { private ShardingSphereDatabase mockDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - ShardingSphereSchema schema = new ShardingSphereSchema(); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME); schema.putTable("foo_table", new ShardingSphereTable()); when(result.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", schema)); return result; diff --git a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/SQLStatementCompilerIT.java b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/SQLStatementCompilerIT.java index be105af3f96e4..ea98d7a4d471b 100644 --- a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/SQLStatementCompilerIT.java +++ b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/it/SQLStatementCompilerIT.java @@ -27,6 +27,7 @@ import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql2rel.SqlToRelConverter; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -81,7 +82,7 @@ void init() { tables.put("t_product_detail", createTProductDetailMetaData()); tables.put("multi_types_first", createMultiTypesFirstTableMetaData()); tables.put("multi_types_second", createMultiTypesSecondTableMetaData()); - sqlStatementCompiler = new SQLStatementCompiler(createSqlToRelConverter(new ShardingSphereSchema(tables, Collections.emptyMap()))); + sqlStatementCompiler = new SQLStatementCompiler(createSqlToRelConverter(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()))); } private ShardingSphereTable createOrderFederationTableMetaData() { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java index 13629a9957680..d861bdf34d5dd 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java @@ -191,7 +191,7 @@ public void reloadTable(final ShardingSphereDatabase database, final String sche } private void persistTable(final ShardingSphereDatabase database, final String schemaName, final String tableName, final GenericSchemaBuilderMaterial material) throws SQLException { - ShardingSphereSchema schema = GenericSchemaBuilder.build(Collections.singleton(tableName), material).getOrDefault(schemaName, new ShardingSphereSchema()); + ShardingSphereSchema schema = GenericSchemaBuilder.build(Collections.singleton(tableName), material).getOrDefault(schemaName, new ShardingSphereSchema(schemaName)); persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataService().getTableMetaDataPersistService() .persist(database.getName(), schemaName, Collections.singletonMap(tableName, schema.getTable(tableName))); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java index 665fc12296c52..cc2dd8684105d 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/DatabaseRuleConfigurationManager.java @@ -115,7 +115,7 @@ private void refreshMetadata(final String databaseName, final ShardingSphereData private Map buildShardingSphereSchemas(final ShardingSphereDatabase database) { Map result = new LinkedHashMap<>(database.getSchemas().size(), 1F); - database.getSchemas().forEach((key, value) -> result.put(key, new ShardingSphereSchema(value.getTables(), value.getViews()))); + database.getSchemas().forEach((key, value) -> result.put(key, new ShardingSphereSchema(key, value.getTables(), value.getViews()))); return result; } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java index 235949b76f922..17742956a7e14 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java @@ -90,7 +90,7 @@ public synchronized void addSchema(final String databaseName, final String schem if (database.containsSchema(schemaName)) { return; } - database.addSchema(schemaName, new ShardingSphereSchema()); + database.addSchema(schemaName, new ShardingSphereSchema(schemaName)); metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/StorageUnitManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/StorageUnitManager.java index c65ea02dbc2c6..7674a691e26b0 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/StorageUnitManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/StorageUnitManager.java @@ -122,7 +122,7 @@ private Map buildShardingSphereDatabase(final Sh private Map buildSchemas(final ShardingSphereDatabase originalDatabase) { Map result = new LinkedHashMap<>(originalDatabase.getSchemas().size(), 1F); originalDatabase.getSchemas().keySet().forEach(schemaName -> result.put(schemaName.toLowerCase(), - new ShardingSphereSchema(originalDatabase.getSchema(schemaName).getTables(), + new ShardingSphereSchema(schemaName, originalDatabase.getSchema(schemaName).getTables(), metaDataPersistService.getDatabaseMetaDataService().getViewMetaDataPersistService().load(originalDatabase.getName(), schemaName)))); return result; } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/AlterViewStatementSchemaRefresher.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/AlterViewStatementSchemaRefresher.java index e4983b3a2b1e8..bfc994501d993 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/AlterViewStatementSchemaRefresher.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/AlterViewStatementSchemaRefresher.java @@ -80,7 +80,7 @@ private ShardingSphereSchema getSchema(final ShardingSphereDatabase database, fi database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); Map schemaMap = GenericSchemaBuilder.build(Collections.singletonList(viewName), material); Optional actualViewMetaData = Optional.ofNullable(schemaMap.get(schemaName)).map(optional -> optional.getTable(viewName)); - ShardingSphereSchema result = new ShardingSphereSchema(); + ShardingSphereSchema result = new ShardingSphereSchema(schemaName); actualViewMetaData.ifPresent(optional -> result.putTable(viewName, optional)); result.putView(viewName, new ShardingSphereView(viewName, viewDefinition)); return result; diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index 8e5dc0ca4383e..530190f0851c8 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -111,7 +111,7 @@ private ShardingSphereDatabase mockDatabase() { when(ruleAttribute.findTableDataNode("foo_schema", "foo_tbl")).thenReturn(Optional.of(mock(DataNode.class))); when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule))); - when(result.getSchemas()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", new ShardingSphereSchema()))); + when(result.getSchemas()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME)))); StorageUnit storageUnit = mock(StorageUnit.class, RETURNS_DEEP_STUBS); when(storageUnit.getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(result.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("foo_ds", storageUnit)); @@ -221,7 +221,7 @@ void assertAlterSchemaForViewDropped() { private ShardingSphereSchema createToBeAlteredSchema() { ShardingSphereTable beforeChangedTable = new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); ShardingSphereView beforeChangedView = new ShardingSphereView("foo_tbl", ""); - return new ShardingSphereSchema(Collections.singletonMap("foo_tbl", beforeChangedTable), Collections.singletonMap("foo_view", beforeChangedView)); + return new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("foo_tbl", beforeChangedTable), Collections.singletonMap("foo_view", beforeChangedView)); } @Test diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriberTest.java index 20ffbeb1b9412..f9bbe6a6545ff 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriberTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.process.Process; import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; @@ -100,7 +101,7 @@ private ContextManagerBuilderParameter createContextManagerBuilderParameter() { } private Map createDatabases() { - when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema())); + when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME))); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL")); when(database.getSchema("foo_schema")).thenReturn(mock(ShardingSphereSchema.class)); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriberTest.java index 54a0c30bbde28..5de411f07858b 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriberTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; @@ -96,7 +97,7 @@ private ContextManagerBuilderParameter createContextManagerBuilderParameter() { } private Map createDatabases() { - when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema())); + when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME))); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(database.getSchema("foo_schema")).thenReturn(mock(ShardingSphereSchema.class)); when(database.getRuleMetaData().getRules()).thenReturn(new LinkedList<>()); diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ResourceMetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ResourceMetaDataChangedSubscriberTest.java index e102dd0a55323..a4ecf6b9a6aad 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ResourceMetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ResourceMetaDataChangedSubscriberTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; @@ -83,7 +84,7 @@ private ContextManagerBuilderParameter createContextManagerBuilderParameter() { private Map createDatabases() { when(database.getName()).thenReturn("db"); - when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema())); + when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME))); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(database.getSchema("foo_schema")).thenReturn(mock(ShardingSphereSchema.class)); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriberTest.java index 7bdd7454c2f71..b04cfe1020681 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriberTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; @@ -87,7 +88,7 @@ private ContextManagerBuilderParameter createContextManagerBuilderParameter() { } private Map createDatabases() { - when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema())); + when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME))); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(database.getSchema("foo_schema")).thenReturn(mock(ShardingSphereSchema.class)); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java index f6adfb2370ea7..00c8eb8f33784 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java @@ -94,7 +94,7 @@ public void dropDatabase(final String databaseName) { @Override public void createSchema(final String databaseName, final String schemaName) { - ShardingSphereSchema schema = new ShardingSphereSchema(); + ShardingSphereSchema schema = new ShardingSphereSchema(schemaName); ShardingSphereMetaData metaData = metaDataContextManager.getMetaDataContexts().get().getMetaData(); ShardingSphereDatabase database = metaData.getDatabase(databaseName); database.addSchema(schemaName, schema); @@ -162,7 +162,7 @@ private void addViewsToDataNode(final ShardingSphereDatabase database, final Str } private void removeSchemaMetaData(final ShardingSphereDatabase database, final String schemaName) { - ShardingSphereSchema schema = new ShardingSphereSchema(database.getSchema(schemaName).getTables(), database.getSchema(schemaName).getViews()); + ShardingSphereSchema schema = new ShardingSphereSchema(schemaName, database.getSchema(schemaName).getTables(), database.getSchema(schemaName).getViews()); database.dropSchema(schemaName); removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), Collections.singletonList(schemaName), schema.getAllTableNames()); } @@ -199,7 +199,7 @@ public void dropSchema(final String databaseName, final Collection schem ShardingSphereMetaData metaData = metaDataContextManager.getMetaDataContexts().get().getMetaData(); ShardingSphereDatabase database = metaData.getDatabase(databaseName); for (String each : schemaNames) { - ShardingSphereSchema schema = new ShardingSphereSchema(database.getSchema(each).getTables(), database.getSchema(each).getViews()); + ShardingSphereSchema schema = new ShardingSphereSchema(each, database.getSchema(each).getTables(), database.getSchema(each).getViews()); database.dropSchema(each); Optional.of(schema).ifPresent(optional -> tobeRemovedTables.addAll(optional.getAllTableNames())); tobeRemovedSchemas.add(each.toLowerCase()); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java index 975e985015ffc..542fa259fa31a 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandlerTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.distsql.statement.ral.queryable.export.ExportDatabaseConfigurationStatement; import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowTableMetaDataStatement; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException; @@ -91,7 +92,7 @@ void assertExecute() { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getName()).thenReturn("foo_db"); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); - when(database.getSchema("foo_db")).thenReturn(new ShardingSphereSchema(createTableMap(), Collections.emptyMap())); + when(database.getSchema("foo_db")).thenReturn(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, createTableMap(), Collections.emptyMap())); when(ProxyContext.getInstance().getContextManager().getDatabase("foo_db")).thenReturn(database); assertDoesNotThrow(() -> new DistSQLQueryBackendHandler(createSqlStatement(), mock(ConnectionSession.class, RETURNS_DEEP_STUBS)).execute()); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java index feeef85142dc5..ced5cdbd5f763 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable; import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowTableMetaDataStatement; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; @@ -77,7 +78,7 @@ private ShardingSphereDatabase mockDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(result.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(result.getName()).thenReturn("foo_db"); - when(result.getSchema("foo_db")).thenReturn(new ShardingSphereSchema(createTableMap(), Collections.emptyMap())); + when(result.getSchema("foo_db")).thenReturn(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, createTableMap(), Collections.emptyMap())); return result; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java index d87adca15e997..dc1868db9548e 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutorTest.java @@ -129,7 +129,7 @@ private ContextManager mockContextManager(final String feature) { .thenReturn(new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(), "MySQL")))); if (null != feature) { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(new ShardingSphereSchema(createTables(), Collections.emptyMap())); + when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, createTables(), Collections.emptyMap())); Map storageUnits = createStorageUnits(); when(database.getResourceMetaData().getStorageUnits()).thenReturn(storageUnits); when(result.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap(feature, database)); diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java index b89f6e499b898..d6b0330bda60f 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; import org.apache.shardingsphere.infra.merge.result.MergedResult; @@ -208,7 +209,7 @@ private Map getDatabases() { tables.put("t_account_bak", new ShardingSphereTable("t_account_bak", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); tables.put("t_account_detail", new ShardingSphereTable("t_account_detail", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); tables.put("t_test", new ShardingSphereTable("T_TEST", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); - ShardingSphereSchema schema = new ShardingSphereSchema(tables, Collections.emptyMap()); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getSchema(String.format(DATABASE_PATTERN, 0))).thenReturn(schema); when(database.isComplete()).thenReturn(true); diff --git a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java index 4b3b66c381708..210d89cb4e287 100644 --- a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java +++ b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; import org.apache.shardingsphere.infra.merge.result.MergedResult; @@ -135,7 +136,7 @@ private Map createShardingSphereDatabaseMap() { new ShardingSphereColumn("datacl", 2003, false, false, false, true, false, false), new ShardingSphereColumn("datfrozenxid64", 1111, false, false, false, true, false, false), new ShardingSphereColumn("datminmxid", 1111, false, false, false, true, false, false)); - ShardingSphereSchema schema = new ShardingSphereSchema( + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("pg_database", new ShardingSphereTable("pg_database", columns, Collections.emptyList(), Collections.emptyList())), Collections.emptyMap()); result.put("sharding_db", new ShardingSphereDatabase("sharding_db", TypedSPILoader.getService(DatabaseType.class, "openGauss"), mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), mock(RuleMetaData.class), Collections.singletonMap("pg_catalog", schema))); diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java index 7a725ac5d9c45..8ea7cd256703b 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java @@ -31,6 +31,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.exception.mysql.exception.TooManyPlaceholdersException; import org.apache.shardingsphere.infra.exception.mysql.exception.UnsupportedPreparedStatementException; @@ -231,7 +232,7 @@ private ContextManager mockContextManager() { ShardingSphereTable table = new ShardingSphereTable("user", Arrays.asList(new ShardingSphereColumn("id", Types.BIGINT, true, false, false, false, true, false), new ShardingSphereColumn("name", Types.VARCHAR, false, false, false, false, false, false), new ShardingSphereColumn("age", Types.SMALLINT, false, false, false, false, true, false)), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME); schema.getTables().put("user", table); ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "MySQL"), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), Collections.singletonMap("foo_db", schema)); diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractorTest.java index 06b93592c0702..e1dd447157162 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractorTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareParameterMarkerExtractorTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.proxy.frontend.mysql.command.query.binary.prepare; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -52,7 +53,7 @@ private ShardingSphereSchema prepareSchema() { table.putColumn(new ShardingSphereColumn("id", Types.BIGINT, true, false, false, false, true, false)); table.putColumn(new ShardingSphereColumn("name", Types.VARCHAR, false, false, false, false, false, false)); table.putColumn(new ShardingSphereColumn("age", Types.SMALLINT, false, false, false, false, true, false)); - ShardingSphereSchema result = new ShardingSphereSchema(); + ShardingSphereSchema result = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME); result.getTables().put("user", table); return result; } diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java index 4fb19b186d507..9eaf16fd942e5 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket; import org.apache.shardingsphere.db.protocol.packet.DatabasePacket; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; @@ -149,7 +150,7 @@ private MetaDataContexts mockMetaDataContexts() { when(result.getMetaData().getProps().getValue(ConfigurationPropertyKey.SQL_SHOW)).thenReturn(false); ShardingSphereTable table = new ShardingSphereTable("t", Arrays.asList(new ShardingSphereColumn("id", Types.BIGINT, true, false, false, false, true, false), new ShardingSphereColumn("v", Types.INTEGER, false, false, false, false, true, false)), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME); schema.getTables().put("t", table); ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "MySQL"), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), Collections.singletonMap("foo_db", schema)); diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java index 0a8be7ac66331..cb307da06d253 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVariableStatement; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; @@ -195,7 +196,7 @@ private ContextManager mockContextManager() { new ShardingSphereColumn("k", Types.VARCHAR, false, false, false, false, false, false), new ShardingSphereColumn("c", Types.VARCHAR, false, false, false, false, true, false), new ShardingSphereColumn("pad", Types.VARCHAR, false, false, false, false, true, false)), Collections.emptyList(), Collections.emptyList()); - ShardingSphereSchema schema = new ShardingSphereSchema(); + ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME); schema.getTables().put("t_test", testTable); schema.getTables().put("sbtest1", sbTestTable); ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"), diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java index f9d0d2898d34f..0577556d62055 100644 --- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java +++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.test.it.rewrite.engine.scenario; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; @@ -95,7 +96,7 @@ protected Map mockSchemas(final String schemaName) new ShardingSphereColumn("email", Types.VARCHAR, false, false, false, true, false, false), new ShardingSphereColumn("telephone", Types.VARCHAR, false, false, false, true, false, false), new ShardingSphereColumn("creation_date", Types.DATE, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList())); - ShardingSphereSchema result = new ShardingSphereSchema(tables, Collections.emptyMap()); + ShardingSphereSchema result = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()); return Collections.singletonMap(schemaName, result); } diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java index 78facc0d75bfd..c44576a09800a 100644 --- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java +++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/MixSQLRewriterIT.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.test.it.rewrite.engine.scenario; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -69,7 +70,7 @@ protected Map mockSchemas(final String schemaName) new ShardingSphereColumn("password", Types.VARCHAR, false, false, false, true, false, false), new ShardingSphereColumn("amount", Types.DECIMAL, false, false, false, true, false, false), new ShardingSphereColumn("status", Types.TINYINT, false, false, false, false, false, false)), Collections.emptyList(), Collections.emptyList())); - ShardingSphereSchema result = new ShardingSphereSchema(tables, Collections.emptyMap()); + ShardingSphereSchema result = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()); return Collections.singletonMap(schemaName, result); } diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java index 404f5ee96218a..f37d27596a92b 100644 --- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java +++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.test.it.rewrite.engine.scenario; +import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -100,7 +101,7 @@ protected Map mockSchemas(final String schemaName) tables.put("t_account_view", new ShardingSphereTable("t_account_view", Arrays.asList( new ShardingSphereColumn("id", Types.INTEGER, false, false, false, true, false, false), new ShardingSphereColumn("account_id", Types.INTEGER, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList())); - ShardingSphereSchema result = new ShardingSphereSchema(tables, Collections.emptyMap()); + ShardingSphereSchema result = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, tables, Collections.emptyMap()); return Collections.singletonMap(schemaName, result); }