diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java index bb59d70b0720d..03dbaa9e6c08e 100644 --- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java +++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporter.java @@ -53,6 +53,6 @@ public Optional export(final String pluginTyp } private int getStorageUnitCount(final MetaDataContexts metaDataContexts) { - return metaDataContexts.getMetaData().getDatabases().values().stream().map(each -> each.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size()).reduce(0, Integer::sum); + return metaDataContexts.getMetaData().getDatabases().values().stream().map(each -> each.getResourceMetaData().getStorageUnitMetaDataMap().size()).reduce(0, Integer::sum); } } diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java index fc33163d59747..7259baae89f39 100644 --- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java +++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/proxy/ProxyMetaDataInfoExporterTest.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -75,7 +75,7 @@ void assertExportWithContextManager() { private ContextManager mockContextManager() { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", mock(NewStorageUnitMetaData.class))); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", mock(StorageUnitMetaData.class))); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); when(metaData.getDatabases()).thenReturn(Collections.singletonMap("sharding_db", database)); diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java index bcb0f68f0bf8e..6fe3a232bc256 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java @@ -114,7 +114,7 @@ private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement sqlStat } private void checkDataSources(final ShardingSphereDatabase database) { - ShardingSpherePreconditions.checkState(!database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().isEmpty(), () -> new EmptyStorageUnitException(database.getName())); + ShardingSpherePreconditions.checkState(!database.getResourceMetaData().getStorageUnitMetaDataMap().isEmpty(), () -> new EmptyStorageUnitException(database.getName())); } @Override diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java index 16db29ea71662..f9a6d9a19987d 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java @@ -126,8 +126,8 @@ private static Collection getDuplicated(final Collection require private static void checkDuplicateRuleNamesWithExistsDataSources(final ShardingSphereDatabase database, final Collection segments) { Collection currentRuleNames = new HashSet<>(); ResourceMetaData resourceMetaData = database.getResourceMetaData(); - if (null != resourceMetaData && null != resourceMetaData.getStorageUnitMetaData().getMetaDataMap()) { - currentRuleNames.addAll(resourceMetaData.getStorageUnitMetaData().getMetaDataMap().keySet()); + if (null != resourceMetaData && null != resourceMetaData.getStorageUnitMetaDataMap()) { + currentRuleNames.addAll(resourceMetaData.getStorageUnitMetaDataMap().keySet()); } currentRuleNames.addAll(getLogicDataSources(database)); Collection toBeCreatedRuleNames = segments.stream().map(ReadwriteSplittingRuleSegment::getName).filter(currentRuleNames::contains).collect(Collectors.toList()); diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java index 7d4943e637916..4553a485022f7 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java @@ -23,7 +23,6 @@ import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; @@ -68,19 +67,18 @@ class CreateReadwriteSplittingRuleStatementUpdaterTest { @BeforeEach void before() { when(database.getResourceMetaData()).thenReturn(resourceMetaData); - when(resourceMetaData.getStorageUnitMetaData()).thenReturn(mock(StorageUnitMetaData.class)); when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.emptyList()); } @Test void assertCheckSQLStatementWithDuplicateRuleNames() { - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.emptyMap()); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.emptyMap()); assertThrows(DuplicateRuleException.class, () -> updater.checkSQLStatement(database, createSQLStatement("TEST"), createCurrentRuleConfiguration())); } @Test void assertCheckSQLStatementWithDuplicateResource() { - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("write_ds", null)); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("write_ds", null)); assertThrows(InvalidRuleConfigurationException.class, () -> updater.checkSQLStatement(database, createSQLStatement("write_ds", "TEST"), createCurrentRuleConfiguration())); } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java index 7c1639db66d35..c2f721e6a4b2a 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereRowData; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData; @@ -81,13 +81,13 @@ private void collectForShardingStatisticTable(final ShardingSphereDatabase datab row.add(each.getLogicTable()); row.add(dataNode.getDataSourceName()); row.add(dataNode.getTableName()); - addTableRowsAndDataLength(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(), dataNode, row); + addTableRowsAndDataLength(database.getResourceMetaData().getStorageUnitMetaDataMap(), dataNode, row); tableData.getRows().add(new ShardingSphereRowData(row)); } } } - private void addTableRowsAndDataLength(final Map metaDataMap, final DataNode dataNode, final List row) throws SQLException { + private void addTableRowsAndDataLength(final Map metaDataMap, final DataNode dataNode, final List row) throws SQLException { DatabaseType databaseType = metaDataMap.get(dataNode.getDataSourceName()).getStorageUnit().getStorageType(); Optional dialectCollector = DatabaseTypedSPILoader.findService(DialectShardingStatisticsTableCollector.class, databaseType); boolean isAppended = false; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java index 6fe38c9890c41..14d73a978936c 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java @@ -113,6 +113,6 @@ private void closeResources(final ShardingSphereDatabase database) { database.getRuleMetaData().findRules(ResourceHeldRule.class).forEach(each -> each.closeStaleResource(databaseName)); database.getRuleMetaData().findSingleRule(StaticDataSourceContainedRule.class).ifPresent(StaticDataSourceContainedRule::cleanStorageNodeDataSources); Optional.ofNullable(database.getResourceMetaData()) - .ifPresent(optional -> optional.getStorageUnitMetaData().getMetaDataMap().values().forEach(each -> new DataSourcePoolDestroyer(each.getDataSource()).asyncDestroy())); + .ifPresent(optional -> optional.getStorageUnitMetaDataMap().values().forEach(each -> new DataSourcePoolDestroyer(each.getDataSource()).asyncDestroy())); } } 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 b98d04ca9bd1b..e455374b4d08f 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 @@ -175,7 +175,7 @@ public void dropSchema(final String schemaName) { * @return is completed or not */ public boolean isComplete() { - return !ruleMetaData.getRules().isEmpty() && !resourceMetaData.getStorageUnitMetaData().getMetaDataMap().isEmpty(); + return !ruleMetaData.getRules().isEmpty() && !resourceMetaData.getStorageUnitMetaDataMap().isEmpty(); } /** @@ -184,7 +184,7 @@ public boolean isComplete() { * @return contains data source or not */ public boolean containsDataSource() { - return !resourceMetaData.getStorageUnitMetaData().getMetaDataMap().isEmpty(); + return !resourceMetaData.getStorageUnitMetaDataMap().isEmpty(); } /** @@ -198,7 +198,7 @@ public synchronized void reloadRules(final Class r Collection databaseRules = new LinkedList<>(ruleMetaData.getRules()); toBeReloadedRules.stream().findFirst().ifPresent(optional -> { databaseRules.removeAll(toBeReloadedRules); - Map dataSources = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map dataSources = resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); databaseRules.add(((MutableDataNodeRule) optional).reloadRule(ruleConfig, name, dataSources, databaseRules)); }); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java index 49ef85f8f46e9..63aa082230ac0 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java @@ -20,6 +20,7 @@ import lombok.Getter; import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource; import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; @@ -44,20 +45,34 @@ public final class ResourceMetaData { private final Map dataSources; - private final StorageUnitMetaData storageUnitMetaData; + private final Map storageUnitMetaDataMap; public ResourceMetaData(final Map dataSources) { this.dataSources = StorageNodeUtils.getStorageNodeDataSources(dataSources); - storageUnitMetaData = new StorageUnitMetaData(null, StorageUnitNodeMapUtils.fromDataSources(dataSources), - dataSources.entrySet().stream().collect( - Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), - this.dataSources); + Map storageNodes = StorageUnitNodeMapUtils.fromDataSources(dataSources); + Map dataSourcePoolPropertiesMap = dataSources.entrySet().stream().collect( + Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); + storageUnitMetaDataMap = new LinkedHashMap<>(); + for (Entry entry : storageNodes.entrySet()) { + DataSource dataSource = dataSources.get(entry.getValue().getName().getName()); + if (!(dataSource instanceof CatalogSwitchableDataSource)) { + dataSource = new CatalogSwitchableDataSource(dataSource, entry.getValue().getCatalog(), entry.getValue().getUrl()); + } + storageUnitMetaDataMap.put(entry.getKey(), new StorageUnitMetaData(null, entry.getValue(), dataSourcePoolPropertiesMap.get(entry.getKey()), dataSource)); + } } public ResourceMetaData(final String databaseName, final Map dataSources, - final Map storageUnitNodeMap, final Map propsMap) { + final Map storageNodes, final Map propsMap) { this.dataSources = dataSources; - storageUnitMetaData = new StorageUnitMetaData(databaseName, storageUnitNodeMap, propsMap, dataSources); + storageUnitMetaDataMap = new LinkedHashMap<>(); + for (Entry entry : storageNodes.entrySet()) { + DataSource dataSource = dataSources.get(entry.getValue().getName()); + if (!(dataSource instanceof CatalogSwitchableDataSource)) { + dataSource = new CatalogSwitchableDataSource(dataSource, entry.getValue().getCatalog(), entry.getValue().getUrl()); + } + storageUnitMetaDataMap.put(entry.getKey(), new StorageUnitMetaData(databaseName, entry.getValue(), propsMap.get(entry.getKey()), dataSource)); + } } /** @@ -67,7 +82,7 @@ public ResourceMetaData(final String databaseName, final Map getAllInstanceDataSourceNames() { Collection result = new LinkedList<>(); - for (String each : storageUnitMetaData.getMetaDataMap().keySet()) { + for (String each : storageUnitMetaDataMap.keySet()) { if (!isExisted(each, result)) { result.add(each); } @@ -76,8 +91,8 @@ public Collection getAllInstanceDataSourceNames() { } private boolean isExisted(final String dataSourceName, final Collection existedDataSourceNames) { - return existedDataSourceNames.stream().anyMatch(each -> storageUnitMetaData.getMetaDataMap().get(dataSourceName).getStorageUnit().getConnectionProperties() - .isInSameDatabaseInstance(storageUnitMetaData.getMetaDataMap().get(each).getStorageUnit().getConnectionProperties())); + return existedDataSourceNames.stream().anyMatch(each -> storageUnitMetaDataMap.get(dataSourceName).getStorageUnit().getConnectionProperties() + .isInSameDatabaseInstance(storageUnitMetaDataMap.get(each).getStorageUnit().getConnectionProperties())); } /** @@ -87,7 +102,7 @@ private boolean isExisted(final String dataSourceName, final Collection * @return connection properties */ public ConnectionProperties getConnectionProperties(final String dataSourceName) { - return storageUnitMetaData.getMetaDataMap().get(dataSourceName).getStorageUnit().getConnectionProperties(); + return storageUnitMetaDataMap.get(dataSourceName).getStorageUnit().getConnectionProperties(); } /** @@ -97,7 +112,7 @@ public ConnectionProperties getConnectionProperties(final String dataSourceName) * @return storage type */ public DatabaseType getStorageType(final String dataSourceName) { - return storageUnitMetaData.getMetaDataMap().get(dataSourceName).getStorageUnit().getStorageType(); + return storageUnitMetaDataMap.get(dataSourceName).getStorageUnit().getStorageType(); } /** @@ -107,6 +122,6 @@ public DatabaseType getStorageType(final String dataSourceName) { * @return not existed resource names */ public Collection getNotExistedDataSources(final Collection resourceNames) { - return resourceNames.stream().filter(each -> !storageUnitMetaData.getMetaDataMap().containsKey(each)).collect(Collectors.toSet()); + return resourceNames.stream().filter(each -> !storageUnitMetaDataMap.containsKey(each)).collect(Collectors.toSet()); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/NewStorageUnitMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/NewStorageUnitMetaData.java deleted file mode 100644 index a9ea079772d4d..0000000000000 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/NewStorageUnitMetaData.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.infra.metadata.database.resource.unit; - -import lombok.Getter; -import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; - -import javax.sql.DataSource; - -/** - * Storage unit meta data. - */ -@Getter -public final class NewStorageUnitMetaData { - - private final StorageNode storageNode; - - private final DataSourcePoolProperties dataSourcePoolProperties; - - private final DataSource dataSource; - - private final StorageUnit storageUnit; - - public NewStorageUnitMetaData(final String databaseName, final StorageNode storageNode, final DataSourcePoolProperties dataSourcePoolProperties, final DataSource dataSource) { - this.storageNode = storageNode; - this.dataSourcePoolProperties = dataSourcePoolProperties; - this.dataSource = dataSource; - storageUnit = new StorageUnit(databaseName, dataSource, dataSourcePoolProperties, storageNode); - } -} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java index f94b9468f128c..093fe10dea56b 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java @@ -18,15 +18,10 @@ package org.apache.shardingsphere.infra.metadata.database.resource.unit; import lombok.Getter; -import org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import javax.sql.DataSource; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; /** * Storage unit meta data. @@ -34,17 +29,18 @@ @Getter public final class StorageUnitMetaData { - private final Map metaDataMap; + private final StorageNode storageNode; - public StorageUnitMetaData(final String databaseName, final Map storageNodes, final Map dataSourcePoolPropertiesMap, - final Map dataSources) { - metaDataMap = new LinkedHashMap<>(); - for (Entry entry : storageNodes.entrySet()) { - DataSource dataSource = dataSources.get(entry.getValue().getName()); - if (!(dataSource instanceof CatalogSwitchableDataSource)) { - dataSource = new CatalogSwitchableDataSource(dataSource, entry.getValue().getCatalog(), entry.getValue().getUrl()); - } - metaDataMap.put(entry.getKey(), new NewStorageUnitMetaData(databaseName, entry.getValue(), dataSourcePoolPropertiesMap.get(entry.getKey()), dataSource)); - } + private final DataSourcePoolProperties dataSourcePoolProperties; + + private final DataSource dataSource; + + private final StorageUnit storageUnit; + + public StorageUnitMetaData(final String databaseName, final StorageNode storageNode, final DataSourcePoolProperties dataSourcePoolProperties, final DataSource dataSource) { + this.storageNode = storageNode; + this.dataSourcePoolProperties = dataSourcePoolProperties; + this.dataSource = dataSource; + storageUnit = new StorageUnit(databaseName, dataSource, dataSourcePoolProperties, storageNode); } } 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 b10c21987f065..d9e15379dbfda 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 @@ -50,11 +50,11 @@ public final class GenericSchemaBuilderMaterial { private final String defaultSchemaName; - public GenericSchemaBuilderMaterial(final DatabaseType protocolType, final StorageUnitMetaData storageUnitMetaData, + public GenericSchemaBuilderMaterial(final DatabaseType protocolType, final Map storageUnitMetaDataMap, final Collection rules, final ConfigurationProperties props, final String defaultSchemaName) { - this(protocolType, storageUnitMetaData.getMetaDataMap().entrySet().stream() + this(protocolType, storageUnitMetaDataMap.entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageUnit().getStorageType(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), - storageUnitMetaData.getMetaDataMap().entrySet().stream() + storageUnitMetaDataMap.entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), rules, props, defaultSchemaName); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereTableDataCollectorUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereTableDataCollectorUtils.java index 037b5583d1eb7..3ce1aada78a27 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereTableDataCollectorUtils.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/ShardingSphereTableDataCollectorUtils.java @@ -20,7 +20,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereRowData; @@ -57,7 +57,7 @@ public static Collection collectRowData(final ShardingSph return Collections.emptyList(); } Collection result = new LinkedList<>(); - for (NewStorageUnitMetaData each : database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().values()) { + for (StorageUnitMetaData each : database.getResourceMetaData().getStorageUnitMetaDataMap().values()) { try ( Connection connection = each.getDataSource().getConnection(); Statement statement = connection.createStatement(); @@ -69,7 +69,7 @@ public static Collection collectRowData(final ShardingSph } private static boolean isDifferentProtocolAndStorageType(final ShardingSphereDatabase database) { - return !database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().values().stream().allMatch(each -> each.getStorageUnit().getStorageType().equals(database.getProtocolType())); + return !database.getResourceMetaData().getStorageUnitMetaDataMap().values().stream().allMatch(each -> each.getStorageUnit().getStorageType().equals(database.getProtocolType())); } private static Collection getRows(final ShardingSphereTable table, final Collection selectedColumnNames, final ResultSet resultSet) throws SQLException { diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java index 4aa84ca8dbf60..e604ce6411b6e 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.ResourceHeldRule; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; @@ -90,8 +90,8 @@ private ShardingSphereDatabase mockDatabase(final ResourceMetaData resourceMetaD ShardingSphereDatabase result = mock(ShardingSphereDatabase.class); when(result.getName()).thenReturn("foo_db"); when(result.getResourceMetaData()).thenReturn(resourceMetaData); - NewStorageUnitMetaData storageUnitMetaData = new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), dataSource); - when(result.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_db", storageUnitMetaData)); + StorageUnitMetaData storageUnitMetaData = new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), dataSource); + when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_db", storageUnitMetaData)); when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(databaseResourceHeldRule))); return result; } diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java index 97bdfe8fc5930..4b2e1a7084b40 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java @@ -66,7 +66,7 @@ private ShardingSphereTable getTable(final ShardingSphereDatabase database, fina ruleMetaData.findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaData(), ruleMetaData.getRules(), props, schemaName); + database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaDataMap(), ruleMetaData.getRules(), props, schemaName); Map schemaMap = GenericSchemaBuilder.build(Collections.singletonList(tableName), material); return Optional.ofNullable(schemaMap.get(schemaName)).map(optional -> optional.getTable(tableName)) .orElseGet(() -> new ShardingSphereTable(tableName, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java index 0b49b2c319fd5..e84b26814b8e6 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java @@ -54,7 +54,7 @@ public void refresh(final ModeContextManager modeContextManager, final ShardingS ruleMetaData.findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaData(), ruleMetaData.getRules(), props, schemaName); + database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaDataMap(), ruleMetaData.getRules(), props, schemaName); Map schemaMap = GenericSchemaBuilder.build(Collections.singletonList(tableName), material); Optional actualTableMetaData = Optional.ofNullable(schemaMap.get(schemaName)).map(optional -> optional.getTable(tableName)); if (actualTableMetaData.isPresent()) { diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java index 3122b4ed5c2b7..ec23c813acaf9 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java @@ -64,7 +64,7 @@ private ShardingSphereTable getTable(final ShardingSphereDatabase database, fina ruleMetaData.findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaData(), ruleMetaData.getRules(), props, schemaName); + database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaDataMap(), ruleMetaData.getRules(), props, schemaName); Map schemaMap = GenericSchemaBuilder.build(Collections.singletonList(tableName), material); return Optional.ofNullable(schemaMap.get(schemaName)).map(optional -> optional.getTable(tableName)) .orElseGet(() -> new ShardingSphereTable(tableName, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java index e8d242841069d..c98fd1d3cce38 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java @@ -78,7 +78,7 @@ private ShardingSphereSchema getSchema(final ShardingSphereDatabase database, fi ruleMetaData.findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaData(), ruleMetaData.getRules(), props, schemaName); + database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaDataMap(), 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(); diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java index aa1cb7dbab30c..2f0d38bfba12b 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java @@ -54,7 +54,7 @@ public void refresh(final ModeContextManager modeContextManager, final ShardingS ruleMetaData.findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( - database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaData(), ruleMetaData.getRules(), props, schemaName); + database.getProtocolType(), database.getResourceMetaData().getStorageUnitMetaDataMap(), ruleMetaData.getRules(), props, schemaName); Map schemaMap = GenericSchemaBuilder.build(Collections.singletonList(viewName), material); Optional actualTableMetaData = Optional.ofNullable(schemaMap.get(schemaName)).map(optional -> optional.getTable(viewName)); if (actualTableMetaData.isPresent()) { diff --git a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java index 3364a65077a7a..e5dd1400c5eec 100644 --- a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java +++ b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java @@ -54,7 +54,7 @@ void assertGenerateExecutionContext() { when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SelectStatement.class)); QueryContext queryContext = new QueryContext(sqlStatementContext, "SELECT * FROM tbl", Collections.emptyList()); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.emptyMap()); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.emptyMap()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), resourceMetaData, new RuleMetaData(mockShardingSphereRule()), Collections.emptyMap()); ConfigurationProperties props = new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString()))); diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java index 8e607ca3bb175..ce4a9e3b9a038 100644 --- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java +++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java @@ -55,17 +55,17 @@ public final class DriverExecutionPrepareEngine @SuppressWarnings("rawtypes") private final SQLExecutionUnitBuilder sqlExecutionUnitBuilder; - private final StorageUnitMetaData storageUnitMetaData; + private final Map storageUnitMetaDataMap; public DriverExecutionPrepareEngine(final String type, final int maxConnectionsSizePerQuery, final DatabaseConnectionManager databaseConnectionManager, final ExecutorStatementManager statementManager, final StorageResourceOption option, final Collection rules, - final StorageUnitMetaData storageUnitMetaData) { + final Map storageUnitMetaDataMap) { super(maxConnectionsSizePerQuery, rules); this.databaseConnectionManager = databaseConnectionManager; this.statementManager = statementManager; this.option = option; sqlExecutionUnitBuilder = getCachedSqlExecutionUnitBuilder(type); - this.storageUnitMetaData = storageUnitMetaData; + this.storageUnitMetaDataMap = storageUnitMetaDataMap; } /** @@ -97,7 +97,7 @@ protected List> group(final String dataSourceName, final int c @SuppressWarnings("unchecked") private ExecutionGroup createExecutionGroup(final String dataSourceName, final List sqlUnits, final C connection, final ConnectionMode connectionMode) throws SQLException { List inputs = new LinkedList<>(); - DatabaseType databaseType = storageUnitMetaData.getMetaDataMap().get(dataSourceName).getStorageUnit().getStorageType(); + DatabaseType databaseType = storageUnitMetaDataMap.get(dataSourceName).getStorageUnit().getStorageType(); for (SQLUnit each : sqlUnits) { inputs.add((T) sqlExecutionUnitBuilder.build(new ExecutionUnit(dataSourceName, each), statementManager, connection, connectionMode, option, databaseType)); } diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java index 0381bdf236174..22c1f74610919 100644 --- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java +++ b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator; @@ -77,7 +77,7 @@ public SQLRewriteResult rewrite(final String sql, final List params, fin SQLRewriteContext sqlRewriteContext = createSQLRewriteContext(sql, params, sqlStatementContext, routeContext, connectionContext, hintValueContext); SQLTranslatorRule rule = globalRuleMetaData.getSingleRule(SQLTranslatorRule.class); DatabaseType protocolType = database.getProtocolType(); - Map storageUnitMetaDataMap = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(); + Map storageUnitMetaDataMap = database.getResourceMetaData().getStorageUnitMetaDataMap(); return routeContext.getRouteUnits().isEmpty() ? new GenericSQLRewriteEngine(rule, protocolType, storageUnitMetaDataMap).rewrite(sqlRewriteContext) : new RouteSQLRewriteEngine(rule, protocolType, storageUnitMetaDataMap).rewrite(sqlRewriteContext, routeContext); diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngine.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngine.java index fed6844ab0908..992552ae630be 100644 --- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngine.java +++ b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngine.java @@ -19,7 +19,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext; import org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult; import org.apache.shardingsphere.infra.rewrite.engine.result.SQLRewriteUnit; @@ -38,7 +38,7 @@ public final class GenericSQLRewriteEngine { private final DatabaseType protocolType; - private final Map storageUnitMetaDataMap; + private final Map storageUnitMetaDataMap; /** * Rewrite SQL and parameters. diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngine.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngine.java index 2f74bd8543787..7fbe66c41f686 100644 --- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngine.java +++ b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngine.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext; import org.apache.shardingsphere.infra.rewrite.engine.result.RouteSQLRewriteResult; import org.apache.shardingsphere.infra.rewrite.engine.result.SQLRewriteUnit; @@ -54,7 +54,7 @@ public final class RouteSQLRewriteEngine { private final DatabaseType protocolType; - private final Map storageUnitMetaDataMap; + private final Map storageUnitMetaDataMap; /** * Rewrite SQL and parameters. diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java index 0e40c97e1d0c8..eab21840bc6ee 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -88,15 +88,15 @@ private ResourceMetaData mockResourceMetaData() { when(storageUnit1.getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "H2")); StorageUnit storageUnit2 = mock(StorageUnit.class); when(storageUnit2.getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL")); - Map metaDataMap = new LinkedHashMap<>(2, 1F); - NewStorageUnitMetaData storageUnitMetaData1 = mock(NewStorageUnitMetaData.class); + Map metaDataMap = new LinkedHashMap<>(2, 1F); + StorageUnitMetaData storageUnitMetaData1 = mock(StorageUnitMetaData.class); when(storageUnitMetaData1.getStorageUnit()).thenReturn(storageUnit1); - NewStorageUnitMetaData storageUnitMetaData2 = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData2 = mock(StorageUnitMetaData.class); when(storageUnitMetaData2.getStorageUnit()).thenReturn(storageUnit2); metaDataMap.put("ds_0", storageUnitMetaData1); metaDataMap.put("ds_1", storageUnitMetaData2); ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - when(result.getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + when(result.getStorageUnitMetaDataMap()).thenReturn(metaDataMap); return result; } } diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java index 5eede96db7390..1aab869aca0f8 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext; import org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult; @@ -63,8 +63,8 @@ void assertRewriteStorageTypeIsEmpty() { assertThat(actual.getSqlRewriteUnit().getParameters(), is(Collections.emptyList())); } - private Map mockStorageUnitMetaData(final DatabaseType databaseType) { - NewStorageUnitMetaData result = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + private Map mockStorageUnitMetaData(final DatabaseType databaseType) { + StorageUnitMetaData result = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(result.getStorageUnit().getStorageType()).thenReturn(databaseType); return Collections.singletonMap("ds_0", result); } diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java index d442e855a7136..765d82ac50ff2 100644 --- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java +++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext; import org.apache.shardingsphere.infra.rewrite.engine.result.RouteSQLRewriteResult; @@ -176,8 +176,8 @@ private ShardingSphereDatabase mockDatabase() { return result; } - private Map mockStorageUnitMetaData(final DatabaseType databaseType) { - NewStorageUnitMetaData result = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + private Map mockStorageUnitMetaData(final DatabaseType databaseType) { + StorageUnitMetaData result = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(result.getStorageUnit().getStorageType()).thenReturn(databaseType); return Collections.singletonMap("ds_0", result); } diff --git a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java index 72979865f6783..e39af52082efd 100644 --- a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java +++ b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java @@ -36,7 +36,7 @@ public final class AllSQLRouteExecutor implements SQLRouteExecutor { @Override public RouteContext route(final ConnectionContext connectionContext, final QueryContext queryContext, final RuleMetaData globalRuleMetaData, final ShardingSphereDatabase database) { RouteContext result = new RouteContext(); - for (String each : database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().keySet()) { + for (String each : database.getResourceMetaData().getStorageUnitMetaDataMap().keySet()) { result.getRouteUnits().add(new RouteUnit(new RouteMapper(each, each), Collections.emptyList())); } return result; diff --git a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java index 2ea31c3580c11..b4c5a4a75c697 100644 --- a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java +++ b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.hint.SQLHintDataSourceNotExistsException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.route.SQLRouter; import org.apache.shardingsphere.infra.route.context.RouteContext; @@ -59,7 +59,7 @@ public PartialSQLRouteExecutor(final Collection rules, final @SuppressWarnings({"unchecked", "rawtypes"}) public RouteContext route(final ConnectionContext connectionContext, final QueryContext queryContext, final RuleMetaData globalRuleMetaData, final ShardingSphereDatabase database) { RouteContext result = new RouteContext(); - Optional dataSourceName = findDataSourceByHint(queryContext.getHintValueContext(), database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()); + Optional dataSourceName = findDataSourceByHint(queryContext.getHintValueContext(), database.getResourceMetaData().getStorageUnitMetaDataMap()); if (dataSourceName.isPresent()) { result.getRouteUnits().add(new RouteUnit(new RouteMapper(dataSourceName.get(), dataSourceName.get()), Collections.emptyList())); return result; @@ -71,14 +71,14 @@ public RouteContext route(final ConnectionContext connectionContext, final Query entry.getValue().decorateRouteContext(result, queryContext, database, entry.getKey(), props, connectionContext); } } - if (result.getRouteUnits().isEmpty() && 1 == database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size()) { - String singleDataSourceName = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().keySet().iterator().next(); + if (result.getRouteUnits().isEmpty() && 1 == database.getResourceMetaData().getStorageUnitMetaDataMap().size()) { + String singleDataSourceName = database.getResourceMetaData().getStorageUnitMetaDataMap().keySet().iterator().next(); result.getRouteUnits().add(new RouteUnit(new RouteMapper(singleDataSourceName, singleDataSourceName), Collections.emptyList())); } return result; } - private Optional findDataSourceByHint(final HintValueContext hintValueContext, final Map metaDataMap) { + private Optional findDataSourceByHint(final HintValueContext hintValueContext, final Map metaDataMap) { Optional result = HintManager.isInstantiated() && HintManager.getDataSourceName().isPresent() ? HintManager.getDataSourceName() : hintValueContext.findHintDataSourceName(); if (result.isPresent() && !metaDataMap.containsKey(result.get())) { throw new SQLHintDataSourceNotExistsException(result.get()); diff --git a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java index e5743ab64323e..46ef9aa72eb3a 100644 --- a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java +++ b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java @@ -42,7 +42,7 @@ class AllSQLRouteExecutorTest { void assertRouteSuccess() { String name = "test"; ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().keySet()).thenReturn(Stream.of(name).collect(Collectors.toSet())); + when(database.getResourceMetaData().getStorageUnitMetaDataMap().keySet()).thenReturn(Stream.of(name).collect(Collectors.toSet())); AllSQLRouteExecutor allSQLRouteExecutor = new AllSQLRouteExecutor(); RouteContext actual = allSQLRouteExecutor.route(new ConnectionContext(), mock(QueryContext.class), mock(RuleMetaData.class), database); assertThat(actual.getRouteUnits().size(), is(1)); diff --git a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutorTest.java b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutorTest.java index 8c56d1b616807..ba236063fd2a9 100644 --- a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutorTest.java +++ b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutorTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.hint.SQLHintDataSourceNotExistsException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; @@ -65,10 +65,10 @@ class PartialSQLRouteExecutorTest { @BeforeEach void setup() { - Map metaDataMap = new HashMap<>(); + Map metaDataMap = new HashMap<>(); metaDataMap.put("ds_0", null); metaDataMap.put("ds_1", null); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); } @Test diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java index ea8fa3130d6a7..307d0e61fb678 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java @@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext; @@ -89,7 +89,7 @@ public final class DriverDatabaseConnectionManager implements DatabaseConnection private final String databaseName; public DriverDatabaseConnectionManager(final String databaseName, final ContextManager contextManager) { - for (Entry entry : contextManager.getStorageUnitMetaDataMap(databaseName).entrySet()) { + for (Entry entry : contextManager.getStorageUnitMetaDataMap(databaseName).entrySet()) { DataSource dataSource = entry.getValue().getDataSource(); String cacheKey = getKey(databaseName, entry.getKey()); dataSourceMap.put(cacheKey, dataSource); diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java index 390da85e974aa..8306082a3759d 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaDataBuilder; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -102,7 +102,7 @@ public Connection getConnection(final String username, final String password) { @Override public void close() throws SQLException { contextManagerDestroyedCallback(databaseName); - for (NewStorageUnitMetaData each : contextManager.getStorageUnitMetaDataMap(databaseName).values()) { + for (StorageUnitMetaData each : contextManager.getStorageUnitMetaDataMap(databaseName).values()) { close(each.getDataSource()); } contextManager.close(); @@ -133,13 +133,13 @@ private void contextManagerDestroyedCallback(final String databaseName) { @Override public int getLoginTimeout() throws SQLException { - Map metaDataMap = contextManager.getStorageUnitMetaDataMap(databaseName); + Map metaDataMap = contextManager.getStorageUnitMetaDataMap(databaseName); return metaDataMap.isEmpty() ? 0 : metaDataMap.values().iterator().next().getDataSource().getLoginTimeout(); } @Override public void setLoginTimeout(final int seconds) throws SQLException { - for (NewStorageUnitMetaData each : contextManager.getStorageUnitMetaDataMap(databaseName).values()) { + for (StorageUnitMetaData each : contextManager.getStorageUnitMetaDataMap(databaseName).values()) { each.getDataSource().setLoginTimeout(seconds); } } diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java index c2bba63790112..eac40fb5e1e0c 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java @@ -326,7 +326,7 @@ private DriverExecutionPrepareEngine createDriver int maxConnectionsSizePerQuery = metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); return new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT, maxConnectionsSizePerQuery, connection.getDatabaseConnectionManager(), statementManager, statementOption, metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRules(), - metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData()); + metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap()); } @Override @@ -679,7 +679,7 @@ private void initBatchPreparedStatementExecutor() throws SQLException { DriverExecutionPrepareEngine prepareEngine = new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT, metaDataContexts.getMetaData().getProps() .getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), connection.getDatabaseConnectionManager(), statementManager, statementOption, metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRules(), - metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData()); + metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap()); List executionUnits = new ArrayList<>(batchPreparedStatementExecutor.getBatchExecutionUnits().size()); for (BatchExecutionUnit each : batchPreparedStatementExecutor.getBatchExecutionUnits()) { ExecutionUnit executionUnit = each.getExecutionUnit(); diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java index fe78fd1d84388..be549419dbec4 100644 --- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java +++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java @@ -238,7 +238,7 @@ private DriverExecutionPrepareEngine createDriver int maxConnectionsSizePerQuery = metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, connection.getDatabaseConnectionManager(), statementManager, statementOption, metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRules(), - metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData()); + metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap()); } @Override diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java index 432cfa3e3078d..9123b85c61895 100644 --- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java +++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; @@ -76,7 +76,7 @@ void setUp() throws SQLException { private ContextManager mockContextManager() throws SQLException { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - Map metaDataMap = mockStorageUnitMetaDataMap(); + Map metaDataMap = mockStorageUnitMetaDataMap(); when(result.getStorageUnitMetaDataMap(DefaultDatabase.LOGIC_NAME)).thenReturn(metaDataMap); MetaDataPersistService persistService = mockMetaDataPersistService(); when(result.getMetaDataContexts().getPersistService()).thenReturn(persistService); @@ -89,8 +89,8 @@ private ContextManager mockContextManager() throws SQLException { return result; } - private Map mockStorageUnitMetaDataMap() throws SQLException { - Map result = new HashMap<>(2, 1F); + private Map mockStorageUnitMetaDataMap() throws SQLException { + Map result = new HashMap<>(2, 1F); result.put("ds", mockStorageUnitMetaData(new MockedDataSource())); DataSource invalidDataSource = mock(DataSource.class); when(invalidDataSource.getConnection()).thenThrow(new SQLException()); @@ -98,8 +98,8 @@ private Map mockStorageUnitMetaDataMap() throws return result; } - private NewStorageUnitMetaData mockStorageUnitMetaData(final DataSource dataSource) { - NewStorageUnitMetaData result = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + private StorageUnitMetaData mockStorageUnitMetaData(final DataSource dataSource) { + StorageUnitMetaData result = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(result.getDataSource()).thenReturn(dataSource); StorageUnit storageUnit = mock(StorageUnit.class); when(result.getStorageUnit()).thenReturn(storageUnit); diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java index 25fbddc4ec64c..95fb177e82086 100644 --- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java +++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java @@ -20,7 +20,7 @@ import lombok.SneakyThrows; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; @@ -253,7 +253,7 @@ private ContextManager mockContextManager() { private ContextManager mockContextManager(final StorageUnit storageUnit) { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getStorageUnit()).thenReturn(storageUnit); DataSource dataSource = storageUnit.getDataSource(); when(storageUnitMetaData.getDataSource()).thenReturn(dataSource); diff --git a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/impl/CDCJobAPI.java b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/impl/CDCJobAPI.java index 2bcadf7dd73c5..483804731052c 100644 --- a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/impl/CDCJobAPI.java +++ b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/impl/CDCJobAPI.java @@ -78,7 +78,7 @@ import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration; import org.apache.shardingsphere.infra.yaml.config.swapper.resource.YamlDataSourceConfigurationSwapper; @@ -160,7 +160,7 @@ private YamlCDCJobConfiguration getYamlCDCJobConfiguration(final StreamDataParam private ShardingSpherePipelineDataSourceConfiguration getDataSourceConfiguration(final ShardingSphereDatabase database) { Map> dataSourcePoolProps = new HashMap<>(); - for (Entry entry : database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet()) { + for (Entry entry : database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet()) { dataSourcePoolProps.put(entry.getKey(), dataSourceConfigSwapper.swapToMap(entry.getValue().getDataSourcePoolProperties())); } YamlRootConfiguration targetRootConfig = new YamlRootConfiguration(); diff --git a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java index 582f9f6d93ab7..a162586fdf17d 100644 --- a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java +++ b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java @@ -85,7 +85,7 @@ import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.json.JsonUtils; import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration; @@ -191,7 +191,7 @@ private YamlPipelineDataSourceConfiguration buildYamlPipelineDataSourceConfigura private PipelineDataSourceConfiguration buildTargetPipelineDataSourceConfiguration(final ShardingSphereDatabase targetDatabase) { Map> targetPoolProps = new HashMap<>(); YamlDataSourceConfigurationSwapper dataSourceConfigSwapper = new YamlDataSourceConfigurationSwapper(); - for (Entry entry : targetDatabase.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet()) { + for (Entry entry : targetDatabase.getResourceMetaData().getStorageUnitMetaDataMap().entrySet()) { targetPoolProps.put(entry.getKey(), dataSourceConfigSwapper.swapToMap(entry.getValue().getDataSourcePoolProperties())); } YamlRootConfiguration targetRootConfig = buildYamlRootConfiguration(targetDatabase.getName(), targetPoolProps, targetDatabase.getRuleMetaData().getConfigurations()); diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java index 11c91a00409ab..89c2a61476416 100644 --- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java +++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java @@ -61,7 +61,7 @@ private Properties createProperties(final Map da private Optional findStorageType(final Collection databases) { return databases.stream() - .flatMap(each -> each.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().values().stream()).findFirst().map(each -> each.getStorageUnit().getStorageType()); + .flatMap(each -> each.getResourceMetaData().getStorageUnitMetaDataMap().values().stream()).findFirst().map(each -> each.getStorageUnit().getStorageType()); } /** diff --git a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactoryTest.java b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactoryTest.java index 110bf526f13b9..68e33928e8168 100644 --- a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactoryTest.java +++ b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactoryTest.java @@ -41,7 +41,7 @@ void assertCreateSingleDatabase() throws SQLException { DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), Collections.emptyList()); ShardingSphereDatabase actual = ExternalMetaDataFactory.create("foo_db", databaseConfig, new ConfigurationProperties(new Properties()), mock(InstanceContext.class)); assertThat(actual.getName(), is("foo_db")); - assertTrue(actual.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().isEmpty()); + assertTrue(actual.getResourceMetaData().getStorageUnitMetaDataMap().isEmpty()); } @Test @@ -50,7 +50,7 @@ void assertCreateDatabaseMap() throws SQLException { Map actual = ExternalMetaDataFactory.create( Collections.singletonMap("foo_db", databaseConfig), new ConfigurationProperties(new Properties()), mock(InstanceContext.class)); assertTrue(actual.containsKey("foo_db")); - assertTrue(actual.get("foo_db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().isEmpty()); + assertTrue(actual.get("foo_db").getResourceMetaData().getStorageUnitMetaDataMap().isEmpty()); } @Test @@ -59,6 +59,6 @@ void assertCreateDatabaseMapWhenConfigUppercaseDatabaseName() throws SQLExceptio Map actual = ExternalMetaDataFactory.create( Collections.singletonMap("FOO_DB", databaseConfig), new ConfigurationProperties(new Properties()), mock(InstanceContext.class)); assertTrue(actual.containsKey("foo_db")); - assertTrue(actual.get("foo_db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().isEmpty()); + assertTrue(actual.get("foo_db").getResourceMetaData().getStorageUnitMetaDataMap().isEmpty()); } } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java index e818800e42cb5..3e1f42e5c5b00 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java @@ -47,7 +47,7 @@ public final class SingleSQLRouter implements SQLRouter { @Override public RouteContext createRouteContext(final QueryContext queryContext, final RuleMetaData globalRuleMetaData, final ShardingSphereDatabase database, final SingleRule rule, final ConfigurationProperties props, final ConnectionContext connectionContext) { - if (1 == database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size()) { + if (1 == database.getResourceMetaData().getStorageUnitMetaDataMap().size()) { return createSingleDataSourceRouteContext(rule, database, queryContext); } RouteContext result = new RouteContext(); @@ -82,7 +82,7 @@ public void decorateRouteContext(final RouteContext routeContext, final QueryCon private RouteContext createSingleDataSourceRouteContext(final SingleRule rule, final ShardingSphereDatabase database, final QueryContext queryContext) { String logicDataSource = rule.getDataSourceNames().iterator().next(); - String actualDataSource = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().keySet().iterator().next(); + String actualDataSource = database.getResourceMetaData().getStorageUnitMetaDataMap().keySet().iterator().next(); RouteContext result = new RouteContext(); result.getRouteUnits().add(new RouteUnit(new RouteMapper(logicDataSource, actualDataSource), createTableMappers(queryContext.getSqlStatementContext().getTablesContext().getTableNames()))); return result; diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java index ac631ea82d724..cdbe185717246 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.SQLRouter; @@ -85,7 +85,7 @@ void assertCreateRouteContextWithSingleDataSource() throws SQLException { private ShardingSphereDatabase mockSingleDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - when(result.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", mock(NewStorageUnitMetaData.class))); + when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", mock(StorageUnitMetaData.class))); return result; } @@ -107,7 +107,7 @@ void assertCreateRouteContextWithReadwriteSplittingDataSource() throws SQLExcept private ShardingSphereDatabase mockReadwriteSplittingDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(result.getName()).thenReturn(" db_schema"); - when(result.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("write_ds", mock(NewStorageUnitMetaData.class))); + when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("write_ds", mock(StorageUnitMetaData.class))); return result; } @@ -148,10 +148,10 @@ private DataNode createDataNode(final String dataSourceName) { private ShardingSphereDatabase mockDatabaseWithMultipleResources() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - Map metaDataMap = new HashMap<>(2, 1F); - metaDataMap.put("ds_0", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - metaDataMap.put("ds_1", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - when(result.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = new HashMap<>(2, 1F); + metaDataMap.put("ds_0", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + metaDataMap.put("ds_1", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); when(result.getName()).thenReturn(DefaultDatabase.LOGIC_NAME); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java index c22d06e587ce1..490b9f067b8ad 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java @@ -64,7 +64,7 @@ public Collection getRows(final ShardingSphereDatabase private Map> getActualDataNodes(final ShardingSphereDatabase database) { ResourceMetaData resourceMetaData = database.getResourceMetaData(); Map aggregateDataSourceMap = SingleTableLoadUtils.getAggregatedDataSourceMap( - resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), database.getRuleMetaData().getRules()); Collection excludedTables = SingleTableLoadUtils.getExcludedTables(database.getRuleMetaData().getRules()); diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java index c86ccf435bcf8..4c962d3d0d659 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableStatementUpdater.java @@ -114,7 +114,7 @@ private void checkActualTableExist(final ShardingSphereDatabase database, final } ResourceMetaData resourceMetaData = database.getResourceMetaData(); Map aggregateDataSourceMap = SingleTableLoadUtils.getAggregatedDataSourceMap( - resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), database.getRuleMetaData().getRules()); Map>> actualTableNodes = new LinkedHashMap<>(); diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitStatementUpdater.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitStatementUpdater.java index 4ecf23f65e5b8..e4d9d04d20761 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitStatementUpdater.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitStatementUpdater.java @@ -40,7 +40,7 @@ public void checkSQLStatement(final ShardingSphereDatabase database, final SetDe private void checkStorageUnitExist(final ShardingSphereDatabase database, final SetDefaultSingleTableStorageUnitStatement sqlStatement) { if (!Strings.isNullOrEmpty(sqlStatement.getDefaultStorageUnit())) { - Collection storageUnitNames = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().keySet(); + Collection storageUnitNames = database.getResourceMetaData().getStorageUnitMetaDataMap().keySet(); ShardingSpherePreconditions.checkState(storageUnitNames.contains(sqlStatement.getDefaultStorageUnit()), () -> new MissingRequiredStorageUnitsException(database.getName(), Collections.singleton(sqlStatement.getDefaultStorageUnit()))); } diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java index 1f23ac6395e8d..82cba50b411ea 100644 --- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java +++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java @@ -71,9 +71,8 @@ private synchronized ShardingSphereTransactionManagerEngine createTransactionMan Map databaseTypes = new LinkedHashMap<>(databases.size(), 1F); for (Entry entry : databases.entrySet()) { ShardingSphereDatabase database = entry.getValue(); - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().forEach((key, value) -> dataSourceMap.put(database.getName() + "." + key, value.getDataSource())); - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap() - .forEach((key, value) -> databaseTypes.put(database.getName() + "." + key, value.getStorageUnit().getStorageType())); + database.getResourceMetaData().getStorageUnitMetaDataMap().forEach((key, value) -> dataSourceMap.put(database.getName() + "." + key, value.getDataSource())); + database.getResourceMetaData().getStorageUnitMetaDataMap().forEach((key, value) -> databaseTypes.put(database.getName() + "." + key, value.getStorageUnit().getStorageType())); } if (dataSourceMap.isEmpty()) { return new ShardingSphereTransactionManagerEngine(defaultType); diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java index 9e8bb9f4fa5de..1a53301b0c970 100644 --- a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java +++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.transaction.api.TransactionType; import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; @@ -62,14 +62,14 @@ void assertAddResource() { assertThat(actual.getDatabases().size(), is(2)); assertTrue(actual.getDatabases().containsKey(SHARDING_DB_1)); ResourceMetaData resourceMetaData1 = actual.getDatabases().get(SHARDING_DB_1).getResourceMetaData(); - assertThat(resourceMetaData1.getStorageUnitMetaData().getMetaDataMap().size(), is(2)); - assertTrue(resourceMetaData1.getStorageUnitMetaData().getMetaDataMap().containsKey("ds_0")); - assertTrue(resourceMetaData1.getStorageUnitMetaData().getMetaDataMap().containsKey("ds_1")); + assertThat(resourceMetaData1.getStorageUnitMetaDataMap().size(), is(2)); + assertTrue(resourceMetaData1.getStorageUnitMetaDataMap().containsKey("ds_0")); + assertTrue(resourceMetaData1.getStorageUnitMetaDataMap().containsKey("ds_1")); assertTrue(actual.getDatabases().containsKey(SHARDING_DB_2)); ResourceMetaData resourceMetaData2 = actual.getDatabases().get(SHARDING_DB_2).getResourceMetaData(); - assertThat(resourceMetaData2.getStorageUnitMetaData().getMetaDataMap().size(), is(2)); - assertTrue(resourceMetaData2.getStorageUnitMetaData().getMetaDataMap().containsKey("ds_0")); - assertTrue(resourceMetaData2.getStorageUnitMetaData().getMetaDataMap().containsKey("ds_1")); + assertThat(resourceMetaData2.getStorageUnitMetaDataMap().size(), is(2)); + assertTrue(resourceMetaData2.getStorageUnitMetaDataMap().containsKey("ds_0")); + assertTrue(resourceMetaData2.getStorageUnitMetaDataMap().containsKey("ds_1")); assertThat(actual.getResource().getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } @@ -99,10 +99,10 @@ private ShardingSphereDatabase createDatabase() { private ResourceMetaData createResourceMetaData() { ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - Map metaDataMap = new HashMap<>(2, 1F); - metaDataMap.put("ds_0", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - metaDataMap.put("ds_1", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - when(result.getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = new HashMap<>(2, 1F); + metaDataMap.put("ds_0", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + metaDataMap.put("ds_1", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + when(result.getStorageUnitMetaDataMap()).thenReturn(metaDataMap); return result; } @@ -116,10 +116,10 @@ private ShardingSphereDatabase createAddDatabase() { private ResourceMetaData createAddResourceMetaData() { ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - Map metaDataMap = new HashMap<>(2, 1F); - metaDataMap.put("ds_0", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - metaDataMap.put("ds_1", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - when(result.getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = new HashMap<>(2, 1F); + metaDataMap.put("ds_0", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + metaDataMap.put("ds_1", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + when(result.getStorageUnitMetaDataMap()).thenReturn(metaDataMap); return result; } diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java index e14d8de11fde8..f490864c8d88f 100644 --- a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java +++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java @@ -49,7 +49,7 @@ void assertBuild() { new RuleMetaData(Collections.singletonList(mock(ShardingSphereRule.class))), Collections.singletonMap("test", mock(ShardingSphereSchema.class))); TransactionRule rule = new TransactionRuleBuilder().build(ruleConfig, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ConfigurationProperties.class)); assertNotNull(rule.getConfiguration()); - assertThat(rule.getDatabases().get("logic_db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size(), is(2)); + assertThat(rule.getDatabases().get("logic_db").getResourceMetaData().getStorageUnitMetaDataMap().size(), is(2)); } private Map createDataSourceMap() { 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 971db5f1d399a..d1849567cb1b6 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 @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.SchemaManager; @@ -105,8 +105,8 @@ public synchronized void renewMetaDataContexts(final MetaDataContexts metaDataCo * @param databaseName database name * @return storage unit meta data map */ - public Map getStorageUnitMetaDataMap(final String databaseName) { - return metaDataContexts.get().getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(); + public Map getStorageUnitMetaDataMap(final String databaseName) { + return metaDataContexts.get().getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap(); } /** @@ -183,8 +183,8 @@ private ShardingSphereSchema loadSchema(final String databaseName, final String ShardingSphereDatabase database = metaDataContexts.get().getMetaData().getDatabase(databaseName); database.reloadRules(MutableDataNodeRule.class); GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getProtocolType(), - Collections.singletonMap(dataSourceName, database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().get(dataSourceName).getStorageUnit().getStorageType()), - Collections.singletonMap(dataSourceName, database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().get(dataSourceName).getDataSource()), + Collections.singletonMap(dataSourceName, database.getResourceMetaData().getStorageUnitMetaDataMap().get(dataSourceName).getStorageUnit().getStorageType()), + Collections.singletonMap(dataSourceName, database.getResourceMetaData().getStorageUnitMetaDataMap().get(dataSourceName).getDataSource()), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); ShardingSphereSchema result = GenericSchemaBuilder.build(material).get(schemaName); result.getViews().putAll(metaDataContexts.get().getPersistService().getDatabaseMetaDataService().getViewMetaDataPersistService().load(database.getName(), schemaName)); @@ -201,7 +201,7 @@ private ShardingSphereSchema loadSchema(final String databaseName, final String public void reloadTable(final String databaseName, final String schemaName, final String tableName) { ShardingSphereDatabase database = metaDataContexts.get().getMetaData().getDatabase(databaseName); GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getProtocolType(), - database.getResourceMetaData().getStorageUnitMetaData(), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); + database.getResourceMetaData().getStorageUnitMetaDataMap(), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); try { persistTable(database, schemaName, tableName, material); } catch (final SQLException ex) { @@ -219,7 +219,7 @@ public void reloadTable(final String databaseName, final String schemaName, fina */ public void reloadTable(final String databaseName, final String schemaName, final String dataSourceName, final String tableName) { ShardingSphereDatabase database = metaDataContexts.get().getMetaData().getDatabase(databaseName); - StorageUnit storageUnit = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().get(dataSourceName).getStorageUnit(); + StorageUnit storageUnit = database.getResourceMetaData().getStorageUnitMetaDataMap().get(dataSourceName).getStorageUnit(); GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(database.getProtocolType(), Collections.singletonMap(dataSourceName, storageUnit.getStorageType()), Collections.singletonMap(dataSourceName, storageUnit.getDataSource()), database.getRuleMetaData().getRules(), metaDataContexts.get().getMetaData().getProps(), schemaName); try { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java index 949bdd5db3011..dcafee869f5ec 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java @@ -32,7 +32,7 @@ import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.SchemaManager; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -175,7 +175,7 @@ public synchronized void alterRuleConfiguration(final String databaseName, final Collection rules = new LinkedList<>(database.getRuleMetaData().getRules()); rules.removeIf(each -> each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass())); rules.addAll(DatabaseRulesBuilder.build(databaseName, - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), database.getRuleMetaData().getRules(), ruleConfig, instanceContext)); refreshMetadata(databaseName, database, rules); @@ -197,7 +197,7 @@ public synchronized void dropRuleConfiguration(final String databaseName, final rules.removeIf(each -> each.getConfiguration().getClass().isAssignableFrom(ruleConfig.getClass())); if (isNotEmptyConfig(ruleConfig)) { rules.addAll(DatabaseRulesBuilder.build(databaseName, - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), database.getRuleMetaData().getRules(), ruleConfig, instanceContext)); } @@ -279,8 +279,8 @@ public void alterSchemaMetaData(final String databaseName, final ShardingSphereD */ public Map renewDatabase(final ShardingSphereDatabase database, final SwitchingResource resource) { Map newStorageNodes = getNewStorageNodes(database.getResourceMetaData().getDataSources(), resource); - Map newStorageUnitNodeMap = getNewStorageUnitNodeMap(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(), resource); - Map propsMap = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map newStorageUnitNodeMap = getNewStorageUnitNodeMap(database.getResourceMetaData().getStorageUnitMetaDataMap(), resource); + Map propsMap = database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> currentValue, LinkedHashMap::new)); return Collections.singletonMap(database.getName().toLowerCase(), new ShardingSphereDatabase(database.getName(), database.getProtocolType(), new ResourceMetaData(database.getName(), newStorageNodes, newStorageUnitNodeMap, propsMap), database.getRuleMetaData(), database.getSchemas())); @@ -296,9 +296,9 @@ private Map getNewStorageNodes(final Map getNewStorageUnitNodeMap(final Map currentStorageUnitMetaDataMap, final SwitchingResource resource) { + private Map getNewStorageUnitNodeMap(final Map currentStorageUnitMetaDataMap, final SwitchingResource resource) { Map result = new LinkedHashMap<>(currentStorageUnitMetaDataMap.size(), 1F); - for (Entry entry : currentStorageUnitMetaDataMap.entrySet()) { + for (Entry entry : currentStorageUnitMetaDataMap.entrySet()) { if (!resource.getStaleStorageResource().getStorageUnitNodeMap().containsKey(entry.getKey())) { result.put(entry.getKey(), entry.getValue().getStorageNode()); } @@ -362,7 +362,7 @@ private DatabaseConfiguration getDatabaseConfiguration(final ResourceMetaData re final Collection toBeCreatedRuleConfigs) { StorageResource storageResource = getMergedStorageResource(resourceMetaData, switchingResource); Map propsMap = null == switchingResource - ? resourceMetaData.getStorageUnitMetaData().getMetaDataMap() + ? resourceMetaData.getStorageUnitMetaDataMap() .entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)) : switchingResource.getMergedDataSourcePoolPropertiesMap(); return new DataSourceProvidedDatabaseConfiguration(storageResource, toBeCreatedRuleConfigs, propsMap); @@ -371,7 +371,7 @@ private DatabaseConfiguration getDatabaseConfiguration(final ResourceMetaData re private StorageResource getMergedStorageResource(final ResourceMetaData currentResourceMetaData, final SwitchingResource switchingResource) { Map storageNodeDataSources = currentResourceMetaData.getDataSources(); Map storageUnitNodeMap = new LinkedHashMap<>( - currentResourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + currentResourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); if (null != switchingResource && null != switchingResource.getNewStorageResource() && !switchingResource.getNewStorageResource().getDataSources().isEmpty()) { storageNodeDataSources.putAll(switchingResource.getNewStorageResource().getDataSources()); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java index c76b2ee80736b..8a96702fc88d7 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java @@ -47,7 +47,7 @@ public final class NewResourceSwitchManager { * @return created switching resource */ public SwitchingResource registerStorageUnit(final ResourceMetaData resourceMetaData, final Map storageUnitDataSourcePoolProps) { - Map mergedPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap() + Map mergedPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap() .entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); mergedPropsMap.putAll(storageUnitDataSourcePoolProps); Map toBeCreatedStorageUintNodeMap = StorageUnitNodeMapUtils.fromDataSourcePoolProperties(storageUnitDataSourcePoolProps); @@ -76,7 +76,7 @@ private StorageResource getRegisterNewStorageResource(final ResourceMetaData res * @return created switching resource */ public SwitchingResource alterStorageUnit(final ResourceMetaData resourceMetaData, final Map propsMap) { - Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap() + Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap() .entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); mergedDataSourcePoolPropertiesMap.putAll(propsMap); Map toBeAlteredStorageUintNodeMap = StorageUnitNodeMapUtils.fromDataSourcePoolProperties(mergedDataSourcePoolPropertiesMap); @@ -113,20 +113,20 @@ private StorageResource getStaleStorageResource(final ResourceMetaData resourceM * @return created switching resource */ public SwitchingResource unregisterStorageUnit(final ResourceMetaData resourceMetaData, final String storageUnitName) { - Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap() + Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap() .entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); mergedDataSourcePoolPropertiesMap.keySet().removeIf(each -> each.equals(storageUnitName)); - resourceMetaData.getStorageUnitMetaData().getMetaDataMap().remove(storageUnitName); + resourceMetaData.getStorageUnitMetaDataMap().remove(storageUnitName); return new SwitchingResource(resourceMetaData, new StorageResource(Collections.emptyMap(), Collections.emptyMap()), getToBeRemovedStaleStorageResource(resourceMetaData, storageUnitName), mergedDataSourcePoolPropertiesMap); } private StorageResource getToBeRemovedStaleStorageResource(final ResourceMetaData resourceMetaData, final String storageUnitName) { Map metaDataMap = new LinkedHashMap<>( - resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); StorageNode storageNode = metaDataMap.remove(storageUnitName); - Map reservedStorageUintNodeMap = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map reservedStorageUintNodeMap = resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode())); Map storageNodes = new LinkedHashMap<>(1, 1F); if (reservedStorageUintNodeMap.values().stream().noneMatch(each -> each.equals(storageNode))) { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java index a9a9b19b89c38..205385a0cbb56 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapUtils; import javax.sql.DataSource; @@ -48,7 +48,7 @@ public final class ResourceSwitchManager { * @return created switching resource */ public SwitchingResource create(final ResourceMetaData resourceMetaData, final Map toBeChangedPropsMap) { - Map mergedPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map mergedPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); mergedPropsMap.putAll(toBeChangedPropsMap); Map toBeChangedStorageUnitNodeMap = StorageUnitNodeMapUtils.fromDataSourcePoolProperties(toBeChangedPropsMap); @@ -64,7 +64,7 @@ public SwitchingResource create(final ResourceMetaData resourceMetaData, final M * @return created switching resource */ public SwitchingResource createByDropResource(final ResourceMetaData resourceMetaData, final Map toBeDeletedPropsMap) { - Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); mergedDataSourcePoolPropertiesMap.keySet().removeIf(toBeDeletedPropsMap::containsKey); Map toRemovedStorageUnitNodeMap = StorageUnitNodeMapUtils.fromDataSourcePoolProperties(toBeDeletedPropsMap); @@ -80,7 +80,7 @@ public SwitchingResource createByDropResource(final ResourceMetaData resourceMet * @return created switching resource */ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMetaData resourceMetaData, final Map toBeChangedPropsMap) { - Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map mergedDataSourcePoolPropertiesMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); mergedDataSourcePoolPropertiesMap.keySet().removeIf(each -> !toBeChangedPropsMap.containsKey(each)); mergedDataSourcePoolPropertiesMap.putAll(toBeChangedPropsMap); @@ -89,7 +89,7 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet Collection toBeChangedStorageNodeNames = toBeChangedStorageUnitNodeMap.values().stream().map(StorageNode::getName).collect(Collectors.toSet()); staleStorageResource.getDataSources().putAll(getToBeDeletedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageNodeNames)); staleStorageResource.getStorageUnitNodeMap().putAll( - getToBeDeletedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getMetaDataMap(), toBeChangedStorageUnitNodeMap.keySet())); + getToBeDeletedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaDataMap(), toBeChangedStorageUnitNodeMap.keySet())); return new SwitchingResource(resourceMetaData, createNewStorageResource(resourceMetaData, toBeChangedStorageUnitNodeMap, toBeChangedPropsMap), staleStorageResource, mergedDataSourcePoolPropertiesMap); } @@ -114,11 +114,11 @@ private Map getNewStorageNodes(final ResourceMetaDa } private Map getNewStorageUnitNodeMap(final ResourceMetaData resourceMetaData, final Map toBeChangedStorageUnitNodeMap) { - Map result = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map result = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); - result.keySet().removeAll(getToBeDeletedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getMetaDataMap(), toBeChangedStorageUnitNodeMap.keySet()).keySet()); - result.putAll(getChangedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getMetaDataMap(), toBeChangedStorageUnitNodeMap)); - result.putAll(getToBeAddedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + result.keySet().removeAll(getToBeDeletedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaDataMap(), toBeChangedStorageUnitNodeMap.keySet()).keySet()); + result.putAll(getChangedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaDataMap(), toBeChangedStorageUnitNodeMap)); + result.putAll(getToBeAddedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), toBeChangedStorageUnitNodeMap)); return result; } @@ -152,7 +152,7 @@ private Map getToBeAddedDataSources(final Map toRemovedStorageUnitNodeMap) { - Map reservedStorageUnitNodeMap = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map reservedStorageUnitNodeMap = resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .filter(entry -> !toRemovedStorageUnitNodeMap.containsKey(entry.getKey())) .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode())); Collection toBeRemovedStorageNodeNames = toRemovedStorageUnitNodeMap.values().stream().map(StorageNode::getName).collect(Collectors.toSet()); @@ -160,7 +160,7 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re Map staleStorageNodes = resourceMetaData.getDataSources().entrySet().stream() .filter(entry -> toBeRemovedStorageNodeNames.contains(entry.getKey()) && !inUsedDataSourceNames.contains(entry.getKey())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - Map staleStorageUnitNodeMap = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map staleStorageUnitNodeMap = resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .filter(entry -> !reservedStorageUnitNodeMap.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getStorageNode())); return new StorageResource(staleStorageNodes, staleStorageUnitNodeMap); } @@ -168,9 +168,9 @@ private StorageResource getToBeRemovedStaleDataSources(final ResourceMetaData re private StorageResource getStaleDataSources(final ResourceMetaData resourceMetaData, final Map toBeChangedStorageUnitNodeMap, final Map storageUnitDataSourcePoolProps) { Map storageNodes = new LinkedHashMap<>(resourceMetaData.getDataSources().size(), 1F); - Map storageUnitNodeMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaData().getMetaDataMap().size(), 1F); + Map storageUnitNodeMap = new LinkedHashMap<>(resourceMetaData.getStorageUnitMetaDataMap().size(), 1F); storageNodes.putAll(getToBeChangedDataSources(resourceMetaData.getDataSources(), StorageUnitNodeMapUtils.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps))); - storageUnitNodeMap.putAll(getChangedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaData().getMetaDataMap(), toBeChangedStorageUnitNodeMap)); + storageUnitNodeMap.putAll(getChangedStorageUnitNodeMap(resourceMetaData.getStorageUnitMetaDataMap(), toBeChangedStorageUnitNodeMap)); return new StorageResource(storageNodes, storageUnitNodeMap); } @@ -197,9 +197,9 @@ private Map getToBeDeletedDataSources(final Map getToBeDeletedStorageUnitNodeMap(final Map storageUnitMetaDataMap, final Collection toBeChangedStorageUnitNames) { + private Map getToBeDeletedStorageUnitNodeMap(final Map storageUnitMetaDataMap, final Collection toBeChangedStorageUnitNames) { Map result = new LinkedHashMap<>(storageUnitMetaDataMap.size(), 1F); - for (Entry entry : storageUnitMetaDataMap.entrySet()) { + for (Entry entry : storageUnitMetaDataMap.entrySet()) { if (!toBeChangedStorageUnitNames.contains(entry.getKey())) { result.put(entry.getKey(), entry.getValue().getStorageNode()); } @@ -207,12 +207,12 @@ private Map getToBeDeletedStorageUnitNodeMap(final Map getChangedStorageUnitNodeMap(final Map storageUnitMetaDataMap, final Map toBeChangedStorageUnitNodeMap) { + private Map getChangedStorageUnitNodeMap(final Map storageUnitMetaDataMap, final Map toBeChangedStorageUnitNodeMap) { return toBeChangedStorageUnitNodeMap.entrySet().stream().filter(entry -> isModifiedStorageUnitNodeMap(storageUnitMetaDataMap, entry.getKey(), entry.getValue())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); } - private boolean isModifiedStorageUnitNodeMap(final Map originalstorageUnitMetaDataMap, + private boolean isModifiedStorageUnitNodeMap(final Map originalstorageUnitMetaDataMap, final String dataSourceName, final StorageNode storageNode) { return originalstorageUnitMetaDataMap.containsKey(dataSourceName) && !storageNode.equals(originalstorageUnitMetaDataMap.get(dataSourceName).getStorageNode()); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java index 79efada097c8d..025186c108dbf 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java @@ -147,7 +147,7 @@ private static void persistDatabaseConfigurations(final MetaDataContexts metadat for (Entry entry : param.getDatabaseConfigs().entrySet()) { String databaseName = entry.getKey(); metadataContexts.getPersistService().persistConfigurations(entry.getKey(), entry.getValue(), - metadataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + metadataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, each -> each.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), metadataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRules()); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/NewMetaDataContextsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/NewMetaDataContextsFactory.java index ce6f65cce7c55..373b53921bc50 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/NewMetaDataContextsFactory.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/NewMetaDataContextsFactory.java @@ -149,7 +149,7 @@ private static void persistDatabaseConfigurations(final MetaDataContexts metadat for (Entry entry : param.getDatabaseConfigs().entrySet()) { String databaseName = entry.getKey(); metadataContexts.getPersistService().persistConfigurations(entry.getKey(), entry.getValue(), - metadataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + metadataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, each -> each.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), metadataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRules()); } 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 78941a7331cd4..b6a29531c9174 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 @@ -31,7 +31,6 @@ import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeUtils; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapUtils; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; @@ -105,12 +104,12 @@ private ShardingSphereDatabase mockDatabase() { when(mutableDataNodeRule.findTableDataNode("foo_schema", "foo_tbl")).thenReturn(Optional.of(mock(DataNode.class))); when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(mutableDataNodeRule))); when(result.getSchemas()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", new ShardingSphereSchema()))); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit().getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); - when(result.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); - Map metaDataMap = Collections.singletonMap("foo_ds", - new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - when(result.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + Map metaDataMap = Collections.singletonMap("foo_ds", + new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); return result; } @@ -226,9 +225,7 @@ void assertAlterRuleConfiguration() { ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); Map dataSources = Collections.singletonMap("foo_ds", new MockedDataSource()); when(resourceMetaData.getDataSources()).thenReturn(StorageNodeUtils.getStorageNodeDataSources(dataSources)); - StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); - when(resourceMetaData.getStorageUnitMetaData()).thenReturn(storageUnitMetaData); - when(storageUnitMetaData.getMetaDataMap()).thenReturn(Collections.emptyMap()); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.emptyMap()); ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), resourceMetaData, mock(RuleMetaData.class), Collections.emptyMap()); when(metaDataContexts.getMetaData().getDatabase("foo_db")).thenReturn(database); @@ -246,7 +243,7 @@ void assertAlterDataSourceConfiguration() { when(metaDataContexts.getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.emptyList())); contextManager.getConfigurationContextManager().alterDataSourceUnitsConfiguration("foo_db", Collections.singletonMap("foo_ds", new DataSourcePoolProperties(MockedDataSource.class.getName(), createProperties("test", "test")))); - assertThat(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size(), is(3)); + assertThat(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaDataMap().size(), is(3)); assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db") .getResourceMetaData().getDataSources().get(new StorageNodeName("foo_ds"))); } @@ -257,13 +254,13 @@ private ResourceMetaData createOriginalResource() { originalDataSources.put("ds_2", new MockedDataSource()); Map storageNodeDataSourceMap = StorageNodeUtils.getStorageNodeDataSources(originalDataSources); Map storageUnitNodeMap = StorageUnitNodeMapUtils.fromDataSources(originalDataSources); - Map metaDataMap = new LinkedHashMap<>(2, 1F); + Map metaDataMap = new LinkedHashMap<>(2, 1F); for (Entry entry : storageUnitNodeMap.entrySet()) { - metaDataMap.put(entry.getKey(), new NewStorageUnitMetaData( + metaDataMap.put(entry.getKey(), new StorageUnitMetaData( "foo_db", storageUnitNodeMap.get(entry.getKey()), mock(DataSourcePoolProperties.class), storageNodeDataSourceMap.get(entry.getValue().getName()))); } ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - when(result.getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + when(result.getStorageUnitMetaDataMap()).thenReturn(metaDataMap); when(result.getDataSources()).thenReturn(storageNodeDataSourceMap); return result; } @@ -305,7 +302,7 @@ void assertReloadTable() { when(persistService.getDatabaseMetaDataService()).thenReturn(databaseMetaDataPersistService); when(metaDataContexts.getPersistService()).thenReturn(persistService); contextManager.reloadTable("foo_db", "foo_schema", "foo_table"); - assertTrue(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().containsKey("foo_ds")); + assertTrue(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaDataMap().containsKey("foo_ds")); } private Map createProperties(final String username, final String password) { diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java index 2168bd2468e53..4272a7ff1a577 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java @@ -113,7 +113,7 @@ private ContextManagerBuilderParameter createContextManagerBuilderParameter() { private Map createDatabases() { when(database.getName()).thenReturn("db"); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.emptyMap()); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.emptyMap()); when(database.getResourceMetaData()).thenReturn(resourceMetaData); when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema())); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); @@ -134,7 +134,7 @@ void assertRenewForRuleConfigurationsChanged() { @Test void assertRenewForDataSourceChanged() { subscriber.renew(new DataSourceUnitsChangedEvent("db", "0", createChangedDataSourcePoolPropertiesMap())); - assertTrue(contextManager.getMetaDataContexts().getMetaData().getDatabase("db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().containsKey("ds_2")); + assertTrue(contextManager.getMetaDataContexts().getMetaData().getDatabase("db").getResourceMetaData().getStorageUnitMetaDataMap().containsKey("ds_2")); } private Map createChangedDataSourcePoolPropertiesMap() { diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java index a86985b96d5ff..3da371a00376e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ResourceMetaDataChangedSubscriberTest.java @@ -114,7 +114,7 @@ void assertRenewForDatabaseAdded() { when(persistService.getDataSourceUnitService().load("db_added")).thenReturn(createDataSourcePoolPropertiesMap()); when(persistService.getDatabaseRulePersistService().load("db_added")).thenReturn(Collections.emptyList()); subscriber.renew(new DatabaseAddedEvent("db_added")); - assertNotNull(contextManager.getMetaDataContexts().getMetaData().getDatabase("db_added").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()); + assertNotNull(contextManager.getMetaDataContexts().getMetaData().getDatabase("db_added").getResourceMetaData().getStorageUnitMetaDataMap()); } private Map createDataSourcePoolPropertiesMap() { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java index 079fe4bea4669..24302508b6309 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java @@ -251,7 +251,7 @@ private DriverExecutionPrepareEngine createDriver JDBCBackendStatement statementManager = (JDBCBackendStatement) databaseConnectionManager.getConnectionSession().getStatementManager(); return new DriverExecutionPrepareEngine<>(driverType, maxConnectionsSizePerQuery, databaseConnectionManager, statementManager, new StatementOption(isReturnGeneratedKeys), metaData.getMetaData().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getRuleMetaData().getRules(), - metaData.getMetaData().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageUnitMetaData()); + metaData.getMetaData().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageUnitMetaDataMap()); } private ResponseHeader processExecuteFederation(final ResultSet resultSet, final MetaDataContexts metaDataContexts) throws SQLException { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java index f97904426a36a..d05190d972fcc 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java @@ -204,7 +204,7 @@ private List useDriverToExecute(final ExecutionContext executionC JDBCBackendStatement statementManager = (JDBCBackendStatement) databaseConnectionManager.getConnectionSession().getStatementManager(); DriverExecutionPrepareEngine prepareEngine = new DriverExecutionPrepareEngine<>( type, maxConnectionsSizePerQuery, databaseConnectionManager, statementManager, new StatementOption(isReturnGeneratedKeys), rules, - ProxyContext.getInstance().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageUnitMetaData()); + ProxyContext.getInstance().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageUnitMetaDataMap()); ExecutionGroupContext executionGroupContext; try { executionGroupContext = prepareEngine.prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits(), diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java index ad781d0cf92ac..b7e636478948c 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java @@ -69,7 +69,7 @@ public List getConnections(final String databaseName, final String d public List getConnections(final String databaseName, final String dataSourceName, final int connectionSize, final ConnectionMode connectionMode, final TransactionType transactionType) throws SQLException { DataSource dataSource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData() - .getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().get(dataSourceName).getDataSource(); + .getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap().get(dataSourceName).getDataSource(); if (dataSourceName.contains(".")) { String dataSourceStr = dataSourceName.split("\\.")[0]; if (GlobalDataSourceRegistry.getInstance().getCachedDataSources().containsKey(dataSourceStr)) { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java index 2291b340b737f..b7f2e16228bde 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/AbstractDatabaseMetaDataExecutor.java @@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; @@ -160,7 +160,7 @@ protected Collection getDatabaseNames(final ConnectionSession connection @Override protected void processMetaData(final String databaseName, final Consumer callback) throws SQLException { ResourceMetaData resourceMetaData = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData(); - Optional storageUnitMetaData = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().values().stream().findFirst(); + Optional storageUnitMetaData = resourceMetaData.getStorageUnitMetaDataMap().values().stream().findFirst(); if (!storageUnitMetaData.isPresent()) { return; } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java index 9f9d61ee2f65f..0f9d8fc0a1ca6 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.util.json.JsonUtils; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.distsql.export.ExportedStorageNode; @@ -87,7 +87,7 @@ private Map> getAllStorageNodes(final Sh private Map> generateDatabaseExportStorageNodesData(final ShardingSphereDatabase database) { Map storageNodes = new LinkedHashMap<>(); - for (Entry entry : database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet()) { + for (Entry entry : database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet()) { ConnectionProperties connectionProps = database.getResourceMetaData().getConnectionProperties(entry.getKey()); String databaseInstanceIp = getDatabaseInstanceIp(connectionProps); if (storageNodes.containsKey(databaseInstanceIp)) { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdater.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdater.java index 7abd6c9f33916..08ea49a23840a 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdater.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataUpdater.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.updater.ConnectionSessionRequiredRALUpdater; @@ -60,7 +60,7 @@ public void executeUpdate(final ConnectionSession connectionSession, final Refre } } - private void checkStorageUnitMetaData(final String databaseName, final Map storageUnitMetaDataMap, final RefreshTableMetaDataStatement sqlStatement) { + private void checkStorageUnitMetaData(final String databaseName, final Map storageUnitMetaDataMap, final RefreshTableMetaDataStatement sqlStatement) { ShardingSpherePreconditions.checkState(!storageUnitMetaDataMap.isEmpty(), () -> new EmptyStorageUnitException(databaseName)); if (sqlStatement.getStorageUnitName().isPresent()) { String storageUnitName = sqlStatement.getStorageUnitName().get(); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/NewRuleDefinitionBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/NewRuleDefinitionBackendHandler.java index 7e74c242bcde9..4779ff9e64e72 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/NewRuleDefinitionBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/NewRuleDefinitionBackendHandler.java @@ -133,7 +133,7 @@ private Collection processAlter(final ShardingSphereDatabase da private RuleConfiguration decorateRuleConfiguration(final ShardingSphereDatabase database, final RuleConfiguration ruleConfig) { Optional decorator = TypedSPILoader.findService(RuleConfigurationDecorator.class, ruleConfig.getClass()); return decorator.map(optional -> optional.decorate(database.getName(), - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), database.getRuleMetaData().getRules(), ruleConfig)).orElse(ruleConfig); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/RuleDefinitionBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/RuleDefinitionBackendHandler.java index 561d0ce961ad7..01d091d647d15 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/RuleDefinitionBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/RuleDefinitionBackendHandler.java @@ -105,7 +105,7 @@ private Collection processSQLStatement(final ShardingSphereDa private RuleConfiguration decorateRuleConfiguration(final ShardingSphereDatabase database, final RuleConfiguration ruleConfig) { Optional decorator = TypedSPILoader.findService(RuleConfigurationDecorator.class, ruleConfig.getClass()); return decorator.map(optional -> optional.decorate(database.getName(), - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), database.getRuleMetaData().getRules(), ruleConfig)).orElse(ruleConfig); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandler.java index c3bd0c2ed2552..86074f2e642e3 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandler.java @@ -34,7 +34,7 @@ import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; @@ -101,13 +101,13 @@ private Collection getDuplicatedStorageUnitNames(final Collection storageUnitNames) { - Map metaDataMap = ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(); + Map metaDataMap = ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap(); Collection notExistedStorageUnitNames = storageUnitNames.stream().filter(each -> !metaDataMap.containsKey(each)).collect(Collectors.toList()); ShardingSpherePreconditions.checkState(notExistedStorageUnitNames.isEmpty(), () -> new MissingRequiredStorageUnitsException(databaseName, notExistedStorageUnitNames)); } private void checkDatabase(final String databaseName, final AlterStorageUnitStatement sqlStatement) { - Map metaDataMap = ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(); + Map metaDataMap = ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap(); Collection invalidStorageUnitNames = sqlStatement.getStorageUnits().stream().collect(Collectors.toMap(DataSourceSegment::getName, each -> each)).entrySet().stream() .filter(each -> !isIdenticalDatabase(each.getValue(), metaDataMap.get(each.getKey()).getDataSource())).map(Entry::getKey).collect(Collectors.toSet()); ShardingSpherePreconditions.checkState(invalidStorageUnitNames.isEmpty(), diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java index f2da5e6dbaf8f..7003636bb0177 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.server.ShardingSphereServerException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; @@ -71,7 +71,7 @@ public void checkSQLStatement(final String databaseName, final UnregisterStorage } private void checkExisted(final String databaseName, final Collection storageUnitNames) { - Map metaDataMap = ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(); + Map metaDataMap = ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap(); Collection notExistedStorageUnits = storageUnitNames.stream().filter(each -> !metaDataMap.containsKey(each)).collect(Collectors.toList()); ShardingSpherePreconditions.checkState(notExistedStorageUnits.isEmpty(), () -> new MissingRequiredStorageUnitsException(databaseName, notExistedStorageUnits)); } @@ -79,7 +79,7 @@ private void checkExisted(final String databaseName, final Collection st private void checkInUsed(final String databaseName, final UnregisterStorageUnitStatement sqlStatement) { ShardingSphereDatabase database = ProxyContext.getInstance().getDatabase(databaseName); Map> inUsedStorageUnits = StorageUnitUtils.getInUsedStorageUnits( - database.getRuleMetaData(), database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size()); + database.getRuleMetaData(), database.getResourceMetaData().getStorageUnitMetaDataMap().size()); Collection inUsedStorageUnitNames = inUsedStorageUnits.keySet(); inUsedStorageUnitNames.retainAll(sqlStatement.getStorageUnitNames()); if (!inUsedStorageUnitNames.isEmpty()) { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java index 38aa774bcb5dd..13aa258b7f531 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java @@ -62,7 +62,7 @@ public final class ShowRulesUsedStorageUnitExecutor implements RQLExecutor getRows(final ShardingSphereDatabase database, final ShowRulesUsedStorageUnitStatement sqlStatement) { Collection result = new LinkedList<>(); String resourceName = sqlStatement.getStorageUnitName().orElse(null); - if (database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().containsKey(resourceName)) { + if (database.getResourceMetaData().getStorageUnitMetaDataMap().containsKey(resourceName)) { result.addAll(getShardingData(database)); result.addAll(getReadwriteSplittingData(database, resourceName)); result.addAll(getEncryptData(database)); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java index 725603ef8f6d5..4c7eb89236da5 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.util.json.JsonUtils; import org.apache.shardingsphere.proxy.backend.util.StorageUnitUtils; @@ -90,15 +90,15 @@ private Map getCustomProps(final Map customProps } private Map getDataSourcePoolPropertiesMap(final ShardingSphereDatabase database, final ShowStorageUnitsStatement sqlStatement) { - Map result = new LinkedHashMap<>(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size(), 1F); - Map propsMap = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map result = new LinkedHashMap<>(database.getResourceMetaData().getStorageUnitMetaDataMap().size(), 1F); + Map propsMap = database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> currentValue, LinkedHashMap::new)); - Map metaDataMap = database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(); + Map metaDataMap = database.getResourceMetaData().getStorageUnitMetaDataMap(); Optional usageCount = sqlStatement.getUsageCount(); if (usageCount.isPresent()) { Map> inUsedStorageUnits = StorageUnitUtils.getInUsedStorageUnits( - database.getRuleMetaData(), database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().size()); - for (Entry entry : database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet()) { + database.getRuleMetaData(), database.getResourceMetaData().getStorageUnitMetaDataMap().size()); + for (Entry entry : database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet()) { Integer currentUsageCount = inUsedStorageUnits.containsKey(entry.getKey()) ? inUsedStorageUnits.get(entry.getKey()).size() : 0; if (usageCount.get().equals(currentUsageCount)) { result.put(entry.getKey(), @@ -106,7 +106,7 @@ private Map getDataSourcePoolPropertiesMap(fin } } } else { - for (Entry entry : metaDataMap.entrySet()) { + for (Entry entry : metaDataMap.entrySet()) { result.put(entry.getKey(), getDataSourcePoolProperties(propsMap, entry.getKey(), metaDataMap.get(entry.getKey()).getStorageUnit().getStorageType(), entry.getValue().getDataSource())); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewExecutor.java index 9d41a7af701b5..1131111ed1ad9 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewExecutor.java @@ -168,7 +168,7 @@ private DriverExecutionPrepareEngine createDriver return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, connectionSession.getDatabaseConnectionManager(), (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(isReturnGeneratedKeys), metaDataContexts.getMetaData().getDatabase(getDatabaseName(connectionSession)).getRuleMetaData().getRules(), - metaDataContexts.getMetaData().getDatabase(getDatabaseName(connectionSession)).getResourceMetaData().getStorageUnitMetaData()); + metaDataContexts.getMetaData().getDatabase(getDatabaseName(connectionSession)).getResourceMetaData().getStorageUnitMetaDataMap()); } private String getDatabaseName(final ConnectionSession connectionSession) { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java index 70a638d47a9ab..c224c907b45b1 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper; @@ -84,11 +84,11 @@ private static void appendDatabaseName(final String databaseName, final StringBu } private static void appendDataSourceConfigurations(final ShardingSphereDatabase database, final StringBuilder stringBuilder) { - if (database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().isEmpty()) { + if (database.getResourceMetaData().getStorageUnitMetaDataMap().isEmpty()) { return; } stringBuilder.append("dataSources:").append(System.lineSeparator()); - for (Entry entry : database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet()) { + for (Entry entry : database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet()) { appendDataSourceConfiguration(entry.getKey(), entry.getValue().getDataSourcePoolProperties(), stringBuilder); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java index add3f8d268b76..bab3e6f3a6e44 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java @@ -44,7 +44,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapUtils; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration; @@ -132,7 +132,7 @@ public void importDatabaseConfiguration(final YamlProxyDatabaseConfiguration yam private void checkDatabase(final String databaseName) { ShardingSpherePreconditions.checkNotNull(databaseName, () -> new UnsupportedSQLOperationException("Property `databaseName` in imported config is required")); if (ProxyContext.getInstance().databaseExists(databaseName)) { - ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().isEmpty(), + ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap().isEmpty(), () -> new UnsupportedSQLOperationException(String.format("Database `%s` exists and is not empty,overwrite is not supported", databaseName))); } } @@ -160,11 +160,11 @@ private void addResources(final String databaseName, final Map metaDataMap = ProxyContext.getInstance().getContextManager() - .getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap(); + Map metaDataMap = ProxyContext.getInstance().getContextManager() + .getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap(); Map toBeAddedStorageNode = StorageUnitNodeMapUtils.fromDataSourcePoolProperties(propsMap); for (Entry entry : propsMap.entrySet()) { - metaDataMap.put(entry.getKey(), new NewStorageUnitMetaData(databaseName, toBeAddedStorageNode.get(entry.getKey()), entry.getValue(), DataSourcePoolCreator.create(entry.getValue()))); + metaDataMap.put(entry.getKey(), new StorageUnitMetaData(databaseName, toBeAddedStorageNode.get(entry.getKey()), entry.getValue(), DataSourcePoolCreator.create(entry.getValue()))); } } @@ -252,7 +252,7 @@ private void addShardingRuleConfiguration(final ShardingRuleConfiguration shardi InstanceContext instanceContext = ProxyContext.getInstance().getContextManager().getInstanceContext(); shardingRuleConfigImportChecker.check(database, shardingRuleConfig); allRuleConfigs.add(shardingRuleConfig); - database.getRuleMetaData().getRules().add(new ShardingRule(shardingRuleConfig, database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().keySet(), instanceContext)); + database.getRuleMetaData().getRules().add(new ShardingRule(shardingRuleConfig, database.getResourceMetaData().getStorageUnitMetaDataMap().keySet(), instanceContext)); } private void addReadwriteSplittingRuleConfiguration(final ReadwriteSplittingRuleConfiguration readwriteSplittingRuleConfig, @@ -285,7 +285,7 @@ private void addMaskRuleConfiguration(final MaskRuleConfiguration maskRuleConfig private void addBroadcastRuleConfiguration(final BroadcastRuleConfiguration broadcastRuleConfig, final Collection allRuleConfigs, final ShardingSphereDatabase database) { allRuleConfigs.add(broadcastRuleConfig); database.getRuleMetaData().getRules().add(new BroadcastRule(broadcastRuleConfig, database.getName(), - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)))); } @@ -293,7 +293,7 @@ private void addSingleRuleConfiguration(final SingleRuleConfiguration broadcastR allRuleConfigs.add(broadcastRuleConfig); database.getRuleMetaData().getRules().add( new SingleRule(broadcastRuleConfig, database.getName(), - database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + database.getResourceMetaData().getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), database.getRuleMetaData().getRules())); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java index f4c0b6501e3d2..1ed6d8b10a8a7 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java @@ -96,7 +96,7 @@ private Map createDatabases() { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getProtocolType()).thenReturn(databaseType); for (Entry entry : mockDataSources(2).entrySet()) { - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().get(entry.getKey()).getDataSource()).thenReturn(entry.getValue()); + when(database.getResourceMetaData().getStorageUnitMetaDataMap().get(entry.getKey()).getDataSource()).thenReturn(entry.getValue()); } return Collections.singletonMap("schema", database); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java index cf8199123d6cd..96eddf0ed5633 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -71,8 +71,8 @@ void assertGetColumns() { @Test void assertExecute() { when(database.getName()).thenReturn("normal_db"); - Map metaDataMap = createStorageUnitMetaDataMap(); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = createStorageUnitMetaDataMap(); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createShardingRuleConfiguration())); Collection actual = new ExportDatabaseConfigurationExecutor().getRows(database, new ExportDatabaseConfigurationStatement(mock(DatabaseSegment.class), null)); assertThat(actual.size(), is(1)); @@ -80,14 +80,14 @@ void assertExecute() { assertThat(row.getCell(1), is(loadExpectedRow())); } - private Map createStorageUnitMetaDataMap() { + private Map createStorageUnitMetaDataMap() { Map propsMap = createDataSourceMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); - Map result = new LinkedHashMap<>(); + Map result = new LinkedHashMap<>(); for (Entry entry : propsMap.entrySet()) { StorageUnit storageUnit = mock(StorageUnit.class); when(storageUnit.getDataSourcePoolProperties()).thenReturn(entry.getValue()); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit()).thenReturn(storageUnit); when(storageUnitMetaData.getDataSourcePoolProperties()).thenReturn(entry.getValue()); result.put(entry.getKey(), storageUnitMetaData); @@ -98,7 +98,7 @@ private Map createStorageUnitMetaDataMap() { @Test void assertExecuteWithEmptyDatabase() { when(database.getName()).thenReturn("empty_db"); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.emptyMap()); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.emptyMap()); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); ExportDatabaseConfigurationStatement sqlStatement = new ExportDatabaseConfigurationStatement(new DatabaseSegment(0, 0, new IdentifierValue("empty_db")), null); Collection actual = new ExportDatabaseConfigurationExecutor().getRows(database, sqlStatement); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java index 2a24cf8c69e1c..09d1e77894211 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java @@ -38,7 +38,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; @@ -111,7 +111,7 @@ void assertExecuteWithEmptyMetaData() { when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); when(ProxyContext.getInstance().getAllDatabaseNames()).thenReturn(Collections.singleton("empty_metadata")); when(database.getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singleton("empty_metadata")); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.emptyMap()); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.emptyMap()); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); ExportMetaDataStatement sqlStatement = new ExportMetaDataStatement(null); Collection actual = new ExportMetaDataExecutor().getRows(contextManager.getMetaDataContexts().getMetaData(), sqlStatement); @@ -134,8 +134,8 @@ private ContextManager mockEmptyContextManager() { void assertExecute() { when(database.getName()).thenReturn("normal_db"); when(database.getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singleton("empty_metadata")); - Map metaDataMap = createStorageUnitMetaDataMap(); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = createStorageUnitMetaDataMap(); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); ContextManager contextManager = mockContextManager(); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); @@ -147,12 +147,12 @@ void assertExecute() { assertThat(row.getCell(3).toString(), is(loadExpectedRow())); } - private Map createStorageUnitMetaDataMap() { + private Map createStorageUnitMetaDataMap() { Map propsMap = createDataSourceMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); - Map result = new LinkedHashMap<>(); + Map result = new LinkedHashMap<>(); for (Entry entry : propsMap.entrySet()) { - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getDataSourcePoolProperties()).thenReturn(entry.getValue()); result.put(entry.getKey(), storageUnitMetaData); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java index 0d3f50a134d36..9904ae0aaca5b 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutorTest.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; @@ -130,8 +130,8 @@ private ContextManager mockEmptyContextManager() { @Test void assertExecute() { when(database.getName()).thenReturn("normal_db"); - Map metaDataMap = createStorageUnitMetaDataMap(); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = createStorageUnitMetaDataMap(); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createShardingRuleConfiguration())); ContextManager contextManager = mockContextManager(); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); @@ -144,8 +144,8 @@ void assertExecute() { @Test void assertExecuteWithDatabaseName() { when(database.getName()).thenReturn("normal_db"); - Map metaDataMap = createStorageUnitMetaDataMap(); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = createStorageUnitMetaDataMap(); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createShardingRuleConfiguration())); ContextManager contextManager = mockContextManager(); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); @@ -165,18 +165,18 @@ private ContextManager mockContextManager() { return result; } - private Map createStorageUnitMetaDataMap() { - NewStorageUnitMetaData storageUnitMetaData1 = mock(NewStorageUnitMetaData.class); + private Map createStorageUnitMetaDataMap() { + StorageUnitMetaData storageUnitMetaData1 = mock(StorageUnitMetaData.class); StorageUnit storageUnit1 = createStorageUnit("demo_ds_0"); when(storageUnitMetaData1.getStorageUnit()).thenReturn(storageUnit1); DataSource dataSource1 = storageUnit1.getDataSource(); when(storageUnitMetaData1.getDataSource()).thenReturn(dataSource1); - NewStorageUnitMetaData storageUnitMetaData2 = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData2 = mock(StorageUnitMetaData.class); StorageUnit storageUnit2 = createStorageUnit("demo_ds_1"); when(storageUnitMetaData2.getStorageUnit()).thenReturn(storageUnit2); DataSource dataSource2 = storageUnit2.getDataSource(); when(storageUnitMetaData2.getDataSource()).thenReturn(dataSource2); - Map result = new LinkedHashMap<>(2, 1F); + Map result = new LinkedHashMap<>(2, 1F); result.put("ds_0", storageUnitMetaData1); result.put("ds_1", storageUnitMetaData2); return result; diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java index 719aa2ca260d1..44ac26d42e6b7 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java @@ -28,7 +28,6 @@ import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException; @@ -137,7 +136,6 @@ private ContextManager mockContextManager(final String databaseName) { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class); - when(resourceMetaData.getStorageUnitMetaData()).thenReturn(mock(StorageUnitMetaData.class)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java index 2bd2642b379a8..988adfaa10858 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; 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; @@ -110,18 +110,18 @@ private ContextManager mockContextManager(final String feature) { if (null != feature) { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(new ShardingSphereSchema(createTableMap(), Collections.emptyMap())); - Map metaDataMap = createStorageUnitMetaDataMap(); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + Map metaDataMap = createStorageUnitMetaDataMap(); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); when(result.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap(feature, database)); when(result.getMetaDataContexts().getMetaData().getDatabase(feature)).thenReturn(database); } return result; } - private Map createStorageUnitMetaDataMap() { - Map result = new LinkedHashMap<>(2, 1F); - result.put("ds_0", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); - result.put("ds_1", new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + private Map createStorageUnitMetaDataMap() { + Map result = new LinkedHashMap<>(2, 1F); + result.put("ds_0", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + result.put("ds_1", new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); return result; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandlerTest.java index 45d66bf43b6b1..72b8cfc236d22 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/AlterStorageUnitBackendHandlerTest.java @@ -29,7 +29,7 @@ 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; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -80,9 +80,9 @@ void assertExecute() { when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); when(ProxyContext.getInstance().getDatabase("foo_db")).thenReturn(database); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getDataSource()).thenReturn(mockHikariDataSource("ds_0")); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", storageUnitMetaData)); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", storageUnitMetaData)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); assertThat(handler.execute("foo_db", createAlterStorageUnitStatement("ds_0")), instanceOf(UpdateResponseHeader.class)); } @@ -107,9 +107,9 @@ void assertExecuteWithAlterDatabase() { when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); when(ProxyContext.getInstance().getDatabase("foo_db")).thenReturn(database); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getDataSource()).thenReturn(mockHikariDataSource("ds_1")); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", storageUnitMetaData)); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", storageUnitMetaData)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); assertThrows(InvalidStorageUnitsException.class, () -> handler.execute("foo_db", createAlterStorageUnitStatement("ds_0"))); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java index 69af68c851adb..ce92452369544 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -85,8 +85,8 @@ class UnregisterStorageUnitBackendHandlerTest { @BeforeEach void setUp() { resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - NewStorageUnitMetaData storageUnitMetaData = new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource()); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + StorageUnitMetaData storageUnitMetaData = new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource()); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); contextManager = mockContextManager(); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); @@ -105,9 +105,9 @@ private ContextManager mockContextManager() { @Test void assertExecute() throws SQLException { - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getDataSource()).thenReturn(new MockedDataSource()); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); when(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database); UnregisterStorageUnitStatement unregisterStorageUnitStatement = new UnregisterStorageUnitStatement(Collections.singleton("foo_ds"), false); @@ -117,7 +117,7 @@ void assertExecute() throws SQLException { @Test void assertStorageUnitNameNotExistedExecute() { - when(ProxyContext.getInstance().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.emptyMap()); + when(ProxyContext.getInstance().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.emptyMap()); assertThrows(MissingRequiredStorageUnitsException.class, () -> handler.execute("foo_db", new UnregisterStorageUnitStatement(Collections.singleton("foo_ds"), false))); } @@ -125,9 +125,9 @@ void assertStorageUnitNameNotExistedExecute() { void assertStorageUnitNameInUseExecute() { when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(shadowRule))); when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("foo_ds"))); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getDataSource()).thenReturn(new MockedDataSource()); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); when(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database); assertThrows(StorageUnitInUsedException.class, @@ -140,9 +140,9 @@ void assertStorageUnitNameInUseWithoutIgnoreSingleTables() { DataNode dataNode = mock(DataNode.class); when(dataNode.getDataSourceName()).thenReturn("foo_ds"); when(singleRule.getAllDataNodes()).thenReturn(Collections.singletonMap("", Collections.singleton(dataNode))); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getDataSource()).thenReturn(new MockedDataSource()); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); when(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database); assertThrows(StorageUnitInUsedException.class, () -> handler.execute("foo_db", new UnregisterStorageUnitStatement(Collections.singleton("foo_ds"), false))); @@ -154,9 +154,9 @@ void assertStorageUnitNameInUseIgnoreSingleTables() throws SQLException { DataNode dataNode = mock(DataNode.class); when(dataNode.getDataSourceName()).thenReturn("foo_ds"); when(singleRule.getAllDataNodes()).thenReturn(Collections.singletonMap("", Collections.singleton(dataNode))); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getDataSource()).thenReturn(new MockedDataSource()); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); when(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database); UnregisterStorageUnitStatement unregisterStorageUnitStatement = new UnregisterStorageUnitStatement(Collections.singleton("foo_ds"), true); diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java index fb52e3c1892e1..24aa23bf588a7 100644 --- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java +++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutor.java @@ -95,7 +95,7 @@ protected Collection getDatabaseNames(final ConnectionSession connection @Override protected void preProcess(final String databaseName, final Map rows, final Map alias) { ResourceMetaData resourceMetaData = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData(); - Collection catalogs = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().keySet() + Collection catalogs = resourceMetaData.getStorageUnitMetaDataMap().keySet() .stream().map(each -> resourceMetaData.getConnectionProperties(each).getCatalog()).collect(Collectors.toSet()); schemaNameAlias = alias.getOrDefault(SCHEMA_NAME, ""); String rowValue = rows.getOrDefault(schemaNameAlias, "").toString(); diff --git a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java index 7ef0dac7a86db..ef8cbef1489e5 100644 --- a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java +++ b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java @@ -100,7 +100,7 @@ private DriverExecutionPrepareEngine createDriver return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, connectionSession.getDatabaseConnectionManager(), connectionSession.getStatementManager(), new StatementOption(false), metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRules(), - metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaData()); + metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData().getStorageUnitMetaDataMap()); } private JDBCExecutorCallback createOpenGaussSystemCatalogAdminQueryCallback(final DatabaseType protocolType, final ResourceMetaData resourceMetaData, diff --git a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java index 2d745e21811df..dab6dc4833deb 100644 --- a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java +++ b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java @@ -76,9 +76,9 @@ private static void setDatabaseVersion(final ShardingSphereDatabase database) { } private static Optional findDataSourceByProtocolType(final String databaseName, final ResourceMetaData resourceMetaData, final DatabaseType protocolType) { - Optional dataSourceName = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet() + Optional dataSourceName = resourceMetaData.getStorageUnitMetaDataMap().entrySet() .stream().filter(entry -> entry.getValue().getStorageUnit().getStorageType().equals(protocolType)).map(Entry::getKey).findFirst(); - Map dataSources = resourceMetaData.getStorageUnitMetaData().getMetaDataMap().entrySet().stream() + Map dataSources = resourceMetaData.getStorageUnitMetaDataMap().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); return dataSourceName.flatMap(optional -> Optional.ofNullable(DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, dataSources).get(optional))); } diff --git a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java index 26a73589af23c..cd4178533cb4a 100644 --- a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java +++ b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -83,8 +83,8 @@ private ShardingSphereDatabase mockDatabase(final String databaseProductName, fi private ResourceMetaData mockResourceMetaData(final String databaseProductName, final String databaseProductVersion) throws SQLException { ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); DataSource dataSource = createDataSource(databaseProductName, databaseProductVersion); - NewStorageUnitMetaData storageUnitMetaData = new NewStorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), dataSource); - when(result.getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + StorageUnitMetaData storageUnitMetaData = new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), dataSource); + when(result.getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); return result; } diff --git a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java index 7aae335bac2f9..66cd6efc4113b 100644 --- a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java +++ b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactory.java @@ -51,7 +51,8 @@ public static DatabaseType getDatabaseType() { return TypedSPILoader.getService(DatabaseType.class, DEFAULT_FRONTEND_DATABASE_PROTOCOL_TYPE); } Optional database = metaDataContexts.getMetaData().getDatabases().values().stream().filter(ShardingSphereDatabase::containsDataSource).findFirst(); - return database.isPresent() ? database.get().getResourceMetaData().getStorageUnitMetaData().getMetaDataMap().values().iterator().next().getStorageUnit().getStorageType() + return database.isPresent() + ? database.get().getResourceMetaData().getStorageUnitMetaDataMap().values().iterator().next().getStorageUnit().getStorageType() : TypedSPILoader.getService(DatabaseType.class, DEFAULT_FRONTEND_DATABASE_PROTOCOL_TYPE); } diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java index 7cf088c7b45eb..f26f71fc5b7bf 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java @@ -140,7 +140,7 @@ public ResponseHeader execute() throws SQLException { DriverExecutionPrepareEngine prepareEngine = new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, metaDataContexts.getMetaData().getProps() .getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), connectionSession.getDatabaseConnectionManager(), (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(false), rules, - metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getResourceMetaData().getStorageUnitMetaData()); + metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getResourceMetaData().getStorageUnitMetaDataMap()); ExecutionGroupContext executionGroupContext = prepareEngine.prepare(anyExecutionContext.getRouteContext(), samplingExecutionUnit(), new ExecutionGroupReportContext(connectionSession.getProcessId(), connectionSession.getDatabaseName(), connectionSession.getGrantee())); for (ExecutionGroup eachGroup : executionGroupContext.getInputGroups()) { diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java index 5f2b906666c59..9d8ec06a38cdb 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; @@ -105,9 +105,9 @@ private ConnectionSession mockConnectionSession() throws SQLException { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singletonList("foo_ds")); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit().getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); - when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()) + when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaDataMap()) .thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL")); when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getRuleMetaData()) diff --git a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java index f9eaf2c296826..5a08f2d524d9e 100644 --- a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java +++ b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; @@ -140,9 +140,9 @@ private ContextManager mockContextManager() { private ShardingSphereDatabase mockDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(result.getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singleton("foo_ds")); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit().getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "openGauss")); - when(result.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.emptyList())); when(result.containsSchema("public")).thenReturn(true); when(result.getSchema("public").containsTable("bmsql")).thenReturn(true); diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java index bff136ac995c7..263fc0720d1f1 100644 --- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java +++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java @@ -151,7 +151,7 @@ private void addBatchedParametersToPreparedStatements() throws SQLException { DriverExecutionPrepareEngine prepareEngine = new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT, metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), connectionSession.getDatabaseConnectionManager(), (JDBCBackendStatement) connectionSession.getStatementManager(), - new StatementOption(false), rules, metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getResourceMetaData().getStorageUnitMetaData()); + new StatementOption(false), rules, metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getResourceMetaData().getStorageUnitMetaDataMap()); executionGroupContext = prepareEngine.prepare(anyExecutionContext.getRouteContext(), executionUnitParams.keySet(), new ExecutionGroupReportContext(connectionSession.getProcessId(), connectionSession.getDatabaseName(), connectionSession.getGrantee())); for (ExecutionGroup eachGroup : executionGroupContext.getInputGroups()) { diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java index c0e6b196116a5..56c9b39e35971 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java @@ -35,7 +35,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; @@ -158,9 +158,9 @@ private ContextManager mockContextManager() { when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singletonList("foo_ds")); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit().getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.emptyList())); when(database.containsSchema("public")).thenReturn(true); when(database.getSchema("public").containsTable("t_order")).thenReturn(true); diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java index 57fba5cc5dde8..f31324877e9b9 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; @@ -133,9 +133,9 @@ private ContextManager mockContextManager() { when(result.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY)).thenReturn(1); when(result.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.SQL_SHOW)).thenReturn(false); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit().getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); - when(database.getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", storageUnitMetaData)); + when(database.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("ds_0", storageUnitMetaData)); when(database.getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singletonList("ds_0")); when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.emptyList())); when(database.containsSchema("public")).thenReturn(true); diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java index 0a1dd82995b3c..9f7a4dbaffb8e 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java @@ -36,7 +36,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -400,9 +400,9 @@ private ContextManager mockContextManager() { when(schema.getTable(TABLE_NAME)).thenReturn(table); when(schema.getAllColumnNames(TABLE_NAME)).thenReturn(Arrays.asList("id", "k", "c", "pad")); when(result.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME).getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class, RETURNS_DEEP_STUBS); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit().getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); - when(result.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME).getResourceMetaData().getStorageUnitMetaData().getMetaDataMap()) + when(result.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME).getResourceMetaData().getStorageUnitMetaDataMap()) .thenReturn(Collections.singletonMap("ds_0", storageUnitMetaData)); when(result.getMetaDataContexts().getMetaData().containsDatabase(DATABASE_NAME)).thenReturn(true); when(result.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME).containsSchema("public")).thenReturn(true); diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java index 7944e4c9644ae..d6c4193f6e01c 100644 --- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java +++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java @@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.resource.unit.NewStorageUnitMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -121,9 +121,9 @@ private Collection createSQLRewriteUnits(final SQLRewriteEngineT new YamlDataSourceConfigurationSwapper().swapToDataSources(rootConfig.getDataSources()), new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(rootConfig.getRules())); mockDataSource(databaseConfig.getDataSources()); DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, testParams.getDatabaseType()); - Map metaDataMap = createStorageUnitMetaDataMap(databaseConfig, databaseType); + Map metaDataMap = createStorageUnitMetaDataMap(databaseConfig, databaseType); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); - when(resourceMetaData.getStorageUnitMetaData().getMetaDataMap()).thenReturn(metaDataMap); + when(resourceMetaData.getStorageUnitMetaDataMap()).thenReturn(metaDataMap); String schemaName = new DatabaseTypeRegistry(databaseType).getDefaultSchemaName(DefaultDatabase.LOGIC_NAME); SQLStatementParserEngine sqlStatementParserEngine = new SQLStatementParserEngine(TypedSPILoader.getService(DatabaseType.class, testParams.getDatabaseType()), sqlParserRule.getSqlStatementCache(), sqlParserRule.getParseTreeCache(), sqlParserRule.isSqlCommentParseEnabled()); @@ -171,12 +171,12 @@ private Collection createGlobalRules() { return result; } - private Map createStorageUnitMetaDataMap(final DatabaseConfiguration databaseConfig, final DatabaseType databaseType) { - Map result = new LinkedHashMap<>(databaseConfig.getDataSources().size(), 1F); + private Map createStorageUnitMetaDataMap(final DatabaseConfiguration databaseConfig, final DatabaseType databaseType) { + Map result = new LinkedHashMap<>(databaseConfig.getDataSources().size(), 1F); for (Entry entry : databaseConfig.getDataSources().entrySet()) { StorageUnit storageUnit = mock(StorageUnit.class); when(storageUnit.getStorageType()).thenReturn(databaseType); - NewStorageUnitMetaData storageUnitMetaData = mock(NewStorageUnitMetaData.class); + StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class); when(storageUnitMetaData.getStorageUnit()).thenReturn(storageUnit); result.put(entry.getKey(), storageUnitMetaData); }