From 7eabecf0f3b5c509b45df6ac2056dd0350e398cc Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 10 Dec 2024 19:12:22 +0800 Subject: [PATCH] Move GenericSchemaBuilderMaterial.protocolType to GenericSchemaBuilder (#33997) --- .../database/ShardingSphereDatabase.java | 4 ++-- .../schema/builder/GenericSchemaBuilder.java | 16 +++++++++------- .../builder/GenericSchemaBuilderMaterial.java | 3 --- .../schema/builder/GenericSchemaBuilderTest.java | 12 ++++++------ .../schema/util/SchemaMetaDataUtilsTest.java | 9 +++------ .../mode/manager/ContextManager.java | 11 +++++------ .../AlterTableStatementSchemaRefresher.java | 5 ++--- .../CreateTableStatementSchemaRefresher.java | 5 ++--- .../RenameTableStatementSchemaRefresher.java | 5 ++--- .../view/AlterViewStatementSchemaRefresher.java | 5 ++--- .../view/CreateViewStatementSchemaRefresher.java | 5 ++--- 11 files changed, 35 insertions(+), 45 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java index ba75ae4b37f64..7da9ea92999e9 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java @@ -102,8 +102,8 @@ public static ShardingSphereDatabase create(final String name, final DatabaseTyp final ConfigurationProperties props, final ComputeNodeInstanceContext computeNodeInstanceContext) throws SQLException { ResourceMetaData resourceMetaData = new ResourceMetaData(databaseConfig.getDataSources(), databaseConfig.getStorageUnits()); Collection databaseRules = DatabaseRulesBuilder.build(name, protocolType, databaseConfig, computeNodeInstanceContext, resourceMetaData); - Map schemas = new ConcurrentHashMap<>(GenericSchemaBuilder.build(new GenericSchemaBuilderMaterial( - protocolType, resourceMetaData.getStorageUnits(), databaseRules, props, new DatabaseTypeRegistry(protocolType).getDefaultSchemaName(name)))); + Map schemas = new ConcurrentHashMap<>(GenericSchemaBuilder.build(protocolType, + new GenericSchemaBuilderMaterial(resourceMetaData.getStorageUnits(), databaseRules, props, new DatabaseTypeRegistry(protocolType).getDefaultSchemaName(name)))); SystemSchemaBuilder.build(name, protocolType, props).forEach(schemas::putIfAbsent); return new ShardingSphereDatabase(name, protocolType, resourceMetaData, new RuleMetaData(databaseRules), schemas.values()); } 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 cc5751aa89c86..4d8fb929da563 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 @@ -61,26 +61,28 @@ public final class GenericSchemaBuilder { /** * Build generic schema. * + * @param protocolType database type * @param material generic schema builder material * @return generic schema map * @throws SQLException SQL exception */ - public static Map build(final GenericSchemaBuilderMaterial material) throws SQLException { - return build(getAllTableNames(material.getRules()), material); + public static Map build(final DatabaseType protocolType, final GenericSchemaBuilderMaterial material) throws SQLException { + return build(getAllTableNames(material.getRules()), protocolType, material); } /** * Build generic schema. * * @param tableNames table names + * @param protocolType database type * @param material generic schema builder material * @return generic schema map * @throws SQLException SQL exception */ - public static Map build(final Collection tableNames, final GenericSchemaBuilderMaterial material) throws SQLException { + public static Map build(final Collection tableNames, final DatabaseType protocolType, final GenericSchemaBuilderMaterial material) throws SQLException { Map result = loadSchemas(tableNames, material); - if (!isSameProtocolAndStorageTypes(material.getProtocolType(), material.getStorageUnits())) { - result = translate(result, material); + if (!isSameProtocolAndStorageTypes(protocolType, material.getStorageUnits())) { + result = translate(result, protocolType, material); } return revise(result, material); } @@ -103,13 +105,13 @@ private static boolean isSameProtocolAndStorageTypes(final DatabaseType protocol return storageUnits.values().stream().map(StorageUnit::getStorageType).allMatch(protocolType::equals); } - private static Map translate(final Map schemaMetaDataMap, final GenericSchemaBuilderMaterial material) { + private static Map translate(final Map schemaMetaDataMap, final DatabaseType protocolType, final GenericSchemaBuilderMaterial material) { Collection tableMetaDataList = new LinkedList<>(); for (StorageUnit each : material.getStorageUnits().values()) { String defaultSchemaName = new DatabaseTypeRegistry(each.getStorageType()).getDefaultSchemaName(material.getDefaultSchemaName()); tableMetaDataList.addAll(Optional.ofNullable(schemaMetaDataMap.get(defaultSchemaName)).map(SchemaMetaData::getTables).orElseGet(Collections::emptyList)); } - String frontendSchemaName = new DatabaseTypeRegistry(material.getProtocolType()).getDefaultSchemaName(material.getDefaultSchemaName()); + String frontendSchemaName = new DatabaseTypeRegistry(protocolType).getDefaultSchemaName(material.getDefaultSchemaName()); Map result = new LinkedHashMap<>(); result.put(frontendSchemaName, new SchemaMetaData(frontendSchemaName, tableMetaDataList)); return result; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java index f77db09a9c3f1..5cd5fa4919182 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderMaterial.java @@ -20,7 +20,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; @@ -34,8 +33,6 @@ @Getter public final class GenericSchemaBuilderMaterial { - private final DatabaseType protocolType; - private final Map storageUnits; private final Collection rules; 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 b09e2640086e7..bac7fc8b37b71 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 @@ -58,39 +58,39 @@ @StaticMockSettings(MetaDataLoader.class) class GenericSchemaBuilderTest { + private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); + private GenericSchemaBuilderMaterial material; @BeforeEach void setUp() { - DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); ShardingSphereRule rule = mock(ShardingSphereRule.class); when(rule.getAttributes()).thenReturn(new RuleAttributes(mock(TableMapperRuleAttribute.class))); StorageUnit storageUnit = mock(StorageUnit.class); when(storageUnit.getStorageType()).thenReturn(databaseType); when(storageUnit.getDataSource()).thenReturn(new MockedDataSource()); - material = new GenericSchemaBuilderMaterial( - databaseType, Collections.singletonMap("foo_schema", storageUnit), Collections.singleton(rule), new ConfigurationProperties(new Properties()), "foo_schema"); + material = new GenericSchemaBuilderMaterial(Collections.singletonMap("foo_schema", storageUnit), Collections.singleton(rule), new ConfigurationProperties(new Properties()), "foo_schema"); } @Test void assertLoadWithExistedTableName() throws SQLException { Collection tableNames = Collections.singletonList("data_node_routed_table1"); when(MetaDataLoader.load(any())).thenReturn(createSchemaMetaDataMap(tableNames, material)); - assertFalse(GenericSchemaBuilder.build(tableNames, material).get("foo_schema").getAllTables().isEmpty()); + assertFalse(GenericSchemaBuilder.build(tableNames, databaseType, material).get("foo_schema").getAllTables().isEmpty()); } @Test void assertLoadWithNotExistedTableName() throws SQLException { Collection tableNames = Collections.singletonList("invalid_table"); when(MetaDataLoader.load(any())).thenReturn(createSchemaMetaDataMap(tableNames, material)); - assertTrue(GenericSchemaBuilder.build(tableNames, material).get("foo_schema").getAllTables().isEmpty()); + assertTrue(GenericSchemaBuilder.build(tableNames, databaseType, material).get("foo_schema").getAllTables().isEmpty()); } @Test void assertLoadAllTables() throws SQLException { Collection tableNames = Arrays.asList("data_node_routed_table1", "data_node_routed_table2"); when(MetaDataLoader.load(any())).thenReturn(createSchemaMetaDataMap(tableNames, material)); - Map actual = GenericSchemaBuilder.build(tableNames, material); + Map actual = GenericSchemaBuilder.build(tableNames, databaseType, material); assertThat(actual.size(), is(1)); assertTables(new ShardingSphereSchema("foo_schema", actual.values().iterator().next().getAllTables(), Collections.emptyList())); } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java index 60877a908a503..63f64317c5a05 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java @@ -53,8 +53,7 @@ void assertGetSchemaMetaDataLoaderMaterialsWhenConfigCheckMetaDataEnable() { when(rule0.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); ShardingSphereRule rule1 = mock(ShardingSphereRule.class); when(rule1.getAttributes()).thenReturn(new RuleAttributes()); - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - mock(DatabaseType.class), mockStorageUnits(), Arrays.asList(rule0, rule1), mock(ConfigurationProperties.class), "sharding_db"); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(mockStorageUnits(), Arrays.asList(rule0, rule1), mock(ConfigurationProperties.class), "sharding_db"); Collection actual = SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_order"), material, true); assertThat(actual.size(), is(2)); Iterator iterator = actual.iterator(); @@ -74,8 +73,7 @@ void assertGetSchemaMetaDataLoaderMaterialsWhenNotConfigCheckMetaDataEnable() { when(rule0.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); ShardingSphereRule rule1 = mock(ShardingSphereRule.class); when(rule1.getAttributes()).thenReturn(new RuleAttributes()); - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - mock(DatabaseType.class), mockStorageUnits(), Arrays.asList(rule0, rule1), mock(ConfigurationProperties.class), "sharding_db"); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(mockStorageUnits(), Arrays.asList(rule0, rule1), mock(ConfigurationProperties.class), "sharding_db"); Collection actual = SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_order"), material, false); assertThat(actual.size(), is(1)); Iterator iterator = actual.iterator(); @@ -92,8 +90,7 @@ void assertGetSchemaMetaDataLoaderMaterialsWhenNotConfigCheckMetaDataEnableForSi when(rule0.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); ShardingSphereRule rule1 = mock(ShardingSphereRule.class); when(rule1.getAttributes()).thenReturn(new RuleAttributes()); - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - mock(DatabaseType.class), mockStorageUnits(), Arrays.asList(rule0, rule1), mock(ConfigurationProperties.class), "public"); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(mockStorageUnits(), Arrays.asList(rule0, rule1), mock(ConfigurationProperties.class), "public"); Collection actual = SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_single"), material, false); assertThat(actual.size(), is(1)); Iterator iterator = actual.iterator(); 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 dcd0c996fe7dd..5afaf40b62535 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 @@ -141,10 +141,9 @@ public void reloadSchema(final ShardingSphereDatabase database, final String sch private ShardingSphereSchema loadSchema(final ShardingSphereDatabase database, final String schemaName, final String dataSourceName) throws SQLException { database.reloadRules(); - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getProtocolType(), - Collections.singletonMap(dataSourceName, database.getResourceMetaData().getStorageUnits().get(dataSourceName)), + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(Collections.singletonMap(dataSourceName, database.getResourceMetaData().getStorageUnits().get(dataSourceName)), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); - ShardingSphereSchema result = GenericSchemaBuilder.build(material).get(schemaName); + ShardingSphereSchema result = GenericSchemaBuilder.build(database.getProtocolType(), material).get(schemaName); persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataFacade().getView().load(database.getName(), schemaName).forEach(result::putView); return result; } @@ -157,7 +156,7 @@ private ShardingSphereSchema loadSchema(final ShardingSphereDatabase database, f * @param tableName to be reloaded table name */ public void reloadTable(final ShardingSphereDatabase database, final String schemaName, final String tableName) { - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getProtocolType(), + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( database.getResourceMetaData().getStorageUnits(), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); try { persistTable(database, schemaName, tableName, material); @@ -176,7 +175,7 @@ public void reloadTable(final ShardingSphereDatabase database, final String sche */ public void reloadTable(final ShardingSphereDatabase database, final String schemaName, final String dataSourceName, final String tableName) { StorageUnit storageUnit = database.getResourceMetaData().getStorageUnits().get(dataSourceName); - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getProtocolType(), + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( Collections.singletonMap(dataSourceName, storageUnit), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); try { persistTable(database, schemaName, tableName, material); @@ -186,7 +185,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(schemaName)); + ShardingSphereSchema schema = GenericSchemaBuilder.build(Collections.singleton(tableName), database.getProtocolType(), material).getOrDefault(schemaName, new ShardingSphereSchema(schemaName)); persistServiceFacade.getMetaDataPersistService().getDatabaseMetaDataFacade().getTable().persist(database.getName(), schemaName, Collections.singleton(schema.getTable(tableName))); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/AlterTableStatementSchemaRefresher.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/AlterTableStatementSchemaRefresher.java index 299669ad48b08..d296cd3c67eb4 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/AlterTableStatementSchemaRefresher.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/AlterTableStatementSchemaRefresher.java @@ -65,9 +65,8 @@ private ShardingSphereTable getTable(final ShardingSphereDatabase database, fina if (TableRefreshUtils.isSingleTable(tableName, database)) { ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); - Map schemas = GenericSchemaBuilder.build(Collections.singletonList(tableName), material); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); + Map schemas = GenericSchemaBuilder.build(Collections.singletonList(tableName), database.getProtocolType(), material); return Optional.ofNullable(schemas.get(schemaName)).map(optional -> optional.getTable(tableName)) .orElseGet(() -> new ShardingSphereTable(tableName, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/CreateTableStatementSchemaRefresher.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/CreateTableStatementSchemaRefresher.java index d2f1201619e0d..2cf7f2d14c3de 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/CreateTableStatementSchemaRefresher.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/CreateTableStatementSchemaRefresher.java @@ -53,9 +53,8 @@ public void refresh(final MetaDataManagerPersistService metaDataManagerPersistSe if (isSingleTable) { ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); - Map schemas = GenericSchemaBuilder.build(Collections.singletonList(tableName), material); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); + Map schemas = GenericSchemaBuilder.build(Collections.singletonList(tableName), database.getProtocolType(), material); Optional actualTableMetaData = Optional.ofNullable(schemas.get(schemaName)).map(optional -> optional.getTable(tableName)); Preconditions.checkState(actualTableMetaData.isPresent(), "Load actual table metadata '%s' failed.", tableName); metaDataManagerPersistService.createTable(database.getName(), schemaName, actualTableMetaData.get(), logicDataSourceNames.isEmpty() ? null : logicDataSourceNames.iterator().next()); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/RenameTableStatementSchemaRefresher.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/RenameTableStatementSchemaRefresher.java index 9a9edd9d996b1..435143a41f228 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/RenameTableStatementSchemaRefresher.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/table/RenameTableStatementSchemaRefresher.java @@ -63,9 +63,8 @@ private ShardingSphereTable getTable(final ShardingSphereDatabase database, fina if (TableRefreshUtils.isSingleTable(tableName, database) && !logicDataSourceNames.isEmpty()) { ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); - Map schemas = GenericSchemaBuilder.build(Collections.singletonList(tableName), material); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); + Map schemas = GenericSchemaBuilder.build(Collections.singletonList(tableName), database.getProtocolType(), material); return Optional.ofNullable(schemas.get(schemaName)).map(optional -> optional.getTable(tableName)) .orElseGet(() -> new ShardingSphereTable(tableName, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); } 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 cfb2afae1b2c9..b1ffa59cedd1f 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 @@ -76,9 +76,8 @@ private ShardingSphereSchema getSchema(final ShardingSphereDatabase database, fi if (TableRefreshUtils.isSingleTable(viewName, database)) { ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); - Map schemas = GenericSchemaBuilder.build(Collections.singletonList(viewName), material); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); + Map schemas = GenericSchemaBuilder.build(Collections.singletonList(viewName), database.getProtocolType(), material); Optional actualViewMetaData = Optional.ofNullable(schemas.get(schemaName)).map(optional -> optional.getTable(viewName)); ShardingSphereSchema result = new ShardingSphereSchema(schemaName); actualViewMetaData.ifPresent(result::putTable); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/CreateViewStatementSchemaRefresher.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/CreateViewStatementSchemaRefresher.java index 7a1e89925326a..371cfc2daab63 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/CreateViewStatementSchemaRefresher.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/type/view/CreateViewStatementSchemaRefresher.java @@ -54,9 +54,8 @@ public void refresh(final MetaDataManagerPersistService metaDataManagerPersistSe if (TableRefreshUtils.isSingleTable(viewName, database)) { ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } - GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); - Map schemas = GenericSchemaBuilder.build(Collections.singletonList(viewName), material); + GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); + Map schemas = GenericSchemaBuilder.build(Collections.singletonList(viewName), database.getProtocolType(), material); Optional actualTableMetaData = Optional.ofNullable(schemas.get(schemaName)).map(optional -> optional.getTable(viewName)); Preconditions.checkState(actualTableMetaData.isPresent(), "Load actual view metadata '%s' failed.", viewName); AlterSchemaMetaDataPOJO alterSchemaMetaDataPOJO = new AlterSchemaMetaDataPOJO(database.getName(), schemaName, logicDataSourceNames);