diff --git a/docs/community/content/powered-by/_index.cn.md b/docs/community/content/powered-by/_index.cn.md index 28d37bfee59a1..d86b3197ca85b 100644 --- a/docs/community/content/powered-by/_index.cn.md +++ b/docs/community/content/powered-by/_index.cn.md @@ -13,7 +13,7 @@ chapter = true ## 谁在使用 ShardingSphere? -共计 203 家公司。 +共计 206 家公司。 ### 基础软件 ### 出行 @@ -299,6 +300,8 @@ chapter = true
  • 未来医生
  • 思派网络
  • 朝前科技
  • +
  • 绿葆
  • +
  • 伊丽汇
  • ### 招聘 diff --git a/docs/community/content/powered-by/_index.en.md b/docs/community/content/powered-by/_index.en.md index 96911c175e5dd..dc61ab3a4414e 100644 --- a/docs/community/content/powered-by/_index.en.md +++ b/docs/community/content/powered-by/_index.en.md @@ -13,7 +13,7 @@ Please register [here](https://github.com/apache/shardingsphere/discussions/1225 ## Who is Using ShardingSphere? -Total: 203 companies. +Total: 206 companies. ### Infra Software ### Transportation @@ -222,7 +223,7 @@ Total: 203 companies. ### Public Utilities ### Recruitment diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java index a00f501202401..55d59f1b18c8b 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.agent.metrics.api.util.MetricsUtil; import org.apache.shardingsphere.agent.metrics.prometheus.wrapper.PrometheusWrapperFactory; import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -65,21 +65,21 @@ public List collect() { private void collectProxy(final GaugeMetricFamily metricFamily) { MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); - metricFamily.addMetric(Collections.singletonList(LOGIC_DB_COUNT), metaDataContexts.getMetaDataMap().size()); + metricFamily.addMetric(Collections.singletonList(LOGIC_DB_COUNT), metaDataContexts.getDatabaseMetaDataMap().size()); metricFamily.addMetric(Collections.singletonList(ACTUAL_DB_COUNT), getDatabaseNames(metaDataContexts).size()); } private Collection getDatabaseNames(final MetaDataContexts metaDataContexts) { Collection result = new HashSet<>(); - for (ShardingSphereMetaData each : metaDataContexts.getMetaDataMap().values()) { + for (ShardingSphereDatabaseMetaData each : metaDataContexts.getDatabaseMetaDataMap().values()) { result.addAll(getDatabaseNames(each)); } return result; } - private Collection getDatabaseNames(final ShardingSphereMetaData metaData) { + private Collection getDatabaseNames(final ShardingSphereDatabaseMetaData databaseMetaData) { Collection result = new HashSet<>(); - for (DataSource each : metaData.getResource().getDataSources().values()) { + for (DataSource each : databaseMetaData.getResource().getDataSources().values()) { getDatabaseName(each).ifPresent(result::add); } return result; diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/ProxyContextRestorer.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/ProxyContextRestorer.java new file mode 100644 index 0000000000000..ad1ef1c442a2c --- /dev/null +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/ProxyContextRestorer.java @@ -0,0 +1,38 @@ +/* + * 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.agent.metrics.prometheus; + +import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.proxy.backend.context.ProxyContext; +import org.junit.After; +import org.junit.Before; + +public abstract class ProxyContextRestorer { + + private ContextManager currentContextManager; + + @Before + public void recordCurrentContextManager() { + currentContextManager = ProxyContext.getInstance().getContextManager(); + } + + @After + public void restorePreviousContextManager() { + ProxyContext.init(currentContextManager); + } +} diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java index 86dd9ca447deb..8e611f177b81a 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.agent.metrics.prometheus.collector; +import org.apache.shardingsphere.agent.metrics.prometheus.ProxyContextRestorer; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.junit.Test; @@ -25,7 +26,7 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; -public final class MetaDataInfoCollectorTest { +public final class MetaDataInfoCollectorTest extends ProxyContextRestorer { @Test public void assertCollect() { diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java index cc2789bb838d3..1585eb945348e 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.agent.metrics.prometheus.collector; +import org.apache.shardingsphere.agent.metrics.prometheus.ProxyContextRestorer; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.instance.InstanceContext; @@ -25,6 +26,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.memory.workerid.generator.MemoryWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.transaction.context.TransactionContexts; import org.junit.Test; @@ -32,13 +34,13 @@ import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.mock; -public final class ProxyInfoCollectorTest { +public final class ProxyInfoCollectorTest extends ProxyContextRestorer { @Test public void assertCollect() { - ContextManager contextManager = new ContextManager(mock(MetaDataContexts.class), mock(TransactionContexts.class), new InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)), - new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class))); - ProxyContext.init(contextManager); + InstanceContext instanceContext = new InstanceContext( + new ComputeNodeInstance(mock(InstanceDefinition.class)), new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class)); + ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class)), mock(TransactionContexts.class), instanceContext)); assertFalse(new ProxyInfoCollector().collect().isEmpty()); } } diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java index dac2e0fa93458..3e16c9cbb4392 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.agent.metrics.prometheus.service; import org.apache.shardingsphere.agent.config.PluginConfiguration; +import org.apache.shardingsphere.agent.metrics.prometheus.ProxyContextRestorer; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.instance.InstanceContext; @@ -26,6 +27,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.memory.workerid.generator.MemoryWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; +import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.transaction.context.TransactionContexts; import org.junit.AfterClass; @@ -38,7 +40,7 @@ import static org.mockito.Mockito.mock; -public final class PrometheusPluginBootServiceTest { +public final class PrometheusPluginBootServiceTest extends ProxyContextRestorer { private static final PrometheusPluginBootService PROMETHEUS_PLUGIN_BOOT_SERVICE = new PrometheusPluginBootService(); @@ -49,9 +51,9 @@ public static void close() { @Test public void assertStart() throws IOException { - ContextManager contextManager = new ContextManager(mock(MetaDataContexts.class), mock(TransactionContexts.class), new InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)), - new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class))); - ProxyContext.init(contextManager); + InstanceContext instanceContext = new InstanceContext( + new ComputeNodeInstance(mock(InstanceDefinition.class)), new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class)); + ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class)), mock(TransactionContexts.class), instanceContext)); PROMETHEUS_PLUGIN_BOOT_SERVICE.start(new PluginConfiguration("localhost", 8090, "", createProperties())); new Socket().connect(new InetSocketAddress("localhost", 8090)); } diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java new file mode 100644 index 0000000000000..fe5e04c8c3188 --- /dev/null +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java @@ -0,0 +1,38 @@ +/* + * 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.agent.plugin.tracing; + +import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.proxy.backend.context.ProxyContext; +import org.junit.After; +import org.junit.Before; + +public abstract class ProxyContextRestorer { + + private ContextManager currentContextManager; + + @Before + public void recordCurrentContextManager() { + currentContextManager = ProxyContext.getInstance().getContextManager(); + } + + @After + public void restorePreviousContextManager() { + ProxyContext.init(currentContextManager); + } +} diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java index bf504f3981307..639f35d351364 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java @@ -21,6 +21,7 @@ import lombok.Getter; import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject; import org.apache.shardingsphere.agent.plugin.tracing.AgentRunner; +import org.apache.shardingsphere.agent.plugin.tracing.ProxyContextRestorer; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -33,7 +34,7 @@ import static org.mockito.Mockito.mock; @RunWith(AgentRunner.class) -public abstract class AbstractCommandExecutorTaskAdviceTest implements AdviceTestBase { +public abstract class AbstractCommandExecutorTaskAdviceTest extends ProxyContextRestorer implements AdviceTestBase { @Getter private AdviceTargetObject targetObject; diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java index bf6eb134da587..e1a947ff4d8f3 100644 --- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java +++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java @@ -61,9 +61,9 @@ public void prepare() { extraMap = new HashMap<>(); Statement statement = mock(Statement.class); Connection connection = mock(Connection.class); - DatabaseMetaData metaData = mock(DatabaseMetaData.class); - when(metaData.getURL()).thenReturn("mock_url"); - when(connection.getMetaData()).thenReturn(metaData); + DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class); + when(databaseMetaData.getURL()).thenReturn("mock_url"); + when(connection.getMetaData()).thenReturn(databaseMetaData); when(statement.getConnection()).thenReturn(connection); executionUnit = new JDBCExecutionUnit(new ExecutionUnit("mock.db", new SQLUnit("select 1", Collections.emptyList())), null, statement); JDBCExecutorCallback mock = mock(JDBCExecutorCallback.class, invocation -> { diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java index f63b8b43f5fae..4b2dcd29f45f2 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.SQLRouter; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; @@ -41,7 +41,7 @@ public final class DatabaseDiscoverySQLRouter implements SQLRouter { @Override - public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) { + public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) { RouteContext result = new RouteContext(); String dataSourceName = new DatabaseDiscoveryDataSourceRouter(rule.getSingleDataSourceRule()).route(); result.getRouteUnits().add(new RouteUnit(new RouteMapper(DefaultDatabase.LOGIC_NAME, dataSourceName), Collections.emptyList())); @@ -50,7 +50,7 @@ public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSp @Override public void decorateRouteContext(final RouteContext routeContext, - final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) { + final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) { Collection toBeRemoved = new LinkedList<>(); Collection toBeAdded = new LinkedList<>(); for (RouteUnit each : routeContext.getRouteUnits()) { diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java index 6e8eb1f760e72..ec3b20412b335 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java @@ -31,10 +31,12 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants; import org.apache.shardingsphere.infra.exception.ShardingSphereException; +import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent; import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; +import org.apache.shardingsphere.infra.rule.identifier.type.InstanceAwareRule; import org.apache.shardingsphere.infra.rule.identifier.type.StatusContainedRule; import org.apache.shardingsphere.mode.metadata.storage.event.DataSourceNameDisabledEvent; import org.apache.shardingsphere.mode.metadata.storage.event.PrimaryDataSourceChangedEvent; @@ -58,13 +60,17 @@ /** * Database discovery rule. */ -public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContainedRule, StatusContainedRule, ExportableRule { +public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContainedRule, StatusContainedRule, ExportableRule, InstanceAwareRule { private final Map discoveryTypes; @Getter private final Map dataSourceRules; + private final String databaseName; + + private final Map dataSourceMap; + public DatabaseDiscoveryRule(final String databaseName, final Map dataSourceMap, final DatabaseDiscoveryRuleConfiguration config) { this(databaseName, dataSourceMap, config.getDataSources(), config.getDiscoveryHeartbeats(), getDiscoveryProviderAlgorithms(config.getDiscoveryTypes())); } @@ -76,10 +82,11 @@ public DatabaseDiscoveryRule(final String databaseName, final Map dataSourceMap, final Collection dataSourceRuleConfigs, final Map heartBeatConfig, final Map discoveryTypes) { this.discoveryTypes = discoveryTypes; + this.databaseName = databaseName; + this.dataSourceMap = dataSourceMap; dataSourceRules = getDataSourceRules(dataSourceRuleConfigs, heartBeatConfig); findMasterSlaveRelation(databaseName, dataSourceMap); initAware(); - initHeartBeatJobs(databaseName, dataSourceMap); } private static Map getDiscoveryProviderAlgorithms(final Map discoveryTypesConfig) { @@ -178,8 +185,8 @@ private Map exportPrimaryDataSourceMap() { return result; } - private void initHeartBeatJobs(final String databaseName, final Map dataSourceMap) { - Optional modeScheduleContext = ModeScheduleContextFactory.getInstance().get(); + private void initHeartBeatJobs(final InstanceContext instanceContext) { + Optional modeScheduleContext = ModeScheduleContextFactory.getInstance().get(instanceContext.getInstance().getInstanceDefinition().getInstanceId().getId()); if (modeScheduleContext.isPresent()) { for (Entry entry : dataSourceRules.entrySet()) { DatabaseDiscoveryDataSourceRule rule = entry.getValue(); @@ -197,4 +204,9 @@ private void initHeartBeatJobs(final String databaseName, final Map routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE)); } @@ -94,9 +94,9 @@ public void assertCreateRouteContextToPrimaryWithoutRouteUnits() { public void assertDecorateRouteContextToPrimaryDataSource() { RouteContext actual = mockRouteContext(); LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + sqlRouter.decorateRouteContext(actual, logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATA_SOURCE_NAME)); assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE)); @@ -105,9 +105,9 @@ public void assertDecorateRouteContextToPrimaryDataSource() { @Test public void assertCreateRouteContextToPrimaryDataSourceWithLock() { LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE)); } @@ -116,9 +116,9 @@ public void assertCreateRouteContextToPrimaryDataSourceWithLock() { public void assertDecorateRouteContextToPrimaryDataSourceWithLock() { RouteContext actual = mockRouteContext(); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + sqlRouter.decorateRouteContext(actual, logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATA_SOURCE_NAME)); assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE)); @@ -127,9 +127,9 @@ public void assertDecorateRouteContextToPrimaryDataSourceWithLock() { @Test public void assertCreateRouteContextToPrimaryDataSource() { LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE)); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java index e4adf5d34683f..5ed25005ee922 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration; import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryHeartbeatsStatement; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import java.util.Arrays; @@ -39,8 +39,8 @@ public final class DatabaseDiscoveryHeartbeatQueryResultSet implements DistSQLRe private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Collection ruleConfig = metaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class); + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Collection ruleConfig = databaseMetaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class); data = ruleConfig.stream().map(DatabaseDiscoveryRuleConfiguration::getDiscoveryHeartbeats) .flatMap(each -> each.entrySet().stream()).collect(Collectors.toMap(Entry::getKey, Entry::getValue)).entrySet().iterator(); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java index bc9fb39698be3..cce43ac52bc8a 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -64,13 +64,13 @@ public final class DatabaseDiscoveryRuleQueryResultSet implements DistSQLResultS @SuppressWarnings("unchecked") @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof DatabaseDiscoveryRuleConfiguration).map(each -> (DatabaseDiscoveryRuleConfiguration) each).findAny(); data = ruleConfig.map(optional -> optional.getDataSources().iterator()).orElseGet(Collections::emptyIterator); discoveryTypes = ruleConfig.map(DatabaseDiscoveryRuleConfiguration::getDiscoveryTypes).orElseGet(Collections::emptyMap); discoveryHeartbeats = ruleConfig.map(DatabaseDiscoveryRuleConfiguration::getDiscoveryHeartbeats).orElseGet(Collections::emptyMap); - Optional exportableRule = metaData.getRuleMetaData().getRules() + Optional exportableRule = databaseMetaData.getRuleMetaData().getRules() .stream().filter(each -> each instanceof ExportableRule) .filter(each -> ((ExportableRule) each).containExportableKey(Collections.singleton(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE))) .map(each -> (ExportableRule) each).findAny(); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java index 98b7d68d44c74..0dda1dd4ab222 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import java.util.Arrays; @@ -39,8 +39,8 @@ public final class DatabaseDiscoveryTypeQueryResultSet implements DistSQLResultS private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Collection ruleConfig = metaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class); + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Collection ruleConfig = databaseMetaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class); data = ruleConfig.stream().map(DatabaseDiscoveryRuleConfiguration::getDiscoveryTypes) .flatMap(each -> each.entrySet().stream()).collect(Collectors.toMap(Entry::getKey, Entry::getValue)).entrySet().iterator(); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java index 42a4d038c3d7d..f39aa289e2afc 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.Map.Entry; @@ -48,9 +48,9 @@ public void updateCurrentRuleConfiguration(final DatabaseDiscoveryRuleConfigurat } @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterDatabaseDiscoveryHeartbeatStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentConfiguration(databaseName, currentRuleConfig); checkDuplicateHeartbeat(databaseName, sqlStatement); checkNotExistHeartbeat(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java index a26932e5ed099..349c8adc02524 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java @@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import java.util.Collection; @@ -50,12 +50,12 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterDatabaseDiscoveryRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkToBeAlteredRules(databaseName, sqlStatement, currentRuleConfig); - checkToBeAlteredResources(databaseName, sqlStatement, shardingSphereMetaData.getResource()); + checkToBeAlteredResources(databaseName, sqlStatement, databaseMetaData.getResource()); checkDiscoverTypeAndHeartbeat(sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java index cadbf196ac6d3..bc2266dfb28e3 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.Map.Entry; @@ -42,9 +42,9 @@ public final class AlterDatabaseDiscoveryTypeStatementUpdater implements RuleDef private static final String RULE_TYPE = "database discovery"; @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterDatabaseDiscoveryTypeStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkDuplicateDiscoveryType(databaseName, sqlStatement); checkNotExistDiscoveryType(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java index 461785e8fbffa..f3948affbab98 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.Map.Entry; @@ -47,9 +47,9 @@ public void updateCurrentRuleConfiguration(final DatabaseDiscoveryRuleConfigurat } @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateDatabaseDiscoveryHeartbeatStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkDuplicateHeartbeat(databaseName, sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java index 568535cf5ea2e..6a91d05ec26bf 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java @@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import java.util.Collection; @@ -50,11 +50,11 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RuleDe private static final String RULE_TYPE = "Database discovery"; @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateDatabaseDiscoveryRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkDuplicateRuleNames(databaseName, sqlStatement, currentRuleConfig); - checkResources(databaseName, sqlStatement, shardingSphereMetaData.getResource()); + checkResources(databaseName, sqlStatement, databaseMetaData.getResource()); checkDiscoverTypeAndHeartbeat(databaseName, sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java index 5f2a8c9a5f84b..1186de9619f0d 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.Map.Entry; @@ -41,9 +41,9 @@ public final class CreateDatabaseDiscoveryTypeStatementUpdater implements RuleDe private static final String RULE_TYPE = "database discovery"; @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateDatabaseDiscoveryTypeStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkDuplicateDiscoveryType(databaseName, sqlStatement, currentRuleConfig); checkInvalidDiscoverType(sqlStatement); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java index 29bd37524c25c..afd7382d453a7 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.stream.Collectors; @@ -37,9 +37,9 @@ public final class DropDatabaseDiscoveryHeartbeatStatementUpdater implements Rul private static final String RULE_TYPE = "Database discovery"; @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig); checkIsInUse(databaseName, sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java index a3b617929e87c..335c82604544d 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import java.util.Collection; @@ -41,11 +41,11 @@ public final class DropDatabaseDiscoveryRuleStatementUpdater implements RuleDefi private static final String RULE_TYPE = "Database discovery"; @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropDatabaseDiscoveryRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig); - checkIsInUse(databaseName, sqlStatement, shardingSphereMetaData); + checkIsInUse(databaseName, sqlStatement, databaseMetaData); } private void checkCurrentRuleConfiguration(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, @@ -64,8 +64,8 @@ private void checkIsExist(final String databaseName, final DropDatabaseDiscovery DistSQLException.predictionThrow(notExistedRuleNames.isEmpty(), () -> new RequiredRuleMissedException(RULE_TYPE, databaseName)); } - private void checkIsInUse(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereMetaData shardingSphereMetaData) throws DistSQLException { - Collection rulesInUse = shardingSphereMetaData.getRuleMetaData().findRules(ExportableRule.class).stream() + private void checkIsInUse(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereDatabaseMetaData databaseMetaData) throws DistSQLException { + Collection rulesInUse = databaseMetaData.getRuleMetaData().findRules(ExportableRule.class).stream() .filter(each -> each.containExportableKey(Collections.singletonList(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE_NAME))) .map(each -> each.export(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE_NAME)).filter(Optional::isPresent) .map(each -> (Collection) each.get()).flatMap(Collection::stream).collect(Collectors.toSet()); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java index 7916db4271350..0c03bf5c2ed16 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.stream.Collectors; @@ -37,9 +37,9 @@ public final class DropDatabaseDiscoveryTypeStatementUpdater implements RuleDefi private static final String RULE_TYPE = "Database discovery"; @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropDatabaseDiscoveryTypeStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDatabaseDiscoveryTypeStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig); checkIsInUse(databaseName, sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java index 14853ce2d7115..6566a4f41516b 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement; import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import java.util.ArrayList; @@ -45,10 +45,10 @@ public final class DatabaseDiscoveryHeartbeatQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration())); DistSQLResultSet resultSet = new DatabaseDiscoveryHeartbeatQueryResultSet(); - resultSet.init(metaData, mock(ShowDatabaseDiscoveryRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowDatabaseDiscoveryRulesStatement.class)); Collection columnNames = resultSet.getColumnNames(); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(columnNames.size(), is(2)); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryProviderAlgorithmQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryProviderAlgorithmQueryResultSetTest.java index e3febd6de7970..4a4410764e26c 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryProviderAlgorithmQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryProviderAlgorithmQueryResultSetTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import java.util.ArrayList; @@ -45,10 +45,10 @@ public final class DatabaseDiscoveryProviderAlgorithmQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration())); DistSQLResultSet resultSet = new DatabaseDiscoveryTypeQueryResultSet(); - resultSet.init(metaData, mock(ShowDatabaseDiscoveryRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowDatabaseDiscoveryRulesStatement.class)); Collection columnNames = resultSet.getColumnNames(); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(columnNames.size(), is(3)); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java index 4d065ceccef8b..61ee723b87ae4 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import org.junit.Test; @@ -48,13 +48,13 @@ public final class DatabaseDiscoveryRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); ExportableRule exportableRule = mock(ExportableRule.class); when(exportableRule.export(anyCollection())).thenReturn(Collections.emptyMap()); - when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.singleton(exportableRule)); + when(databaseMetaData.getRuleMetaData().getRules()).thenReturn(Collections.singleton(exportableRule)); DistSQLResultSet resultSet = new DatabaseDiscoveryRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowDatabaseDiscoveryRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowDatabaseDiscoveryRulesStatement.class)); Collection columnNames = resultSet.getColumnNames(); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(columnNames.size(), is(5)); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdaterTest.java index 9b25d59dabd9f..5e83027c701ca 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdaterTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -42,16 +42,16 @@ @RunWith(MockitoJUnitRunner.class) public final class AlterDatabaseDiscoveryHeartbeatStatementUpdaterTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; - private final AlterDatabaseDiscoveryHeartbeatStatementUpdater updater = new AlterDatabaseDiscoveryHeartbeatStatementUpdater(); + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private ShardingSphereDatabaseMetaData databaseMetaData; + @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicateHeartbeatNames() throws DistSQLException { DatabaseDiscoveryHeartbeatSegment segment1 = new DatabaseDiscoveryHeartbeatSegment("heartbeat", createProperties("key", "value")); DatabaseDiscoveryHeartbeatSegment segment2 = new DatabaseDiscoveryHeartbeatSegment("heartbeat", createProperties("key", "value")); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryHeartbeatStatement(Arrays.asList(segment1, segment2)), + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryHeartbeatStatement(Arrays.asList(segment1, segment2)), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); } @@ -59,7 +59,7 @@ public void assertCheckSQLStatementWithDuplicateHeartbeatNames() throws DistSQLE public void assertCheckSQLStatementWithNotExistDiscoveryHeartbeatName() throws DistSQLException { DatabaseDiscoveryHeartbeatSegment segment = new DatabaseDiscoveryHeartbeatSegment("heartbeat", createProperties("key", "value")); DatabaseDiscoveryRuleConfiguration config = new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.singletonMap("heartbeat1", null), Collections.emptyMap()); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryHeartbeatStatement(Collections.singleton(segment)), config); + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryHeartbeatStatement(Collections.singleton(segment)), config); } @Test diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java index 5a5a08e6934b7..53681df05bcae 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -49,18 +49,18 @@ @RunWith(MockitoJUnitRunner.class) public final class AlterDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; - private final AlterDatabaseDiscoveryTypeStatementUpdater updater = new AlterDatabaseDiscoveryTypeStatementUpdater(); + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private ShardingSphereDatabaseMetaData databaseMetaData; + @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicate() throws DistSQLException { DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "test"); List algorithmSegments = Arrays.asList( new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())), new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()))); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap(), Collections.emptyMap())); } @@ -68,7 +68,7 @@ public void assertCheckSQLStatementWithDuplicate() throws DistSQLException { public void assertCheckSQLStatementWithNotExist() throws DistSQLException { List algorithmSegments = Collections.singletonList(new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type_1", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()))); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.singletonMap("discovery_type", new ShardingSphereAlgorithmConfiguration("DISTSQL.FIXTURE", new Properties())))); } @@ -77,7 +77,7 @@ public void assertCheckSQLStatementWithNotExist() throws DistSQLException { public void assertCheckSQLStatementWithDatabaseDiscoveryType() throws DistSQLException { Collection algorithmSegments = Collections.singleton( new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("INVALID_TYPE", new Properties()))); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.singletonMap("discovery_type", new ShardingSphereAlgorithmConfiguration("DISTSQL.FIXTURE", new Properties())))); } @@ -92,7 +92,7 @@ public void assertBuildAndUpdate() throws DistSQLException { props.put("key", "value_1"); Set algorithmSegments = Collections.singleton( new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("DISTSQL.FIXTURE", props))); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryTypeStatement(algorithmSegments), currentRuleConfig); DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = (DatabaseDiscoveryRuleConfiguration) updater.buildToBeAlteredRuleConfiguration(new AlterDatabaseDiscoveryTypeStatement(algorithmSegments)); DatabaseDiscoveryRuleConfiguration currentConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(), new LinkedHashMap<>()); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java index 16e9351c28409..e1b780f46aa9d 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.junit.Before; import org.junit.Test; @@ -54,7 +54,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereResource resource; @@ -63,18 +63,18 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdaterTest { @Before public void before() { - when(shardingSphereMetaData.getResource()).thenReturn(resource); + when(databaseMetaData.getResource()).thenReturn(resource); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.emptyList()), null); + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.emptyList()), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeAlteredDatabaseDiscoveryRule() throws DistSQLException { DatabaseDiscoveryConstructionSegment segment = new DatabaseDiscoveryConstructionSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), "", ""); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(segment)), + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(segment)), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); } @@ -85,7 +85,7 @@ public void assertCheckSQLStatementWithoutExistedResources() throws DistSQLExcep DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "TEST"); DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), Collections.singletonMap("readwrite_ds_mgr", null), Collections.singletonMap("readwrite_ds_heartbeat", null)); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(segment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singletonList(segment)), ruleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -95,7 +95,7 @@ public void assertCheckSQLStatementWithDatabaseDiscoveryType() throws DistSQLExc DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "TEST"); DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), Collections.singletonMap("readwrite_ds_mgr", null), Collections.singletonMap("readwrite_ds_heartbeat", null)); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); } @Test(expected = RequiredAlgorithmMissedException.class) @@ -104,7 +104,7 @@ public void assertCheckSQLStatementWithNotExistDiscoveryTypeName() throws DistSQ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "TEST"); DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), Collections.singletonMap("readwrite_ds_mgr", null), Collections.singletonMap("readwrite_ds_heartbeat", null)); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); } @Test(expected = RequiredAlgorithmMissedException.class) @@ -114,7 +114,7 @@ public void assertCheckSQLStatementWithNotExistDiscoveryHeartbeatName() throws D DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "TEST"); DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), Collections.singletonMap("readwrite_ds_mgr", null), Collections.singletonMap("readwrite_ds_heartbeat", null)); - updater.checkSQLStatement(shardingSphereMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new AlterDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdaterTest.java index d009a83f37997..325aad9feeff3 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryHeartbeatStatement; import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -41,16 +41,16 @@ @RunWith(MockitoJUnitRunner.class) public final class CreateDatabaseDiscoveryHeartbeatStatementUpdaterTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; - private final CreateDatabaseDiscoveryHeartbeatStatementUpdater updater = new CreateDatabaseDiscoveryHeartbeatStatementUpdater(); + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private ShardingSphereDatabaseMetaData databaseMetaData; + @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicateHeartbeatNames() throws DistSQLException { DatabaseDiscoveryHeartbeatSegment segment1 = new DatabaseDiscoveryHeartbeatSegment("heartbeat", createProperties("key", "value")); DatabaseDiscoveryHeartbeatSegment segment2 = new DatabaseDiscoveryHeartbeatSegment("heartbeat", createProperties("key", "value")); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryHeartbeatStatement(Arrays.asList(segment1, segment2)), + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryHeartbeatStatement(Arrays.asList(segment1, segment2)), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); } @@ -58,7 +58,7 @@ public void assertCheckSQLStatementWithDuplicateHeartbeatNames() throws DistSQLE public void assertCheckSQLStatementWithExistDiscoveryHeartbeatName() throws DistSQLException { DatabaseDiscoveryHeartbeatSegment segment = new DatabaseDiscoveryHeartbeatSegment("heartbeat", createProperties("key", "value")); DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.singletonMap("heartbeat", null), Collections.emptyMap()); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryHeartbeatStatement(Collections.singleton(segment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryHeartbeatStatement(Collections.singleton(segment)), ruleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java index a66fb2aa310c1..7bf52f11d418f 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -46,18 +46,18 @@ @RunWith(MockitoJUnitRunner.class) public final class CreateDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; - private final CreateDatabaseDiscoveryTypeStatementUpdater updater = new CreateDatabaseDiscoveryTypeStatementUpdater(); + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private ShardingSphereDatabaseMetaData databaseMetaData; + @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicate() throws DistSQLException { DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "test"); Collection algorithmSegments = Arrays.asList( new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())), new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()))); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap(), Collections.emptyMap())); } @@ -66,7 +66,7 @@ public void assertCheckSQLStatementWithExist() throws DistSQLException { DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "test"); Collection algorithmSegments = Collections.singletonList( new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()))); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap(), Collections.singletonMap("discovery_type", new ShardingSphereAlgorithmConfiguration("DISTSQL.FIXTURE", new Properties())))); } @@ -75,14 +75,14 @@ public void assertCheckSQLStatementWithExist() throws DistSQLException { public void assertCheckSQLStatementWithDatabaseDiscoveryType() throws DistSQLException { Collection algorithmSegments = Collections.singleton( new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("INVALID_TYPE", new Properties()))); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), null); + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), null); } @Test public void assertBuildAndUpdate() throws DistSQLException { Collection algorithmSegments = Collections.singleton( new DatabaseDiscoveryProviderAlgorithmSegment("discovery_type", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()))); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), null); + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryTypeStatement(algorithmSegments), null); DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = (DatabaseDiscoveryRuleConfiguration) updater.buildToBeCreatedRuleConfiguration(new CreateDatabaseDiscoveryTypeStatement(algorithmSegments)); DatabaseDiscoveryRuleConfiguration currentConfig = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(), new LinkedHashMap<>()); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java index 2fdccb6e652ad..4d80d4d8e60de 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.junit.Before; import org.junit.Test; @@ -53,24 +53,24 @@ @RunWith(MockitoJUnitRunner.class) public final class CreateDatabaseDiscoveryRuleStatementUpdaterTest { + private final CreateDatabaseDiscoveryRuleStatementUpdater updater = new CreateDatabaseDiscoveryRuleStatementUpdater(); + @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereResource resource; - private final CreateDatabaseDiscoveryRuleStatementUpdater updater = new CreateDatabaseDiscoveryRuleStatementUpdater(); - @Before public void before() { - when(shardingSphereMetaData.getResource()).thenReturn(resource); + when(databaseMetaData.getResource()).thenReturn(resource); } @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicateRuleNames() throws DistSQLException { DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("readwrite_ds", Collections.emptyList(), "ha-heartbeat", "test"); DatabaseDiscoveryConstructionSegment segment = new DatabaseDiscoveryConstructionSegment("readwrite_ds", Collections.emptyList(), "", ""); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap(), Collections.emptyMap())); } @@ -78,21 +78,21 @@ public void assertCheckSQLStatementWithDuplicateRuleNames() throws DistSQLExcept public void assertCheckSQLStatementWithoutExistedResources() throws DistSQLException { when(resource.getNotExistedResources(any())).thenReturn(Collections.singleton("ds_read_0")); DatabaseDiscoveryConstructionSegment segment = new DatabaseDiscoveryConstructionSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), "", ""); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), null); + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), null); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckSQLStatementWithDatabaseDiscoveryType() throws DistSQLException { AlgorithmSegment algorithmSegment = new AlgorithmSegment("INVALID_TYPE", new Properties()); DatabaseDiscoveryDefinitionSegment segment = new DatabaseDiscoveryDefinitionSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), algorithmSegment, new Properties()); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), null); + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), null); } @Test(expected = RequiredAlgorithmMissedException.class) public void assertCheckSQLStatementWithNotExistDiscoveryTypeName() throws DistSQLException { DatabaseDiscoveryConstructionSegment segment = new DatabaseDiscoveryConstructionSegment("readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), "not_exist_discovery_type_name", ""); DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap()); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); } @Test(expected = RequiredAlgorithmMissedException.class) @@ -101,7 +101,7 @@ public void assertCheckSQLStatementWithNotExistDiscoveryHeartbeatName() throws D "readwrite_ds", Arrays.asList("ds_read_0", "ds_read_1"), "discovery_type_name", "not_exist_heartbeat_name"); DatabaseDiscoveryRuleConfiguration ruleConfig = new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.singletonMap("discovery_type_name", null)); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(segment)), ruleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdaterTest.java index 8a353f185155d..c1e51c8db4925 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdaterTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -44,25 +44,25 @@ @RunWith(MockitoJUnitRunner.class) public final class DropDatabaseDiscoveryHeartbeatStatementUpdaterTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; - private final DropDatabaseDiscoveryHeartbeatStatementUpdater updater = new DropDatabaseDiscoveryHeartbeatStatementUpdater(); + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private ShardingSphereDatabaseMetaData databaseMetaData; + @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentHeartbeat() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeDroppedHeartbeat() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); } @Test(expected = RuleInUsedException.class) public void assertCheckSQLStatementWithInUsed() throws DistSQLException { DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("name", Collections.emptyList(), "heartbeat_name", ""); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(ruleConfig), + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(ruleConfig), Collections.singletonMap("heartbeat_name", null), Collections.emptyMap())); } @@ -77,7 +77,7 @@ public void assertUpdateCurrentRuleConfiguration() { public void assertUpdateCurrentRuleConfigurationWithIfExists() throws DistSQLException { DatabaseDiscoveryRuleConfiguration ruleConfig = createCurrentRuleConfiguration(); DropDatabaseDiscoveryHeartbeatStatement dropDatabaseDiscoveryHeartbeatStatement = createSQLStatementWithIfExists(); - updater.checkSQLStatement(shardingSphereMetaData, dropDatabaseDiscoveryHeartbeatStatement, ruleConfig); + updater.checkSQLStatement(databaseMetaData, dropDatabaseDiscoveryHeartbeatStatement, ruleConfig); assertFalse(updater.updateCurrentRuleConfiguration(dropDatabaseDiscoveryHeartbeatStatement, ruleConfig)); assertTrue(ruleConfig.getDiscoveryHeartbeats().containsKey("heartbeat_name")); assertThat(ruleConfig.getDiscoveryHeartbeats().size(), is(2)); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java index 8264954232a7d..eb8c5ca9bacd7 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -44,25 +44,25 @@ @RunWith(MockitoJUnitRunner.class) public final class DropDatabaseDiscoveryProviderAlgorithmStatementUpdaterTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; - private final DropDatabaseDiscoveryTypeStatementUpdater updater = new DropDatabaseDiscoveryTypeStatementUpdater(); + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private ShardingSphereDatabaseMetaData databaseMetaData; + @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentType() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeDroppedTypes() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); } @Test(expected = RuleInUsedException.class) public void assertCheckSQLStatementWithInUsed() throws DistSQLException { DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("name", Collections.emptyList(), "", "type_name"); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(dataSourceRuleConfig), + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(dataSourceRuleConfig), Collections.emptyMap(), Collections.singletonMap("type_name", null))); } @@ -77,7 +77,7 @@ public void assertUpdateCurrentRuleConfiguration() { public void assertUpdateCurrentRuleConfigurationWithIfExists() throws DistSQLException { DatabaseDiscoveryRuleConfiguration ruleConfig = createCurrentRuleConfiguration(); DropDatabaseDiscoveryTypeStatement dropDatabaseDiscoveryRuleStatement = createSQLStatementWithIfExists(); - updater.checkSQLStatement(shardingSphereMetaData, dropDatabaseDiscoveryRuleStatement, ruleConfig); + updater.checkSQLStatement(databaseMetaData, dropDatabaseDiscoveryRuleStatement, ruleConfig); assertFalse(updater.updateCurrentRuleConfiguration(dropDatabaseDiscoveryRuleStatement, ruleConfig)); assertTrue(ruleConfig.getDiscoveryTypes().containsKey("type_name")); assertThat(ruleConfig.getDiscoveryTypes().size(), is(2)); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java index b2ff45e2e3aab..7aa14ead61555 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.junit.Before; import org.junit.Test; @@ -44,24 +44,24 @@ public final class DropDatabaseDiscoveryRuleStatementUpdaterTest { - private ShardingSphereMetaData shardingSphereMetaData; - private final DropDatabaseDiscoveryRuleStatementUpdater updater = new DropDatabaseDiscoveryRuleStatementUpdater(); + private ShardingSphereDatabaseMetaData databaseMetaData; + @Before public void init() { - shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(shardingSphereMetaData.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(null, Collections.emptyList())); + databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(null, Collections.emptyList())); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeDroppedRules() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())); } @Test @@ -76,7 +76,7 @@ public void assertUpdateCurrentRuleConfiguration() { public void assertUpdateCurrentRuleConfigurationWithIfExists() throws DistSQLException { DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = createCurrentRuleConfiguration(); DropDatabaseDiscoveryRuleStatement dropDatabaseDiscoveryRuleStatement = createSQLStatementWithIfExists(); - updater.checkSQLStatement(shardingSphereMetaData, dropDatabaseDiscoveryRuleStatement, databaseDiscoveryRuleConfig); + updater.checkSQLStatement(databaseMetaData, dropDatabaseDiscoveryRuleStatement, databaseDiscoveryRuleConfig); assertFalse(updater.updateCurrentRuleConfiguration(dropDatabaseDiscoveryRuleStatement, databaseDiscoveryRuleConfig)); assertThat(databaseDiscoveryRuleConfig.getDataSources().size(), is(1)); assertThat(databaseDiscoveryRuleConfig.getDiscoveryTypes().size(), is(1)); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java index 264de7f0884b5..d81b7c93b1cb2 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngine.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.merge.engine.decorator.ResultDecorator; import org.apache.shardingsphere.infra.merge.engine.decorator.ResultDecoratorEngine; import org.apache.shardingsphere.infra.merge.engine.decorator.impl.TransparentResultDecorator; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement; /** @@ -38,10 +38,10 @@ public final class EncryptResultDecoratorEngine implements ResultDecoratorEngine { @Override - public ResultDecorator newInstance(final DatabaseType databaseType, final String databaseName, final ShardingSphereMetaData metaData, + public ResultDecorator newInstance(final DatabaseType databaseType, final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final EncryptRule encryptRule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext) { if (sqlStatementContext instanceof SelectStatementContext) { - EncryptAlgorithmMetaData algorithmMetaData = new EncryptAlgorithmMetaData(databaseName, metaData, encryptRule, (SelectStatementContext) sqlStatementContext); + EncryptAlgorithmMetaData algorithmMetaData = new EncryptAlgorithmMetaData(databaseName, databaseMetaData, encryptRule, (SelectStatementContext) sqlStatementContext); return new EncryptDQLResultDecorator(algorithmMetaData); } if (sqlStatementContext.getSqlStatement() instanceof DALStatement) { diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java index 1d5f53004b2d0..d883a7929a2e4 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaData.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection; import org.apache.shardingsphere.infra.binder.segment.table.TablesContext; import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collections; import java.util.List; @@ -41,7 +41,7 @@ public final class EncryptAlgorithmMetaData { private final String databaseName; - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final EncryptRule encryptRule; @@ -81,8 +81,9 @@ public Optional findEncryptContext(final int columnIndex) { return Optional.empty(); } TablesContext tablesContext = selectStatementContext.getTablesContext(); - String schemaName = tablesContext.getSchemaName().orElse(selectStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName())); - Map expressionTableNames = tablesContext.findTableNamesByColumnProjection(Collections.singletonList(columnProjection.get()), metaData.getSchemaByName(schemaName)); + String schemaName = tablesContext.getSchemaName().orElse(selectStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName())); + Map expressionTableNames = tablesContext.findTableNamesByColumnProjection( + Collections.singletonList(columnProjection.get()), databaseMetaData.getDatabase().getSchema(schemaName)); Optional tableName = findTableName(columnProjection.get(), expressionTableNames); return tableName.map(optional -> EncryptContextBuilder.build(databaseName, schemaName, optional, columnProjection.get().getName(), encryptRule)); } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java index b4e5a8771010f..3c4a5e18f7bde 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/EncryptResultDecoratorEngineTest.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.merge.engine.ResultProcessEngineFactory; import org.apache.shardingsphere.infra.merge.engine.decorator.ResultDecorator; import org.apache.shardingsphere.infra.merge.engine.decorator.impl.TransparentResultDecorator; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLExplainStatement; import org.junit.Test; @@ -56,13 +56,13 @@ public final class EncryptResultDecoratorEngineTest { private DatabaseType databaseType; @Mock - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Test public void assertNewInstanceWithSelectStatement() { EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule); ResultDecorator actual = engine.newInstance( - databaseType, DefaultDatabase.LOGIC_NAME, metaData, rule, mock(ConfigurationProperties.class), mock(SelectStatementContext.class, RETURNS_DEEP_STUBS)); + databaseType, DefaultDatabase.LOGIC_NAME, databaseMetaData, rule, mock(ConfigurationProperties.class), mock(SelectStatementContext.class, RETURNS_DEEP_STUBS)); assertThat(actual, instanceOf(EncryptDQLResultDecorator.class)); } @@ -71,14 +71,14 @@ public void assertNewInstanceWithDALStatement() { SQLStatementContext sqlStatementContext = mock(ExplainStatementContext.class); when(sqlStatementContext.getSqlStatement()).thenReturn(mock(MySQLExplainStatement.class)); EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule); - ResultDecorator actual = engine.newInstance(databaseType, DefaultDatabase.LOGIC_NAME, metaData, rule, mock(ConfigurationProperties.class), sqlStatementContext); + ResultDecorator actual = engine.newInstance(databaseType, DefaultDatabase.LOGIC_NAME, databaseMetaData, rule, mock(ConfigurationProperties.class), sqlStatementContext); assertThat(actual, instanceOf(EncryptDALResultDecorator.class)); } @Test public void assertNewInstanceWithOtherStatement() { EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) ResultProcessEngineFactory.getInstances(Collections.singleton(rule)).get(rule); - ResultDecorator actual = engine.newInstance(databaseType, DefaultDatabase.LOGIC_NAME, metaData, rule, mock(ConfigurationProperties.class), mock(InsertStatementContext.class)); + ResultDecorator actual = engine.newInstance(databaseType, DefaultDatabase.LOGIC_NAME, databaseMetaData, rule, mock(ConfigurationProperties.class), mock(InsertStatementContext.class)); assertThat(actual, instanceOf(TransparentResultDecorator.class)); } } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java index 60dc9bd8d37b0..8507646bffcbf 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.junit.Before; import org.junit.Test; @@ -56,7 +56,7 @@ public final class EncryptAlgorithmMetaDataTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereSchema schema; @@ -86,8 +86,8 @@ public void setUp() { when(columnProjection.getExpression()).thenReturn("id"); when(selectStatementContext.getTablesContext()).thenReturn(tablesContext); when(selectStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType()); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); encryptAlgorithm = EncryptAlgorithmFactory.newInstance(new ShardingSphereAlgorithmConfiguration("MD5", new Properties())); } @@ -96,7 +96,7 @@ public void assertFindEncryptContextByMetaData() { Map columnTableNames = new HashMap<>(); columnTableNames.put(columnProjection.getExpression(), "t_order"); when(tablesContext.findTableNamesByColumnProjection(Collections.singletonList(columnProjection), schema)).thenReturn(columnTableNames); - EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, metaData, encryptRule, selectStatementContext); + EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, databaseMetaData, encryptRule, selectStatementContext); Optional actual = encryptAlgorithmMetaData.findEncryptContext(1); assertTrue(actual.isPresent()); assertThat(actual.get().getDatabaseName(), is(DefaultDatabase.LOGIC_NAME)); @@ -109,7 +109,7 @@ public void assertFindEncryptContextByStatementContext() { when(tablesContext.findTableNamesByColumnProjection(Collections.singletonList(columnProjection), schema)).thenReturn(Collections.emptyMap()); when(tablesContext.getTableNames()).thenReturn(Arrays.asList("t_user", "t_user_item", "t_order_item")); when(encryptRule.findEncryptor("t_order_item", "id")).thenReturn(Optional.of(encryptAlgorithm)); - EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, metaData, encryptRule, selectStatementContext); + EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, databaseMetaData, encryptRule, selectStatementContext); Optional actual = encryptAlgorithmMetaData.findEncryptContext(1); assertTrue(actual.isPresent()); assertThat(actual.get().getDatabaseName(), is(DefaultDatabase.LOGIC_NAME)); @@ -120,7 +120,7 @@ public void assertFindEncryptContextByStatementContext() { @Test public void assertFindEncryptContextWhenColumnProjectionIsNotExist() { when(projectionsContext.getExpandProjections()).thenReturn(Collections.singletonList(mock(DerivedProjection.class))); - EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, metaData, encryptRule, selectStatementContext); + EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, databaseMetaData, encryptRule, selectStatementContext); Optional actual = encryptAlgorithmMetaData.findEncryptContext(1); assertFalse(actual.isPresent()); } @@ -129,7 +129,7 @@ public void assertFindEncryptContextWhenColumnProjectionIsNotExist() { @Test public void assertFindEncryptor() { when(encryptRule.findEncryptor("t_order", "id")).thenReturn(Optional.of(encryptAlgorithm)); - EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, metaData, encryptRule, selectStatementContext); + EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, databaseMetaData, encryptRule, selectStatementContext); Optional actualEncryptor = encryptAlgorithmMetaData.findEncryptor("t_order", "id"); assertTrue(actualEncryptor.isPresent()); assertThat(actualEncryptor.get().getType(), is("MD5")); @@ -138,7 +138,7 @@ public void assertFindEncryptor() { @Test public void assertIsQueryWithCipherColumn() { when(encryptRule.isQueryWithCipherColumn("t_order", "id")).thenReturn(true); - EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, metaData, encryptRule, selectStatementContext); + EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(DefaultDatabase.LOGIC_NAME, databaseMetaData, encryptRule, selectStatementContext); assertTrue(encryptAlgorithmMetaData.isQueryWithCipherColumn("t_order", "id")); } } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java index 17963d2df277a..e201fe279c148 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.encrypt.distsql.parser.statement.ShowEncryptRulesStatement; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.properties.PropertiesConverter; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -44,8 +44,8 @@ public final class EncryptRuleQueryResultSet implements DistSQLResultSet { private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().findRuleConfiguration(EncryptRuleConfiguration.class).stream().findAny(); + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().findRuleConfiguration(EncryptRuleConfiguration.class).stream().findAny(); ruleConfig.ifPresent(optional -> data = buildData(optional, (ShowEncryptRulesStatement) sqlStatement).iterator()); } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java index 07971e2959ded..50de3469eaa47 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java @@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidRuleConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.Collections; @@ -45,9 +45,9 @@ public final class AlterEncryptRuleStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterEncryptRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkToBeAlteredRules(databaseName, sqlStatement, currentRuleConfig); checkToBeAlteredEncryptors(sqlStatement); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java index 009d21b23883d..4cf0e95cb8733 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidRuleConfigurationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.Collections; @@ -42,9 +42,9 @@ public final class CreateEncryptRuleStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateEncryptRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) throws DistSQLException { - checkDuplicateRuleNames(shardingSphereMetaData.getDatabase().getName(), sqlStatement, currentRuleConfig); + checkDuplicateRuleNames(databaseMetaData.getDatabase().getName(), sqlStatement, currentRuleConfig); checkDataType(sqlStatement); checkToBeCreatedEncryptors(sqlStatement); // TODO check resource diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java index ac0b74bd9ecd4..2f0493c2b7a0e 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.Optional; @@ -35,9 +35,9 @@ public final class DropEncryptRuleStatementUpdater implements RuleDefinitionDropUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropEncryptRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkToBeDroppedEncryptTableNames(databaseName, sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java index 698457013330e..335542c17b023 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSetTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import java.util.Collection; @@ -43,10 +43,10 @@ public final class EncryptRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(getRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(getRuleConfiguration())); DistSQLResultSet resultSet = new EncryptRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowEncryptRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowEncryptRulesStatement.class)); Collection actual = resultSet.getRowData(); assertThat(actual.size(), is(12)); assertTrue(actual.contains("t_encrypt")); diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java index 74edecc115254..6d891dbb04acd 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdaterTest.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidRuleConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -42,23 +42,23 @@ public final class AlterEncryptRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final AlterEncryptRuleStatementUpdater updater = new AlterEncryptRuleStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("MD5"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("MD5"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeAlteredRules() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("MD5"), new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("MD5"), new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckSQLStatementWithoutToBeAlteredEncryptors() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("INVALID_TYPE"), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("INVALID_TYPE"), createCurrentRuleConfiguration()); } @Test(expected = InvalidRuleConfigurationException.class) @@ -67,7 +67,7 @@ public void assertCheckSQLStatementWithIncompleteDataType() throws DistSQLExcept "int varchar(10)", null, null, null, new AlgorithmSegment("test", new Properties()), null); EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", Collections.singleton(columnSegment), null); AlterEncryptRuleStatement statement = new AlterEncryptRuleStatement(Collections.singleton(ruleSegment)); - updater.checkSQLStatement(shardingSphereMetaData, statement, createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, statement, createCurrentRuleConfiguration()); } private AlterEncryptRuleStatement createSQLStatement(final String encryptorName) { diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java index a628530d1307a..2effd44bd2a31 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdaterTest.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidRuleConfigurationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -41,18 +41,18 @@ public final class CreateEncryptRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final CreateEncryptRuleStatementUpdater updater = new CreateEncryptRuleStatementUpdater(); @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicateEncryptRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("MD5"), getCurrentRuleConfig()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("MD5"), getCurrentRuleConfig()); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckSQLStatementWithoutToBeCreatedEncryptors() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("INVALID_TYPE"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("INVALID_TYPE"), null); } @Test(expected = InvalidRuleConfigurationException.class) @@ -61,7 +61,7 @@ public void assertCheckSQLStatementWithIncompleteDataType() throws DistSQLExcept "int varchar(10)", null, null, null, new AlgorithmSegment("test", new Properties()), null); EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", Collections.singleton(columnSegment), null); CreateEncryptRuleStatement statement = new CreateEncryptRuleStatement(Collections.singleton(ruleSegment)); - updater.checkSQLStatement(shardingSphereMetaData, statement, null); + updater.checkSQLStatement(databaseMetaData, statement, null); } private CreateEncryptRuleStatement createSQLStatement(final String encryptorName) { diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java index 3fc8060c642d6..9306b974a16e5 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -48,18 +48,18 @@ public final class DropEncryptRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropEncryptRuleStatementUpdater updater = new DropEncryptRuleStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_encrypt"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_encrypt"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeDroppedRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_encrypt"), new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_encrypt"), new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); } @Test @@ -85,7 +85,7 @@ public void assertUpdateCurrentRuleConfigurationWithIfExists() throws DistSQLExc EncryptRuleConfiguration ruleConfig = createCurrentRuleConfiguration(); DropEncryptRuleStatement statement = createSQLStatement("t_encrypt_1"); statement.setContainsExistClause(true); - updater.checkSQLStatement(shardingSphereMetaData, statement, mock(EncryptRuleConfiguration.class)); + updater.checkSQLStatement(databaseMetaData, statement, mock(EncryptRuleConfiguration.class)); assertFalse(updater.updateCurrentRuleConfiguration(statement, ruleConfig)); assertThat(ruleConfig.getEncryptors().size(), is(1)); } diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouter.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouter.java index 5e8b25e88d403..4ae8619bd444f 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouter.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouter.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.SQLRouter; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; @@ -40,7 +40,7 @@ public final class ReadwriteSplittingSQLRouter implements SQLRouter { @Override - public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ReadwriteSplittingRule rule, final ConfigurationProperties props) { + public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ReadwriteSplittingRule rule, final ConfigurationProperties props) { RouteContext result = new RouteContext(); ReadwriteSplittingDataSourceRule singleDataSourceRule = rule.getSingleDataSourceRule(); String dataSourceName = new ReadwriteSplittingDataSourceRouter(singleDataSourceRule).route(logicSQL.getSqlStatementContext()); @@ -50,7 +50,7 @@ public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSp @Override public void decorateRouteContext(final RouteContext routeContext, - final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ReadwriteSplittingRule rule, final ConfigurationProperties props) { + final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ReadwriteSplittingRule rule, final ConfigurationProperties props) { Collection toBeRemoved = new LinkedList<>(); Collection toBeAdded = new LinkedList<>(); for (RouteUnit each : routeContext.getRouteUnits()) { diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java index 483241c4861e2..ba4ec9a838745 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -94,9 +94,9 @@ private Properties createProperties() { public void assertCreateRouteContextToPrimaryWithoutRouteUnits() { LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); assertThat(actual.getRouteUnits().size(), is(1)); RouteUnit routeUnit = actual.getRouteUnits().iterator().next(); assertThat(routeUnit.getDataSourceMapper().getLogicName(), is(DATASOURCE_NAME)); @@ -110,9 +110,9 @@ public void assertDecorateRouteContextToPrimaryDataSource() { RouteContext actual = mockRouteContext(); LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + sqlRouter.decorateRouteContext(actual, logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(NONE_READWRITE_SPLITTING_DATASOURCE_NAME)); assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE)); @@ -125,9 +125,9 @@ public void assertCreateRouteContextToReplicaDataSource() { when(selectStatement.getLock()).thenReturn(Optional.empty()); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); assertThat(actual.getRouteUnits().size(), is(1)); RouteUnit routeUnit = actual.getRouteUnits().iterator().next(); assertThat(routeUnit.getDataSourceMapper().getLogicName(), is(DATASOURCE_NAME)); @@ -144,9 +144,9 @@ public void assertDecorateRouteContextToReplicaDataSource() { when(selectStatement.getLock()).thenReturn(Optional.empty()); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + sqlRouter.decorateRouteContext(actual, logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(NONE_READWRITE_SPLITTING_DATASOURCE_NAME)); assertThat(routedDataSourceNames.next(), is(READ_DATASOURCE)); @@ -159,9 +159,9 @@ public void assertCreateRouteContextToPrimaryDataSourceWithLock() { when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class))); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE)); } @@ -174,9 +174,9 @@ public void assertDecorateRouteContextToPrimaryDataSourceWithLock() { when(selectStatement.getLock()).thenReturn(Optional.of(mock(LockSegment.class))); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + sqlRouter.decorateRouteContext(actual, logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(NONE_READWRITE_SPLITTING_DATASOURCE_NAME)); assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE)); @@ -187,9 +187,9 @@ public void assertCreateRouteContextToPrimaryDataSource() { when(sqlStatementContext.getSqlStatement()).thenReturn(mock(InsertStatement.class)); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE)); } @@ -200,16 +200,16 @@ public void assertCreateRouteContextToReadDataSource() { when(sqlStatementContext.getSqlStatement()).thenReturn(insertStatement); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE)); MySQLSelectStatement selectStatement = mock(MySQLSelectStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement); when(selectStatement.getLock()).thenReturn(Optional.empty()); logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); - actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(READ_DATASOURCE)); } @@ -222,9 +222,9 @@ public void assertSqlHintRouteWriteOnly() { when(sqlStatementContext.isHintWriteRouteOnly()).thenReturn(true); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); - RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties())); + RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties())); Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator(); assertThat(routedDataSourceNames.next(), is(WRITE_DATASOURCE)); } diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java index 33b7b4f9aa887..4761858f928e9 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSet.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.properties.PropertiesConverter; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; @@ -50,14 +50,14 @@ public final class ReadwriteSplittingRuleQueryResultSet implements DistSQLResult private Map> exportableDataSourceMap = Collections.emptyMap(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().findRuleConfiguration(ReadwriteSplittingRuleConfiguration.class).stream().findAny(); - buildExportableMap(metaData); + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().findRuleConfiguration(ReadwriteSplittingRuleConfiguration.class).stream().findAny(); + buildExportableMap(databaseMetaData); ruleConfig.ifPresent(optional -> data = buildData(optional).iterator()); } - private void buildExportableMap(final ShardingSphereMetaData metaData) { - Optional exportableRule = getExportableRule(metaData); + private void buildExportableMap(final ShardingSphereDatabaseMetaData databaseMetaData) { + Optional exportableRule = getExportableRule(databaseMetaData); exportableRule.ifPresent(optional -> { Map exportable = exportableRule.get() .export(Arrays.asList(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE, ExportableConstants.EXPORTABLE_KEY_ENABLED_DATA_SOURCE)); @@ -66,8 +66,8 @@ private void buildExportableMap(final ShardingSphereMetaData metaData) { }); } - private Optional getExportableRule(final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().findRules(ExportableRule.class).stream() + private Optional getExportableRule(final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().findRules(ExportableRule.class).stream() .filter(each -> each.containExportableKey(Arrays.asList(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE, ExportableConstants.EXPORTABLE_KEY_ENABLED_DATA_SOURCE))).findAny(); } diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdater.java index ef4b981b1a73d..53bb0ab3bd9de 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdater.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -50,12 +50,12 @@ public final class AlterReadwriteSplittingRuleStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterReadwriteSplittingRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkToBeAlteredRules(databaseName, sqlStatement, currentRuleConfig); - checkToBeAlteredResources(databaseName, sqlStatement, shardingSphereMetaData); + checkToBeAlteredResources(databaseName, sqlStatement, databaseMetaData); checkToBeAlteredLoadBalancer(sqlStatement); } @@ -86,8 +86,8 @@ private void checkToBeAlteredLoadBalancer(final AlterReadwriteSplittingRuleState } } - private void checkToBeAlteredResources(final String databaseName, final AlterReadwriteSplittingRuleStatement sqlStatement, - final ShardingSphereMetaData shardingSphereMetaData) throws DistSQLException { + private void checkToBeAlteredResources(final String databaseName, + final AlterReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereDatabaseMetaData databaseMetaData) throws DistSQLException { Collection requireResources = new LinkedHashSet<>(); Collection requireDiscoverableResources = new LinkedHashSet<>(); sqlStatement.getRules().forEach(each -> { @@ -98,17 +98,17 @@ private void checkToBeAlteredResources(final String databaseName, final AlterRea requireDiscoverableResources.add(each.getAutoAwareResource()); } }); - Collection notExistResources = shardingSphereMetaData.getResource().getNotExistedResources(requireResources); + Collection notExistResources = databaseMetaData.getResource().getNotExistedResources(requireResources); DistSQLException.predictionThrow(notExistResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistResources)); - Collection logicResources = getLogicResources(shardingSphereMetaData); + Collection logicResources = getLogicResources(databaseMetaData); Set notExistLogicResources = requireDiscoverableResources.stream().filter(each -> !logicResources.contains(each)).collect(Collectors.toSet()); DistSQLException.predictionThrow(notExistLogicResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistLogicResources)); } @SuppressWarnings("unchecked") - private Collection getLogicResources(final ShardingSphereMetaData shardingSphereMetaData) { + private Collection getLogicResources(final ShardingSphereDatabaseMetaData databaseMetaData) { Collection result = new LinkedHashSet<>(); - Optional exportableRule = shardingSphereMetaData.getRuleMetaData().findRules(ExportableRule.class).stream() + Optional exportableRule = databaseMetaData.getRuleMetaData().findRules(ExportableRule.class).stream() .filter(each -> each.containExportableKey(Collections.singletonList(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE))).findAny(); exportableRule.ifPresent(optional -> { Map exportData = optional.export(Collections.singletonList(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE)); diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdater.java index cff31db3a8df5..7ed8ed2af6414 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdater.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidRuleConfigurationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; @@ -51,11 +51,11 @@ public final class CreateReadwriteSplittingRuleStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateReadwriteSplittingRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); - checkDuplicateRuleNames(databaseName, sqlStatement, currentRuleConfig, shardingSphereMetaData.getResource()); - checkToBeCreatedResources(databaseName, sqlStatement, shardingSphereMetaData); + String databaseName = databaseMetaData.getDatabase().getName(); + checkDuplicateRuleNames(databaseName, sqlStatement, currentRuleConfig, databaseMetaData.getResource()); + checkToBeCreatedResources(databaseName, sqlStatement, databaseMetaData); checkToBeCreatedLoadBalancers(sqlStatement); } @@ -78,8 +78,8 @@ private void checkDuplicateRuleNames(final String databaseName, final CreateRead } } - private void checkToBeCreatedResources(final String databaseName, final CreateReadwriteSplittingRuleStatement sqlStatement, - final ShardingSphereMetaData shardingSphereMetaData) throws DistSQLException { + private void checkToBeCreatedResources(final String databaseName, + final CreateReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereDatabaseMetaData databaseMetaData) throws DistSQLException { Collection requireResources = new LinkedHashSet<>(); Collection requireDiscoverableResources = new LinkedHashSet<>(); sqlStatement.getRules().forEach(each -> { @@ -90,17 +90,17 @@ private void checkToBeCreatedResources(final String databaseName, final CreateRe requireDiscoverableResources.add(each.getAutoAwareResource()); } }); - Collection notExistResources = shardingSphereMetaData.getResource().getNotExistedResources(requireResources); + Collection notExistResources = databaseMetaData.getResource().getNotExistedResources(requireResources); DistSQLException.predictionThrow(notExistResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistResources)); - Collection logicResources = getLogicResources(shardingSphereMetaData); + Collection logicResources = getLogicResources(databaseMetaData); Set notExistLogicResources = requireDiscoverableResources.stream().filter(each -> !logicResources.contains(each)).collect(Collectors.toSet()); DistSQLException.predictionThrow(notExistLogicResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistLogicResources)); } @SuppressWarnings("unchecked") - private Collection getLogicResources(final ShardingSphereMetaData shardingSphereMetaData) { + private Collection getLogicResources(final ShardingSphereDatabaseMetaData databaseMetaData) { Collection result = new LinkedHashSet<>(); - Optional exportableRule = shardingSphereMetaData.getRuleMetaData().findRules(ExportableRule.class).stream() + Optional exportableRule = databaseMetaData.getRuleMetaData().findRules(ExportableRule.class).stream() .filter(each -> each.containExportableKey(Collections.singletonList(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE))).findAny(); exportableRule.ifPresent(optional -> { Map exportData = optional.export(Collections.singletonList(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE)); diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java index 51e153ef18809..8c9eaf8b192a8 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.DropReadwriteSplittingRuleStatement; @@ -38,15 +38,15 @@ public final class DropReadwriteSplittingRuleStatementUpdater implements RuleDefinitionDropUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropReadwriteSplittingRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); if (!isExistRuleConfig(currentRuleConfig) && sqlStatement.isContainsExistClause()) { return; } checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkToBeDroppedRuleNames(databaseName, sqlStatement, currentRuleConfig); - checkToBeDroppedInUsed(databaseName, sqlStatement, shardingSphereMetaData); + checkToBeDroppedInUsed(databaseName, sqlStatement, databaseMetaData); } private void checkCurrentRuleConfiguration(final String databaseName, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws RequiredRuleMissedException { @@ -67,9 +67,9 @@ private void checkToBeDroppedRuleNames(final String databaseName, final DropRead } } - private void checkToBeDroppedInUsed(final String databaseName, final DropReadwriteSplittingRuleStatement sqlStatement, - final ShardingSphereMetaData shardingSphereMetaData) throws RuleInUsedException { - Collection resourceBeUsed = shardingSphereMetaData.getRuleMetaData().findRuleConfiguration(ResourceRequiredRuleConfiguration.class).stream() + private void checkToBeDroppedInUsed(final String databaseName, + final DropReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereDatabaseMetaData databaseMetaData) throws RuleInUsedException { + Collection resourceBeUsed = databaseMetaData.getRuleMetaData().findRuleConfiguration(ResourceRequiredRuleConfiguration.class).stream() .map(ResourceRequiredRuleConfiguration::getRequiredResource).flatMap(Collection::stream).collect(Collectors.toSet()); Collection ruleInUsed = sqlStatement.getRuleNames().stream().filter(resourceBeUsed::contains).collect(Collectors.toSet()); if (!ruleInUsed.isEmpty()) { diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java index 34aefb3fd87c2..1937ee11f5194 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -46,13 +46,13 @@ public final class ReadwriteSplittingRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); ExportableRule exportableRule = mock(ExportableRule.class); - when(metaData.getRuleMetaData().findRules(any())).thenReturn(Collections.singletonList(exportableRule)); + when(databaseMetaData.getRuleMetaData().findRules(any())).thenReturn(Collections.singletonList(exportableRule)); when(exportableRule.export(anyCollection())).thenReturn(Collections.emptyMap()); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration())); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration())); ReadwriteSplittingRuleQueryResultSet resultSet = new ReadwriteSplittingRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowReadwriteSplittingRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowReadwriteSplittingRulesStatement.class)); Collection actual = resultSet.getRowData(); assertThat(actual.size(), is(6)); assertTrue(actual.contains("readwrite_ds")); @@ -72,13 +72,13 @@ private RuleConfiguration createRuleConfiguration() { @Test public void assertGetRowDataWithoutLoadBalancer() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); ExportableRule exportableRule = mock(ExportableRule.class); - when(metaData.getRuleMetaData().findRules(any())).thenReturn(Collections.singletonList(exportableRule)); + when(databaseMetaData.getRuleMetaData().findRules(any())).thenReturn(Collections.singletonList(exportableRule)); when(exportableRule.export(anyCollection())).thenReturn(Collections.emptyMap()); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfigurationWithoutLoadBalancer())); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfigurationWithoutLoadBalancer())); ReadwriteSplittingRuleQueryResultSet resultSet = new ReadwriteSplittingRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowReadwriteSplittingRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowReadwriteSplittingRulesStatement.class)); Collection actual = resultSet.getRowData(); assertThat(actual.size(), is(6)); assertTrue(actual.contains("readwrite_ds")); @@ -101,15 +101,15 @@ private Properties getProperties(final String writeDataSource, final String read @Test public void assertGetRowDataWithAutoAwareDataSource() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); ExportableRule exportableRule = mock(ExportableRule.class); when(exportableRule.containExportableKey(anyCollection())).thenReturn(true); - when(metaData.getRuleMetaData().findRules(any())).thenReturn(Collections.singletonList(exportableRule)); + when(databaseMetaData.getRuleMetaData().findRules(any())).thenReturn(Collections.singletonList(exportableRule)); when(exportableRule.export(anyCollection())).thenReturn( Collections.singletonMap(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE, Collections.singletonMap("readwrite_ds", getAutoAwareDataSources()))); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfigurationWithAutoAwareDataSource())); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfigurationWithAutoAwareDataSource())); ReadwriteSplittingRuleQueryResultSet resultSet = new ReadwriteSplittingRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowReadwriteSplittingRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowReadwriteSplittingRulesStatement.class)); Collection actual = resultSet.getRowData(); assertThat(actual.size(), is(6)); assertTrue(actual.contains("readwrite_ds")); diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java index 26ad7fba7953c..9b204892dc033 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleStatementUpdaterTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -46,7 +46,7 @@ public final class AlterReadwriteSplittingRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereResource resource; @@ -55,29 +55,29 @@ public final class AlterReadwriteSplittingRuleStatementUpdaterTest { @Before public void before() { - when(shardingSphereMetaData.getResource()).thenReturn(resource); + when(databaseMetaData.getResource()).thenReturn(resource); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("TEST"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("TEST"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeAlteredRules() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("TEST"), new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("TEST"), new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); } @Test(expected = RequiredResourceMissedException.class) public void assertCheckSQLStatementWithoutExistedResources() throws DistSQLException { when(resource.getNotExistedResources(any())).thenReturn(Collections.singleton("read_ds_0")); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("TEST"), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("TEST"), createCurrentRuleConfiguration()); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckSQLStatementWithoutToBeAlteredLoadBalancers() throws DistSQLException { - when(shardingSphereMetaData.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList()); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("INVALID_TYPE"), createCurrentRuleConfiguration()); + when(databaseMetaData.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("INVALID_TYPE"), createCurrentRuleConfiguration()); } private AlterReadwriteSplittingRuleStatement createSQLStatement(final String loadBalancerTypeName) { diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java index 219b088cd1fca..c25f9e3f6b5e9 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidRuleConfigurationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -49,7 +49,7 @@ public final class CreateReadwriteSplittingRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereResource resource; @@ -58,34 +58,34 @@ public final class CreateReadwriteSplittingRuleStatementUpdaterTest { @Before public void before() { - when(shardingSphereMetaData.getResource()).thenReturn(resource); + when(databaseMetaData.getResource()).thenReturn(resource); } @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicateRuleNames() throws DistSQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getResource().getDataSources().keySet()).thenReturn(Collections.emptySet()); - updater.checkSQLStatement(metaData, createSQLStatement("TEST"), createCurrentRuleConfiguration()); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getResource().getDataSources().keySet()).thenReturn(Collections.emptySet()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("TEST"), createCurrentRuleConfiguration()); } @Test(expected = InvalidRuleConfigurationException.class) public void assertCheckSQLStatementWithDuplicateResource() throws DistSQLException { - ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(shardingSphereMetaData.getResource()).thenReturn(resource); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getResource()).thenReturn(resource); when(resource.getDataSources()).thenReturn(Collections.singletonMap("write_ds", null)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("write_ds", "TEST"), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("write_ds", "TEST"), createCurrentRuleConfiguration()); } @Test(expected = RequiredResourceMissedException.class) public void assertCheckSQLStatementWithoutExistedResources() throws DistSQLException { when(resource.getNotExistedResources(any())).thenReturn(Arrays.asList("read_ds_0", "read_ds_1")); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("TEST"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("TEST"), null); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckSQLStatementWithoutToBeCreatedLoadBalancers() throws DistSQLException { - when(shardingSphereMetaData.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList()); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("INVALID_TYPE"), null); + when(databaseMetaData.getRuleMetaData().findRules(any())).thenReturn(Collections.emptyList()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("INVALID_TYPE"), null); } private CreateReadwriteSplittingRuleStatement createSQLStatement(final String loadBalancerName) { diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java index e12a3a7820876..788394af2dc69 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.DropReadwriteSplittingRuleStatement; @@ -51,31 +51,31 @@ public final class DropReadwriteSplittingRuleStatementUpdaterTest { private final DropReadwriteSplittingRuleStatementUpdater updater = new DropReadwriteSplittingRuleStatementUpdater(); @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutToBeDroppedRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); } @Test public void assertCheckSQLStatementWithIfExists() throws RuleDefinitionViolationException { - when(shardingSphereMetaData.getRuleMetaData().findRuleConfiguration(ResourceRequiredRuleConfiguration.class)).thenReturn(Collections.emptyList()); - updater.checkSQLStatement(shardingSphereMetaData, new DropReadwriteSplittingRuleStatement(true, Collections.singleton("readwrite_ds")), + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(ResourceRequiredRuleConfiguration.class)).thenReturn(Collections.emptyList()); + updater.checkSQLStatement(databaseMetaData, new DropReadwriteSplittingRuleStatement(true, Collections.singleton("readwrite_ds")), new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap())); - updater.checkSQLStatement(shardingSphereMetaData, new DropReadwriteSplittingRuleStatement(true, Collections.singleton("readwrite_ds")), null); + updater.checkSQLStatement(databaseMetaData, new DropReadwriteSplittingRuleStatement(true, Collections.singleton("readwrite_ds")), null); } @Test(expected = RuleInUsedException.class) public void assertCheckSQLStatementWithInUsed() throws RuleDefinitionViolationException { - when(shardingSphereMetaData.getRuleMetaData().findRuleConfiguration(any())) + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())) .thenReturn(Collections.singletonList((ResourceRequiredRuleConfiguration) () -> Collections.singleton("readwrite_ds"))); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), createCurrentRuleConfiguration()); } @Test diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java index 38cb871250be3..941b100ddadc6 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouter.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.SQLRouter; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.shadow.constant.ShadowOrder; @@ -32,14 +32,14 @@ public final class ShadowSQLRouter implements SQLRouter { @Override - public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShadowRule rule, final ConfigurationProperties props) { + public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ShadowRule rule, final ConfigurationProperties props) { // TODO return new RouteContext(); } @Override public void decorateRouteContext(final RouteContext routeContext, - final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShadowRule rule, final ConfigurationProperties props) { + final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ShadowRule rule, final ConfigurationProperties props) { ShadowRouteEngineFactory.newInstance(logicSQL).route(routeContext, rule); } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouterTest.java index 6c7264d38edca..608c84f80d54b 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/ShadowSQLRouterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.rule.ShadowRule; import org.junit.Test; @@ -30,6 +30,6 @@ public final class ShadowSQLRouterTest { @Test public void assertCreateRouteContext() { - assertNotNull(new ShadowSQLRouter().createRouteContext(mock(LogicSQL.class), mock(ShardingSphereMetaData.class), mock(ShadowRule.class), mock(ConfigurationProperties.class))); + assertNotNull(new ShadowSQLRouter().createRouteContext(mock(LogicSQL.class), mock(ShardingSphereDatabaseMetaData.class), mock(ShadowRule.class), mock(ConfigurationProperties.class))); } } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java index 0521f40b71d35..3ba6dfe11f3a4 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment; import java.util.Collection; @@ -53,12 +53,12 @@ public static void checkConfigurationExist(final String databaseName, final Sche * Check if resources exist in meta data. * * @param resources resource being checked - * @param metaData meta rules + * @param databaseMetaData database meta rules * @param databaseName database name * @throws DistSQLException DistSQL exception */ - public static void checkResourceExist(final Collection resources, final ShardingSphereMetaData metaData, final String databaseName) throws DistSQLException { - Collection notExistedResources = metaData.getResource().getNotExistedResources(resources); + public static void checkResourceExist(final Collection resources, final ShardingSphereDatabaseMetaData databaseMetaData, final String databaseName) throws DistSQLException { + Collection notExistedResources = databaseMetaData.getResource().getNotExistedResources(resources); DistSQLException.predictionThrow(notExistedResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistedResources)); } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmQueryResultSet.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmQueryResultSet.java index 74dc5cfa196e8..3202cf18034df 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmQueryResultSet.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.properties.PropertiesConverter; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement; @@ -52,8 +52,8 @@ public final class ShadowAlgorithmQueryResultSet implements DistSQLResultSet { private String defaultAlgorithm; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional rule = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional rule = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShadowRuleConfiguration).map(each -> (ShadowRuleConfiguration) each).findAny(); rule.ifPresent(optional -> { data = optional.getShadowAlgorithms().entrySet().iterator(); diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowRuleQueryResultSet.java index daa787a340f32..3409bcf3958ba 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowRuleQueryResultSet.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.shadow.distsql.handler.query; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; @@ -52,8 +52,8 @@ public final class ShadowRuleQueryResultSet implements DistSQLResultSet { private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations().stream() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations().stream() .filter(each -> each instanceof ShadowRuleConfiguration).map(each -> (ShadowRuleConfiguration) each).findAny(); ruleConfig.ifPresent(optional -> buildDataSourceIterator(optional, (ShowShadowRulesStatement) sqlStatement)); } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowTableRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowTableRuleQueryResultSet.java index 9f93997aaceec..e0b7c5a4b4a47 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowTableRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowTableRuleQueryResultSet.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.shadow.distsql.handler.query; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowTableRulesStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -45,8 +45,8 @@ public final class ShadowTableRuleQueryResultSet implements DistSQLResultSet { private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShadowRuleConfiguration).map(each -> (ShadowRuleConfiguration) each).findAny(); ruleConfig.ifPresent(optional -> data = buildData(optional).iterator()); } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java index c9c6fc2d3e1a6..d426962e1678e 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowAlgorithmStatementUpdater.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker; import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment; @@ -58,8 +58,9 @@ public void updateCurrentRuleConfiguration(final ShadowRuleConfiguration current } @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final AlterShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, + final AlterShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { + String databaseName = databaseMetaData.getDatabase().getName(); checkConfigurationExist(databaseName, currentRuleConfig); checkAlgorithms(databaseName, sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java index 5f855c2927ba7..27dccbe484510 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; @@ -67,12 +67,13 @@ private void updateTables(final Map currentTab } @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final AlterShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, + final AlterShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { + String databaseName = databaseMetaData.getDatabase().getName(); Collection rules = sqlStatement.getRules(); checkConfigurationExist(databaseName, currentRuleConfig); checkRuleNames(databaseName, rules, currentRuleConfig); - checkResources(databaseName, rules, metaData); + checkResources(databaseName, databaseMetaData, rules); checkAlgorithms(databaseName, rules); } @@ -87,9 +88,9 @@ private void checkRuleNames(final String databaseName, final Collection new InvalidAlgorithmConfigurationException("shadow rule name ", different)); } - private void checkResources(final String databaseName, final Collection rules, final ShardingSphereMetaData metaData) throws DistSQLException { + private void checkResources(final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final Collection rules) throws DistSQLException { Collection requireResource = ShadowRuleStatementSupporter.getResourceNames(rules); - ShadowRuleStatementChecker.checkResourceExist(requireResource, metaData, databaseName); + ShadowRuleStatementChecker.checkResourceExist(requireResource, databaseMetaData, databaseName); } private void checkAlgorithms(final String databaseName, final Collection rules) throws DistSQLException { diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java index 6f834100ded54..46596b5ba0143 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateDefaultShadowAlgorithmStatementUpdater.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.parser.statement.CreateDefaultShadowAlgorithmStatement; @@ -45,9 +45,9 @@ public void updateCurrentRuleConfiguration(final ShadowRuleConfiguration current } @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final CreateDefaultShadowAlgorithmStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkAlgorithmExist(databaseName, sqlStatement, currentRuleConfig); } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowAlgorithmStatementUpdater.java index 79633a58fef1d..bde0271a8d0c5 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowAlgorithmStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker; import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment; @@ -60,8 +60,9 @@ public void updateCurrentRuleConfiguration(final ShadowRuleConfiguration current } @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final CreateShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, + final CreateShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { + String databaseName = databaseMetaData.getDatabase().getName(); ShadowRuleStatementChecker.checkAlgorithmCompleteness(sqlStatement.getAlgorithms()); checkDuplicatedInput(databaseName, sqlStatement); checkExist(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java index 3bd2759e56106..b0fe926dc1100 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/CreateShadowRuleStatementUpdater.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker; @@ -60,11 +60,12 @@ private void updateTables(final Map currentTab } @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final CreateShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, + final CreateShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { + String databaseName = databaseMetaData.getDatabase().getName(); Collection rules = sqlStatement.getRules(); checkRuleNames(databaseName, rules, currentRuleConfig); - checkResources(databaseName, rules, metaData); + checkResources(databaseName, databaseMetaData, rules); checkAlgorithms(databaseName, rules, currentRuleConfig); } @@ -75,9 +76,9 @@ private void checkRuleNames(final String databaseName, final Collection new DuplicateRuleException(SHADOW, databaseName, identical)); } - private void checkResources(final String databaseName, final Collection rules, final ShardingSphereMetaData metaData) throws DistSQLException { + private void checkResources(final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final Collection rules) throws DistSQLException { Collection requireResource = ShadowRuleStatementSupporter.getResourceNames(rules); - ShadowRuleStatementChecker.checkResourceExist(requireResource, metaData, databaseName); + ShadowRuleStatementChecker.checkResourceExist(requireResource, databaseMetaData, databaseName); } private void checkAlgorithms(final String databaseName, final Collection rules, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java index 37ba684ea6320..83f45e7e23125 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmStatementUpdater.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker; import org.apache.shardingsphere.shadow.distsql.parser.statement.DropDefaultShadowAlgorithmStatement; @@ -36,9 +36,9 @@ public final class DropDefaultShadowAlgorithmStatementUpdater implements RuleDef private static final String SHADOW = "shadow"; @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final DropDefaultShadowAlgorithmStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); if (sqlStatement.isContainsExistClause() && !isExistRuleConfig(currentRuleConfig)) { return; } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmStatementUpdater.java index fc094943a0106..38c8fc079684d 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmStatementUpdater.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker; @@ -44,8 +44,9 @@ public final class DropShadowAlgorithmStatementUpdater implements RuleDefinition private static final String SHADOW = "shadow"; @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final DropShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, + final DropShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { + String databaseName = databaseMetaData.getDatabase().getName(); if (sqlStatement.isContainsExistClause() && !isExistRuleConfig(currentRuleConfig)) { return; } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleStatementUpdater.java index f306ccf4aaf07..3a1836f56decb 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleStatementUpdater.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.checker.ShadowRuleStatementChecker; import org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowRuleStatement; @@ -35,8 +35,9 @@ public final class DropShadowRuleStatementUpdater implements RuleDefinitionDropU private static final String SHADOW = "shadow"; @Override - public void checkSQLStatement(final ShardingSphereMetaData metaData, final DropShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = metaData.getDatabase().getName(); + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, + final DropShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException { + String databaseName = databaseMetaData.getDatabase().getName(); if (sqlStatement.isContainsExistClause() && !isExistRuleConfig(currentRuleConfig)) { return; } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java index 665533a2fed69..6b764e0669d9c 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.query.ShadowAlgorithmQueryResultSet; @@ -42,10 +42,10 @@ public final class ShadowAlgorithmQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); DistSQLResultSet resultSet = new ShadowAlgorithmQueryResultSet(); - resultSet.init(metaData, mock(ShowShadowAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShadowAlgorithmsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(4)); assertThat(actual.get(0), is("shadowAlgorithmName")); diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java index 3ceff5a64b491..ca3e0b62b5386 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; @@ -41,10 +41,10 @@ public final class ShadowRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); DistSQLResultSet resultSet = new ShadowRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowShadowRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShadowRulesStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(4)); assertThat(actual.get(0), is("shadow_rule")); diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java index 22b3e1baa5a68..6f917ec79cdb7 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.query.ShadowTableRuleQueryResultSet; @@ -43,10 +43,10 @@ public final class ShadowTableRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); DistSQLResultSet resultSet = new ShadowTableRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowShadowAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShadowAlgorithmsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(2)); assertThat(actual.get(0), is("t_order")); diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowAlgorithmStatementUpdaterTest.java index e0336239ae974..5e4f962ef3bdb 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowAlgorithmStatementUpdaterTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.update.AlterShadowAlgorithmStatementUpdater; import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment; @@ -44,7 +44,7 @@ public final class AlterShadowAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShadowRuleConfiguration currentConfig; @@ -57,7 +57,7 @@ public void assertExecuteDuplicateAlgorithm() throws DistSQLException { prop.setProperty("type", "value"); AlterShadowAlgorithmStatement sqlStatement = createSQLStatement(new ShadowAlgorithmSegment("simpleHintAlgorithm", new AlgorithmSegment("SIMPLE_HINT", prop)), new ShadowAlgorithmSegment("simpleHintAlgorithm", new AlgorithmSegment("SIMPLE_HINT", prop))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = RequiredRuleMissedException.class) @@ -65,7 +65,7 @@ public void assertExecuteAlgorithmWithoutConfiguration() throws DistSQLException Properties prop = new Properties(); prop.setProperty("type", "value"); AlterShadowAlgorithmStatement sqlStatement = createSQLStatement(new ShadowAlgorithmSegment("simpleHintAlgorithm", new AlgorithmSegment("SIMPLE_HINT", prop))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, null); + updater.checkSQLStatement(databaseMetaData, sqlStatement, null); } @Test(expected = RequiredAlgorithmMissedException.class) @@ -74,7 +74,7 @@ public void assertExecuteAlgorithmNotInMetaData() throws DistSQLException { prop.setProperty("type", "value"); when(currentConfig.getShadowAlgorithms()).thenReturn(Collections.singletonMap("simpleHintAlgorithm", new ShardingSphereAlgorithmConfiguration("type", prop))); AlterShadowAlgorithmStatement sqlStatement = createSQLStatement(new ShadowAlgorithmSegment("simpleHintAlgorithm1", new AlgorithmSegment("SIMPLE_HINT", prop))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } private AlterShadowAlgorithmStatement createSQLStatement(final ShadowAlgorithmSegment... ruleSegments) { diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java index 41282ef1117cc..cf2fb57a10c4d 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; @@ -53,7 +53,7 @@ public final class AlterShadowRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereResource resource; @@ -68,26 +68,26 @@ public void before() { Map map = new HashMap<>(); map.put("initRuleName1", new ShadowDataSourceConfiguration("ds1", "ds_shadow1")); map.put("initRuleName2", new ShadowDataSourceConfiguration("ds2", "ds_shadow2")); - when(shardingSphereMetaData.getResource()).thenReturn(resource); + when(databaseMetaData.getResource()).thenReturn(resource); when(currentConfig.getDataSources()).thenReturn(map); } @Test(expected = RequiredRuleMissedException.class) public void assertExecuteWithoutCurrentConfiguration() throws DistSQLException { ShadowRuleSegment ruleSegment = new ShadowRuleSegment("ruleName", null, null, null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(ruleSegment, ruleSegment), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(ruleSegment, ruleSegment), null); } @Test(expected = DuplicateRuleException.class) public void assertExecuteWithDuplicateRuleName() throws DistSQLException { ShadowRuleSegment ruleSegment = new ShadowRuleSegment("ruleName", null, null, null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(ruleSegment, ruleSegment), currentConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(ruleSegment, ruleSegment), currentConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertExecuteWithRuleNameNotInMetaData() throws DistSQLException { ShadowRuleSegment ruleSegment = new ShadowRuleSegment("ruleName", null, null, null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(ruleSegment), currentConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(ruleSegment), currentConfig); } @Test(expected = RequiredResourceMissedException.class) @@ -95,7 +95,7 @@ public void assertExecuteWithNotExistResource() throws DistSQLException { List dataSources = Arrays.asList("ds", "ds0"); when(resource.getNotExistedResources(any())).thenReturn(dataSources); AlterShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("initRuleName1", "ds3", null, null)); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = AlgorithmInUsedException.class) @@ -105,7 +105,7 @@ public void assertExecuteDuplicateAlgorithm() throws DistSQLException { ShadowAlgorithmSegment segment = new ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name", prop)); AlterShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("initRuleName1", "ds", null, Collections.singletonMap("t_order", Collections.singleton(segment))), new ShadowRuleSegment("initRuleName2", "ds1", null, Collections.singletonMap("t_order_1", Collections.singletonList(segment)))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = AlgorithmInUsedException.class) @@ -115,7 +115,7 @@ public void assertExecuteDuplicateAlgorithmWithoutConfiguration() throws DistSQL ShadowAlgorithmSegment segment = new ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name", prop)); AlterShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("initRuleName1", "ds", null, Collections.singletonMap("t_order", Collections.singleton(segment))), new ShadowRuleSegment("initRuleName2", "ds1", null, Collections.singletonMap("t_order_1", Collections.singletonList(segment)))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test @@ -126,7 +126,7 @@ public void assertExecuteSuccess() throws DistSQLException { ShadowAlgorithmSegment segment2 = new ShadowAlgorithmSegment("algorithmName2", new AlgorithmSegment("name", prop)); AlterShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("initRuleName1", "ds", null, Collections.singletonMap("t_order", Collections.singleton(segment1))), new ShadowRuleSegment("initRuleName2", "ds1", null, Collections.singletonMap("t_order_1", Collections.singletonList(segment2)))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } private AlterShadowRuleStatement createSQLStatement(final ShadowRuleSegment... ruleSegments) { diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java index 7a30b29b2088b..86b6cae18df09 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.update.CreateDefaultShadowAlgorithmStatementUpdater; import org.apache.shardingsphere.shadow.distsql.parser.statement.CreateDefaultShadowAlgorithmStatement; @@ -37,7 +37,7 @@ public final class CreateDefaultShadowAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShadowRuleConfiguration currentConfig; @@ -47,6 +47,6 @@ public final class CreateDefaultShadowAlgorithmStatementUpdaterTest { @Test(expected = RequiredAlgorithmMissedException.class) public void assertExecuteWithNotExistAlgorithm() throws DistSQLException { when(currentConfig.getShadowAlgorithms()).thenReturn(Collections.singletonMap("default_name", null)); - updater.checkSQLStatement(shardingSphereMetaData, new CreateDefaultShadowAlgorithmStatement("input_default_name"), currentConfig); + updater.checkSQLStatement(databaseMetaData, new CreateDefaultShadowAlgorithmStatement("input_default_name"), currentConfig); } } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowAlgorithmStatementUpdaterTest.java index da203bd348d76..04e0084ead623 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowAlgorithmStatementUpdaterTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.update.CreateShadowAlgorithmStatementUpdater; import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment; @@ -42,7 +42,7 @@ public final class CreateShadowAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShadowRuleConfiguration currentConfig; @@ -55,7 +55,7 @@ public void assertExecuteWithDuplicateAlgorithm() throws DistSQLException { props.setProperty("type", "value"); CreateShadowAlgorithmStatement sqlStatement = createSQLStatement(new ShadowAlgorithmSegment("foo_algorithm", new AlgorithmSegment("SIMPLE_HINT", props)), new ShadowAlgorithmSegment("foo_algorithm", new AlgorithmSegment("SIMPLE_HINT", props))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = DuplicateRuleException.class) @@ -64,7 +64,7 @@ public void assertExecuteWithExistAlgorithm() throws DistSQLException { Properties props = new Properties(); props.setProperty("type", "value"); CreateShadowAlgorithmStatement sqlStatement = createSQLStatement(new ShadowAlgorithmSegment("foo_algorithm", new AlgorithmSegment("SIMPLE_HINT", props))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -72,7 +72,7 @@ public void assertExecuteWithAlgorithmCompleteness() throws DistSQLException { Properties props = new Properties(); props.setProperty("type", "value"); CreateShadowAlgorithmStatement sqlStatement = createSQLStatement(new ShadowAlgorithmSegment("foo_algorithm", new AlgorithmSegment("", props))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -80,7 +80,7 @@ public void assertExecuteWithInvalidAlgorithmType() throws DistSQLException { Properties props = new Properties(); props.setProperty("type", "value"); CreateShadowAlgorithmStatement sqlStatement = createSQLStatement(new ShadowAlgorithmSegment("foo_algorithm", new AlgorithmSegment("NOT_EXISTED_ALGORITHM", props))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } private CreateShadowAlgorithmStatement createSQLStatement(final ShadowAlgorithmSegment... ruleSegments) { diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java index e9c4fe280d141..c1373de83f5e9 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; @@ -49,7 +49,7 @@ public final class CreateShadowRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereResource resource; @@ -61,21 +61,21 @@ public final class CreateShadowRuleStatementUpdaterTest { @Before public void before() { - when(shardingSphereMetaData.getResource()).thenReturn(resource); + when(databaseMetaData.getResource()).thenReturn(resource); when(currentConfig.getDataSources()).thenReturn(Collections.singletonMap("initRuleName", new ShadowDataSourceConfiguration("initDs0", "initDs0Shadow"))); } @Test(expected = DuplicateRuleException.class) public void assertExecuteWithDuplicateRuleName() throws DistSQLException { ShadowRuleSegment ruleSegment = new ShadowRuleSegment("ruleName", null, null, null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(ruleSegment, ruleSegment), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(ruleSegment, ruleSegment), null); } @Test(expected = DuplicateRuleException.class) public void assertExecuteWithDuplicateRuleNameInMetaData() throws DistSQLException { when(currentConfig.getDataSources()).thenReturn(Collections.singletonMap("ruleName", null)); ShadowRuleSegment ruleSegment = new ShadowRuleSegment("ruleName", null, null, null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(ruleSegment), currentConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(ruleSegment), currentConfig); } @Test(expected = RequiredResourceMissedException.class) @@ -83,7 +83,7 @@ public void assertExecuteWithNotExistResource() throws DistSQLException { List dataSources = Arrays.asList("ds0", "ds1"); when(resource.getNotExistedResources(any())).thenReturn(dataSources); CreateShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("ruleName", "ds1", null, null)); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = DuplicateRuleException.class) @@ -93,7 +93,7 @@ public void assertExecuteDuplicateAlgorithm() throws DistSQLException { ShadowAlgorithmSegment segment = new ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name", prop)); CreateShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("ruleName", "ds", null, Collections.singletonMap("t_order", Collections.singleton(segment))), new ShadowRuleSegment("ruleName1", "ds1", null, Collections.singletonMap("t_order_1", Collections.singletonList(segment)))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } @Test(expected = DuplicateRuleException.class) @@ -103,7 +103,7 @@ public void assertExecuteDuplicateAlgorithmWithoutConfiguration() throws DistSQL ShadowAlgorithmSegment segment = new ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name", prop)); CreateShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("ruleName", "ds", null, Collections.singletonMap("t_order", Collections.singleton(segment))), new ShadowRuleSegment("ruleName1", "ds1", null, Collections.singletonMap("t_order_1", Collections.singletonList(segment)))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, null); + updater.checkSQLStatement(databaseMetaData, sqlStatement, null); } @Test(expected = DuplicateRuleException.class) @@ -113,7 +113,7 @@ public void assertExecuteDuplicateAlgorithmInMetaData() throws DistSQLException when(currentConfig.getShadowAlgorithms()).thenReturn(Collections.singletonMap("algorithmName", new ShardingSphereAlgorithmConfiguration("type", prop))); ShadowAlgorithmSegment segment = new ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("type", prop)); CreateShadowRuleStatement sqlStatement = createSQLStatement(new ShadowRuleSegment("ruleName", "ds", null, Collections.singletonMap("t_order", Collections.singleton(segment)))); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentConfig); } private CreateShadowRuleStatement createSQLStatement(final ShadowRuleSegment... ruleSegments) { diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java index 164d859dc6850..9dc3dc8367602 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.update.DropDefaultShadowAlgorithmStatementUpdater; import org.apache.shardingsphere.shadow.distsql.parser.statement.DropDefaultShadowAlgorithmStatement; @@ -36,7 +36,7 @@ public final class DropDefaultShadowAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShadowRuleConfiguration currentConfig; @@ -45,13 +45,13 @@ public final class DropDefaultShadowAlgorithmStatementUpdaterTest { @Test(expected = RequiredAlgorithmMissedException.class) public void assertCheckWithoutDefaultAlgorithm() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new DropDefaultShadowAlgorithmStatement(), currentConfig); + updater.checkSQLStatement(databaseMetaData, new DropDefaultShadowAlgorithmStatement(), currentConfig); } @Test public void assertCheckWithIfExists() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new DropDefaultShadowAlgorithmStatement(true), currentConfig); - updater.checkSQLStatement(shardingSphereMetaData, new DropDefaultShadowAlgorithmStatement(true), null); + updater.checkSQLStatement(databaseMetaData, new DropDefaultShadowAlgorithmStatement(true), currentConfig); + updater.checkSQLStatement(databaseMetaData, new DropDefaultShadowAlgorithmStatement(true), null); } @Test @@ -59,7 +59,7 @@ public void assertUpdate() throws DistSQLException { ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration(); ruleConfig.setDefaultShadowAlgorithmName("default"); DropDefaultShadowAlgorithmStatement statement = new DropDefaultShadowAlgorithmStatement(); - updater.checkSQLStatement(shardingSphereMetaData, new DropDefaultShadowAlgorithmStatement(true), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new DropDefaultShadowAlgorithmStatement(true), ruleConfig); assertTrue(updater.hasAnyOneToBeDropped(statement, ruleConfig)); updater.updateCurrentRuleConfiguration(statement, ruleConfig); assertNull(ruleConfig.getDefaultShadowAlgorithmName()); diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowAlgorithmStatementUpdaterTest.java index 844c1c1b5418c..1950c1c97b0bf 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowAlgorithmStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.update.DropShadowAlgorithmStatementUpdater; @@ -41,20 +41,20 @@ public final class DropShadowAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropShadowAlgorithmStatementUpdater updater = new DropShadowAlgorithmStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertExecuteWithoutAlgorithmNameInMetaData() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("ruleSegment"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("ruleSegment"), null); } @Test public void assertExecuteWithIfExists() throws DistSQLException { DropShadowAlgorithmStatement sqlStatement = createSQLStatement("ruleSegment"); sqlStatement.setContainsExistClause(true); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, mock(ShadowRuleConfiguration.class)); + updater.checkSQLStatement(databaseMetaData, sqlStatement, mock(ShadowRuleConfiguration.class)); } @Test @@ -63,7 +63,7 @@ public void assertUpdate() throws DistSQLException { sqlStatement.setContainsExistClause(true); ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration(); ruleConfig.getTables().put("t_order", new ShadowTableConfiguration(new ArrayList<>(Collections.singleton("ds_0")), Collections.emptyList())); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, ruleConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, ruleConfig); updater.updateCurrentRuleConfiguration(sqlStatement, ruleConfig); assertFalse(ruleConfig.getTables().containsKey("ds_0")); } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowRuleStatementUpdaterTest.java index cabcfa2cca727..c58c21adc3295 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropShadowRuleStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; import org.apache.shardingsphere.shadow.distsql.handler.update.DropShadowRuleStatementUpdater; @@ -43,7 +43,7 @@ public final class DropShadowRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShadowRuleConfiguration currentConfig; @@ -57,14 +57,14 @@ public void before() { @Test(expected = RequiredRuleMissedException.class) public void assertExecuteWithoutRuleNameInMetaData() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("ruleSegment"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("ruleSegment"), null); } @Test public void assertExecuteWithIfExists() throws DistSQLException { DropShadowRuleStatement sqlStatement = createSQLStatement("ruleSegment"); sqlStatement.setContainsExistClause(true); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, mock(ShadowRuleConfiguration.class)); + updater.checkSQLStatement(databaseMetaData, sqlStatement, mock(ShadowRuleConfiguration.class)); } @Test @@ -73,14 +73,14 @@ public void assertUpdate() throws DistSQLException { sqlStatement.setContainsExistClause(true); ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration(); ruleConfig.getTables().put("t_order", new ShadowTableConfiguration(new ArrayList<>(Collections.singleton("ds_0")), Collections.emptyList())); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, ruleConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, ruleConfig); updater.updateCurrentRuleConfiguration(sqlStatement, ruleConfig); assertFalse(ruleConfig.getTables().containsKey("ds_0")); } @Test public void assertExecuteSuccess() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("initRuleName"), currentConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("initRuleName"), currentConfig); } private DropShadowRuleStatement createSQLStatement(final String... ruleName) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java index f971f818a0222..2105e9d5794bc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java @@ -26,11 +26,15 @@ import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue; import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.OffsetDateTime; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAccessor; import java.util.Collection; import java.util.Date; import java.util.HashSet; @@ -157,11 +161,14 @@ private LocalDateTime parseLocalDateTime(final Comparable endpoint) { } private String getDateTimeText(final Comparable endpoint) { - if (endpoint instanceof LocalDateTime) { - return ((LocalDateTime) endpoint).format(dateTimeFormatter); + if (endpoint instanceof LocalDateTime || endpoint instanceof ZonedDateTime || endpoint instanceof OffsetDateTime) { + return dateTimeFormatter.format((TemporalAccessor) endpoint); + } + if (endpoint instanceof Instant) { + return dateTimeFormatter.withZone(ZoneId.systemDefault()).format((Instant) endpoint); } if (endpoint instanceof Date) { - return ((Date) endpoint).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().format(dateTimeFormatter); + return dateTimeFormatter.format(((Date) endpoint).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()); } return endpoint.toString(); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/data/pipeline/ShardingRuleAlteredJobConfigurationPreparer.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/data/pipeline/ShardingRuleAlteredJobConfigurationPreparer.java index 351c53ea46720..c1c17a2e86321 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/data/pipeline/ShardingRuleAlteredJobConfigurationPreparer.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/data/pipeline/ShardingRuleAlteredJobConfigurationPreparer.java @@ -38,7 +38,7 @@ import org.apache.shardingsphere.infra.config.rulealtered.OnRuleAlteredActionConfiguration; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.yaml.config.swapper.YamlDataSourceConfigurationSwapper; import org.apache.shardingsphere.infra.yaml.engine.YamlEngine; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -147,13 +147,13 @@ public TaskConfiguration createTaskConfiguration(final RuleAlteredJobConfigurati tableNameMap.put(new ActualTableName(dataNode.getTableName()), new LogicTableName(each.getLogicTableName())); } } - ShardingSphereMetaData metaData = PipelineContext.getContextManager().getMetaDataContexts().getMetaData(jobConfig.getDatabaseName()); + ShardingSphereDatabaseMetaData databaseMetaData = PipelineContext.getContextManager().getMetaDataContexts().getDatabaseMetaData(jobConfig.getDatabaseName()); DumperConfiguration dumperConfig = createDumperConfiguration(jobConfig.getDatabaseName(), dataSourceName, - dataSourcePropsMap.get(dataSourceName).getAllLocalProperties(), tableNameMap, metaData); + dataSourcePropsMap.get(dataSourceName).getAllLocalProperties(), tableNameMap, databaseMetaData); Optional targetRuleConfigOptional = getTargetRuleConfiguration(jobConfig); Set reShardNeededTables = jobConfig.splitLogicTableNames().stream().map(LogicTableName::new).collect(Collectors.toSet()); Map> shardingColumnsMap = getShardingColumnsMap(targetRuleConfigOptional.orElse(sourceRuleConfig), reShardNeededTables); - ImporterConfiguration importerConfig = createImporterConfiguration(jobConfig, onRuleAlteredActionConfig, shardingColumnsMap, metaData); + ImporterConfiguration importerConfig = createImporterConfiguration(jobConfig, onRuleAlteredActionConfig, shardingColumnsMap, databaseMetaData); TaskConfiguration result = new TaskConfiguration(jobConfig, dumperConfig, importerConfig); log.info("createTaskConfiguration, dataSourceName={}, result={}", dataSourceName, result); return result; @@ -209,20 +209,20 @@ private static Set extractShardingColumns(final ShardingStrategyConfigur } private static DumperConfiguration createDumperConfiguration(final String databaseName, final String dataSourceName, final Map props, - final Map tableNameMap, final ShardingSphereMetaData metaData) { + final Map tableNameMap, final ShardingSphereDatabaseMetaData databaseMetaData) { DumperConfiguration result = new DumperConfiguration(); result.setDatabaseName(databaseName); result.setDataSourceName(dataSourceName); result.setDataSourceConfig(new StandardPipelineDataSourceConfiguration(YamlEngine.marshal(props))); result.setTableNameMap(tableNameMap); - result.setTableNameSchemaNameMapping(new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(metaData.getDatabase().getSchemas()))); + result.setTableNameSchemaNameMapping(new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(databaseMetaData.getDatabase().getSchemas()))); return result; } private static ImporterConfiguration createImporterConfiguration(final RuleAlteredJobConfiguration jobConfig, final OnRuleAlteredActionConfiguration onRuleAlteredActionConfig, - final Map> shardingColumnsMap, final ShardingSphereMetaData metaData) { + final Map> shardingColumnsMap, final ShardingSphereDatabaseMetaData databaseMetaData) { PipelineDataSourceConfiguration dataSourceConfig = PipelineDataSourceConfigurationFactory.newInstance(jobConfig.getTarget().getType(), jobConfig.getTarget().getParameter()); - TableNameSchemaNameMapping tableNameSchemaNameMapping = new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(metaData.getDatabase().getSchemas())); + TableNameSchemaNameMapping tableNameSchemaNameMapping = new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(databaseMetaData.getDatabase().getSchemas())); int batchSize = onRuleAlteredActionConfig.getOutput().getBatchSize(); int retryTimes = jobConfig.getRetryTimes(); return new ImporterConfiguration(dataSourceConfig, unmodifiable(shardingColumnsMap), tableNameSchemaNameMapping, batchSize, retryTimes); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java index 60356b7bcdab8..3410c1d2d62ee 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.merge.engine.merger.ResultMerger; import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.merge.dal.common.SingleLocalDataMergedResult; import org.apache.shardingsphere.sharding.merge.dal.show.LogicTablesMergedResult; @@ -53,13 +53,13 @@ public final class ShardingDALResultMerger implements ResultMerger { private final ShardingRule shardingRule; @Override - public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereMetaData metaData) throws SQLException { + public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereDatabaseMetaData databaseMetaData) throws SQLException { SQLStatement dalStatement = sqlStatementContext.getSqlStatement(); - String schemaName = sqlStatementContext.getTablesContext().getSchemaName().orElse(sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName())); + String schemaName = sqlStatementContext.getTablesContext().getSchemaName().orElse(sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName())); if (dalStatement instanceof MySQLShowDatabasesStatement) { return new SingleLocalDataMergedResult(Collections.singletonList(databaseName)); } - ShardingSphereSchema schema = metaData.getSchemaByName(schemaName); + ShardingSphereSchema schema = databaseMetaData.getDatabase().getSchema(schemaName); if (dalStatement instanceof MySQLShowTablesStatement) { return new LogicTablesMergedResult(shardingRule, sqlStatementContext, schema, queryResults); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java index 79daf6ad38ff9..6628470ea930c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.engine.merger.ResultMerger; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByMemoryMergedResult; import org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByStreamMergedResult; @@ -54,14 +54,14 @@ public final class ShardingDQLResultMerger implements ResultMerger { private final DatabaseType databaseType; @Override - public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereMetaData metaData) throws SQLException { + public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereDatabaseMetaData databaseMetaData) throws SQLException { if (1 == queryResults.size() && !isNeedAggregateRewrite(sqlStatementContext)) { return new IteratorStreamMergedResult(queryResults); } Map columnLabelIndexMap = getColumnLabelIndexMap(queryResults.get(0)); SelectStatementContext selectStatementContext = (SelectStatementContext) sqlStatementContext; selectStatementContext.setIndexes(columnLabelIndexMap); - MergedResult mergedResult = build(queryResults, selectStatementContext, columnLabelIndexMap, metaData); + MergedResult mergedResult = build(queryResults, selectStatementContext, columnLabelIndexMap, databaseMetaData); return decorate(queryResults, selectStatementContext, mergedResult); } @@ -78,9 +78,10 @@ private Map getColumnLabelIndexMap(final QueryResult queryResul } private MergedResult build(final List queryResults, final SelectStatementContext selectStatementContext, - final Map columnLabelIndexMap, final ShardingSphereMetaData metaData) throws SQLException { - String defaultSchema = selectStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); - ShardingSphereSchema schema = selectStatementContext.getTablesContext().getSchemaName().map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + final Map columnLabelIndexMap, final ShardingSphereDatabaseMetaData databaseMetaData) throws SQLException { + String defaultSchema = selectStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); + ShardingSphereSchema schema = selectStatementContext.getTablesContext().getSchemaName() + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); if (isNeedProcessGroupBy(selectStatementContext)) { return getGroupByMergedResult(queryResults, selectStatementContext, columnLabelIndexMap, schema); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java index f6037675522dc..30f2893f4db81 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.SQLRouter; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.constant.ShardingOrder; @@ -45,24 +45,24 @@ public final class ShardingSQLRouter implements SQLRouter { @SuppressWarnings({"rawtypes", "unchecked"}) @Override - public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShardingRule rule, final ConfigurationProperties props) { + public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ShardingRule rule, final ConfigurationProperties props) { SQLStatement sqlStatement = logicSQL.getSqlStatementContext().getSqlStatement(); - ShardingConditions shardingConditions = createShardingConditions(logicSQL, metaData, rule); + ShardingConditions shardingConditions = createShardingConditions(logicSQL, databaseMetaData, rule); Optional validator = ShardingStatementValidatorFactory.newInstance(sqlStatement, shardingConditions); - validator.ifPresent(optional -> optional.preValidate(rule, logicSQL.getSqlStatementContext(), logicSQL.getParameters(), metaData)); + validator.ifPresent(optional -> optional.preValidate(rule, logicSQL.getSqlStatementContext(), logicSQL.getParameters(), databaseMetaData)); if (sqlStatement instanceof DMLStatement && shardingConditions.isNeedMerge()) { shardingConditions.merge(); } - RouteContext result = ShardingRouteEngineFactory.newInstance(rule, metaData, logicSQL.getSqlStatementContext(), shardingConditions, props).route(rule); - validator.ifPresent(optional -> optional.postValidate(rule, logicSQL.getSqlStatementContext(), logicSQL.getParameters(), metaData, props, result)); + RouteContext result = ShardingRouteEngineFactory.newInstance(rule, databaseMetaData, logicSQL.getSqlStatementContext(), shardingConditions, props).route(rule); + validator.ifPresent(optional -> optional.postValidate(rule, logicSQL.getSqlStatementContext(), logicSQL.getParameters(), databaseMetaData, props, result)); return result; } @SuppressWarnings({"rawtypes", "unchecked"}) - private ShardingConditions createShardingConditions(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShardingRule rule) { + private ShardingConditions createShardingConditions(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ShardingRule rule) { List shardingConditions; if (logicSQL.getSqlStatementContext().getSqlStatement() instanceof DMLStatement) { - ShardingConditionEngine shardingConditionEngine = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, metaData, rule); + ShardingConditionEngine shardingConditionEngine = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, databaseMetaData, rule); shardingConditions = shardingConditionEngine.createShardingConditions(logicSQL.getSqlStatementContext(), logicSQL.getParameters()); } else { shardingConditions = Collections.emptyList(); @@ -71,7 +71,7 @@ private ShardingConditions createShardingConditions(final LogicSQL logicSQL, fin } @Override - public void decorateRouteContext(final RouteContext routeContext, final LogicSQL logicSQL, final ShardingSphereMetaData metaData, + public void decorateRouteContext(final RouteContext routeContext, final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ShardingRule rule, final ConfigurationProperties props) { // TODO } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java index 4e15d7f09dd61..03b1c397046a1 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java @@ -21,7 +21,7 @@ import lombok.NoArgsConstructor; import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine; import org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.WhereClauseShardingConditionEngine; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -36,13 +36,13 @@ public final class ShardingConditionEngineFactory { * Create new instance of sharding condition engine. * * @param logicSQL logic SQL - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param rule sharding rule * @return created instance */ - public static ShardingConditionEngine createShardingConditionEngine(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ShardingRule rule) { + public static ShardingConditionEngine createShardingConditionEngine(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ShardingRule rule) { return logicSQL.getSqlStatementContext() instanceof InsertStatementContext - ? new InsertClauseShardingConditionEngine(rule, metaData) - : new WhereClauseShardingConditionEngine(rule, metaData); + ? new InsertClauseShardingConditionEngine(rule, databaseMetaData) + : new WhereClauseShardingConditionEngine(rule, databaseMetaData); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java index ac273cda2d3f5..8ecb20ed5b7ce 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.datetime.DatetimeService; import org.apache.shardingsphere.infra.datetime.DatetimeServiceFactory; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition; import org.apache.shardingsphere.sharding.route.engine.condition.engine.ShardingConditionEngine; @@ -55,7 +55,7 @@ public final class InsertClauseShardingConditionEngine implements ShardingCondit private final ShardingRule shardingRule; - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; @Override public List createShardingConditions(final InsertStatementContext sqlStatementContext, final List parameters) { @@ -123,7 +123,7 @@ private Comparable getShardingValue(final SimpleExpressionSegment expressionS private List createShardingConditionsWithInsertSelect(final InsertStatementContext sqlStatementContext, final List parameters) { SelectStatementContext selectStatementContext = sqlStatementContext.getInsertSelectContext().getSelectStatementContext(); - return new LinkedList<>(new WhereClauseShardingConditionEngine(shardingRule, metaData).createShardingConditions(selectStatementContext, parameters)); + return new LinkedList<>(new WhereClauseShardingConditionEngine(shardingRule, databaseMetaData).createShardingConditions(selectStatementContext, parameters)); } private void appendGeneratedKeyConditions(final InsertStatementContext sqlStatementContext, final List shardingConditions) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java index fcebdbc128b39..1a5166a7050dc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.type.WhereAvailable; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.route.engine.condition.AlwaysFalseShardingCondition; import org.apache.shardingsphere.sharding.route.engine.condition.Column; @@ -60,7 +60,7 @@ public final class WhereClauseShardingConditionEngine implements ShardingConditi private final ShardingRule shardingRule; - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; @Override public List createShardingConditions(final SQLStatementContext sqlStatementContext, final List parameters) { @@ -68,8 +68,9 @@ public List createShardingConditions(final SQLStatementContex return Collections.emptyList(); } Collection columnSegments = ((WhereAvailable) sqlStatementContext).getColumnSegments(); - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); - ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); + ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName() + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); Map columnExpressionTableNames = sqlStatementContext.getTablesContext().findTableNamesByColumnSegment(columnSegments, schema); List result = new ArrayList<>(); for (WhereSegment each : ((WhereAvailable) sqlStatementContext).getWhereSegments()) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java index ebd4f8b658eb8..4de3d57236b1e 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.binder.type.TableAvailable; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions; import org.apache.shardingsphere.sharding.route.engine.condition.value.ShardingConditionValue; @@ -77,31 +77,31 @@ public final class ShardingRouteEngineFactory { * Create new instance of routing engine. * * @param shardingRule sharding rule - * @param metaData ShardingSphere metaData + * @param databaseMetaData database meta data * @param sqlStatementContext SQL statement context * @param shardingConditions shardingConditions * @param props ShardingSphere properties * @return created instance */ - public static ShardingRouteEngine newInstance(final ShardingRule shardingRule, final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext, + public static ShardingRouteEngine newInstance(final ShardingRule shardingRule, final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatementContext sqlStatementContext, final ShardingConditions shardingConditions, final ConfigurationProperties props) { SQLStatement sqlStatement = sqlStatementContext.getSqlStatement(); if (sqlStatement instanceof TCLStatement) { return new ShardingDatabaseBroadcastRoutingEngine(); } if (sqlStatement instanceof DDLStatement) { - return getDDLRoutingEngine(shardingRule, metaData, sqlStatementContext); + return getDDLRoutingEngine(shardingRule, databaseMetaData, sqlStatementContext); } if (sqlStatement instanceof DALStatement) { - return getDALRoutingEngine(shardingRule, metaData, sqlStatementContext); + return getDALRoutingEngine(shardingRule, databaseMetaData, sqlStatementContext); } if (sqlStatement instanceof DCLStatement) { - return getDCLRoutingEngine(shardingRule, metaData, sqlStatementContext); + return getDCLRoutingEngine(shardingRule, databaseMetaData, sqlStatementContext); } - return getDQLRoutingEngine(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + return getDQLRoutingEngine(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); } - private static ShardingRouteEngine getDDLRoutingEngine(final ShardingRule shardingRule, final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext) { + private static ShardingRouteEngine getDDLRoutingEngine(final ShardingRule shardingRule, final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatementContext sqlStatementContext) { SQLStatement sqlStatement = sqlStatementContext.getSqlStatement(); boolean functionStatement = sqlStatement instanceof CreateFunctionStatement || sqlStatement instanceof AlterFunctionStatement || sqlStatement instanceof DropFunctionStatement; boolean procedureStatement = sqlStatement instanceof CreateProcedureStatement || sqlStatement instanceof AlterProcedureStatement || sqlStatement instanceof DropProcedureStatement; @@ -109,7 +109,7 @@ private static ShardingRouteEngine getDDLRoutingEngine(final ShardingRule shardi return new ShardingDatabaseBroadcastRoutingEngine(); } if (sqlStatement instanceof CreateTablespaceStatement || sqlStatement instanceof AlterTablespaceStatement || sqlStatement instanceof DropTablespaceStatement) { - return new ShardingInstanceBroadcastRoutingEngine(metaData.getResource().getDataSourcesMetaData()); + return new ShardingInstanceBroadcastRoutingEngine(databaseMetaData.getResource().getDataSourcesMetaData()); } Collection tableNames = sqlStatementContext instanceof TableAvailable ? ((TableAvailable) sqlStatementContext).getAllTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toSet()) @@ -118,10 +118,10 @@ private static ShardingRouteEngine getDDLRoutingEngine(final ShardingRule shardi if (!tableNames.isEmpty() && shardingRuleTableNames.isEmpty()) { return new ShardingIgnoreRoutingEngine(); } - return new ShardingTableBroadcastRoutingEngine(metaData, sqlStatementContext, shardingRuleTableNames); + return new ShardingTableBroadcastRoutingEngine(databaseMetaData, sqlStatementContext, shardingRuleTableNames); } - private static ShardingRouteEngine getDALRoutingEngine(final ShardingRule shardingRule, final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext) { + private static ShardingRouteEngine getDALRoutingEngine(final ShardingRule shardingRule, final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatementContext sqlStatementContext) { SQLStatement sqlStatement = sqlStatementContext.getSqlStatement(); if (sqlStatement instanceof MySQLUseStatement) { return new ShardingIgnoreRoutingEngine(); @@ -131,7 +131,7 @@ private static ShardingRouteEngine getDALRoutingEngine(final ShardingRule shardi return new ShardingDatabaseBroadcastRoutingEngine(); } if (isResourceGroupStatement(sqlStatement)) { - return new ShardingInstanceBroadcastRoutingEngine(metaData.getResource().getDataSourcesMetaData()); + return new ShardingInstanceBroadcastRoutingEngine(databaseMetaData.getResource().getDataSourcesMetaData()); } Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); Collection shardingRuleTableNames = shardingRule.getShardingRuleTableNames(tableNames); @@ -139,11 +139,11 @@ private static ShardingRouteEngine getDALRoutingEngine(final ShardingRule shardi return new ShardingIgnoreRoutingEngine(); } if (sqlStatement instanceof MySQLOptimizeTableStatement) { - return new ShardingTableBroadcastRoutingEngine(metaData, sqlStatementContext, shardingRuleTableNames); + return new ShardingTableBroadcastRoutingEngine(databaseMetaData, sqlStatementContext, shardingRuleTableNames); } if (sqlStatement instanceof AnalyzeTableStatement) { return shardingRuleTableNames.isEmpty() ? new ShardingDatabaseBroadcastRoutingEngine() - : new ShardingTableBroadcastRoutingEngine(metaData, sqlStatementContext, shardingRuleTableNames); + : new ShardingTableBroadcastRoutingEngine(databaseMetaData, sqlStatementContext, shardingRuleTableNames); } if (!shardingRuleTableNames.isEmpty()) { return new ShardingUnicastRoutingEngine(shardingRuleTableNames); @@ -156,14 +156,14 @@ private static boolean isResourceGroupStatement(final SQLStatement sqlStatement) return sqlStatement instanceof MySQLCreateResourceGroupStatement || sqlStatement instanceof MySQLSetResourceGroupStatement; } - private static ShardingRouteEngine getDCLRoutingEngine(final ShardingRule shardingRule, final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext) { + private static ShardingRouteEngine getDCLRoutingEngine(final ShardingRule shardingRule, final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatementContext sqlStatementContext) { if (isDCLForSingleTable(sqlStatementContext)) { Collection shardingRuleTableNames = shardingRule.getShardingRuleTableNames(sqlStatementContext.getTablesContext().getTableNames()); return !shardingRuleTableNames.isEmpty() - ? new ShardingTableBroadcastRoutingEngine(metaData, sqlStatementContext, shardingRuleTableNames) + ? new ShardingTableBroadcastRoutingEngine(databaseMetaData, sqlStatementContext, shardingRuleTableNames) : new ShardingIgnoreRoutingEngine(); } else { - return new ShardingInstanceBroadcastRoutingEngine(metaData.getResource().getDataSourcesMetaData()); + return new ShardingInstanceBroadcastRoutingEngine(databaseMetaData.getResource().getDataSourcesMetaData()); } } @@ -175,7 +175,7 @@ private static boolean isDCLForSingleTable(final SQLStatementContext sqlState return false; } - private static ShardingRouteEngine getDQLRoutingEngine(final ShardingRule shardingRule, final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext, + private static ShardingRouteEngine getDQLRoutingEngine(final ShardingRule shardingRule, final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatementContext sqlStatementContext, final ShardingConditions shardingConditions, final ConfigurationProperties props) { Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); if (shardingRule.isAllBroadcastTables(tableNames)) { @@ -188,12 +188,13 @@ private static ShardingRouteEngine getDQLRoutingEngine(final ShardingRule shardi if (shardingLogicTableNames.isEmpty()) { return new ShardingIgnoreRoutingEngine(); } - return getDQLRouteEngineForShardingTable(shardingRule, metaData, sqlStatementContext, shardingConditions, props, shardingLogicTableNames); + return getDQLRouteEngineForShardingTable(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props, shardingLogicTableNames); } - private static ShardingRouteEngine getDQLRouteEngineForShardingTable(final ShardingRule shardingRule, final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext, - final ShardingConditions shardingConditions, final ConfigurationProperties props, final Collection tableNames) { - boolean allBindingTables = tableNames.size() > 1 && shardingRule.isAllBindingTables(metaData, sqlStatementContext, tableNames); + private static ShardingRouteEngine getDQLRouteEngineForShardingTable(final ShardingRule shardingRule, final ShardingSphereDatabaseMetaData databaseMetaData, + final SQLStatementContext sqlStatementContext, final ShardingConditions shardingConditions, + final ConfigurationProperties props, final Collection tableNames) { + boolean allBindingTables = tableNames.size() > 1 && shardingRule.isAllBindingTables(databaseMetaData, sqlStatementContext, tableNames); if (isShardingFederatedQuery(shardingRule, sqlStatementContext, shardingConditions, props, tableNames, allBindingTables)) { return new ShardingFederatedRoutingEngine(tableNames); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngine.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngine.java index 95a01d0cfbb3b..f5e07a72d0f62 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngine.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngine.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.binder.type.IndexAvailable; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.QualifiedTable; import org.apache.shardingsphere.infra.metadata.schema.util.IndexMetaDataUtil; import org.apache.shardingsphere.infra.route.context.RouteContext; @@ -45,7 +45,7 @@ @RequiredArgsConstructor public final class ShardingTableBroadcastRoutingEngine implements ShardingRouteEngine { - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final SQLStatementContext sqlStatementContext; @@ -108,13 +108,13 @@ private Collection getLogicTableNames() { if (!shardingRuleTableNames.isEmpty()) { return shardingRuleTableNames; } - return sqlStatementContext instanceof IndexAvailable ? getTableNames(metaData, + return sqlStatementContext instanceof IndexAvailable ? getTableNames(databaseMetaData, ((IndexAvailable) sqlStatementContext).getIndexes(), sqlStatementContext.getDatabaseType()) : Collections.emptyList(); } - private Collection getTableNames(final ShardingSphereMetaData metaData, final Collection indexes, final DatabaseType databaseType) { + private Collection getTableNames(final ShardingSphereDatabaseMetaData databaseMetaData, final Collection indexes, final DatabaseType databaseType) { Collection result = new LinkedList<>(); - for (QualifiedTable each : IndexMetaDataUtil.getTableNamesFromMetaData(metaData, indexes, databaseType)) { + for (QualifiedTable each : IndexMetaDataUtil.getTableNamesFromMetaData(databaseMetaData, indexes, databaseType)) { result.add(each.getTableName()); } return result; diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java index 054b24c81f0be..839335d1a653e 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -39,9 +39,9 @@ public interface ShardingStatementValidator { * @param shardingRule sharding rule * @param sqlStatementContext SQL statement context * @param parameters SQL parameters - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data */ - void preValidate(ShardingRule shardingRule, SQLStatementContext sqlStatementContext, List parameters, ShardingSphereMetaData metaData); + void preValidate(ShardingRule shardingRule, SQLStatementContext sqlStatementContext, List parameters, ShardingSphereDatabaseMetaData databaseMetaData); /** * Validate whether sharding operation is supported after route. @@ -49,10 +49,10 @@ public interface ShardingStatementValidator { * @param shardingRule sharding rule * @param sqlStatementContext SQL statement context * @param parameters SQL parameters - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param props props * @param routeContext route context */ void postValidate(ShardingRule shardingRule, SQLStatementContext sqlStatementContext, List parameters, - ShardingSphereMetaData metaData, ConfigurationProperties props, RouteContext routeContext); + ShardingSphereDatabaseMetaData databaseMetaData, ConfigurationProperties props, RouteContext routeContext); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java index 97b476a0c5948..dfebcd5e73c49 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterIndexStatementValidator.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; @@ -39,11 +39,11 @@ public final class ShardingAlterIndexStatementValidator extends ShardingDDLState @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { Optional index = sqlStatementContext.getSqlStatement().getIndex(); - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); - ShardingSphereSchema schema = index.isPresent() ? index.get().getOwner().map(optional -> optional.getIdentifier().getValue()) - .map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)) : metaData.getSchemaByName(defaultSchema); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); + ShardingSphereSchema schema = index.flatMap(optional -> optional.getOwner() + .map(owner -> databaseMetaData.getDatabase().getSchema(owner.getIdentifier().getValue()))).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); if (index.isPresent() && !isSchemaContainsIndex(schema, index.get())) { throw new ShardingSphereException("Index '%s' does not exist.", index.get().getIndexName().getIdentifier().getValue()); } @@ -55,6 +55,6 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java index 781d8488b107b..1e2254324b05e 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.type.TableAvailable; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -40,7 +40,7 @@ public final class ShardingAlterTableStatementValidator extends ShardingDDLState @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { Collection tableNames = sqlStatementContext instanceof TableAvailable ? ((TableAvailable) sqlStatementContext).getAllTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()) : sqlStatementContext.getTablesContext().getTableNames(); @@ -56,7 +56,7 @@ private boolean containsShardingBroadcastTable(final ShardingRule shardingRule, @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { String primaryTable = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue(); if (isRouteUnitDataNodeDifferentSize(shardingRule, routeContext, primaryTable)) { throw new ShardingSphereException("ALTER TABLE ... statement can not route correctly for tables %s.", sqlStatementContext.getTablesContext().getTableNames()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java index aa7cf84d93f59..4cbf7add339de 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterViewStatementValidator.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -38,7 +38,7 @@ public final class ShardingAlterViewStatementValidator extends ShardingDDLStatem @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { Optional selectStatement = AlterViewStatementHandler.getSelectStatement(sqlStatementContext.getSqlStatement()); if (selectStatement.isPresent()) { TableExtractor extractor = new TableExtractor(); @@ -49,6 +49,6 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java index 45c1d67a4bd91..b54499912c9b4 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateFunctionStatementValidator.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; @@ -41,7 +41,7 @@ public final class ShardingCreateFunctionStatementValidator extends ShardingDDLS @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { Optional routineBodySegment = CreateFunctionStatementHandler.getRoutineBodySegment(sqlStatementContext.getSqlStatement()); if (!routineBodySegment.isPresent()) { return; @@ -49,15 +49,15 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte TableExtractor extractor = new TableExtractor(); Collection existTables = extractor.extractExistTableFromRoutineBody(routineBodySegment.get()); validateShardingTable(shardingRule, existTables); - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); ShardingSphereSchema schema = sqlStatementContext.getSqlStatement().getFunctionName().flatMap(optional -> optional.getOwner() - .map(owner -> metaData.getSchemaByName(owner.getIdentifier().getValue()))).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + .map(owner -> databaseMetaData.getDatabase().getSchema(owner.getIdentifier().getValue()))).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); validateTableExist(schema, existTables); validateTableNotExist(schema, extractor.extractNotExistTableFromRoutineBody(routineBodySegment.get())); } @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java index c5dc40f02a542..d845bfc7816d0 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.type.IndexAvailable; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; @@ -38,9 +38,10 @@ public final class ShardingCreateIndexStatementValidator extends ShardingDDLStat @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); - ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); + ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName() + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); validateTableExist(schema, Collections.singletonList(sqlStatementContext.getSqlStatement().getTable())); String tableName = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue(); String indexName = ((IndexAvailable) sqlStatementContext).getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).findFirst().orElse(null); @@ -51,6 +52,6 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java index d1025d74fb905..5be5a192a99fe 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateProcedureStatementValidator.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; @@ -41,15 +41,15 @@ public final class ShardingCreateProcedureStatementValidator extends ShardingDDL @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { Optional routineBodySegment = CreateProcedureStatementHandler.getRoutineBodySegment(sqlStatementContext.getSqlStatement()); if (!routineBodySegment.isPresent()) { return; } TableExtractor extractor = new TableExtractor(); - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); ShardingSphereSchema schema = sqlStatementContext.getSqlStatement().getProcedureName().flatMap(optional -> optional.getOwner() - .map(owner -> metaData.getSchemaByName(owner.getIdentifier().getValue()))).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + .map(owner -> databaseMetaData.getDatabase().getSchema(owner.getIdentifier().getValue()))).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); Collection existTables = extractor.extractExistTableFromRoutineBody(routineBodySegment.get()); validateShardingTable(shardingRule, existTables); validateTableExist(schema, existTables); @@ -59,6 +59,6 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateTableStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateTableStatementValidator.java index e3ea47296127a..4c92aaeef0639 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateTableStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateTableStatementValidator.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; @@ -38,17 +38,18 @@ public final class ShardingCreateTableStatementValidator extends ShardingDDLStat @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { if (!CreateTableStatementHandler.containsNotExistClause(sqlStatementContext.getSqlStatement())) { - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); - ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); + ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName() + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); validateTableNotExist(schema, Collections.singletonList(sqlStatementContext.getSqlStatement().getTable())); } } @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { String primaryTable = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue(); if (isRouteUnitDataNodeDifferentSize(shardingRule, routeContext, primaryTable)) { throw new ShardingSphereException("CREATE TABLE ... statement can not route correctly for tables %s.", sqlStatementContext.getTablesContext().getTableNames()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java index 3e38730141af7..d5ba0eb74f34b 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateViewStatementValidator.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -37,7 +37,7 @@ public final class ShardingCreateViewStatementValidator extends ShardingDDLState @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { Optional selectStatement = sqlStatementContext.getSqlStatement().getSelect(); if (selectStatement.isPresent()) { TableExtractor extractor = new TableExtractor(); @@ -48,6 +48,6 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java index 255cab55a3796..2da4ced118655 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropIndexStatementValidator.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; @@ -41,13 +41,14 @@ public final class ShardingDropIndexStatementValidator extends ShardingDDLStatem @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { if (DropIndexStatementHandler.containsExistClause(sqlStatementContext.getSqlStatement())) { return; } - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); for (IndexSegment each : sqlStatementContext.getSqlStatement().getIndexes()) { - ShardingSphereSchema schema = each.getOwner().map(optional -> optional.getIdentifier().getValue()).map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + ShardingSphereSchema schema = each.getOwner().map(optional -> optional.getIdentifier().getValue()) + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); if (!isSchemaContainsIndex(schema, each)) { throw new ShardingSphereException("Index '%s' does not exist.", each.getIndexName().getIdentifier().getValue()); } @@ -56,16 +57,16 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { Collection indexSegments = sqlStatementContext.getSqlStatement().getIndexes(); Optional logicTableName = DropIndexStatementHandler.getSimpleTableSegment(sqlStatementContext.getSqlStatement()).map(optional -> optional.getTableName().getIdentifier().getValue()); if (logicTableName.isPresent()) { validateDropIndexRouteUnit(shardingRule, routeContext, indexSegments, logicTableName.get()); } else { - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); for (IndexSegment each : indexSegments) { ShardingSphereSchema schema = each.getOwner().map(optional -> optional.getIdentifier().getValue()) - .map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); logicTableName = schema.getAllTableNames().stream().filter(tableName -> schema.get(tableName).getIndexes().containsKey(each.getIndexName().getIdentifier().getValue())).findFirst(); logicTableName.ifPresent(optional -> validateDropIndexRouteUnit(shardingRule, routeContext, indexSegments, optional)); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java index 48497ea501104..cf7dff44b8e67 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; @@ -43,17 +43,19 @@ public final class ShardingDropTableStatementValidator extends ShardingDDLStatementValidator { @Override - public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, final ShardingSphereMetaData metaData) { + public void preValidate(final ShardingRule shardingRule, + final SQLStatementContext sqlStatementContext, final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { if (!DropTableStatementHandler.containsExistClause(sqlStatementContext.getSqlStatement())) { - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); - ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); + ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName() + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); validateTableExist(schema, sqlStatementContext.getTablesContext().getTables()); } } @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { checkTableInUsed(shardingRule, sqlStatementContext.getSqlStatement(), routeContext); for (SimpleTableSegment each : sqlStatementContext.getSqlStatement().getTables()) { if (isRouteUnitDataNodeDifferentSize(shardingRule, routeContext, each.getTableName().getIdentifier().getValue())) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java index a1d149d017fa5..b5bdb427126fc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingPrepareStatementValidator.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteUnit; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; @@ -37,12 +37,12 @@ public final class ShardingPrepareStatementValidator extends ShardingDDLStatemen @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { } @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { if (routeContext.getRouteUnits().isEmpty()) { throw new ShardingSphereException("Can not get route result, please check your sharding table config."); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java index becfc82dd08dd..65bf026d37afd 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.type.TableAvailable; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -40,7 +40,7 @@ public final class ShardingRenameTableStatementValidator extends ShardingDDLStat @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { Collection tableNames = sqlStatementContext instanceof TableAvailable ? ((TableAvailable) sqlStatementContext).getAllTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()) : sqlStatementContext.getTablesContext().getTableNames(); @@ -56,7 +56,7 @@ private boolean containsShardingBroadcastTable(final ShardingRule shardingRule, @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { for (RenameTableDefinitionSegment each : sqlStatementContext.getSqlStatement().getRenameTables()) { String primaryTable = each.getTable().getTableName().getIdentifier().getValue(); if (isRouteUnitDataNodeDifferentSize(shardingRule, routeContext, primaryTable)) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java index ff51f9652a847..ba3ca1fbd9e76 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.dml.ShardingDMLStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -34,7 +34,8 @@ public final class ShardingCopyStatementValidator extends ShardingDMLStatementValidator { @Override - public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, final ShardingSphereMetaData metaData) { + public void preValidate(final ShardingRule shardingRule, + final SQLStatementContext sqlStatementContext, final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { String tableName = sqlStatementContext.getSqlStatement().getTableSegment().getTableName().getIdentifier().getValue(); if (shardingRule.isShardingTable(tableName)) { throw new ShardingSphereException("COPY statement can not support sharding table %s.", tableName); @@ -43,6 +44,6 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java index b0dfb06783cbb..903107b77f86d 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingDeleteStatementValidator.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.dml.ShardingDMLStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -36,13 +36,13 @@ public final class ShardingDeleteStatementValidator extends ShardingDMLStatement @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { validateMultipleTable(shardingRule, sqlStatementContext); } @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { if (DeleteStatementHandler.getLimitSegment(sqlStatementContext.getSqlStatement()).isPresent() && routeContext.getRouteUnits().size() > 1) { throw new ShardingSphereException("DELETE ... LIMIT can not support sharding route to multiple data nodes."); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingInsertStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingInsertStatementValidator.java index c32bf10a75446..0fb61f1840341 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingInsertStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingInsertStatementValidator.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions; import org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine; @@ -52,7 +52,7 @@ public final class ShardingInsertStatementValidator extends ShardingDMLStatement @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { if (null == ((InsertStatementContext) sqlStatementContext).getInsertSelectContext()) { validateMultipleTable(shardingRule, sqlStatementContext); } @@ -83,7 +83,7 @@ private boolean isAllSameTables(final Collection tableNames) { @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { Optional insertSelect = sqlStatementContext.getSqlStatement().getInsertSelect(); if (insertSelect.isPresent() && shardingConditions.isNeedMerge()) { boolean singleRoutingOrSameShardingCondition = routeContext.isSingleRouting() || shardingConditions.isSameShardingCondition(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java index afee6f9102fc6..c745e2959df4f 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java @@ -20,7 +20,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.validator.dml.ShardingDMLStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -36,11 +36,11 @@ public final class ShardingSelectStatementValidator extends ShardingDMLStatement @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { } @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java index 56a0ab89fb2ff..2570d620f3835 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingUpdateStatementValidator.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions; import org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine; @@ -39,13 +39,13 @@ public final class ShardingUpdateStatementValidator extends ShardingDMLStatement @Override public void preValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, - final List parameters, final ShardingSphereMetaData metaData) { + final List parameters, final ShardingSphereDatabaseMetaData databaseMetaData) { validateMultipleTable(shardingRule, sqlStatementContext); } @Override public void postValidate(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext, final List parameters, - final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { String tableName = sqlStatementContext.getTablesContext().getTableNames().iterator().next(); Optional shardingConditions = createShardingConditions(sqlStatementContext, shardingRule, sqlStatementContext.getSqlStatement().getSetAssignment().getAssignments(), parameters); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java index c579689a97583..3b1ef846cf967 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.expr.InlineExpressionParser; import org.apache.shardingsphere.infra.instance.InstanceContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; @@ -374,20 +374,21 @@ public boolean isAllBindingTables(final Collection logicTableNames) { /** * Judge whether logic table is all binding tables. * - * @param metaData meta data + * @param databaseMetaData database meta data * @param sqlStatementContext sqlStatementContext * @param logicTableNames logic table names * @return whether logic table is all binding tables */ - public boolean isAllBindingTables(final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext, final Collection logicTableNames) { + public boolean isAllBindingTables(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatementContext sqlStatementContext, final Collection logicTableNames) { if (!(sqlStatementContext instanceof SelectStatementContext && ((SelectStatementContext) sqlStatementContext).isContainsJoinQuery())) { return isAllBindingTables(logicTableNames); } if (!isAllBindingTables(logicTableNames)) { return false; } - String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName()); - ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName().map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + String defaultSchema = sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName()); + ShardingSphereSchema schema = sqlStatementContext.getTablesContext().getSchemaName() + .map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); SelectStatementContext select = (SelectStatementContext) sqlStatementContext; Collection joinSegments = WhereExtractUtil.getJoinWhereSegments(select.getSqlStatement()); return isJoinConditionContainsShardingColumns(schema, select, logicTableNames, joinSegments) diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java index 40bd07a981448..f38b614009ee9 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java @@ -27,9 +27,13 @@ import org.junit.Before; import org.junit.Test; +import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Collection; import java.util.LinkedList; @@ -237,20 +241,40 @@ public void assertFormat() { } @Test - public void assertLocalDateTimeWithZeroMillisecond() { - Collection actual = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, + @SneakyThrows(ParseException.class) + public void assertTimestampInJDBCTypeWithZeroMillisecond() { + Collection actualAsLocalDateTime = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed(LocalDateTime.of(2021, 6, 15, 2, 25, 27), LocalDateTime.of(2021, 7, 31, 2, 25, 27)))); - assertThat(actual.size(), is(24)); - } - - @Test - @SneakyThrows(ParseException.class) - public void assertDateWithZeroMillisecond() { + assertThat(actualAsLocalDateTime.size(), is(24)); + Collection actualAsInstant = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, + new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, + Range.closed( + LocalDateTime.of(2021, 6, 15, 2, 25, 27).atZone(ZoneId.systemDefault()).toInstant(), + LocalDateTime.of(2021, 7, 31, 2, 25, 27).atZone(ZoneId.systemDefault()).toInstant()))); + assertThat(actualAsInstant.size(), is(24)); + Collection actualAsTimestamp = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, + new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, + Range.closed( + Timestamp.valueOf(LocalDateTime.of(2021, 6, 15, 2, 25, 27)), + Timestamp.valueOf(LocalDateTime.of(2021, 7, 31, 2, 25, 27))))); + assertThat(actualAsTimestamp.size(), is(24)); + Collection actualAsOffsetDateTime = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, + new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, + Range.closed( + OffsetDateTime.of(2021, 6, 15, 2, 25, 27, 0, OffsetDateTime.now().getOffset()), + OffsetDateTime.of(2021, 7, 31, 2, 25, 27, 0, OffsetDateTime.now().getOffset())))); + assertThat(actualAsOffsetDateTime.size(), is(24)); + Collection actualAsZonedDateTime = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, + new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, + Range.closed( + ZonedDateTime.of(2021, 6, 15, 2, 25, 27, 0, ZoneId.systemDefault()), + ZonedDateTime.of(2021, 7, 31, 2, 25, 27, 0, ZoneId.systemDefault())))); + assertThat(actualAsZonedDateTime.size(), is(24)); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - Collection actual = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, + Collection actualAsDate = shardingAlgorithmByDayWithMillisecond.doSharding(availableTablesForDayWithMillisecondDataSources, new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed(simpleDateFormat.parse("2021-06-15 02:25:27.000"), simpleDateFormat.parse("2021-07-31 02:25:27.000")))); - assertThat(actual.size(), is(24)); + assertThat(actualAsDate.size(), is(24)); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java index 80cffac5de4a7..88de9f1d84639 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java @@ -92,13 +92,21 @@ public void assertRangeDoShardingWithAllTargetsZeroPadding() { } @Test(expected = IllegalArgumentException.class) - public void assertRangeDoShardingWithWrongArgument() { + public void assertRangeDoShardingWithWrongArgumentForStartOffset() { Properties properties = createZeroPaddingProperties(); properties.setProperty("start-offset", "-1"); ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new ShardingSphereAlgorithmConfiguration("MOD", properties)); assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07")); } + @Test(expected = IllegalArgumentException.class) + public void assertRangeDoShardingWithWrongArgumentForStopOffset() { + Properties properties = createZeroPaddingProperties(); + properties.setProperty("stop-offset", "-1"); + ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new ShardingSphereAlgorithmConfiguration("MOD", properties)); + assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07")); + } + private Properties createZeroPaddingProperties() { Properties result = new Properties(); result.setProperty("sharding-count", "16"); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java index 8eb30bf1dec2a..e08713edcec6a 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.merge.engine.merger.impl.TransparentResultMerger; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.merge.dal.ShardingDALResultMerger; import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger; @@ -51,6 +51,7 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -83,10 +84,10 @@ public void assertNewInstanceWithSelectStatementForSQLServer() { private void assertNewInstanceWithSelectStatement(final SelectStatement selectStatement) { ConfigurationProperties props = new ConfigurationProperties(new Properties()); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext sqlStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext sqlStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), null, props, sqlStatementContext), instanceOf(ShardingDQLResultMerger.class)); @@ -113,9 +114,9 @@ public void assertNewInstanceWithOtherStatement() { } private InsertStatementContext createInsertStatementContext(final InsertStatement insertStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); - Map metaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData); - return new InsertStatementContext(metaDataMap, Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + Map databaseMetaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData); + return new InsertStatementContext(databaseMetaDataMap, Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java index b8c40e664fb0c..c2f0457b943b6 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.merge.dal.common.SingleLocalDataMergedResult; import org.apache.shardingsphere.sharding.merge.dal.show.LogicTablesMergedResult; import org.apache.shardingsphere.sharding.merge.dal.show.ShowCreateTableMergedResult; @@ -66,9 +66,9 @@ public void assertMergeForShowDatabasesStatement() throws SQLException { DALStatement dalStatement = new MySQLShowDatabasesStatement(); SQLStatementContext sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(DefaultDatabase.LOGIC_NAME, null); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(queryResults, sqlStatementContext, metaData), instanceOf(SingleLocalDataMergedResult.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + assertThat(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData), instanceOf(SingleLocalDataMergedResult.class)); } @Test @@ -76,9 +76,9 @@ public void assertMergeForShowShowTablesStatement() throws SQLException { DALStatement dalStatement = new MySQLShowTablesStatement(); SQLStatementContext sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(DefaultDatabase.LOGIC_NAME, null); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(queryResults, sqlStatementContext, metaData), instanceOf(LogicTablesMergedResult.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + assertThat(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData), instanceOf(LogicTablesMergedResult.class)); } @Test @@ -86,9 +86,9 @@ public void assertMergeForShowCreateTableStatement() throws SQLException { DALStatement dalStatement = new MySQLShowCreateTableStatement(); SQLStatementContext sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(DefaultDatabase.LOGIC_NAME, null); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(queryResults, sqlStatementContext, metaData), instanceOf(ShowCreateTableMergedResult.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + assertThat(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData), instanceOf(ShowCreateTableMergedResult.class)); } @Test @@ -96,9 +96,9 @@ public void assertMergeForShowOtherStatement() throws SQLException { DALStatement dalStatement = new MySQLShowOtherStatement(); SQLStatementContext sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(DefaultDatabase.LOGIC_NAME, null); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(queryResults, sqlStatementContext, metaData), instanceOf(TransparentMergedResult.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + assertThat(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData), instanceOf(TransparentMergedResult.class)); } @Test @@ -106,9 +106,9 @@ public void assertMergeForDescribeStatement() throws SQLException { DALStatement dalStatement = new MySQLExplainStatement(); SQLStatementContext sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(DefaultDatabase.LOGIC_NAME, mock(ShardingRule.class)); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(queryResults, sqlStatementContext, metaData), instanceOf(TransparentMergedResult.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + assertThat(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData), instanceOf(TransparentMergedResult.class)); } @Test @@ -116,9 +116,9 @@ public void assertMergeForShowIndexStatement() throws SQLException { DALStatement dalStatement = new MySQLShowIndexStatement(); SQLStatementContext sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(DefaultDatabase.LOGIC_NAME, mock(ShardingRule.class)); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(queryResults, sqlStatementContext, metaData), instanceOf(ShowIndexMergedResult.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + assertThat(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData), instanceOf(ShowIndexMergedResult.class)); } @Test @@ -126,9 +126,9 @@ public void assertMergeForShowTableStatusStatement() throws SQLException { DALStatement dalStatement = new MySQLShowTableStatusStatement(); SQLStatementContext sqlStatementContext = mockSQLStatementContext(dalStatement); ShardingDALResultMerger resultMerger = new ShardingDALResultMerger(DefaultDatabase.LOGIC_NAME, mock(ShardingRule.class)); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(queryResults, sqlStatementContext, metaData), instanceOf(ShowTableStatusMergedResult.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + assertThat(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData), instanceOf(ShowTableStatusMergedResult.class)); } @SuppressWarnings("unchecked") diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java index 0fa541b5fa37b..5f6e39bc326e7 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -80,39 +80,39 @@ public final class ShardingDQLResultMergerTest { @Test public void assertBuildIteratorStreamMergedResult() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); SelectStatement selectStatement = buildSelectStatement(new MySQLSelectStatement()); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()), instanceOf(IteratorStreamMergedResult.class)); + assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()), instanceOf(IteratorStreamMergedResult.class)); } @Test public void assertBuildIteratorStreamMergedResultWithLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(Collections.singletonList(createQueryResult()), selectStatementContext, buildMetaData()), instanceOf(IteratorStreamMergedResult.class)); + assertThat(resultMerger.merge(Collections.singletonList(createQueryResult()), selectStatementContext, createDatabaseMetaData()), instanceOf(IteratorStreamMergedResult.class)); } @Test public void assertBuildIteratorStreamMergedResultWithMySQLLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(LimitDecoratorMergedResult.class)); assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class)); } @@ -120,7 +120,7 @@ public void assertBuildIteratorStreamMergedResultWithMySQLLimit() throws SQLExce @Test public void assertBuildIteratorStreamMergedResultWithOracleLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - final ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + final ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); OracleSelectStatement selectStatement = (OracleSelectStatement) buildSelectStatement(new OracleSelectStatement()); selectStatement.setProjections(new ProjectionsSegment(0, 0)); WhereSegment whereSegment = mock(WhereSegment.class); @@ -141,9 +141,9 @@ public void assertBuildIteratorStreamMergedResultWithOracleLimit() throws SQLExc when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment); selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class)); assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class)); } @@ -151,14 +151,14 @@ public void assertBuildIteratorStreamMergedResultWithOracleLimit() throws SQLExc @Test public void assertBuildIteratorStreamMergedResultWithSQLServerLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement()); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class)); assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class)); } @@ -166,28 +166,28 @@ public void assertBuildIteratorStreamMergedResultWithSQLServerLimit() throws SQL @Test public void assertBuildOrderByStreamMergedResult() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()), instanceOf(OrderByStreamMergedResult.class)); + assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()), instanceOf(OrderByStreamMergedResult.class)); } @Test public void assertBuildOrderByStreamMergedResultWithMySQLLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(LimitDecoratorMergedResult.class)); assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(OrderByStreamMergedResult.class)); } @@ -195,7 +195,7 @@ public void assertBuildOrderByStreamMergedResultWithMySQLLimit() throws SQLExcep @Test public void assertBuildOrderByStreamMergedResultWithOracleLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - final ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + final ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); WhereSegment whereSegment = mock(WhereSegment.class); BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class); when(binaryOperationExpression.getLeft()).thenReturn(new ColumnSegment(0, 0, new IdentifierValue("row_id"))); @@ -217,9 +217,9 @@ public void assertBuildOrderByStreamMergedResultWithOracleLimit() throws SQLExce selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class)); assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(OrderByStreamMergedResult.class)); } @@ -227,15 +227,15 @@ public void assertBuildOrderByStreamMergedResultWithOracleLimit() throws SQLExce @Test public void assertBuildOrderByStreamMergedResultWithSQLServerLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement()); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class)); assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(OrderByStreamMergedResult.class)); } @@ -243,30 +243,30 @@ public void assertBuildOrderByStreamMergedResultWithSQLServerLimit() throws SQLE @Test public void assertBuildGroupByStreamMergedResult() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()), instanceOf(GroupByStreamMergedResult.class)); + assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()), instanceOf(GroupByStreamMergedResult.class)); } @Test public void assertBuildGroupByStreamMergedResultWithMySQLLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(LimitDecoratorMergedResult.class)); assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class)); } @@ -274,7 +274,7 @@ public void assertBuildGroupByStreamMergedResultWithMySQLLimit() throws SQLExcep @Test public void assertBuildGroupByStreamMergedResultWithOracleLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - final ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + final ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); WhereSegment whereSegment = mock(WhereSegment.class); BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class); when(binaryOperationExpression.getLeft()).thenReturn(new ColumnSegment(0, 0, new IdentifierValue("row_id"))); @@ -297,9 +297,9 @@ public void assertBuildGroupByStreamMergedResultWithOracleLimit() throws SQLExce selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class)); assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class)); } @@ -307,16 +307,16 @@ public void assertBuildGroupByStreamMergedResultWithOracleLimit() throws SQLExce @Test public void assertBuildGroupByStreamMergedResultWithSQLServerLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement()); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class)); assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class)); } @@ -324,28 +324,28 @@ public void assertBuildGroupByStreamMergedResultWithSQLServerLimit() throws SQLE @Test public void assertBuildGroupByMemoryMergedResult() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()), instanceOf(GroupByStreamMergedResult.class)); + assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()), instanceOf(GroupByStreamMergedResult.class)); } @Test public void assertBuildGroupByMemoryMergedResultWithMySQLLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(LimitDecoratorMergedResult.class)); assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class)); } @@ -353,7 +353,7 @@ public void assertBuildGroupByMemoryMergedResultWithMySQLLimit() throws SQLExcep @Test public void assertBuildGroupByMemoryMergedResultWithOracleLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - final ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + final ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); WhereSegment whereSegment = mock(WhereSegment.class); BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class); when(binaryOperationExpression.getLeft()).thenReturn(new ColumnSegment(0, 0, new IdentifierValue("row_id"))); @@ -376,9 +376,9 @@ public void assertBuildGroupByMemoryMergedResultWithOracleLimit() throws SQLExce selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class)); assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class)); } @@ -386,17 +386,17 @@ public void assertBuildGroupByMemoryMergedResultWithOracleLimit() throws SQLExce @Test public void assertBuildGroupByMemoryMergedResultWithSQLServerLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement()); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)))); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class)); assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class)); } @@ -404,31 +404,31 @@ public void assertBuildGroupByMemoryMergedResultWithSQLServerLimit() throws SQLE @Test public void assertBuildGroupByMemoryMergedResultWithAggregationOnly() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)")); selectStatement.setProjections(projectionsSegment); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()), instanceOf(GroupByMemoryMergedResult.class)); + assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()), instanceOf(GroupByMemoryMergedResult.class)); } @Test public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit() throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement()); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)")); selectStatement.setProjections(projectionsSegment); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); DatabaseType databaseType = DatabaseTypeFactory.getInstance("MySQL"); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(databaseType); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(LimitDecoratorMergedResult.class)); assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class)); } @@ -436,7 +436,7 @@ public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimi @Test public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - final ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + final ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); WhereSegment whereSegment = mock(WhereSegment.class); BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class); when(binaryOperationExpression.getLeft()).thenReturn(new ColumnSegment(0, 0, new IdentifierValue("row_id"))); @@ -459,9 +459,9 @@ public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLim selectStatement.setProjections(projectionsSegment); selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class)); assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class)); } @@ -469,16 +469,16 @@ public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLim @Test public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement()); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)")); selectStatement.setProjections(projectionsSegment); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabaseMetaData()); assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class)); assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class)); } @@ -501,13 +501,13 @@ private QueryResult createQueryResult() throws SQLException { return result; } - private ShardingSphereMetaData buildMetaData() { + private ShardingSphereDatabaseMetaData createDatabaseMetaData() { ColumnMetaData columnMetaData1 = new ColumnMetaData("col1", 0, false, false, false); ColumnMetaData columnMetaData2 = new ColumnMetaData("col2", 0, false, false, false); ColumnMetaData columnMetaData3 = new ColumnMetaData("col3", 0, false, false, false); TableMetaData tableMetaData = new TableMetaData("tbl", Arrays.asList(columnMetaData1, columnMetaData2, columnMetaData3), Collections.emptyList(), Collections.emptyList()); ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", tableMetaData)); - return new ShardingSphereMetaData(DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResource.class), + return new ShardingSphereDatabaseMetaData(DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema))); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java index dfd6705645edc..8914036a46b16 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger; @@ -65,12 +65,12 @@ public final class GroupByMemoryMergedResultTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Test public void assertNextForResultSetsAllEmpty() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult()), createSelectStatementContext(), metaData); + MergedResult actual = resultMerger.merge(Arrays.asList(createQueryResult(), createQueryResult(), createQueryResult()), createSelectStatementContext(), databaseMetaData); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class), is(0)); assertNull(actual.getValue(2, Object.class)); @@ -95,7 +95,7 @@ public void assertNextForSomeResultSetsEmpty() throws SQLException { when(queryResult3.getValue(4, Object.class)).thenReturn(2, 2, 3); when(queryResult3.getValue(5, Object.class)).thenReturn(20, 20, 30); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), metaData); + MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), databaseMetaData); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class), is(new BigDecimal(30))); assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10)); @@ -119,14 +119,13 @@ private SelectStatementContext createSelectStatementContext() { selectStatement.setProjections(projectionsSegment); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC)))); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setProjections(projectionsSegment); - return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); } - private SelectStatementContext createSelectStatementContext(final ShardingSphereMetaData metaData) { + private SelectStatementContext createSelectStatementContext(final ShardingSphereDatabaseMetaData databaseMetaData) { SelectStatement selectStatement = new MySQLSelectStatement(); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.setDistinctRow(true); @@ -135,7 +134,7 @@ private SelectStatementContext createSelectStatementContext(final ShardingSphere selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); selectStatement.setProjections(projectionsSegment); - return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); } @Test @@ -156,7 +155,7 @@ public void assertNextForAggregationResultSetsEmpty() throws SQLException { when(queryResult3.getValue(4, Object.class)).thenReturn(2, 2, 3); when(queryResult3.getValue(5, Object.class)).thenReturn(20, 20, 30); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), metaData); + MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), databaseMetaData); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class), is(new BigDecimal(30))); assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10)); @@ -193,13 +192,13 @@ public void assertNextForDistinctShorthandResultSetsEmpty() throws SQLException TableMetaData tableMetaData = mock(TableMetaData.class); when(schema.get("t_order")).thenReturn(tableMetaData); when(tableMetaData.getColumns()).thenReturn(Collections.emptyMap()); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); - when(metaData.getDatabase().getSchemas()).thenReturn(mockSchemas(schema)); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + when(databaseMetaData.getDatabase().getSchemas()).thenReturn(mockSchemas(schema)); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); when(schema.getAllColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "content")); ShardingDQLResultMerger merger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = merger.merge(Arrays.asList(queryResult, queryResult, queryResult), createSelectStatementContext(metaData), metaData); + MergedResult actual = merger.merge(Arrays.asList(queryResult, queryResult, queryResult), createSelectStatementContext(databaseMetaData), databaseMetaData); assertFalse(actual.next()); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java index 66bf3bc889d0b..1dff5178afa63 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; @@ -80,8 +80,8 @@ public void assertCompareToForAscWithOrderByItemsForSQLServer() throws SQLExcept } private void assertCompareToForAscWithOrderByItems(final SelectStatement selectStatement) throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList( new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC)))); @@ -89,7 +89,7 @@ private void assertCompareToForAscWithOrderByItems(final SelectStatement selectS new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives); MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2")); @@ -123,8 +123,8 @@ public void assertCompareToForDecsWithOrderByItemsForSQLServer() throws SQLExcep } private void assertCompareToForDecsWithOrderByItems(final SelectStatement selectStatement) throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList( new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC)))); @@ -132,7 +132,7 @@ private void assertCompareToForDecsWithOrderByItems(final SelectStatement select new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives); MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2")); @@ -166,8 +166,8 @@ public void assertCompareToForEqualWithOrderByItemsForSQLServer() throws SQLExce } private void assertCompareToForEqualWithOrderByItems(final SelectStatement selectStatement) throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList( new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC)))); @@ -175,7 +175,7 @@ private void assertCompareToForEqualWithOrderByItems(final SelectStatement selec new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives); MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2")); @@ -209,14 +209,14 @@ public void assertCompareToForAscWithGroupByItemsForSQLServer() throws SQLExcept } private void assertCompareToForAscWithGroupByItems(final SelectStatement selectStatement) throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList( new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList())); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives); MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2")); @@ -250,14 +250,14 @@ public void assertCompareToForDecsWithGroupByItemsForSQLServer() throws SQLExcep } private void assertCompareToForDecsWithGroupByItems(final SelectStatement selectStatement) throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList( new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList())); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives); MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2")); @@ -291,14 +291,14 @@ public void assertCompareToForEqualWithGroupByItemsForSQLServer() throws SQLExce } private void assertCompareToForEqualWithGroupByItems(final SelectStatement selectStatement) throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList( new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList())); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives); MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java index f24718b36fdd5..0ffc6df36abf6 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -63,7 +63,7 @@ public final class GroupByStreamMergedResultTest { @Test public void assertNextForResultSetsAllEmpty() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult()), createSelectStatementContext(), buildMetaData()); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult()), createSelectStatementContext(), createDatabaaseMetaData()); assertFalse(actual.next()); } @@ -87,7 +87,7 @@ public void assertNextForSomeResultSetsEmpty() throws SQLException { when(queryResult3.getValue(5, Object.class)).thenReturn(2, 2, 3); when(queryResult3.getValue(6, Object.class)).thenReturn(20, 20, 30); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), buildMetaData()); + MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), createDatabaaseMetaData()); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class), is(new BigDecimal(40))); assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10)); @@ -129,7 +129,7 @@ public void assertNextForMix() throws SQLException { when(queryResult3.getValue(5, Object.class)).thenReturn(1, 1, 3); when(queryResult3.getValue(6, Object.class)).thenReturn(10, 10, 30); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), buildMetaData()); + MergedResult actual = resultMerger.merge(Arrays.asList(queryResult1, queryResult2, queryResult3), createSelectStatementContext(), createDatabaaseMetaData()); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class), is(new BigDecimal(10))); assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10)); @@ -161,24 +161,24 @@ private SelectStatementContext createSelectStatementContext() { SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(10, 13, new IdentifierValue("tbl"))); MySQLSelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setFrom(tableSegment); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)")); projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.AVG, "(num)")); selectStatement.setProjections(projectionsSegment); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC)))); - return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); } - private ShardingSphereMetaData buildMetaData() { + private ShardingSphereDatabaseMetaData createDatabaaseMetaData() { ColumnMetaData columnMetaData1 = new ColumnMetaData("col1", 0, false, false, false); ColumnMetaData columnMetaData2 = new ColumnMetaData("col2", 0, false, false, false); ColumnMetaData columnMetaData3 = new ColumnMetaData("col3", 0, false, false, false); TableMetaData tableMetaData = new TableMetaData("tbl", Arrays.asList(columnMetaData1, columnMetaData2, columnMetaData3), Collections.emptyList(), Collections.emptyList()); ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", tableMetaData)); - return new ShardingSphereMetaData(DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResource.class), + return new ShardingSphereDatabaseMetaData(DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema))); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/iterator/IteratorStreamMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/iterator/IteratorStreamMergedResultTest.java index 04f20dde9f1c5..5442251856e3f 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/iterator/IteratorStreamMergedResultTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/iterator/IteratorStreamMergedResultTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement; @@ -47,18 +47,19 @@ public final class IteratorStreamMergedResultTest { @Before public void setUp() { MySQLSelectStatement selectStatement = new MySQLSelectStatement(); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + selectStatementContext = new SelectStatementContext( + Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); } @Test public void assertNextForResultSetsAllEmpty() throws SQLException { List queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS)); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, databaseMetaData); assertFalse(actual.next()); } @@ -69,9 +70,9 @@ public void assertNextForResultSetsAllNotEmpty() throws SQLException { when(each.next()).thenReturn(true, false); } ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); @@ -83,9 +84,9 @@ public void assertNextForFirstResultSetsNotEmptyOnly() throws SQLException { List queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS)); when(queryResults.get(0).next()).thenReturn(true, false); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertFalse(actual.next()); } @@ -95,9 +96,9 @@ public void assertNextForMiddleResultSetsNotEmpty() throws SQLException { List queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS)); when(queryResults.get(1).next()).thenReturn(true, false); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertFalse(actual.next()); } @@ -107,9 +108,9 @@ public void assertNextForLastResultSetsNotEmptyOnly() throws SQLException { List queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS)); when(queryResults.get(2).next()).thenReturn(true, false); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertFalse(actual.next()); } @@ -122,9 +123,9 @@ public void assertNextForMix() throws SQLException { when(queryResults.get(3).next()).thenReturn(true, false); when(queryResults.get(5).next()).thenReturn(true, false); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java index ac8275577e99a..aee26bb42f05a 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -70,15 +70,16 @@ public void setUp() { new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC), new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC)))); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); + selectStatementContext = new SelectStatementContext( + Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); } @Test public void assertNextForResultSetsAllEmpty() throws SQLException { List queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS)); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabaseMetaData()); assertFalse(actual.next()); } @@ -96,7 +97,7 @@ public void assertNextForSomeResultSetsEmpty() throws SQLException { when(queryResults.get(0).getValue(1, Object.class)).thenReturn("2"); when(queryResults.get(2).next()).thenReturn(true, true, false); when(queryResults.get(2).getValue(1, Object.class)).thenReturn("1", "1", "3", "3"); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabaseMetaData()); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("1")); assertTrue(actual.next()); @@ -122,7 +123,7 @@ public void assertNextForMix() throws SQLException { when(queryResults.get(1).getValue(1, Object.class)).thenReturn("2", "2", "3", "3", "4", "4"); when(queryResults.get(2).next()).thenReturn(true, true, false); when(queryResults.get(2).getValue(1, Object.class)).thenReturn("1", "1", "3", "3"); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabaseMetaData()); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("1")); assertTrue(actual.next()); @@ -154,7 +155,7 @@ public void assertNextForCaseSensitive() throws SQLException { when(queryResults.get(2).next()).thenReturn(true, false); when(queryResults.get(2).getValue(1, Object.class)).thenReturn("A"); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabaseMetaData()); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("A")); assertTrue(actual.next()); @@ -182,7 +183,7 @@ public void assertNextForCaseInsensitive() throws SQLException { when(queryResults.get(2).next()).thenReturn(true, false); when(queryResults.get(2).getValue(2, Object.class)).thenReturn("A"); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, buildMetaData()); + MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, createDatabaseMetaData()); assertTrue(actual.next()); assertThat(actual.getValue(2, Object.class).toString(), is("a")); assertTrue(actual.next()); @@ -194,12 +195,12 @@ public void assertNextForCaseInsensitive() throws SQLException { assertFalse(actual.next()); } - private ShardingSphereMetaData buildMetaData() { + private ShardingSphereDatabaseMetaData createDatabaseMetaData() { ColumnMetaData columnMetaData1 = new ColumnMetaData("col1", 0, false, false, true); ColumnMetaData columnMetaData2 = new ColumnMetaData("col2", 0, false, false, false); TableMetaData tableMetaData = new TableMetaData("tbl", Arrays.asList(columnMetaData1, columnMetaData2), Collections.emptyList(), Collections.emptyList()); ShardingSphereSchema schema = new ShardingSphereSchema(Collections.singletonMap("tbl", tableMetaData)); - return new ShardingSphereMetaData(DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResource.class), + return new ShardingSphereDatabaseMetaData(DatabaseTypeFactory.getInstance("MySQL"), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema))); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java index 4fcc0a9da7396..2460a0a3c587c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem; import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; @@ -83,9 +83,9 @@ public void assertCompareToForAscForSQLServer() throws SQLException, NoSuchField private void assertCompareToForAsc(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException, IllegalAccessException { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(createOrderBySegment()); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); QueryResult queryResult1 = createQueryResult("1", "2"); @@ -136,9 +136,9 @@ public void assertCompareToForDescForSQLServer() throws SQLException, NoSuchFiel private void assertCompareToForDesc(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException, IllegalAccessException { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(createOrderBySegment()); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.get("table")).thenReturn(new TableMetaData()); @@ -190,9 +190,9 @@ public void assertCompareToWhenEqualForSQLServer() throws SQLException, NoSuchFi private void assertCompareToWhenEqual(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException, IllegalAccessException { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(createOrderBySegment()); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); QueryResult queryResult1 = createQueryResult("1", "2"); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java index 24f0684a9ca1d..ab77f9695f36e 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment; @@ -44,29 +44,29 @@ public final class LimitDecoratorMergedResultTest { @Test public void assertNextForSkipAll() throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); MySQLSelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, metaData); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, databaseMetaData); assertFalse(actual.next()); } @Test public void assertNextWithoutRowCount() throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); MySQLSelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, metaData); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, databaseMetaData); for (int i = 0; i < 6; i++) { assertTrue(actual.next()); } @@ -75,15 +75,15 @@ public void assertNextWithoutRowCount() throws SQLException { @Test public void assertNextWithRowCount() throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); MySQLSelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), new NumberLiteralLimitValueSegment(0, 0, 2))); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL")); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, metaData); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java index c3e8fc42b78c3..7dc46c13e4f8f 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression; @@ -74,22 +74,24 @@ public void assertNextForSkipAll() throws SQLException { selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + SelectStatementContext selectStatementContext = new SelectStatementContext( + Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, databaseMetaData); assertFalse(actual.next()); } @Test public void assertNextWithoutOffsetWithoutRowCount() throws SQLException { ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); OracleSelectStatement selectStatement = new OracleSelectStatement(); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, metaData); + SelectStatementContext selectStatementContext = new SelectStatementContext( + Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, databaseMetaData); for (int i = 0; i < 8; i++) { assertTrue(actual.next()); } @@ -120,10 +122,11 @@ public void assertNextForRowCountBoundOpenedFalse() throws SQLException { selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + SelectStatementContext selectStatementContext = new SelectStatementContext( + Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); @@ -153,10 +156,11 @@ public void assertNextForRowCountBoundOpenedTrue() throws SQLException { selectStatement.setFrom(subqueryTableSegment); selectStatement.setWhere(whereSegment); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + SelectStatementContext selectStatementContext = new SelectStatementContext( + Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), null, selectStatement, DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, databaseMetaData); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java index d9841ee89a5a7..c9099d92bda13 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; @@ -54,31 +54,31 @@ public void setUp() { @Test public void assertNextForSkipAll() throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement(); sqlStatement.setProjections(new ProjectionsSegment(0, 0)); sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), - mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); assertFalse(actual.next()); } @Test public void assertNextWithoutOffsetWithRowCount() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement(); sqlStatement.setProjections(new ProjectionsSegment(0, 0)); sqlStatement.setLimit(new LimitSegment(0, 0, null, new NumberLiteralLimitValueSegment(0, 0, 5))); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME); MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), - mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); for (int i = 0; i < 5; i++) { assertTrue(actual.next()); } @@ -87,16 +87,16 @@ public void assertNextWithoutOffsetWithRowCount() throws SQLException { @Test public void assertNextWithOffsetWithoutRowCount() throws SQLException { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement(); sqlStatement.setProjections(new ProjectionsSegment(0, 0)); sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), null)); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME); ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), - mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); for (int i = 0; i < 7; i++) { assertTrue(actual.next()); } @@ -106,15 +106,15 @@ public void assertNextWithOffsetWithoutRowCount() throws SQLException { @Test public void assertNextWithOffsetBoundOpenedFalse() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - final ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + final ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement(); sqlStatement.setProjections(new ProjectionsSegment(0, 0)); sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, false), new NumberLiteralLimitValueSegment(0, 0, 4))); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME); MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), - mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); @@ -123,15 +123,15 @@ public void assertNextWithOffsetBoundOpenedFalse() throws SQLException { @Test public void assertNextWithOffsetBoundOpenedTrue() throws SQLException { final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer")); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement(); sqlStatement.setProjections(new ProjectionsSegment(0, 0)); sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4))); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME); MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), - mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + mockQueryResult(), mockQueryResult()), selectStatementContext, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/InsertClauseShardingConditionEngineTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/InsertClauseShardingConditionEngineTest.java index 55bf9f35075fa..a502b1088dcf5 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/InsertClauseShardingConditionEngineTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/InsertClauseShardingConditionEngineTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext; import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition; import org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -66,7 +66,7 @@ public final class InsertClauseShardingConditionEngineTest { @Before public void setUp() { InsertStatement insertStatement = mockInsertStatement(); - shardingConditionEngine = new InsertClauseShardingConditionEngine(shardingRule, mock(ShardingSphereMetaData.class)); + shardingConditionEngine = new InsertClauseShardingConditionEngine(shardingRule, mock(ShardingSphereDatabaseMetaData.class)); when(insertStatementContext.getSqlStatement()).thenReturn(insertStatement); when(insertStatementContext.getColumnNames()).thenReturn(Collections.singletonList("foo_col")); when(insertStatementContext.getInsertValueContexts()).thenReturn(Collections.singletonList(createInsertValueContext())); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java index 18705fae1b36e..fb8d2f38c882c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine; import org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.WhereClauseShardingConditionEngine; @@ -45,14 +45,14 @@ public final class ShardingConditionEngineFactoryTest { private LogicSQL logicSQL; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingRule shardingRule; @Before public void setUp() { - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); } @SuppressWarnings({"rawtypes", "unchecked"}) @@ -60,13 +60,13 @@ public void setUp() { public void assertCreateInsertClauseShardingConditionEngine() { SQLStatementContext insertStatementContext = mock(InsertStatementContext.class); when(logicSQL.getSqlStatementContext()).thenReturn(insertStatementContext); - ShardingConditionEngine actual = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, metaData, shardingRule); + ShardingConditionEngine actual = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, databaseMetaData, shardingRule); assertThat(actual, instanceOf(InsertClauseShardingConditionEngine.class)); } @Test public void assertCreateWhereClauseShardingConditionEngine() { - ShardingConditionEngine actual = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, metaData, shardingRule); + ShardingConditionEngine actual = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, databaseMetaData, shardingRule); assertThat(actual, instanceOf(WhereClauseShardingConditionEngine.class)); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java index 18b5e208971c6..ab5abd58b0817 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions; import org.apache.shardingsphere.sharding.route.engine.type.broadcast.ShardingDataSourceGroupBroadcastRoutingEngine; @@ -87,7 +87,7 @@ public final class ShardingRouteEngineFactoryTest { private ShardingRule shardingRule; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private SQLStatementContext sqlStatementContext; @@ -105,7 +105,7 @@ public final class ShardingRouteEngineFactoryTest { @Before public void setUp() { when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); tableNames = new ArrayList<>(); when(tablesContext.getTableNames()).thenReturn(tableNames); } @@ -114,14 +114,14 @@ public void setUp() { public void assertNewInstanceForTCL() { TCLStatement tclStatement = mock(TCLStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(tclStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingDatabaseBroadcastRoutingEngine.class)); } @Test public void assertNewInstanceForDDLWithShardingRule() { when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DDLStatement.class)); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingTableBroadcastRoutingEngine.class)); } @@ -131,7 +131,7 @@ public void assertNewInstanceForDALWithTables() { when(shardingRule.getShardingRuleTableNames(tableNames)).thenReturn(tableNames); DALStatement dalStatement = mock(DALStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingUnicastRoutingEngine.class)); } @@ -139,7 +139,7 @@ public void assertNewInstanceForDALWithTables() { public void assertNewInstanceForDALWithoutTables() { DALStatement dalStatement = mock(DALStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingDataSourceGroupBroadcastRoutingEngine.class)); } @@ -147,7 +147,7 @@ public void assertNewInstanceForDALWithoutTables() { public void assertNewInstanceForDALShow() { DALStatement dalStatement = mock(MySQLShowDatabasesStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingDatabaseBroadcastRoutingEngine.class)); } @@ -163,7 +163,7 @@ public void assertNewInstanceForDALSetForPostgreSQL() { private void assertNewInstanceForDALSet(final DALStatement dalStatement) { when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingDatabaseBroadcastRoutingEngine.class)); } @@ -200,14 +200,14 @@ public void assertNewInstanceForDCLForSingleTableForSQL92() { private void assertNewInstanceForDCLForSingleTableWithShardingRule(final GrantStatement grantStatement) { grantStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); GrantStatementContext sqlStatementContext = new GrantStatementContext(grantStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingIgnoreRoutingEngine.class)); } private void assertNewInstanceForDCLForSingleTableWithoutShardingRule(final GrantStatement grantStatement) { grantStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); GrantStatementContext sqlStatementContext = new GrantStatementContext(grantStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingIgnoreRoutingEngine.class)); } @@ -215,7 +215,7 @@ private void assertNewInstanceForDCLForSingleTableWithoutShardingRule(final Gran public void assertNewInstanceForDCLForNoSingleTable() { DCLStatement dclStatement = mock(DCLStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(dclStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingInstanceBroadcastRoutingEngine.class)); } @@ -223,7 +223,7 @@ public void assertNewInstanceForDCLForNoSingleTable() { public void assertNewInstanceForSelectWithoutSingleTable() { SQLStatement sqlStatement = mock(MySQLSelectStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingUnicastRoutingEngine.class)); } @@ -232,7 +232,7 @@ public void assertNewInstanceForInsertBroadcastTable() { when(shardingRule.isAllBroadcastTables(tableNames)).thenReturn(true); SQLStatement sqlStatement = mock(InsertStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingDatabaseBroadcastRoutingEngine.class)); } @@ -241,7 +241,7 @@ public void assertNewInstanceForSelectBroadcastTable() { when(shardingRule.isAllBroadcastTables(tableNames)).thenReturn(true); SQLStatement sqlStatement = mock(MySQLSelectStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingUnicastRoutingEngine.class)); } @@ -249,7 +249,7 @@ public void assertNewInstanceForSelectBroadcastTable() { public void assertNewInstanceForAlwaysFalse() { SQLStatement sqlStatement = mock(SQLStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingUnicastRoutingEngine.class)); } @@ -260,7 +260,7 @@ public void assertNewInstanceForStandard() { tableNames.add(""); when(shardingRule.getShardingLogicTableNames(sqlStatementContext.getTablesContext().getTableNames())).thenReturn(tableNames); when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingStandardRoutingEngine.class)); } @@ -271,7 +271,7 @@ public void assertNewInstanceForComplex() { tableNames.add("1"); tableNames.add("2"); when(shardingRule.getShardingLogicTableNames(tableNames)).thenReturn(tableNames); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingComplexRoutingEngine.class)); } @@ -281,7 +281,7 @@ public void assertNewInstanceForShowCreateTableWithTableRule() { when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); tableNames.add("table_1"); when(shardingRule.getShardingRuleTableNames(tableNames)).thenReturn(tableNames); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingUnicastRoutingEngine.class)); } @@ -291,7 +291,7 @@ public void assertNewInstanceForShowColumnsWithTableRule() { when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); tableNames.add("table_1"); when(shardingRule.getShardingRuleTableNames(tableNames)).thenReturn(tableNames); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingUnicastRoutingEngine.class)); } @@ -306,7 +306,7 @@ public void assertNewInstanceForSubqueryWithDifferentConditions() { when(shardingRule.getTableRule("t_order").getActualDatasourceNames()).thenReturn(Arrays.asList("ds_0", "ds_1")); when(shardingConditions.isNeedMerge()).thenReturn(true); when(shardingConditions.isSameShardingCondition()).thenReturn(false); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, createFederationConfigurationProperties()); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, createFederationConfigurationProperties()); assertThat(actual, instanceOf(ShardingFederatedRoutingEngine.class)); } @@ -327,7 +327,7 @@ public void assertNewInstanceForSubqueryWithSameConditions() { when(shardingRule.isAllShardingTables(Collections.singletonList("t_order"))).thenReturn(true); when(shardingConditions.isNeedMerge()).thenReturn(true); when(shardingConditions.isSameShardingCondition()).thenReturn(true); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, createFederationConfigurationProperties()); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, createFederationConfigurationProperties()); assertThat(actual, instanceOf(ShardingStandardRoutingEngine.class)); } @@ -335,7 +335,7 @@ public void assertNewInstanceForSubqueryWithSameConditions() { public void assertNewInstanceForCreateResourceGroup() { MySQLCreateResourceGroupStatement resourceGroupStatement = mock(MySQLCreateResourceGroupStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(resourceGroupStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingInstanceBroadcastRoutingEngine.class)); } @@ -343,7 +343,7 @@ public void assertNewInstanceForCreateResourceGroup() { public void assertNewInstanceForSetResourceGroup() { MySQLSetResourceGroupStatement resourceGroupStatement = mock(MySQLSetResourceGroupStatement.class); when(sqlStatementContext.getSqlStatement()).thenReturn(resourceGroupStatement); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingInstanceBroadcastRoutingEngine.class)); } @@ -353,7 +353,7 @@ public void assertNewInstanceForOptimizeTableWithShardingTable() { when(sqlStatementContext.getSqlStatement()).thenReturn(optimizeTableStatement); tableNames.add("table_1"); when(shardingRule.getShardingRuleTableNames(tableNames)).thenReturn(tableNames); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingTableBroadcastRoutingEngine.class)); } @@ -363,7 +363,7 @@ public void assertNewInstanceForOptimizeTableWithSingleTable() { when(sqlStatementContext.getSqlStatement()).thenReturn(optimizeTableStatement); tableNames.add("table_1"); when(shardingRule.getShardingRuleTableNames(tableNames)).thenReturn(Collections.emptyList()); - ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, metaData, sqlStatementContext, shardingConditions, props); + ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, databaseMetaData, sqlStatementContext, shardingConditions, props); assertThat(actual, instanceOf(ShardingIgnoreRoutingEngine.class)); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java index 1b501fa249391..a9b132bad3139 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRoutingEngineTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.binder.type.IndexAvailable; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -61,7 +61,7 @@ public final class ShardingTableBroadcastRoutingEngineTest extends AbstractRouti public void assertRouteForEmptyTable() { Collection tableNames = Collections.emptyList(); ShardingTableBroadcastRoutingEngine shardingTableBroadcastRoutingEngine = - new ShardingTableBroadcastRoutingEngine(mock(ShardingSphereMetaData.class), createSQLStatementContext(tableNames), tableNames); + new ShardingTableBroadcastRoutingEngine(mock(ShardingSphereDatabaseMetaData.class), createSQLStatementContext(tableNames), tableNames); RouteContext routeContext = shardingTableBroadcastRoutingEngine.route(createShardingRule(false)); assertRouteUnitWithoutTables(routeContext); } @@ -70,7 +70,7 @@ public void assertRouteForEmptyTable() { public void assertRouteForNormalTable() { Collection tableNames = Collections.singletonList("t_order"); ShardingTableBroadcastRoutingEngine shardingTableBroadcastRoutingEngine = - new ShardingTableBroadcastRoutingEngine(mock(ShardingSphereMetaData.class), createSQLStatementContext(tableNames), tableNames); + new ShardingTableBroadcastRoutingEngine(mock(ShardingSphereDatabaseMetaData.class), createSQLStatementContext(tableNames), tableNames); RouteContext routeContext = shardingTableBroadcastRoutingEngine.route(createShardingRule(false)); assertThat(routeContext.getActualDataSourceNames().size(), is(2)); assertThat(routeContext.getRouteUnits().size(), is(4)); @@ -85,7 +85,7 @@ public void assertRouteForNormalTable() { public void assertRouteForBroadcastTable() { Collection tableNames = Collections.singletonList("t_order"); ShardingTableBroadcastRoutingEngine shardingTableBroadcastRoutingEngine = - new ShardingTableBroadcastRoutingEngine(mock(ShardingSphereMetaData.class), createSQLStatementContext(tableNames), tableNames); + new ShardingTableBroadcastRoutingEngine(mock(ShardingSphereDatabaseMetaData.class), createSQLStatementContext(tableNames), tableNames); RouteContext routeContext = shardingTableBroadcastRoutingEngine.route(createShardingRule(true)); assertThat(routeContext.getActualDataSourceNames().size(), is(2)); assertThat(routeContext.getRouteUnits().size(), is(2)); @@ -108,9 +108,9 @@ public void assertRouteForDropIndexStatement() { when(sqlStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType()); when(((IndexAvailable) sqlStatementContext).getIndexes()).thenReturn(Collections.singletonList(segment)); Map schemas = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( new MySQLDatabaseType(), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, schemas)); - ShardingTableBroadcastRoutingEngine shardingTableBroadcastRoutingEngine = new ShardingTableBroadcastRoutingEngine(metaData, sqlStatementContext, tableNames); + ShardingTableBroadcastRoutingEngine shardingTableBroadcastRoutingEngine = new ShardingTableBroadcastRoutingEngine(databaseMetaData, sqlStatementContext, tableNames); RouteContext routeContext = shardingTableBroadcastRoutingEngine.route(createShardingRule(false)); assertThat(routeContext.getActualDataSourceNames().size(), is(2)); Iterator routeUnits = routeContext.getRouteUnits().iterator(); @@ -130,9 +130,9 @@ public void assertRouteForDropIndexStatementDoNotFoundTables() { Collection tableNames = Collections.emptyList(); when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(tableNames); Map schemas = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( new MySQLDatabaseType(), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, schemas)); - ShardingTableBroadcastRoutingEngine shardingTableBroadcastRoutingEngine = new ShardingTableBroadcastRoutingEngine(metaData, sqlStatementContext, tableNames); + ShardingTableBroadcastRoutingEngine shardingTableBroadcastRoutingEngine = new ShardingTableBroadcastRoutingEngine(databaseMetaData, sqlStatementContext, tableNames); RouteContext routeContext = shardingTableBroadcastRoutingEngine.route(createShardingRule(false)); assertRouteUnitWithoutTables(routeContext); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java index af5429ff69712..b7d9c3ae4a180 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -67,11 +67,12 @@ protected final RouteContext assertRoute(final String sql, final List pa ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Arrays.asList(shardingRule, singleTableRule)); ShardingSphereResource resource = mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS); when(resource.getDatabaseType()).thenReturn(new MySQLDatabaseType()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(DatabaseTypeFactory.getInstance("MySQL"), resource, ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, schemas)); - Map metaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataMap, parameters, sqlStatementParserEngine.parse(sql, false), DefaultDatabase.LOGIC_NAME); + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( + DatabaseTypeFactory.getInstance("MySQL"), resource, ruleMetaData, new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, schemas)); + Map databaseMetaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData); + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(databaseMetaDataMap, parameters, sqlStatementParserEngine.parse(sql, false), DefaultDatabase.LOGIC_NAME); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, parameters); - return new SQLRouteEngine(Arrays.asList(shardingRule, singleTableRule), props).route(logicSQL, metaData); + return new SQLRouteEngine(Arrays.asList(shardingRule, singleTableRule), props).route(logicSQL, databaseMetaData); } private Map buildSchemas() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java index dd561461d232b..1a4a6b41e4085 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterIndexStatementValidatorTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.AlterIndexStatementContext; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingAlterIndexStatementValidator; @@ -48,7 +48,7 @@ public final class ShardingAlterIndexStatementValidatorTest { private ShardingRule shardingRule; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Test public void assertPreValidateAlterIndexWhenIndexExistRenameIndexNotExistForPostgreSQL() { @@ -58,11 +58,11 @@ public void assertPreValidateAlterIndexWhenIndexExistRenameIndexNotExistForPostg TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); when(indexes.containsKey("t_order_index")).thenReturn(true); when(indexes.containsKey("t_order_index_new")).thenReturn(false); - new ShardingAlterIndexStatementValidator().preValidate(shardingRule, new AlterIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingAlterIndexStatementValidator().preValidate(shardingRule, new AlterIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -73,10 +73,10 @@ public void assertPreValidateAlterIndexWhenIndexNotExistRenameIndexNotExistForPo TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); when(indexes.containsKey("t_order_index")).thenReturn(false); - new ShardingAlterIndexStatementValidator().preValidate(shardingRule, new AlterIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingAlterIndexStatementValidator().preValidate(shardingRule, new AlterIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -87,10 +87,10 @@ public void assertPreValidateAlterIndexWhenIndexExistRenameIndexExistForPostgreS TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); when(indexes.containsKey("t_order_index")).thenReturn(true); when(indexes.containsKey("t_order_index_new")).thenReturn(true); - new ShardingAlterIndexStatementValidator().preValidate(shardingRule, new AlterIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingAlterIndexStatementValidator().preValidate(shardingRule, new AlterIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java index d9004821cb8ff..80ffc930420fa 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.AlterTableStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; @@ -54,7 +54,7 @@ public final class ShardingAlterTableStatementValidatorTest { private ShardingRule shardingRule; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private RouteContext routeContext; @@ -66,7 +66,7 @@ public void assertPreValidateAlterTableWithRenameTableWithShardingTableForPostgr sqlStatement.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_new")))); SQLStatementContext sqlStatementContext = new AlterTableStatementContext(sqlStatement); when(shardingRule.tableRuleExists(Arrays.asList("t_order", "t_order_new"))).thenReturn(true); - new ShardingAlterTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingAlterTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -77,7 +77,7 @@ public void assertPreValidateAlterTableWithRenameTableWithBroadcastTableForPostg SQLStatementContext sqlStatementContext = new AlterTableStatementContext(sqlStatement); when(shardingRule.tableRuleExists(Arrays.asList("t_order", "t_order_new"))).thenReturn(false); when(shardingRule.isBroadcastTable("t_order")).thenReturn(true); - new ShardingAlterTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingAlterTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test @@ -91,7 +91,7 @@ public void assertPostValidateAlterTableWithSameRouteResultShardingTableForPostg routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingAlterTableStatementValidator().postValidate(shardingRule, new AlterTableStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -104,7 +104,7 @@ public void assertPostValidateAlterTableWithDifferentRouteResultShardingTableFor routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingAlterTableStatementValidator().postValidate(shardingRule, new AlterTableStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test @@ -118,7 +118,7 @@ public void assertPostValidateAlterTableWithSameRouteResultBroadcastTableForPost routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingAlterTableStatementValidator().postValidate(shardingRule, new AlterTableStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -131,6 +131,6 @@ public void assertPostValidateAlterTableWithDifferentRouteResultBroadcastTableFo routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingAlterTableStatementValidator().postValidate(shardingRule, new AlterTableStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java index 96a0cbc3738fa..591220f54cabc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterViewStatementValidatorTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingAlterViewStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; @@ -52,9 +52,9 @@ public void assertPreValidateAlterViewForMySQL() { MySQLAlterViewStatement sqlStatement = new MySQLAlterViewStatement(); sqlStatement.setSelect(selectStatement); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); when(shardingRule.isShardingTable("t_order")).thenReturn(false); - new ShardingAlterViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingAlterViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -63,9 +63,9 @@ public void assertPreValidateAlterViewWithShardingTableForMySQL() { selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); MySQLAlterViewStatement sqlStatement = new MySQLAlterViewStatement(); sqlStatement.setSelect(selectStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); when(shardingRule.isShardingTable("t_order")).thenReturn(true); - new ShardingAlterViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingAlterViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java index 1cd4129dc88ef..720ebfd0768fd 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateFunctionStatementValidatorTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.exception.NoSuchTableException; import org.apache.shardingsphere.sharding.route.engine.exception.TableExistsException; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingCreateFunctionStatementValidator; @@ -68,10 +68,10 @@ public void assertPreValidateCreateFunctionForMySQL() { MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME).containsTable("t_order_item")).thenReturn(true); - new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order_item")).thenReturn(true); + new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -85,7 +85,7 @@ public void assertPreValidateCreateFunctionWithShardingTableForMySQL() { MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test(expected = NoSuchTableException.class) @@ -99,7 +99,7 @@ public void assertPreValidateCreateFunctionWithNoSuchTableForMySQL() { MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test(expected = TableExistsException.class) @@ -113,9 +113,9 @@ public void assertPreValidateCreateFunctionWithTableExistsForMySQL() { MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true); - new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true); + new ShardingCreateFunctionStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java index 49c00715ef40b..2a2dfb5652d26 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateIndexStatementValidatorTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.CreateIndexStatementContext; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; import org.apache.shardingsphere.sharding.route.engine.exception.NoSuchTableException; @@ -52,20 +52,20 @@ public final class ShardingCreateIndexStatementValidatorTest { private ShardingRule shardingRule; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Test public void assertPreValidateCreateIndexWhenTableExistIndexNotExistForPostgreSQL() { PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); - when(metaData.getSchemaByName("public").containsTable("t_order")).thenReturn(true); + when(databaseMetaData.getDatabase().getSchema("public").containsTable("t_order")).thenReturn(true); TableMetaData tableMetaData = mock(TableMetaData.class); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); when(indexes.containsKey("t_order_index")).thenReturn(false); - new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test(expected = NoSuchTableException.class) @@ -73,8 +73,8 @@ public void assertPreValidateCreateIndexWhenTableNotExistIndexNotExistForPostgre PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); - when(metaData.getSchemaByName("public").containsTable("t_order")).thenReturn(false); - new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + when(databaseMetaData.getDatabase().getSchema("public").containsTable("t_order")).thenReturn(false); + new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -82,13 +82,13 @@ public void assertPreValidateCreateIndexWhenTableExistIndexExistForPostgreSQL() PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); - when(metaData.getSchemaByName("public").containsTable("t_order")).thenReturn(true); + when(databaseMetaData.getDatabase().getSchema("public").containsTable("t_order")).thenReturn(true); TableMetaData tableMetaData = mock(TableMetaData.class); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); when(indexes.containsKey("t_order_index")).thenReturn(true); - new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test @@ -97,12 +97,12 @@ public void assertPreValidateCreateIndexWithoutIndexNameWhenTableExistIndexNotEx sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setColumns(Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("content")))); sqlStatement.setGeneratedIndexStartIndex(10); - when(metaData.getSchemaByName("public").containsTable("t_order")).thenReturn(true); + when(databaseMetaData.getDatabase().getSchema("public").containsTable("t_order")).thenReturn(true); TableMetaData tableMetaData = mock(TableMetaData.class); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test(expected = NoSuchTableException.class) @@ -111,8 +111,8 @@ public void assertPreValidateCreateIndexWithoutIndexNameWhenTableNotExistIndexNo sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setColumns(Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("content")))); sqlStatement.setGeneratedIndexStartIndex(10); - when(metaData.getSchemaByName("public").containsTable("t_order")).thenReturn(false); - new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + when(databaseMetaData.getDatabase().getSchema("public").containsTable("t_order")).thenReturn(false); + new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -121,12 +121,12 @@ public void assertPreValidateCreateIndexWithoutIndexNameWhenTableExistIndexExist sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setColumns(Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("content")))); sqlStatement.setGeneratedIndexStartIndex(10); - when(metaData.getSchemaByName("public").containsTable("t_order")).thenReturn(true); + when(databaseMetaData.getDatabase().getSchema("public").containsTable("t_order")).thenReturn(true); TableMetaData tableMetaData = mock(TableMetaData.class); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); when(indexes.containsKey("content_idx")).thenReturn(true); - new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingCreateIndexStatementValidator().preValidate(shardingRule, new CreateIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java index 7f4925c14c5d9..0237350453f82 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateProcedureStatementValidatorTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.exception.NoSuchTableException; import org.apache.shardingsphere.sharding.route.engine.exception.TableExistsException; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingCreateProcedureStatementValidator; @@ -67,12 +67,12 @@ public void assertPreValidateCreateProcedureForMySQL() { routineBody.getValidStatements().add(selectValidStatementSegment); MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME).containsTable("t_order_item")).thenReturn(true); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order_item")).thenReturn(true); when(shardingRule.isShardingTable("t_order_item")).thenReturn(false); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -86,7 +86,7 @@ public void assertPreValidateCreateProcedureWithShardingTableForMySQL() { MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test(expected = NoSuchTableException.class) @@ -100,7 +100,7 @@ public void assertPreValidateCreateProcedureWithNoSuchTableForMySQL() { MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test(expected = TableExistsException.class) @@ -114,9 +114,9 @@ public void assertPreValidateCreateProcedureWithTableExistsForMySQL() { MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true); - new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true); + new ShardingCreateProcedureStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateTableStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateTableStatementValidatorTest.java index f1a3e765b4b5a..f4b181e578149 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateTableStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateTableStatementValidatorTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.CreateTableStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; @@ -60,7 +60,7 @@ public final class ShardingCreateTableStatementValidatorTest { private ShardingRule shardingRule; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private RouteContext routeContext; @@ -104,10 +104,10 @@ public void assertPreValidateCreateTableForSQLServer() { private void assertPreValidateCreateTable(final CreateTableStatement sqlStatement, final String schemaName) { SQLStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn("sharding_db"); - when(metaData.getSchemaByName(schemaName).containsTable("t_order")).thenReturn(true); - new ShardingCreateTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn("sharding_db"); + when(databaseMetaData.getDatabase().getSchema(schemaName).containsTable("t_order")).thenReturn(true); + new ShardingCreateTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test @@ -128,8 +128,8 @@ public void assertPreValidateCreateTableIfNotExistsForPostgreSQL() { private void assertPreValidateCreateTableIfNotExists(final CreateTableStatement sqlStatement) { SQLStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - new ShardingCreateTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + new ShardingCreateTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test @@ -143,7 +143,7 @@ public void assertPostValidateCreateTableWithSameRouteResultShardingTableForPost routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingCreateTableStatementValidator().postValidate(shardingRule, - new CreateTableStatementContext(sqlStatement), Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + new CreateTableStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -156,7 +156,7 @@ public void assertPostValidateCreateTableWithDifferentRouteResultShardingTableFo routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingCreateTableStatementValidator().postValidate(shardingRule, - new CreateTableStatementContext(sqlStatement), Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + new CreateTableStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test @@ -170,7 +170,7 @@ public void assertPostValidateCreateTableWithSameRouteResultBroadcastTableForPos routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingCreateTableStatementValidator().postValidate(shardingRule, - new CreateTableStatementContext(sqlStatement), Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + new CreateTableStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -183,6 +183,6 @@ public void assertPostValidateCreateTableWithDifferentRouteResultBroadcastTableF routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingCreateTableStatementValidator().postValidate(shardingRule, - new CreateTableStatementContext(sqlStatement), Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + new CreateTableStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java index 5dbc01be48d0c..f6379806d00db 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingCreateViewStatementValidatorTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingCreateViewStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; @@ -53,7 +53,7 @@ public void assertPreValidateCreateViewForMySQL() { sqlStatement.setSelect(selectStatement); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); when(shardingRule.isShardingTable("t_order")).thenReturn(false); - new ShardingCreateViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingCreateViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class)); } @Test(expected = ShardingSphereException.class) @@ -62,9 +62,9 @@ public void assertPreValidateCreateViewWithShardingTableForMySQL() { selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); MySQLCreateViewStatement sqlStatement = new MySQLCreateViewStatement(); sqlStatement.setSelect(selectStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); when(shardingRule.isShardingTable("t_order")).thenReturn(true); - new ShardingCreateViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingCreateViewStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java index 05cc7f750250f..aa75712f27cf2 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropIndexStatementValidatorTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.DropIndexStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; @@ -56,7 +56,7 @@ public final class ShardingDropIndexStatementValidatorTest { private ShardingRule shardingRule; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private RouteContext routeContext; @@ -69,11 +69,11 @@ public void assertPreValidateDropIndexWhenIndexExistForPostgreSQL() { TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); when(indexes.containsKey("t_order_index")).thenReturn(true); when(indexes.containsKey("t_order_index_new")).thenReturn(true); - new ShardingDropIndexStatementValidator().preValidate(shardingRule, new DropIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingDropIndexStatementValidator().preValidate(shardingRule, new DropIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -84,10 +84,10 @@ public void assertPreValidateDropIndexWhenIndexNotExistForPostgreSQL() { TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); when(indexes.containsKey("t_order_index")).thenReturn(false); - new ShardingDropIndexStatementValidator().preValidate(shardingRule, new DropIndexStatementContext(sqlStatement), Collections.emptyList(), metaData); + new ShardingDropIndexStatementValidator().preValidate(shardingRule, new DropIndexStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData); } @Test @@ -98,8 +98,8 @@ public void assertPostValidateDropIndexWithSameRouteResultShardingTableIndexForP TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); when(indexes.containsKey("t_order_index")).thenReturn(true); when(shardingRule.isShardingTable("t_order")).thenReturn(true); when(shardingRule.getTableRule("t_order")).thenReturn(new TableRule(Arrays.asList("ds_0", "ds_1"), "t_order")); @@ -108,7 +108,7 @@ public void assertPostValidateDropIndexWithSameRouteResultShardingTableIndexForP routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropIndexStatementValidator().postValidate(shardingRule, new DropIndexStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -119,8 +119,8 @@ public void assertPostValidateDropIndexWithDifferentRouteResultShardingTableInde TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); - when(metaData.getSchemaByName("public").get("t_order")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_order")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_order")).thenReturn(tableMetaData); when(indexes.containsKey("t_order_index")).thenReturn(true); when(shardingRule.isShardingTable("t_order")).thenReturn(true); when(shardingRule.getTableRule("t_order")).thenReturn(new TableRule(Arrays.asList("ds_0", "ds_1"), "t_order")); @@ -128,7 +128,7 @@ public void assertPostValidateDropIndexWithDifferentRouteResultShardingTableInde routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropIndexStatementValidator().postValidate(shardingRule, new DropIndexStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test @@ -139,8 +139,8 @@ public void assertPostValidateDropIndexWithSameRouteResultBroadcastTableIndexFor TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_config")); - when(metaData.getSchemaByName("public").get("t_config")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_config")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_config")).thenReturn(tableMetaData); when(indexes.containsKey("t_config_index")).thenReturn(true); when(shardingRule.isBroadcastTable("t_config")).thenReturn(true); when(shardingRule.getTableRule("t_config")).thenReturn(new TableRule(Arrays.asList("ds_0", "ds_1"), "t_config")); @@ -149,7 +149,7 @@ public void assertPostValidateDropIndexWithSameRouteResultBroadcastTableIndexFor routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropIndexStatementValidator().postValidate(shardingRule, new DropIndexStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -160,8 +160,8 @@ public void assertPostValidateDropIndexWithDifferentRouteResultBroadcastTableInd TableMetaData tableMetaData = mock(TableMetaData.class); Map indexes = mock(HashMap.class); when(tableMetaData.getIndexes()).thenReturn(indexes); - when(metaData.getSchemaByName("public").getAllTableNames()).thenReturn(Collections.singletonList("t_config")); - when(metaData.getSchemaByName("public").get("t_config")).thenReturn(tableMetaData); + when(databaseMetaData.getDatabase().getSchema("public").getAllTableNames()).thenReturn(Collections.singletonList("t_config")); + when(databaseMetaData.getDatabase().getSchema("public").get("t_config")).thenReturn(tableMetaData); when(indexes.containsKey("t_config_index")).thenReturn(true); when(shardingRule.isBroadcastTable("t_config")).thenReturn(true); when(shardingRule.getTableRule("t_config")).thenReturn(new TableRule(Arrays.asList("ds_0", "ds_1"), "t_config")); @@ -169,6 +169,6 @@ public void assertPostValidateDropIndexWithDifferentRouteResultBroadcastTableInd routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropIndexStatementValidator().postValidate(shardingRule, new DropIndexStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java index e2949cfa0b715..dca17a7d5200c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; @@ -77,9 +77,9 @@ public void assertPreValidateDropTableForMySQL() { MySQLDropTableStatement sqlStatement = new MySQLDropTableStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_item")))); SQLStatementContext sqlStatementContext = new CommonSQLStatementContext<>(sqlStatement); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); ShardingDropTableStatementValidator validator = new ShardingDropTableStatementValidator(); - validator.preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + validator.preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); Collection routeUnits = new LinkedList<>(); RouteMapper dataSourceMapper = new RouteMapper("db", "db1"); Collection tableMapper = new LinkedList<>(); @@ -89,7 +89,7 @@ public void assertPreValidateDropTableForMySQL() { routeUnits.add(routeUnit); RouteContext routeContext = mock(RouteContext.class); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - validator.postValidate(shardingRule, new DropTableStatementContext(sqlStatement), Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + validator.postValidate(shardingRule, new DropTableStatementContext(sqlStatement), Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } private TableRule generateShardingRule(final String tableName) { @@ -122,7 +122,7 @@ public void assertPostValidateDropTableWithSameRouteResultShardingTableForPostgr routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropTableStatementValidator().postValidate(shardingRule, new DropTableStatementContext(sqlStatement), - Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -135,7 +135,7 @@ public void assertPostValidateDropTableWithDifferentRouteResultShardingTableForP routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropTableStatementValidator().postValidate(shardingRule, new DropTableStatementContext(sqlStatement), - Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test @@ -149,7 +149,7 @@ public void assertPostValidateDropTableWithSameRouteResultBroadcastTableForPostg routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropTableStatementValidator().postValidate(shardingRule, new DropTableStatementContext(sqlStatement), - Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -162,6 +162,6 @@ public void assertPostValidateDropTableWithDifferentRouteResultBroadcastTableFor routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingDropTableStatementValidator().postValidate(shardingRule, new DropTableStatementContext(sqlStatement), - Collections.emptyList(), mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java index d7234fecf9f24..0280e1490b859 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingPrepareStatementValidatorTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.PrepareStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; @@ -48,7 +48,7 @@ public final class ShardingPrepareStatementValidatorTest { private ShardingRule shardingRule; @Mock - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private RouteContext routeContext; @@ -58,7 +58,7 @@ public void assertPostValidatePrepareWithEmptyRouteResultForPostgreSQL() { PrepareStatement sqlStatement = new PostgreSQLPrepareStatement(); when(routeContext.getRouteUnits()).thenReturn(Collections.emptyList()); new ShardingPrepareStatementValidator().postValidate(shardingRule, new PrepareStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test @@ -69,7 +69,7 @@ public void assertPostValidatePrepareWithDifferentDataSourceForPostgreSQL() { Arrays.asList(new RouteMapper("t_order", "t_order_0"), new RouteMapper("t_order_item", "t_order_item_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); new ShardingPrepareStatementValidator().postValidate(shardingRule, new PrepareStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } @Test(expected = ShardingSphereException.class) @@ -82,6 +82,6 @@ public void assertPostValidatePrepareWithSameDataSourceForPostgreSQL() { when(routeContext.getRouteUnits()).thenReturn(routeUnits); PrepareStatement sqlStatement = new PostgreSQLPrepareStatement(); new ShardingPrepareStatementValidator().postValidate(shardingRule, new PrepareStatementContext(sqlStatement), - Collections.emptyList(), metaData, mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), databaseMetaData, mock(ConfigurationProperties.class), routeContext); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java index 307b0e0020976..11aeba8a10e99 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteUnit; import org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingRenameTableStatementValidator; @@ -56,24 +56,24 @@ public final class ShardingRenameTableStatementValidatorTest { @Test(expected = ShardingSphereException.class) public void assertPreValidateShardingTable() { SQLStatementContext sqlStatementContext = createRenameTableStatementContext("t_order", "t_user_order"); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); when(shardingRule.tableRuleExists(argThat(tableNames -> tableNames.contains("t_order") || tableNames.contains("t_user_order")))).thenReturn(true); - new ShardingRenameTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingRenameTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) public void assertPreValidateBroadcastTable() { SQLStatementContext sqlStatementContext = createRenameTableStatementContext("t_order", "t_user_order"); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); when(shardingRule.isBroadcastTable(eq("t_order"))).thenReturn(true); - new ShardingRenameTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + new ShardingRenameTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test public void assertPreValidateNormalCase() { SQLStatementContext sqlStatementContext = createRenameTableStatementContext("t_not_sharding_table", "t_not_sharding_table_new"); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - new ShardingRenameTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); + new ShardingRenameTableStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -85,9 +85,9 @@ public void assertPostValidateDifferentRouteUnitsAndDataNodesSize() { when(shardingRule.getTableRule("t_order")).thenReturn(tableRule); when(shardingRule.isShardingTable("t_order")).thenReturn(true); SQLStatementContext sqlStatementContext = createRenameTableStatementContext("t_order", "t_user_order"); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); ConfigurationProperties props = mock(ConfigurationProperties.class); - new ShardingRenameTableStatementValidator().postValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData, props, routeContext); + new ShardingRenameTableStatementValidator().postValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData, props, routeContext); } @Test @@ -99,9 +99,9 @@ public void assertPostValidateNormalCase() { when(shardingRule.getTableRule("t_order")).thenReturn(tableRule); when(shardingRule.isShardingTable("t_order")).thenReturn(true); SQLStatementContext sqlStatementContext = createRenameTableStatementContext("t_order", "t_user_order"); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); ConfigurationProperties props = mock(ConfigurationProperties.class); - new ShardingRenameTableStatementValidator().postValidate(shardingRule, sqlStatementContext, Collections.emptyList(), metaData, props, routeContext); + new ShardingRenameTableStatementValidator().postValidate(shardingRule, sqlStatementContext, Collections.emptyList(), databaseMetaData, props, routeContext); } private SQLStatementContext createRenameTableStatementContext(final String originTableName, final String newTableName) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java index d85b892187f8e..8373a70ff1f84 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.DeleteStatementContext; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingDeleteStatementValidator; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.DeleteMultiTableSegment; @@ -86,6 +86,6 @@ private void assertPreValidateWhenDeleteMultiTables(final DeleteStatement sqlSta Collection tableNames = new HashSet<>(Arrays.asList("user", "order", "order_item")); when(shardingRule.isAllShardingTables(tableNames)).thenReturn(false); when(shardingRule.tableRuleExists(tableNames)).thenReturn(true); - new ShardingDeleteStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingDeleteStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class)); } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java index 0c0b87932373c..03808576af45b 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; @@ -65,6 +65,7 @@ import java.util.Optional; import java.util.Properties; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -86,13 +87,14 @@ public void assertPreValidateWhenInsertMultiTables() { Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); when(shardingRule.isAllShardingTables(tableNames)).thenReturn(false); when(shardingRule.tableRuleExists(tableNames)).thenReturn(true); - new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, + sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } private InsertStatementContext createInsertStatementContext(final List parameters, final InsertStatement insertStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); - return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), parameters, insertStatement, DefaultDatabase.LOGIC_NAME); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), parameters, insertStatement, DefaultDatabase.LOGIC_NAME); } @Test(expected = ShardingSphereException.class) @@ -101,7 +103,8 @@ public void assertPreValidateWhenInsertSelectWithoutKeyGenerateColumn() { when(shardingRule.isGenerateKeyColumn("id", "user")).thenReturn(false); SQLStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement()); sqlStatementContext.getTablesContext().getTableNames().addAll(createSingleTablesContext().getTableNames()); - new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, + sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test @@ -110,7 +113,8 @@ public void assertPreValidateWhenInsertSelectWithKeyGenerateColumn() { when(shardingRule.isGenerateKeyColumn("id", "user")).thenReturn(true); SQLStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement()); sqlStatementContext.getTablesContext().getTableNames().addAll(createSingleTablesContext().getTableNames()); - new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, + sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test(expected = ShardingSphereException.class) @@ -122,7 +126,8 @@ public void assertPreValidateWhenInsertSelectWithoutBindingTables() { when(shardingRule.tableRuleExists(multiTablesContext.getTableNames())).thenReturn(true); SQLStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement()); sqlStatementContext.getTablesContext().getTableNames().addAll(multiTablesContext.getTableNames()); - new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, + sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test @@ -132,7 +137,8 @@ public void assertPreValidateWhenInsertSelectWithBindingTables() { TablesContext multiTablesContext = createMultiTablesContext(); SQLStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement()); sqlStatementContext.getTablesContext().getTableNames().addAll(multiTablesContext.getTableNames()); - new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, + sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } @Test @@ -140,7 +146,7 @@ public void assertPostValidateWhenInsertWithSingleRouting() { SQLStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertStatement()); when(routeContext.isSingleRouting()).thenReturn(true); new ShardingInsertStatementValidator(shardingConditions).postValidate(shardingRule, sqlStatementContext, - Collections.emptyList(), mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test @@ -149,7 +155,7 @@ public void assertPostValidateWhenInsertWithBroadcastTable() { when(routeContext.isSingleRouting()).thenReturn(false); when(shardingRule.isBroadcastTable(sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue())).thenReturn(true); new ShardingInsertStatementValidator(shardingConditions).postValidate(shardingRule, sqlStatementContext, - Collections.emptyList(), mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test @@ -159,7 +165,7 @@ public void assertPostValidateWhenInsertWithRoutingToSingleDataNode() { when(shardingRule.isBroadcastTable(sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue())).thenReturn(false); when(routeContext.getOriginalDataNodes()).thenReturn(getSingleRouteDataNodes()); new ShardingInsertStatementValidator(shardingConditions).postValidate(shardingRule, sqlStatementContext, - Collections.emptyList(), mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test(expected = IllegalStateException.class) @@ -169,7 +175,7 @@ public void assertPostValidateWhenInsertWithRoutingToMultipleDataNodes() { when(shardingRule.isBroadcastTable(sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue())).thenReturn(false); when(routeContext.getOriginalDataNodes()).thenReturn(getMultipleRouteDataNodes()); new ShardingInsertStatementValidator(shardingConditions).postValidate(shardingRule, sqlStatementContext, - Collections.emptyList(), mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), routeContext); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test @@ -179,7 +185,7 @@ public void assertPostValidateWhenNotOnDuplicateKeyUpdateShardingColumn() { when(routeContext.isSingleRouting()).thenReturn(true); InsertStatementContext insertStatementContext = createInsertStatementContext(parameters, createInsertStatement()); new ShardingInsertStatementValidator(mock(ShardingConditions.class)).postValidate(shardingRule, - insertStatementContext, parameters, mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), routeContext); + insertStatementContext, parameters, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext); } @Test @@ -188,7 +194,7 @@ public void assertPostValidateWhenOnDuplicateKeyUpdateShardingColumnWithSameRout List parameters = Collections.singletonList(1); InsertStatementContext insertStatementContext = createInsertStatementContext(parameters, createInsertStatement()); new ShardingInsertStatementValidator(mock(ShardingConditions.class)).postValidate(shardingRule, - insertStatementContext, parameters, mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), createSingleRouteContext()); + insertStatementContext, parameters, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), createSingleRouteContext()); } @Test(expected = ShardingSphereException.class) @@ -197,7 +203,7 @@ public void assertPostValidateWhenOnDuplicateKeyUpdateShardingColumnWithDifferen List parameters = Collections.singletonList(1); InsertStatementContext insertStatementContext = createInsertStatementContext(parameters, createInsertStatement()); new ShardingInsertStatementValidator(mock(ShardingConditions.class)).postValidate(shardingRule, - insertStatementContext, parameters, mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), createFullRouteContext()); + insertStatementContext, parameters, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), createFullRouteContext()); } private void mockShardingRuleForUpdateShardingColumn() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java index 55d25fe9591b8..3b43e48d41e28 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; @@ -74,7 +74,7 @@ public void assertPreValidateWhenUpdateSingleTable() { Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true); when(shardingRule.tableRuleExists(tableNames)).thenReturn(true); - new ShardingUpdateStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingUpdateStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class)); } @Test(expected = ShardingSphereException.class) @@ -88,28 +88,28 @@ public void assertPreValidateWhenUpdateMultipleTables() { Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); when(shardingRule.isAllShardingTables(tableNames)).thenReturn(false); when(shardingRule.tableRuleExists(tableNames)).thenReturn(true); - new ShardingUpdateStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereMetaData.class)); + new ShardingUpdateStatementValidator().preValidate(shardingRule, sqlStatementContext, Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class)); } @Test public void assertPostValidateWhenNotUpdateShardingColumn() { UpdateStatementContext sqlStatementContext = new UpdateStatementContext(createUpdateStatement()); new ShardingUpdateStatementValidator().postValidate(shardingRule, sqlStatementContext, Collections.emptyList(), - mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), mock(RouteContext.class)); + mock(ShardingSphereDatabaseMetaData.class), mock(ConfigurationProperties.class), mock(RouteContext.class)); } @Test public void assertPostValidateWhenUpdateShardingColumnWithSameRouteContext() { mockShardingRuleForUpdateShardingColumn(); new ShardingUpdateStatementValidator().postValidate(shardingRule, new UpdateStatementContext(createUpdateStatement()), - Collections.emptyList(), mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), createSingleRouteContext()); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class), mock(ConfigurationProperties.class), createSingleRouteContext()); } @Test(expected = ShardingSphereException.class) public void assertPostValidateWhenUpdateShardingColumnWithDifferentRouteContext() { mockShardingRuleForUpdateShardingColumn(); new ShardingUpdateStatementValidator().postValidate(shardingRule, new UpdateStatementContext(createUpdateStatement()), - Collections.emptyList(), mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class), createFullRouteContext()); + Collections.emptyList(), mock(ShardingSphereDatabaseMetaData.class), mock(ConfigurationProperties.class), createFullRouteContext()); } private void mockShardingRuleForUpdateShardingColumn() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java index ec0add928af33..cbf0ebf24e009 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm; import org.apache.shardingsphere.sharding.algorithm.keygen.UUIDKeyGenerateAlgorithm; @@ -524,14 +524,16 @@ private ShardingTableRuleConfiguration createTableRuleConfigWithComplexStrategie @Test public void assertIsAllBindingTableWithUpdateStatementContext() { SQLStatementContext sqlStatementContext = mock(UpdateStatementContext.class); - assertTrue(createMaximumShardingRule().isAllBindingTables(mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); + assertTrue( + createMaximumShardingRule().isAllBindingTables(mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); } @Test public void assertIsAllBindingTableWithoutJoinQuery() { SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class); when(sqlStatementContext.isContainsJoinQuery()).thenReturn(false); - assertTrue(createMaximumShardingRule().isAllBindingTables(mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); + assertTrue( + createMaximumShardingRule().isAllBindingTables(mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); } @Test @@ -541,7 +543,8 @@ public void assertIsAllBindingTableWithJoinQueryWithoutJoinCondition() { when(sqlStatementContext.getSqlStatement()).thenReturn(mock(MySQLSelectStatement.class)); when(sqlStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType()); when(sqlStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.empty()); - assertFalse(createMaximumShardingRule().isAllBindingTables(mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); + assertFalse( + createMaximumShardingRule().isAllBindingTables(mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); } @Test @@ -560,10 +563,10 @@ public void assertIsAllBindingTableWithJoinQueryWithDatabaseJoinCondition() { when(sqlStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.empty()); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(sqlStatementContext.getTablesContext().findTableNamesByColumnSegment(Arrays.asList(leftDatabaseJoin, rightDatabaseJoin), schema)).thenReturn(createColumnTableNameMap()); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); - assertFalse(createMaximumShardingRule().isAllBindingTables(metaData, sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + assertFalse(createMaximumShardingRule().isAllBindingTables(databaseMetaData, sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); } @Test @@ -584,11 +587,11 @@ public void assertIsAllBindingTableWithJoinQueryWithDatabaseJoinConditionInUpper TablesContext tablesContext = new TablesContext(tableSegments, Collections.emptyMap(), DatabaseTypeEngine.getDatabaseType("MySQL")); when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext); when(sqlStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType()); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME).getAllColumnNames("LOGIC_TABLE")).thenReturn(Arrays.asList("user_id", "order_id")); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME).getAllColumnNames("SUB_LOGIC_TABLE")).thenReturn(Arrays.asList("uid", "order_id")); - assertFalse(createMaximumShardingRule().isAllBindingTables(metaData, sqlStatementContext, Arrays.asList("LOGIC_TABLE", "SUB_LOGIC_TABLE"))); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME).getAllColumnNames("LOGIC_TABLE")).thenReturn(Arrays.asList("user_id", "order_id")); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME).getAllColumnNames("SUB_LOGIC_TABLE")).thenReturn(Arrays.asList("uid", "order_id")); + assertFalse(createMaximumShardingRule().isAllBindingTables(databaseMetaData, sqlStatementContext, Arrays.asList("LOGIC_TABLE", "SUB_LOGIC_TABLE"))); } @Test @@ -612,10 +615,10 @@ public void assertIsAllBindingTableWithJoinQueryWithDatabaseTableJoinCondition() ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(sqlStatementContext.getTablesContext().findTableNamesByColumnSegment(Arrays.asList(leftDatabaseJoin, rightDatabaseJoin), schema)).thenReturn(createColumnTableNameMap()); when(sqlStatementContext.getTablesContext().findTableNamesByColumnSegment(Arrays.asList(leftTableJoin, rightTableJoin), schema)).thenReturn(createColumnTableNameMap()); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); - assertTrue(createMaximumShardingRule().isAllBindingTables(metaData, sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn(DefaultDatabase.LOGIC_NAME); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); + assertTrue(createMaximumShardingRule().isAllBindingTables(databaseMetaData, sqlStatementContext, Arrays.asList("logic_Table", "sub_Logic_Table"))); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/CheckScalingQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/CheckScalingQueryResultSet.java index bdf534dbcbaf2..b5c062d367b88 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/CheckScalingQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/CheckScalingQueryResultSet.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.data.pipeline.api.RuleAlteredJobAPI; import org.apache.shardingsphere.data.pipeline.api.check.consistency.DataConsistencyCheckResult; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.CheckScalingStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -42,7 +42,7 @@ public final class CheckScalingQueryResultSet implements DistSQLResultSet { private Iterator> data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { CheckScalingStatement checkScalingStatement = (CheckScalingStatement) sqlStatement; Map checkResultMap; if (null == checkScalingStatement.getTypeStrategy()) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSet.java index 4a315a8bbaa42..70e034a3d402c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSet.java @@ -20,7 +20,7 @@ import com.google.gson.Gson; import org.apache.shardingsphere.infra.config.rulealtered.OnRuleAlteredActionConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.ShowShardingScalingRulesStatement; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -41,8 +41,8 @@ public final class ShardingScalingRulesQueryResultSet implements DistSQLResultSe private Iterator> data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) each).findAny(); data = ruleConfig.map(ShardingRuleConfiguration::getScaling).orElse(Collections.emptyMap()).entrySet().iterator(); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSet.java index 1e44ff0121a26..f5c2a0e0e340b 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSet.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.data.pipeline.api.RuleAlteredJobAPI; import org.apache.shardingsphere.data.pipeline.api.RuleAlteredJobAPIFactory; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.ShowScalingCheckAlgorithmsStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -39,7 +39,7 @@ public final class ShowScalingCheckAlgorithmsQueryResultSet implements DistSQLRe private Iterator> data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { data = RULE_ALTERED_JOB_API.listDataConsistencyCheckAlgorithms().stream().map( each -> (Collection) Arrays.asList(each.getType(), String.join(",", each.getSupportedDatabaseTypes()), each.getDescription())).collect(Collectors.toList()).iterator(); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingJobStatusQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingJobStatusQueryResultSet.java index 1558171bce182..c30daac594646 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingJobStatusQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingJobStatusQueryResultSet.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.data.pipeline.api.RuleAlteredJobAPIFactory; import org.apache.shardingsphere.data.pipeline.api.RuleAlteredJobAPI; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.ShowScalingStatusStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -41,7 +41,7 @@ public final class ShowScalingJobStatusQueryResultSet implements DistSQLResultSe private Iterator> data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { long currentTimeMillis = System.currentTimeMillis(); data = RULE_ALTERED_JOB_API.getProgress(((ShowScalingStatusStatement) sqlStatement).getJobId()).entrySet().stream() .map(entry -> { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingListQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingListQueryResultSet.java index c16ca108f9630..677b915fe2c3b 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingListQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingListQueryResultSet.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.data.pipeline.api.RuleAlteredJobAPIFactory; import org.apache.shardingsphere.data.pipeline.api.RuleAlteredJobAPI; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.ShowScalingListStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -40,7 +40,7 @@ public final class ShowScalingListQueryResultSet implements DistSQLResultSet { private Iterator> data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { data = RULE_ALTERED_JOB_API.list().stream() .map(each -> { Collection result = new LinkedList<>(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java index 6461cefe51196..94b7219af48e8 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.handler.converter.ShardingScalingRuleStatementConverter; import org.apache.shardingsphere.scaling.distsql.statement.CreateShardingScalingRuleStatement; import org.apache.shardingsphere.scaling.distsql.statement.segment.ShardingScalingRuleConfigurationSegment; @@ -44,9 +44,9 @@ public final class CreateShardingScalingRuleStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateShardingScalingRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateShardingScalingRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkDuplicate(databaseName, sqlStatement, currentRuleConfig); checkAlgorithms(sqlStatement.getScalingRuleConfigSegment()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisableShardingScalingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisableShardingScalingRuleStatementUpdater.java index b9d3d2d549961..09865df913b7f 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisableShardingScalingRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisableShardingScalingRuleStatementUpdater.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDisabledException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.DisableShardingScalingRuleStatement; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -31,9 +31,9 @@ public final class DisableShardingScalingRuleStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DisableShardingScalingRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DisableShardingScalingRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkExist(databaseName, sqlStatement, currentRuleConfig); checkDisabled(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdater.java index 5d6a779fe5ed6..9565d1689790c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdater.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.DropShardingScalingRuleStatement; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -30,9 +30,9 @@ public final class DropShardingScalingRuleStatementUpdater implements RuleDefinitionDropUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropShardingScalingRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropShardingScalingRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); if (!isExistRuleConfig(currentRuleConfig) && sqlStatement.isContainsExistClause()) { return; } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdater.java index 77ef4ae6fec7a..7535af3dd71a8 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdater.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleEnabledException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.EnableShardingScalingRuleStatement; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -31,9 +31,9 @@ public final class EnableShardingScalingRuleStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final EnableShardingScalingRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final EnableShardingScalingRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkExist(databaseName, sqlStatement, currentRuleConfig); checkEnabled(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java index 9f5f558592ac4..348f84f1166da 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.expr.InlineExpressionParser; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; @@ -63,50 +63,50 @@ public final class ShardingTableRuleStatementChecker { /** * Check create sharing table rule statement. * - * @param shardingSphereMetaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param rules rules * @param currentRuleConfig current rule configuration * @throws DistSQLException definition violation exception */ - public static void checkCreation(final ShardingSphereMetaData shardingSphereMetaData, final Collection rules, + public static void checkCreation(final ShardingSphereDatabaseMetaData databaseMetaData, final Collection rules, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - check(shardingSphereMetaData, rules, currentRuleConfig, true); + check(databaseMetaData, rules, currentRuleConfig, true); } /** * Check alter sharing table rule statement. * - * @param shardingSphereMetaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param rules rules * @param currentRuleConfig current rule configuration * @throws DistSQLException definition violation exception */ - public static void checkAlteration(final ShardingSphereMetaData shardingSphereMetaData, final Collection rules, + public static void checkAlteration(final ShardingSphereDatabaseMetaData databaseMetaData, final Collection rules, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - check(shardingSphereMetaData, rules, currentRuleConfig, false); + check(databaseMetaData, rules, currentRuleConfig, false); } - private static void check(final ShardingSphereMetaData shardingSphereMetaData, final Collection rules, + private static void check(final ShardingSphereDatabaseMetaData databaseMetaData, final Collection rules, final ShardingRuleConfiguration currentRuleConfig, final boolean isCreate) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkShardingTables(databaseName, rules, currentRuleConfig, isCreate); - checkResources(databaseName, rules, shardingSphereMetaData); + checkResources(databaseName, rules, databaseMetaData); checkKeyGenerators(rules, currentRuleConfig); Map> groupedTableRule = groupingByClassType(rules); checkAutoTableRule(groupedTableRule.getOrDefault(AutoTableRuleSegment.class.getSimpleName(), Collections.emptyList())); checkTableRule(databaseName, currentRuleConfig, groupedTableRule.getOrDefault(TableRuleSegment.class.getSimpleName(), Collections.emptyList())); } - private static void checkResources(final String databaseName, final Collection rules, final ShardingSphereMetaData shardingSphereMetaData) throws DistSQLException { + private static void checkResources(final String databaseName, final Collection rules, final ShardingSphereDatabaseMetaData databaseMetaData) throws DistSQLException { Collection requiredResource = getRequiredResources(rules); - Collection notExistedResources = shardingSphereMetaData.getResource().getNotExistedResources(requiredResource); - Collection logicResources = getLogicResources(shardingSphereMetaData); + Collection notExistedResources = databaseMetaData.getResource().getNotExistedResources(requiredResource); + Collection logicResources = getLogicResources(databaseMetaData); notExistedResources.removeIf(logicResources::contains); DistSQLException.predictionThrow(notExistedResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistedResources)); } - private static Collection getLogicResources(final ShardingSphereMetaData shardingSphereMetaData) { - return shardingSphereMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataSourceContainedRule) + private static Collection getLogicResources(final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataSourceContainedRule) .map(each -> ((DataSourceContainedRule) each).getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new)); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/DefaultShardingStrategyQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/DefaultShardingStrategyQueryResultSet.java index 731006b361fc4..18c6e9a6d4682 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/DefaultShardingStrategyQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/DefaultShardingStrategyQueryResultSet.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.enums.ShardingStrategyType; @@ -44,8 +44,8 @@ public final class DefaultShardingStrategyQueryResultSet implements DistSQLResul private Iterator>> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional shardingRuleConfig = metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class).stream().findAny(); + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional shardingRuleConfig = databaseMetaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class).stream().findAny(); shardingRuleConfig.ifPresent(optional -> data = buildData(optional).entrySet().iterator()); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingAlgorithmsQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingAlgorithmsQueryResultSet.java index ae31656c4d24e..38b3189c3ea64 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingAlgorithmsQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingAlgorithmsQueryResultSet.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.properties.PropertiesConverter; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingAlgorithmsStatement; @@ -43,8 +43,8 @@ public final class ShardingAlgorithmsQueryResultSet implements DistSQLResultSet private Iterator> data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) each).findAny(); data = ruleConfig.map(ShardingRuleConfiguration::getShardingAlgorithms).orElseGet(Collections::emptyMap).entrySet().iterator(); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java index ef7a9248f7e98..5f876f0f342c9 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBindingTableRuleQueryResultSet.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.query; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBindingTableRulesStatement; @@ -36,8 +36,8 @@ public final class ShardingBindingTableRuleQueryResultSet implements DistSQLResu private Iterator data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional shardingRuleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional shardingRuleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) each).findFirst(); data = shardingRuleConfig.map(each -> each.getBindingTableGroups().iterator()).orElseGet(Collections::emptyIterator); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBroadcastTableRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBroadcastTableRuleQueryResultSet.java index f567912e9cf8b..10c6652c62462 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBroadcastTableRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingBroadcastTableRuleQueryResultSet.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.query; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBroadcastTableRulesStatement; @@ -36,8 +36,8 @@ public final class ShardingBroadcastTableRuleQueryResultSet implements DistSQLRe private Iterator data; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional shardingRuleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional shardingRuleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) each).findFirst(); data = shardingRuleConfig.map(optional -> optional.getBroadcastTables().iterator()).orElseGet(Collections::emptyIterator); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingKeyGeneratorsQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingKeyGeneratorsQueryResultSet.java index 8c95952e290f9..8fe4d6caa2395 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingKeyGeneratorsQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingKeyGeneratorsQueryResultSet.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingKeyGeneratorsStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -39,8 +39,8 @@ public final class ShardingKeyGeneratorsQueryResultSet implements DistSQLResultS private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class) + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + databaseMetaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class) .forEach(each -> data = each.getKeyGenerators().entrySet().iterator()); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesQueryResultSet.java index 43e024b604eeb..d3cf837b9afac 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableNodesQueryResultSet.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; import org.apache.shardingsphere.infra.expr.InlineExpressionParser; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -55,8 +55,8 @@ public final class ShardingTableNodesQueryResultSet implements DistSQLResultSet private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - metaData.getRuleMetaData().getConfigurations().stream() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + databaseMetaData.getRuleMetaData().getConfigurations().stream() .filter(each -> each instanceof ShardingRuleConfiguration) .map(each -> (ShardingRuleConfiguration) each) .forEach(each -> data = getData(each, (ShowShardingTableNodesStatement) sqlStatement).entrySet().iterator()); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRuleQueryResultSet.java index 543855fcad2fa..0c4cf363d55bd 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRuleQueryResultSet.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.query; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.properties.PropertiesConverter; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -53,9 +53,9 @@ public final class ShardingTableRuleQueryResultSet implements DistSQLResultSet { private ShardingRuleConfiguration shardingRuleConfig; @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { String tableName = ((ShowShardingTableRulesStatement) sqlStatement).getTableName(); - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations() + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) each).findAny(); if (Objects.isNull(tableName)) { tables = ruleConfig.map(optional -> optional.getTables().iterator()).orElseGet(Collections::emptyIterator); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAlgorithmQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAlgorithmQueryResultSet.java index 0f51663d2832e..f10f43052d2f0 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAlgorithmQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAlgorithmQueryResultSet.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.query; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedAlgorithmStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -37,11 +37,11 @@ public final class ShardingTableRulesUsedAlgorithmQueryResultSet implements Dist private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { ShowShardingTableRulesUsedAlgorithmStatement statement = (ShowShardingTableRulesUsedAlgorithmStatement) sqlStatement; Collection> data = new LinkedList<>(); - Collection shardingTableRules = metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class); - shardingTableRules.forEach(each -> requireResult(statement, metaData.getDatabase().getName(), data, each)); + Collection shardingTableRules = databaseMetaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class); + shardingTableRules.forEach(each -> requireResult(statement, databaseMetaData.getDatabase().getName(), data, each)); this.data = data.iterator(); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedKeyGeneratorQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedKeyGeneratorQueryResultSet.java index 4313011d27b59..3182f5f3615ff 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedKeyGeneratorQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedKeyGeneratorQueryResultSet.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.sharding.distsql.handler.query; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedKeyGeneratorStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -38,11 +38,11 @@ public final class ShardingTableRulesUsedKeyGeneratorQueryResultSet implements D private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { ShowShardingTableRulesUsedKeyGeneratorStatement statement = (ShowShardingTableRulesUsedKeyGeneratorStatement) sqlStatement; List> result = new ArrayList<>(); - Collection shardingTableRules = metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class); - shardingTableRules.forEach(each -> requireResult(statement, metaData.getDatabase().getName(), result, each)); + Collection shardingTableRules = databaseMetaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class); + shardingTableRules.forEach(each -> requireResult(statement, databaseMetaData.getDatabase().getName(), result, each)); data = result.iterator(); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java index 2960b889deef3..eaf492580dd14 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingAlgorithmsQueryResultSet.java @@ -20,7 +20,7 @@ import com.google.common.base.Strings; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.properties.PropertiesConverter; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; @@ -56,8 +56,8 @@ public final class UnusedShardingAlgorithmsQueryResultSet implements DistSQLResu private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) each).findAny(); ruleConfig.ifPresent(this::getUnusedShardingAlgorithms); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java index 84d339ab608e6..afa1d71599ef9 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/UnusedShardingKeyGeneratorsQueryResultSet.java @@ -20,7 +20,7 @@ import com.google.common.base.Strings; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.properties.PropertiesConverter; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; @@ -56,8 +56,8 @@ public final class UnusedShardingKeyGeneratorsQueryResultSet implements DistSQLR private Iterator> data = Collections.emptyIterator(); @Override - public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) { - Optional ruleConfig = metaData.getRuleMetaData().getConfigurations() + public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) { + Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations() .stream().filter(each -> each instanceof ShardingRuleConfiguration).map(each -> (ShardingRuleConfiguration) each).findAny(); ruleConfig.ifPresent(this::getUnusedKeyGenerators); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyStatementUpdater.java index bc8443309b5ba..d07a83011b449 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter; @@ -43,9 +43,9 @@ public final class AlterDefaultShardingStrategyStatementUpdater implements RuleD private static final String TYPE = AlterDefaultShardingStrategyStatement.class.getName(); @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterDefaultShardingStrategyStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterDefaultShardingStrategyStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkAlgorithm(databaseName, currentRuleConfig, sqlStatement); checkExist(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingAlgorithmStatementUpdater.java index 9af39cd02f42e..18685307f8df8 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingAlgorithmStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingAlgorithmSegment; @@ -41,9 +41,9 @@ public final class AlterShardingAlgorithmStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterShardingAlgorithmStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterShardingAlgorithmStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); Collection requireNames = sqlStatement.getAlgorithmSegments().stream().map(ShardingAlgorithmSegment::getShardingAlgorithmName).collect(Collectors.toList()); checkDuplicate(databaseName, requireNames); checkExist(requireNames, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRulesStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRulesStatementUpdater.java index 70768fff75c21..878253781b3c1 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRulesStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBindingTableRulesStatementUpdater.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -39,9 +39,9 @@ public final class AlterShardingBindingTableRulesStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterShardingBindingTableRulesStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkToBeAlertedBindingTables(databaseName, sqlStatement, currentRuleConfig); checkToBeAlteredDuplicateBindingTables(databaseName, sqlStatement); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementUpdater.java index 34ccb58ff798a..93448a33dd233 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingBroadcastTableRuleStatementUpdater.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBroadcastTableRulesStatement; @@ -30,9 +30,9 @@ public final class AlterShardingBroadcastTableRuleStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterShardingBroadcastTableRulesStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException { - checkCurrentRuleConfiguration(shardingSphereMetaData.getDatabase().getName(), currentRuleConfig); + checkCurrentRuleConfiguration(databaseMetaData.getDatabase().getName(), currentRuleConfig); } private void checkCurrentRuleConfiguration(final String databaseName, final ShardingRuleConfiguration currentRuleConfig) throws RequiredRuleMissedException { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingKeyGeneratorStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingKeyGeneratorStatementUpdater.java index 9fd65a65f2ac5..13fb9e8a6f513 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingKeyGeneratorStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingKeyGeneratorStatementUpdater.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment; @@ -41,9 +41,9 @@ public final class AlterShardingKeyGeneratorStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterShardingKeyGeneratorStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterShardingKeyGeneratorStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); Collection requireNames = sqlStatement.getKeyGeneratorSegments().stream().map(ShardingKeyGeneratorSegment::getKeyGeneratorName).collect(Collectors.toList()); checkDuplicate(databaseName, requireNames); checkExist(requireNames, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java index 676ee294eccb8..c7eeedfd047cc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleStatementUpdater.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -37,10 +37,10 @@ public final class AlterShardingTableRuleStatementUpdater implements RuleDefinitionAlterUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterShardingTableRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - DistSQLException.predictionThrow(null != currentRuleConfig, () -> new RequiredRuleMissedException("Sharding", shardingSphereMetaData.getDatabase().getName())); - ShardingTableRuleStatementChecker.checkAlteration(shardingSphereMetaData, sqlStatement.getRules(), currentRuleConfig); + DistSQLException.predictionThrow(null != currentRuleConfig, () -> new RequiredRuleMissedException("Sharding", databaseMetaData.getDatabase().getName())); + ShardingTableRuleStatementChecker.checkAlteration(databaseMetaData, sqlStatement.getRules(), currentRuleConfig); } @Override diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateDefaultShardingStrategyStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateDefaultShardingStrategyStatementUpdater.java index e3d12b2c4bcc9..3fe0bae87d9d2 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateDefaultShardingStrategyStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateDefaultShardingStrategyStatementUpdater.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.enums.ShardingStrategyType; @@ -44,9 +44,9 @@ public final class CreateDefaultShardingStrategyStatementUpdater implements Rule private static final String TYPE = CreateDefaultShardingStrategyStatement.class.getName(); @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateDefaultShardingStrategyStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDefaultShardingStrategyStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkAlgorithm(databaseName, currentRuleConfig, sqlStatement); checkExist(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingAlgorithmStatementUpdater.java index 211d071c08725..be913ce3744ff 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingAlgorithmStatementUpdater.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingAlgorithmSegment; @@ -41,9 +41,9 @@ public final class CreateShardingAlgorithmStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateShardingAlgorithmStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateShardingAlgorithmStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkDuplicate(databaseName, sqlStatement, currentRuleConfig); checkAlgorithm(sqlStatement); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpdater.java index 37170ebcde105..adcc72b8c587e 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBindingTableRuleStatementUpdater.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -39,9 +39,9 @@ public final class CreateShardingBindingTableRuleStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateShardingBindingTableRulesStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkToBeCreatedBindingTables(databaseName, sqlStatement, currentRuleConfig); checkToBeCreatedDuplicateBindingTables(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatementUpdater.java index d1417f537e170..8c9746be423e8 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingBroadcastTableRuleStatementUpdater.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingBroadcastTableRulesStatement; @@ -30,9 +30,9 @@ public final class CreateShardingBroadcastTableRuleStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateShardingBroadcastTableRulesStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException { - checkCurrentRuleConfiguration(shardingSphereMetaData.getDatabase().getName(), currentRuleConfig); + checkCurrentRuleConfiguration(databaseMetaData.getDatabase().getName(), currentRuleConfig); } private void checkCurrentRuleConfiguration(final String databaseName, final ShardingRuleConfiguration currentRuleConfig) throws RuleInUsedException { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingKeyGeneratorStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingKeyGeneratorStatementUpdater.java index 76566a25ea8af..edf089d00774b 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingKeyGeneratorStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingKeyGeneratorStatementUpdater.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateKeyGeneratorException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment; @@ -41,9 +41,9 @@ public final class CreateShardingKeyGeneratorStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateShardingKeyGeneratorStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateShardingKeyGeneratorStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - checkDuplicate(shardingSphereMetaData.getDatabase().getName(), sqlStatement, currentRuleConfig); + checkDuplicate(databaseMetaData.getDatabase().getName(), sqlStatement, currentRuleConfig); checkKeyGeneratorAlgorithm(sqlStatement); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java index d6fb26797fbe3..882ca57f9e080 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableRuleStatementUpdater.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.checker.ShardingTableRuleStatementChecker; import org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter; @@ -31,9 +31,9 @@ public final class CreateShardingTableRuleStatementUpdater implements RuleDefinitionCreateUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateShardingTableRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, sqlStatement.getRules(), currentRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, sqlStatement.getRules(), currentRuleConfig); } @Override diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultStrategyStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultStrategyStatementUpdater.java index 657dd67d021e0..568549fa08ea7 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultStrategyStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultStrategyStatementUpdater.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.enums.ShardingStrategyLevelType; @@ -34,9 +34,9 @@ public final class DropDefaultStrategyStatementUpdater implements RuleDefinitionDropUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropDefaultShardingStrategyStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDefaultShardingStrategyStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); if (!isExistRuleConfig(currentRuleConfig) && sqlStatement.isContainsExistClause()) { return; } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmStatementUpdater.java index ee604a2c7f123..70c657e53a043 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmStatementUpdater.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingAlgorithmStatement; @@ -37,12 +37,12 @@ public final class DropShardingAlgorithmStatementUpdater implements RuleDefinitionDropUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropShardingAlgorithmStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropShardingAlgorithmStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException { if (null == currentRuleConfig && sqlStatement.isContainsExistClause()) { return; } - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkCurrentRuleConfiguration(databaseName, currentRuleConfig); checkToBeDroppedShardingAlgorithms(databaseName, sqlStatement, currentRuleConfig); checkShardingAlgorithmsInUsed(databaseName, sqlStatement, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java index 7d486ee8ac9cd..047b0bc6bc918 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBindingTableRuleStatementUpdater.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.segment.BindingTableRuleSegment; import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBindingTableRulesStatement; @@ -46,9 +46,9 @@ public final class DropShardingBindingTableRuleStatementUpdater implements RuleD private Map bindingTableRules = Collections.emptyMap(); @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropShardingBindingTableRulesStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropShardingBindingTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); if (!isExistRuleConfig(currentRuleConfig) && sqlStatement.isContainsExistClause()) { return; } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpdater.java index a3b5ae2c40765..fa8db3e14f317 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingBroadcastTableRuleStatementUpdater.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingBroadcastTableRulesStatement; @@ -33,9 +33,9 @@ public final class DropShardingBroadcastTableRuleStatementUpdater implements RuleDefinitionDropUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropShardingBroadcastTableRulesStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropShardingBroadcastTableRulesStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); if (!isExistRuleConfig(currentRuleConfig) && sqlStatement.isContainsExistClause()) { return; } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorStatementUpdater.java index ede1e50513254..0515392d1b433 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorStatementUpdater.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.KeyGeneratorInUsedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredKeyGeneratorMissedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.DropShardingKeyGeneratorStatement; @@ -41,12 +41,12 @@ public final class DropShardingKeyGeneratorStatementUpdater implements RuleDefin private static final String TYPE = DropShardingKeyGeneratorStatement.class.getName(); @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropShardingKeyGeneratorStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropShardingKeyGeneratorStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { if (null == currentRuleConfig && sqlStatement.isContainsExistClause()) { return; } - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); Collection keyGeneratorNames = new LinkedList<>(sqlStatement.getKeyGeneratorNames()); checkExist(databaseName, keyGeneratorNames, currentRuleConfig, sqlStatement); checkInUsed(databaseName, keyGeneratorNames, currentRuleConfig); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java index 399d1c4a27efa..1b502644cf21d 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -42,9 +42,9 @@ public final class DropShardingTableRuleStatementUpdater implements RuleDefinitionDropUpdater { @Override - public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropShardingTableRuleStatement sqlStatement, + public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) throws RuleDefinitionViolationException { - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); if (!isExistRuleConfig(currentRuleConfig) && sqlStatement.isContainsExistClause()) { return; } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java index 60f9ad0c5ee0a..a4e8db4fd3c02 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.rulealtered.OnRuleAlteredActionConfiguration; import org.apache.shardingsphere.infra.config.rulealtered.OnRuleAlteredActionConfiguration.InputConfiguration; import org.apache.shardingsphere.infra.config.rulealtered.OnRuleAlteredActionConfiguration.OutputConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingAlgorithmsStatement; import org.junit.Test; @@ -43,10 +43,10 @@ public final class ShardingScalingRulesQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); ShardingScalingRulesQueryResultSet resultSet = new ShardingScalingRulesQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingAlgorithmsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(6)); assertThat(actual.get(0), is("scaling_name")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSetTest.java index 551d80bda6eed..4f948ae10663b 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShowScalingCheckAlgorithmsQueryResultSetTest.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.scaling.distsql.handler.query; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.ShowScalingCheckAlgorithmsStatement; import org.apache.shardingsphere.scaling.distsql.util.PipelineContextUtil; import org.junit.BeforeClass; @@ -38,7 +38,7 @@ public final class ShowScalingCheckAlgorithmsQueryResultSetTest { @Mock - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShowScalingCheckAlgorithmsStatement showScalingCheckAlgorithmsStatement; @@ -51,7 +51,7 @@ public static void beforeClass() { @Test public void assertGetRowData() { ShowScalingCheckAlgorithmsQueryResultSet resultSet = new ShowScalingCheckAlgorithmsQueryResultSet(); - resultSet.init(shardingSphereMetaData, showScalingCheckAlgorithmsStatement); + resultSet.init(databaseMetaData, showScalingCheckAlgorithmsStatement); Collection algorithmTypes = new LinkedHashSet<>(); while (resultSet.next()) { Collection actual = resultSet.getRowData(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdaterTest.java index 3a05c2dcbda64..9f25be5f24f9a 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdaterTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.CreateShardingScalingRuleStatement; import org.apache.shardingsphere.scaling.distsql.statement.segment.InputOrOutputSegment; import org.apache.shardingsphere.scaling.distsql.statement.segment.ShardingScalingRuleConfigurationSegment; @@ -47,61 +47,61 @@ public final class CreateShardingScalingRuleStatementUpdaterTest { private static final String LIMIT_TYPE_OUTPUT = "FIXTURE_OUTPUT"; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final CreateShardingScalingRuleStatementUpdater updater = new CreateShardingScalingRuleStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckWithoutShardingRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new CreateShardingScalingRuleStatement("default_scaling", null), null); + updater.checkSQLStatement(databaseMetaData, new CreateShardingScalingRuleStatement("default_scaling", null), null); } @Test(expected = DuplicateRuleException.class) public void assertCheckWithExist() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.getScaling().put("default_scaling", null); - updater.checkSQLStatement(shardingSphereMetaData, new CreateShardingScalingRuleStatement("default_scaling", null), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, new CreateShardingScalingRuleStatement("default_scaling", null), currentRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckInvalidRateLimiter() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); CreateShardingScalingRuleStatement statement = new CreateShardingScalingRuleStatement("default_scaling", createConfigurationWithInvalidRateLimiter()); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckInvalidStreamChannel() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); CreateShardingScalingRuleStatement statement = new CreateShardingScalingRuleStatement("default_scaling", createConfigurationWithInvalidStreamChannel()); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckInvalidCompletionDetector() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); CreateShardingScalingRuleStatement statement = new CreateShardingScalingRuleStatement("default_scaling", createConfigurationWithInvalidCompletionDetector()); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertCheckInvalidDataConsistencyCalculator() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); CreateShardingScalingRuleStatement statement = new CreateShardingScalingRuleStatement("default_scaling", createConfigurationWithInvalidDataConsistencyCalculator()); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test public void assertCheckSuccessWithoutConfiguration() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); - updater.checkSQLStatement(shardingSphereMetaData, new CreateShardingScalingRuleStatement("default_scaling", null), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, new CreateShardingScalingRuleStatement("default_scaling", null), currentRuleConfig); } @Test public void assertCheckSuccessWithCompleteConfiguration() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); CreateShardingScalingRuleStatement statement = new CreateShardingScalingRuleStatement("default_scaling", createCompleteConfiguration()); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisabledShardingScalingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisabledShardingScalingRuleStatementUpdaterTest.java index 403fc3e37b053..e8ad71c3022bc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisabledShardingScalingRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DisabledShardingScalingRuleStatementUpdaterTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDisabledException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.DisableShardingScalingRuleStatement; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.junit.Before; @@ -37,25 +37,25 @@ public final class DisabledShardingScalingRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DisableShardingScalingRuleStatementUpdater updater = new DisableShardingScalingRuleStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckWithoutShardingRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("default_scaling"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("default_scaling"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckNotExist() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.getScaling().put("default_scaling", null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("new_scaling"), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("new_scaling"), currentRuleConfig); } @Test(expected = RuleDisabledException.class) @@ -63,7 +63,7 @@ public void assertCheckDisabled() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); String scalingName = "default_scaling"; currentRuleConfig.getScaling().put(scalingName, null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(scalingName), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(scalingName), currentRuleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdaterTest.java index 9aea333161589..9c993482e5f6f 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/DropShardingScalingRuleStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.DropShardingScalingRuleStatement; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.junit.Before; @@ -37,37 +37,37 @@ public final class DropShardingScalingRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropShardingScalingRuleStatementUpdater updater = new DropShardingScalingRuleStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckWithoutShardingRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("default_scaling"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("default_scaling"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckWithNotExist() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("default_scaling"), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("default_scaling"), currentRuleConfig); } @Test public void assertCheckWithIfExists() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new DropShardingScalingRuleStatement(true, "default_scaling"), new ShardingRuleConfiguration()); - updater.checkSQLStatement(shardingSphereMetaData, new DropShardingScalingRuleStatement(true, "default_scaling"), null); + updater.checkSQLStatement(databaseMetaData, new DropShardingScalingRuleStatement(true, "default_scaling"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, new DropShardingScalingRuleStatement(true, "default_scaling"), null); } @Test public void assertCheckSuccess() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.getScaling().put("default_scaling", null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("default_scaling"), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("default_scaling"), currentRuleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdaterTest.java index 972ecb2c06ef4..54db32c19a5c2 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/update/EnableShardingScalingRuleStatementUpdaterTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleEnabledException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.scaling.distsql.statement.EnableShardingScalingRuleStatement; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.junit.Before; @@ -39,25 +39,25 @@ public final class EnableShardingScalingRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final EnableShardingScalingRuleStatementUpdater updater = new EnableShardingScalingRuleStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckWithoutShardingRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("default_scaling"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("default_scaling"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckNotExist() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.getScaling().put("default_scaling", null); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("new_scaling"), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("new_scaling"), currentRuleConfig); } @Test(expected = RuleEnabledException.class) @@ -66,7 +66,7 @@ public void assertCheckEnabled() throws DistSQLException { String scalingName = "default_scaling"; currentRuleConfig.getScaling().put(scalingName, null); currentRuleConfig.setScalingName(scalingName); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(scalingName), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(scalingName), currentRuleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java index 66a083460df88..4dcd2610bc829 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -62,7 +62,7 @@ public final class ShardingRuleStatementCheckerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereRuleMetaData shardingSphereRuleMetaData; @@ -73,9 +73,9 @@ public final class ShardingRuleStatementCheckerTest { @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("schema"); - when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource); - when(shardingSphereMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData); + when(databaseMetaData.getDatabase().getName()).thenReturn("schema"); + when(databaseMetaData.getResource()).thenReturn(shardingSphereResource); + when(databaseMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData); when(shardingSphereRuleMetaData.getRules()).thenReturn(Collections.emptyList()); } @@ -84,10 +84,10 @@ public void assertCheckerAutoTableSuccess() throws DistSQLException { Collection rules = new LinkedList<>(); rules.add(createCompleteAutoTableRule()); rules.add(createCompleteTableRule()); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); rules.clear(); rules.add(new AutoTableRuleSegment("t_order", Arrays.asList("ds_0", "ds_1"))); - ShardingTableRuleStatementChecker.checkAlteration(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkAlteration(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = DuplicateRuleException.class) @@ -95,25 +95,25 @@ public void assertCheckCreationWithDuplicated() throws DistSQLException { List rules = Arrays.asList( new AutoTableRuleSegment("t_order_duplicated", Arrays.asList("ds_0", "ds_1")), new AutoTableRuleSegment("t_order_duplicated", Arrays.asList("ds_0", "ds_1"))); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = DuplicateRuleException.class) public void assertCheckCreationWithIdentical() throws DistSQLException { List rules = Collections.singletonList(new AutoTableRuleSegment("t_order", Arrays.asList("ds_0", "ds_1"))); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckAlterationWithRuleRequiredMissed() throws DistSQLException { List rules = Collections.singletonList(new AutoTableRuleSegment("t_order_required_missed", Arrays.asList("ds_0", "ds_1"))); - ShardingTableRuleStatementChecker.checkAlteration(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkAlteration(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = RequiredResourceMissedException.class) public void assertCheckCreationWithResourceRequiredMissed() throws DistSQLException { List rules = Collections.singletonList(new AutoTableRuleSegment("t_product", Arrays.asList("ds_required_missed", "ds_1"))); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -121,7 +121,7 @@ public void assertCheckCreationWithInvalidKeyGenerateAlgorithm() throws DistSQLE AutoTableRuleSegment autoTableRuleSegment = new AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1")); autoTableRuleSegment.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("invalid", newProperties("invalid", "invalid")))); List rules = Collections.singletonList(autoTableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -130,7 +130,7 @@ public void assertCheckAutoTableWithInvalidShardingAlgorithms() throws DistSQLEx autoTableRuleSegment.setShardingColumn("product_id"); autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("invalid", newProperties("", ""))); List rules = Collections.singletonList(autoTableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -138,7 +138,7 @@ public void assertCheckTableWithInvalidShardingStrategyType() throws DistSQLExce TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1")); tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("invalid", "product_id", "t_order_algorithm", null)); List rules = Collections.singletonList(tableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -146,7 +146,7 @@ public void assertCheckTableWithUnmatchedShardingStrategyType1() throws DistSQLE TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1")); tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("complex", "product_id", "t_order_algorithm", null)); List rules = Collections.singletonList(tableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -154,7 +154,7 @@ public void assertCheckTableWithUnmatchedShardingStrategyType2() throws DistSQLE TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1")); tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id,user_id", "t_order_algorithm", null)); List rules = Collections.singletonList(tableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -162,7 +162,7 @@ public void assertCheckTableWithInvalidAlgorithmName() throws DistSQLException { TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1")); tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("hint", "product_id", "invalid", null)); List rules = Collections.singletonList(tableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -170,7 +170,7 @@ public void assertCheckTableWithInvalidAlgorithmNameWhenCurrentRuleConfigIsNull( TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1")); tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("hint", "product_id", "invalid", null)); List rules = Collections.singletonList(tableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, null); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, null); } @Test @@ -179,7 +179,7 @@ public void assertCheckNullAlgorithmNameAndAlgorithmSegment() throws DistSQLExce AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${product_id% 2}")); tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id", null, databaseAlgorithmSegment)); List rules = Collections.singletonList(tableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -187,7 +187,7 @@ public void assertCheckNullAlgorithmNameAndNullAlgorithmSegment() throws DistSQL TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1")); tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id", null, null)); List rules = Collections.singletonList(tableRuleSegment); - ShardingTableRuleStatementChecker.checkCreation(shardingSphereMetaData, rules, shardingRuleConfig); + ShardingTableRuleStatementChecker.checkCreation(databaseMetaData, rules, shardingRuleConfig); } private static ShardingRuleConfiguration createShardingRuleConfiguration() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmsQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmsQueryResultSetTest.java index e48f13ddbfb30..dbb456498a197 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmsQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmsQueryResultSetTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingAlgorithmsQueryResultSet; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingAlgorithmsStatement; @@ -40,10 +40,10 @@ public final class ShardingAlgorithmsQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); ShardingAlgorithmsQueryResultSet resultSet = new ShardingAlgorithmsQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingAlgorithmsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(3)); assertThat(actual.get(0), is("database_inline")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java index 5154c1368bfc1..699051fe201df 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBindingTableRuleQueryResultSetTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.sharding.distsql.query; import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingBindingTableRuleQueryResultSet; @@ -39,10 +39,10 @@ public final class ShardingBindingTableRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); ShardingBindingTableRuleQueryResultSet resultSet = new ShardingBindingTableRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingBindingTableRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingBindingTableRulesStatement.class)); Collection actual = resultSet.getRowData(); assertThat(actual.size(), is(1)); assertTrue(actual.contains("t_order,t_order_item")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBroadcastTableRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBroadcastTableRuleQueryResultSetTest.java index ff1ad4452d87c..429d28e029a63 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBroadcastTableRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingBroadcastTableRuleQueryResultSetTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.sharding.distsql.query; import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingBroadcastTableRuleQueryResultSet; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBroadcastTableRulesStatement; @@ -38,10 +38,10 @@ public final class ShardingBroadcastTableRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); ShardingBroadcastTableRuleQueryResultSet resultSet = new ShardingBroadcastTableRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingBroadcastTableRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingBroadcastTableRulesStatement.class)); Collection actual = resultSet.getRowData(); assertThat(actual.size(), is(1)); assertThat(actual, is(Collections.singleton("t_order"))); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyQueryResultSetTest.java index 26c4f9a97e1e3..004eeaef6c6d2 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyQueryResultSetTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ComplexShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration; @@ -45,10 +45,10 @@ public final class ShardingDefaultShardingStrategyQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration1())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration1())); DefaultShardingStrategyQueryResultSet resultSet = new DefaultShardingStrategyQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingAlgorithmsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(6)); assertThat(actual.get(0), is("TABLE")); @@ -65,9 +65,9 @@ public void assertGetRowData() { assertThat(actual.get(3), is("database_inline")); assertThat(actual.get(4), is("INLINE")); assertThat(actual.get(5).toString(), is("{algorithm-expression=ds_${user_id % 2}}")); - when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration2())); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration2())); resultSet = new DefaultShardingStrategyQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingAlgorithmsStatement.class)); actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(6)); assertThat(actual.get(0), is("TABLE")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingKeyGeneratorsQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingKeyGeneratorsQueryResultSetTest.java index 464a33d74f73c..886351e380e83 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingKeyGeneratorsQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingKeyGeneratorsQueryResultSetTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.sharding.distsql.query; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingKeyGeneratorsQueryResultSet; import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingKeyGeneratorsStatement; @@ -40,10 +40,10 @@ public final class ShardingKeyGeneratorsQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class)).thenReturn(createRuleConfigurations()); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class)).thenReturn(createRuleConfigurations()); ShardingKeyGeneratorsQueryResultSet resultSet = new ShardingKeyGeneratorsQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingKeyGeneratorsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingKeyGeneratorsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(3)); assertThat(actual.get(0), is("snowflake")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableNodesQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableNodesQueryResultSetTest.java index 5d23fcbfe9547..fb77250e69515 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableNodesQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableNodesQueryResultSetTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -44,10 +44,10 @@ public final class ShardingTableNodesQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); DistSQLResultSet resultSet = new ShardingTableNodesQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingTableNodesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingTableNodesStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(2)); assertThat(actual.get(0), is("t_order")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleQueryResultSetTest.java index a163c7397d68a..87ed625cd3755 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleQueryResultSetTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; @@ -45,10 +45,10 @@ public final class ShardingTableRuleQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); DistSQLResultSet resultSet = new ShardingTableRuleQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingTableRulesStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingTableRulesStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(14)); assertThat(actual.get(0), is("t_order")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmQueryResultSetTest.java index b31cd4fd5d610..e38169db6b681 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmQueryResultSetTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -46,20 +46,20 @@ public final class ShowShardingTableRulesUsedAlgorithmQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class)).thenReturn(Collections.singleton(createRuleConfiguration())); - when(metaData.getDatabase().getName()).thenReturn("sharding_db"); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class)).thenReturn(Collections.singleton(createRuleConfiguration())); + when(databaseMetaData.getDatabase().getName()).thenReturn("sharding_db"); DistSQLResultSet resultSet = new ShardingTableRulesUsedAlgorithmQueryResultSet(); ShowShardingTableRulesUsedAlgorithmStatement statement = mock(ShowShardingTableRulesUsedAlgorithmStatement.class); when(statement.getAlgorithmName()).thenReturn(Optional.of("t_order_inline")); - resultSet.init(metaData, statement); + resultSet.init(databaseMetaData, statement); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(3)); assertThat(actual.get(0), is("sharding_db")); assertThat(actual.get(1), is("table")); assertThat(actual.get(2), is("t_order")); when(statement.getAlgorithmName()).thenReturn(Optional.of("auto_mod")); - resultSet.init(metaData, statement); + resultSet.init(databaseMetaData, statement); actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(3)); assertThat(actual.get(0), is("sharding_db")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorQueryResultSetTest.java index bd8b0a018b65b..cb50e2dc60a16 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorQueryResultSetTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -46,13 +46,13 @@ public final class ShowShardingTableRulesUsedKeyGeneratorQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class)).thenReturn(Collections.singleton(createRuleConfiguration())); - when(metaData.getDatabase().getName()).thenReturn("sharding_db"); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class)).thenReturn(Collections.singleton(createRuleConfiguration())); + when(databaseMetaData.getDatabase().getName()).thenReturn("sharding_db"); DistSQLResultSet resultSet = new ShardingTableRulesUsedKeyGeneratorQueryResultSet(); ShowShardingTableRulesUsedKeyGeneratorStatement statement = mock(ShowShardingTableRulesUsedKeyGeneratorStatement.class); when(statement.getKeyGeneratorName()).thenReturn(Optional.of("snowflake")); - resultSet.init(metaData, statement); + resultSet.init(databaseMetaData, statement); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(3)); assertThat(actual.get(0), is("sharding_db")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsQueryResultSetTest.java index fca5651915192..9f839f9e18385 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsQueryResultSetTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration; @@ -42,10 +42,10 @@ public final class UnusedShardingAlgorithmsQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); UnusedShardingAlgorithmsQueryResultSet resultSet = new UnusedShardingAlgorithmsQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingAlgorithmsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(3)); assertThat(actual.get(0), is("database_inline")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingKeyGeneratorsQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingKeyGeneratorsQueryResultSetTest.java index bca88a8fb7049..c8dc6aea46db7 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingKeyGeneratorsQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingKeyGeneratorsQueryResultSetTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; @@ -42,10 +42,10 @@ public final class UnusedShardingKeyGeneratorsQueryResultSetTest { @Test public void assertGetRowData() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration())); UnusedShardingKeyGeneratorsQueryResultSet resultSet = new UnusedShardingKeyGeneratorsQueryResultSet(); - resultSet.init(metaData, mock(ShowShardingAlgorithmsStatement.class)); + resultSet.init(databaseMetaData, mock(ShowShardingAlgorithmsStatement.class)); List actual = new ArrayList<>(resultSet.getRowData()); assertThat(actual.size(), is(3)); assertThat(actual.get(0), is("uuid_key_generator")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java index ad0cb8a79a0ac..87b4a9d1b50cb 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.AlterDefaultShardingStrategyStatementUpdater; @@ -44,24 +44,24 @@ public final class AlterDefaultShardingStrategyStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final AlterDefaultShardingStrategyStatementUpdater updater = new AlterDefaultShardingStrategyStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertExecuteWithInvalidStrategyType() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new AlterDefaultShardingStrategyStatement("TABLE", "invalidType", null, "order_id_algorithm", null), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, new AlterDefaultShardingStrategyStatement("TABLE", "invalidType", null, "order_id_algorithm", null), new ShardingRuleConfiguration()); } @Test(expected = RequiredRuleMissedException.class) public void assertExecuteWithoutCurrentConfiguration() throws DistSQLException { AlterDefaultShardingStrategyStatement statement = new AlterDefaultShardingStrategyStatement("TABLE", "standard", "order_id", "order_id_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, null); + updater.checkSQLStatement(databaseMetaData, statement, null); } @Test(expected = RequiredAlgorithmMissedException.class) @@ -70,7 +70,7 @@ public void assertExecuteWithNotExist() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm")); currentRuleConfig.getShardingAlgorithms().put("not_exist_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -79,7 +79,7 @@ public void assertExecuteWithUnmatchedStrategy() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm")); currentRuleConfig.getShardingAlgorithms().put("order_id_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test @@ -88,7 +88,7 @@ public void assertAlterDefaultTableShardingStrategy() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm")); currentRuleConfig.getShardingAlgorithms().put("order_id_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeAlteredRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig); StandardShardingStrategyConfiguration defaultTableShardingStrategy = (StandardShardingStrategyConfiguration) currentRuleConfig.getDefaultTableShardingStrategy(); @@ -102,7 +102,7 @@ public void assertAlterDefaultDatabaseShardingStrategy() throws DistSQLException AlterDefaultShardingStrategyStatement statement = new AlterDefaultShardingStrategyStatement("DATABASE", "standard", "user_id", null, databaseAlgorithmSegment); ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm")); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeAlteredRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig); StandardShardingStrategyConfiguration defaultDatabaseShardingStrategy = (StandardShardingStrategyConfiguration) currentRuleConfig.getDefaultDatabaseShardingStrategy(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingAlgorithmStatementUpdaterTest.java index b99f29588946f..e5316ca4d6b7d 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingAlgorithmStatementUpdaterTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingAlgorithmStatementUpdater; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingAlgorithmSegment; @@ -46,13 +46,13 @@ public final class AlterShardingAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final AlterShardingAlgorithmStatementUpdater updater = new AlterShardingAlgorithmStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = DuplicateRuleException.class) @@ -60,7 +60,7 @@ public void assertExecuteWithDuplicate() throws DistSQLException { Properties props = new Properties(); props.put("input_key", "input_value"); ShardingAlgorithmSegment algorithmSegment = new ShardingAlgorithmSegment("input_algorithm_name", new AlgorithmSegment("input_algorithm_name", props)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(algorithmSegment, algorithmSegment), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(algorithmSegment, algorithmSegment), null); } @Test(expected = RequiredAlgorithmMissedException.class) @@ -70,7 +70,7 @@ public void assertExecuteWithNotExist() throws DistSQLException { ShardingAlgorithmSegment algorithmSegment = new ShardingAlgorithmSegment("not_exist_algorithm_name", new AlgorithmSegment("input_algorithm_name", props)); ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getShardingAlgorithms().put("exist_algorithm_name", new ShardingSphereAlgorithmConfiguration("hash_mod", props)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(algorithmSegment), shardingRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(algorithmSegment), shardingRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -80,7 +80,7 @@ public void assertExecuteWithInvalidAlgorithm() throws DistSQLException { ShardingAlgorithmSegment algorithmSegment = new ShardingAlgorithmSegment("exist_algorithm_name", new AlgorithmSegment("input_algorithm_name", props)); ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration(); ruleConfig.getShardingAlgorithms().put("exist_algorithm_name", new ShardingSphereAlgorithmConfiguration("invalid_algorithm", props)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(algorithmSegment), ruleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(algorithmSegment), ruleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRulesStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRulesStatementUpdaterTest.java index 68d80323b81a9..646bef75cf866 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRulesStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBindingTableRulesStatementUpdaterTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingBindingTableRulesStatementUpdater; @@ -40,27 +40,27 @@ public final class AlterShardingBindingTableRulesStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final AlterShardingBindingTableRulesStatementUpdater updater = new AlterShardingBindingTableRulesStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), null); } @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicateTables() throws RuleDefinitionViolationException { List segments = Arrays.asList(new BindingTableRuleSegment("t_order,t_order_item"), new BindingTableRuleSegment("t_order,t_order_item")); AlterShardingBindingTableRulesStatement statement = new AlterShardingBindingTableRulesStatement(segments); - updater.checkSQLStatement(shardingSphereMetaData, statement, createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, statement, createCurrentRuleConfiguration()); } @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDifferentCaseDuplicateTables() throws RuleDefinitionViolationException { List segments = Arrays.asList(new BindingTableRuleSegment("T_ORDER,T_ORDER_ITEM"), new BindingTableRuleSegment("t_order,t_order_item")); AlterShardingBindingTableRulesStatement statement = new AlterShardingBindingTableRulesStatement(segments); - updater.checkSQLStatement(shardingSphereMetaData, statement, createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, statement, createCurrentRuleConfiguration()); } private AlterShardingBindingTableRulesStatement createSQLStatement() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java index 478285120bc76..57a41267621e0 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingBroadcastTableRuleStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingBroadcastTableRuleStatementUpdater; import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingBroadcastTableRulesStatement; import org.junit.Test; @@ -35,7 +35,7 @@ public final class AlterShardingBroadcastTableRuleStatementUpdaterTest { @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS), createSQLStatement(), null); + updater.checkSQLStatement(mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS), createSQLStatement(), null); } private AlterShardingBroadcastTableRulesStatement createSQLStatement() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingKeyGeneratorStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingKeyGeneratorStatementUpdaterTest.java index b14d5501a92dc..d3c531ec37127 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingKeyGeneratorStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingKeyGeneratorStatementUpdaterTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingKeyGeneratorStatementUpdater; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment; @@ -49,17 +49,17 @@ public final class AlterShardingKeyGeneratorStatementUpdaterTest { private final AlterShardingKeyGeneratorStatementUpdater updater = new AlterShardingKeyGeneratorStatementUpdater(); @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = DuplicateRuleException.class) public void assertExecuteWithDuplicate() throws DistSQLException { ShardingKeyGeneratorSegment keyGeneratorSegment = new ShardingKeyGeneratorSegment("input_key_generator_name", new AlgorithmSegment("snowflake", createProperties())); - updater.checkSQLStatement(shardingSphereMetaData, new AlterShardingKeyGeneratorStatement(Arrays.asList(keyGeneratorSegment, keyGeneratorSegment)), null); + updater.checkSQLStatement(databaseMetaData, new AlterShardingKeyGeneratorStatement(Arrays.asList(keyGeneratorSegment, keyGeneratorSegment)), null); } @Test(expected = RequiredAlgorithmMissedException.class) @@ -68,7 +68,7 @@ public void assertExecuteWithNotExist() throws DistSQLException { ShardingKeyGeneratorSegment keyGeneratorSegment = new ShardingKeyGeneratorSegment("not_exist_key_generator_name", new AlgorithmSegment("snowflake", props)); ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration(); ruleConfig.getKeyGenerators().put("exist_key_generator_name", new ShardingSphereAlgorithmConfiguration("hash_mod", props)); - updater.checkSQLStatement(shardingSphereMetaData, new AlterShardingKeyGeneratorStatement(Collections.singletonList(keyGeneratorSegment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new AlterShardingKeyGeneratorStatement(Collections.singletonList(keyGeneratorSegment)), ruleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -77,7 +77,7 @@ public void assertExecuteWithInvalidAlgorithm() throws DistSQLException { ShardingKeyGeneratorSegment keyGeneratorSegment = new ShardingKeyGeneratorSegment("exist_key_generator_name", new AlgorithmSegment("snowflake", props)); ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration(); ruleConfig.getKeyGenerators().put("exist_key_generator_name", new ShardingSphereAlgorithmConfiguration("invalid_type", props)); - updater.checkSQLStatement(shardingSphereMetaData, new AlterShardingKeyGeneratorStatement(Collections.singletonList(keyGeneratorSegment)), ruleConfig); + updater.checkSQLStatement(databaseMetaData, new AlterShardingKeyGeneratorStatement(Collections.singletonList(keyGeneratorSegment)), ruleConfig); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java index 2ba76b9253202..393eba65f0be9 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -58,7 +58,7 @@ public final class AlterShardingTableRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereRuleMetaData shardingSphereRuleMetaData; @@ -71,16 +71,16 @@ public final class AlterShardingTableRuleStatementUpdaterTest { @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("schema"); - when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource); - when(shardingSphereMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData); + when(databaseMetaData.getDatabase().getName()).thenReturn("schema"); + when(databaseMetaData.getResource()).thenReturn(shardingSphereResource); + when(databaseMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData); when(shardingSphereRuleMetaData.getRules()).thenReturn(Collections.emptyList()); } @Test public void assertUpdate() throws DistSQLException { AlterShardingTableRuleStatement statement = new AlterShardingTableRuleStatement(Arrays.asList(createCompleteAutoTableRule("t_order_item"), createCompleteTableRule("t_order"))); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeAlteredRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig); assertThat(currentRuleConfig.getTables().size(), is(1)); @@ -105,7 +105,7 @@ public void assertUpdate() throws DistSQLException { @Test public void assertUpdateWithDifferentCase() throws DistSQLException { AlterShardingTableRuleStatement statement = new AlterShardingTableRuleStatement(Arrays.asList(createCompleteAutoTableRule("T_ORDER_ITEM"), createCompleteTableRule("T_ORDER"))); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeAlteredRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig); assertThat(currentRuleConfig.getTables().size(), is(1)); @@ -130,7 +130,7 @@ public void assertUpdateWithDifferentCase() throws DistSQLException { @Test public void assertUpdateTableType() throws DistSQLException { AlterShardingTableRuleStatement statement = new AlterShardingTableRuleStatement(Arrays.asList(createCompleteAutoTableRule("t_order"), createCompleteTableRule("t_order_item"))); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeAlteredRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig); assertThat(currentRuleConfig.getTables().size(), is(1)); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java index f8c02cb1e3aff..c04a4eaca61dc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.CreateDefaultShardingStrategyStatementUpdater; @@ -44,24 +44,24 @@ public final class CreateDefaultShardingStrategyStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final CreateDefaultShardingStrategyStatementUpdater updater = new CreateDefaultShardingStrategyStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertExecuteWithInvalidStrategyType() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new CreateDefaultShardingStrategyStatement("TABLE", "invalidType", null, "order_id_algorithm", null), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, new CreateDefaultShardingStrategyStatement("TABLE", "invalidType", null, "order_id_algorithm", null), new ShardingRuleConfiguration()); } @Test(expected = RequiredRuleMissedException.class) public void assertExecuteWithoutCurrentConfiguration() throws DistSQLException { CreateDefaultShardingStrategyStatement statement = new CreateDefaultShardingStrategyStatement("TABLE", "standard", "order_id", "order_id_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, null); + updater.checkSQLStatement(databaseMetaData, statement, null); } @Test(expected = DuplicateRuleException.class) @@ -70,7 +70,7 @@ public void assertExecuteWithExist() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm")); currentRuleConfig.getShardingAlgorithms().put("order_id_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -79,7 +79,7 @@ public void assertExecuteWithUnmatchedStrategy() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm")); currentRuleConfig.getShardingAlgorithms().put("order_id_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); } @Test @@ -88,7 +88,7 @@ public void assertCreateDefaultTableShardingStrategy() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm")); currentRuleConfig.getShardingAlgorithms().put("order_id_algorithm", null); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig); StandardShardingStrategyConfiguration defaultTableShardingStrategy = (StandardShardingStrategyConfiguration) currentRuleConfig.getDefaultTableShardingStrategy(); @@ -101,7 +101,7 @@ public void assertCreateDefaultDatabaseShardingStrategy() throws DistSQLExceptio AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${user_id% 2}")); CreateDefaultShardingStrategyStatement statement = new CreateDefaultShardingStrategyStatement("DATABASE", "standard", "user_id", null, databaseAlgorithmSegment); ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig); StandardShardingStrategyConfiguration defaultDatabaseShardingStrategy = (StandardShardingStrategyConfiguration) currentRuleConfig.getDefaultDatabaseShardingStrategy(); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingAlgorithmStatementUpdaterTest.java index 0acc91e3c9499..6c40e87e97075 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingAlgorithmStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingAlgorithmStatementUpdater; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingAlgorithmSegment; @@ -43,13 +43,13 @@ public final class CreateShardingAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final CreateShardingAlgorithmStatementUpdater updater = new CreateShardingAlgorithmStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = DuplicateRuleException.class) @@ -57,7 +57,7 @@ public void assertExecuteWithDuplicate() throws DistSQLException { Properties props = new Properties(); props.put("inputKey", "inputValue"); ShardingAlgorithmSegment algorithmSegment = new ShardingAlgorithmSegment("inputAlgorithmName", new AlgorithmSegment("inputAlgorithmName", props)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(algorithmSegment, algorithmSegment), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(algorithmSegment, algorithmSegment), null); } @Test(expected = DuplicateRuleException.class) @@ -67,7 +67,7 @@ public void assertExecuteWithExist() throws DistSQLException { ShardingAlgorithmSegment algorithmSegment = new ShardingAlgorithmSegment("existAlgorithmName", new AlgorithmSegment("inputAlgorithmName", props)); ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration(); ruleConfig.getShardingAlgorithms().put("existAlgorithmName", new ShardingSphereAlgorithmConfiguration("hash_mod", props)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(algorithmSegment), ruleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(algorithmSegment), ruleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -75,7 +75,7 @@ public void assertExecuteWithoutRuleConfiguration() throws DistSQLException { Properties props = new Properties(); props.put("inputKey", "inputValue"); ShardingAlgorithmSegment algorithmSegment = new ShardingAlgorithmSegment("inputAlgorithmName", new AlgorithmSegment("inputAlgorithmName", props)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(algorithmSegment), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(algorithmSegment), null); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -85,7 +85,7 @@ public void assertExecuteWithInvalidAlgorithm() throws DistSQLException { ShardingAlgorithmSegment algorithmSegment = new ShardingAlgorithmSegment("inputAlgorithmName", new AlgorithmSegment("inputAlgorithmName", props)); ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration(); ruleConfig.getShardingAlgorithms().put("existAlgorithmName", new ShardingSphereAlgorithmConfiguration("InvalidAlgorithm", props)); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(algorithmSegment), ruleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(algorithmSegment), ruleConfig); } private CreateShardingAlgorithmStatement createSQLStatement(final ShardingAlgorithmSegment... ruleSegments) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java index 7c12f474e0fe4..be0a7a0fa4c5a 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingBindingTableRuleStatementUpdaterTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingBindingTableRuleStatementUpdater; @@ -39,27 +39,27 @@ public final class CreateShardingBindingTableRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final CreateShardingBindingTableRuleStatementUpdater updater = new CreateShardingBindingTableRuleStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentTableRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new ShardingRuleConfiguration()); } @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDuplicateTables() throws DistSQLException { List segments = Arrays.asList(new BindingTableRuleSegment("t_order,t_order_item"), new BindingTableRuleSegment("t_order,t_order_item")); CreateShardingBindingTableRulesStatement statement = new CreateShardingBindingTableRulesStatement(segments); - updater.checkSQLStatement(shardingSphereMetaData, statement, getCurrentRuleConfig()); + updater.checkSQLStatement(databaseMetaData, statement, getCurrentRuleConfig()); } @Test(expected = DuplicateRuleException.class) public void assertCheckSQLStatementWithDifferentCaseDuplicateTables() throws DistSQLException { List segments = Arrays.asList(new BindingTableRuleSegment("T_ORDER,T_ORDER_ITEM"), new BindingTableRuleSegment("t_order,t_order_item")); CreateShardingBindingTableRulesStatement statement = new CreateShardingBindingTableRulesStatement(segments); - updater.checkSQLStatement(shardingSphereMetaData, statement, getCurrentRuleConfig()); + updater.checkSQLStatement(databaseMetaData, statement, getCurrentRuleConfig()); } private CreateShardingBindingTableRulesStatement createSQLStatement() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingKeyGeneratorStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingKeyGeneratorStatementUpdaterTest.java index c87f217303e72..553b2ebb2c437 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingKeyGeneratorStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingKeyGeneratorStatementUpdaterTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateKeyGeneratorException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingKeyGeneratorStatementUpdater; import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingKeyGeneratorSegment; @@ -43,20 +43,20 @@ public final class CreateShardingKeyGeneratorStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private CreateShardingKeyGeneratorStatementUpdater updater; @Before public void before() { updater = new CreateShardingKeyGeneratorStatementUpdater(); - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = DuplicateKeyGeneratorException.class) public void assertExecuteWithDuplicate() throws DistSQLException { ShardingKeyGeneratorSegment keyGeneratorSegment = buildShardingKeyGeneratorSegment(); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(keyGeneratorSegment, keyGeneratorSegment), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(keyGeneratorSegment, keyGeneratorSegment), null); } @Test(expected = DuplicateKeyGeneratorException.class) @@ -64,13 +64,13 @@ public void assertExecuteWithExist() throws DistSQLException { ShardingKeyGeneratorSegment keyGeneratorSegment = buildShardingKeyGeneratorSegment(); ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration(); ruleConfig.getKeyGenerators().put("uuid_key_generator", new ShardingSphereAlgorithmConfiguration("uuid", new Properties())); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(keyGeneratorSegment), ruleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(keyGeneratorSegment), ruleConfig); } @Test(expected = InvalidAlgorithmConfigurationException.class) public void assertExecuteWithoutRuleConfiguration() throws DistSQLException { ShardingKeyGeneratorSegment keyGeneratorSegment = buildShardingKeyGeneratorSegment(); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(keyGeneratorSegment), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(keyGeneratorSegment), null); } @Test(expected = InvalidAlgorithmConfigurationException.class) @@ -78,7 +78,7 @@ public void assertExecuteWithInvalidAlgorithm() throws DistSQLException { ShardingKeyGeneratorSegment keyGeneratorSegment = buildShardingKeyGeneratorSegment(); ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration(); ruleConfig.getKeyGenerators().put("snowflake_key_generator", new ShardingSphereAlgorithmConfiguration("INVALID_ALGORITHM", new Properties())); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(keyGeneratorSegment), ruleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(keyGeneratorSegment), ruleConfig); } private CreateShardingKeyGeneratorStatement createSQLStatement(final ShardingKeyGeneratorSegment... ruleSegments) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java index 01ff71cacf8d0..0ac0f9fa0ceb1 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; @@ -61,7 +61,7 @@ public final class CreateShardingTableRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereRuleMetaData shardingSphereRuleMetaData; @@ -74,16 +74,16 @@ public final class CreateShardingTableRuleStatementUpdaterTest { @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("schema"); - when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource); - when(shardingSphereMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData); + when(databaseMetaData.getDatabase().getName()).thenReturn("schema"); + when(databaseMetaData.getResource()).thenReturn(shardingSphereResource); + when(databaseMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData); when(shardingSphereRuleMetaData.getRules()).thenReturn(Collections.singleton(new MockDataSourceContainedRule())); } @Test public void assertUpdate() throws DistSQLException { CreateShardingTableRuleStatement statement = new CreateShardingTableRuleStatement(Arrays.asList(createCompleteAutoTableRule(), createCompleteTableRule())); - updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, statement, currentRuleConfig); ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeCreatedRuleConfiguration(statement); updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig); assertThat(currentRuleConfig.getTables().size(), is(2)); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java index 5daef025a7c5f..0e59a0668e7d1 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration; import org.apache.shardingsphere.sharding.distsql.handler.update.DropDefaultStrategyStatementUpdater; @@ -36,24 +36,24 @@ public final class DropDefaultShardingStrategyStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropDefaultStrategyStatementUpdater updater = new DropDefaultStrategyStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new DropDefaultShardingStrategyStatement("TABLE"), null); + updater.checkSQLStatement(databaseMetaData, new DropDefaultShardingStrategyStatement("TABLE"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutExistedAlgorithm() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("table"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("table"), new ShardingRuleConfiguration()); } @Test public void assertCheckSQLStatementWithIfExists() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, new DropDefaultShardingStrategyStatement(true, "table"), new ShardingRuleConfiguration()); - updater.checkSQLStatement(shardingSphereMetaData, new DropDefaultShardingStrategyStatement(true, "table"), null); + updater.checkSQLStatement(databaseMetaData, new DropDefaultShardingStrategyStatement(true, "table"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, new DropDefaultShardingStrategyStatement(true, "table"), null); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingAlgorithmStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingAlgorithmStatementUpdaterTest.java index d2a7807fb0049..ae2805bf86439 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingAlgorithmStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingAlgorithmStatementUpdaterTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration; @@ -45,40 +45,40 @@ public final class DropShardingAlgorithmStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropShardingAlgorithmStatementUpdater updater = new DropShardingAlgorithmStatementUpdater(); @Test(expected = RequiredAlgorithmMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, new DropShardingAlgorithmStatement(Collections.emptyList()), null); + updater.checkSQLStatement(databaseMetaData, new DropShardingAlgorithmStatement(Collections.emptyList()), null); } @Test public void assertCheckSQLStatementWithoutCurrentRuleWithIfExists() throws RuleDefinitionViolationException { DropShardingAlgorithmStatement dropShardingAlgorithmStatement = new DropShardingAlgorithmStatement(Collections.emptyList()); dropShardingAlgorithmStatement.setContainsExistClause(true); - updater.checkSQLStatement(shardingSphereMetaData, dropShardingAlgorithmStatement, null); + updater.checkSQLStatement(databaseMetaData, dropShardingAlgorithmStatement, null); } @Test(expected = RequiredAlgorithmMissedException.class) public void assertCheckSQLStatementWithoutExistedAlgorithm() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_order"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_order"), new ShardingRuleConfiguration()); } @Test public void assertCheckSQLStatementWithoutExistedAlgorithmWithIfExists() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatementWithIfExists("t_order"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatementWithIfExists("t_order"), new ShardingRuleConfiguration()); } @Test(expected = AlgorithmInUsedException.class) public void assertCheckSQLStatementWithBindingTableRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_order_tb_inline"), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_order_tb_inline"), createCurrentRuleConfiguration()); } @Test(expected = AlgorithmInUsedException.class) public void assertCheckSQLStatementWithBindingTableRuleWithIfExists() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatementWithIfExists("t_order_tb_inline"), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatementWithIfExists("t_order_tb_inline"), createCurrentRuleConfiguration()); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java index fba6c6f385e97..85ea6b4b93528 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBindingTableRuleStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -46,26 +46,26 @@ public final class DropShardingBindingTableRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropShardingBindingTableRuleStatementUpdater updater = new DropShardingBindingTableRuleStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutExistedBindingTableRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(), new ShardingRuleConfiguration()); } @Test public void assertCheckSQLStatementWithIfExists() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(true, "t_1,t_2"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(true, "t_1,t_2"), null); ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.setBindingTableGroups(Collections.singletonList("t_3,t_4")); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(true, "t_1,t_2"), shardingRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(true, "t_1,t_2"), shardingRuleConfig); } @Test @@ -94,7 +94,7 @@ public void assertDropSpecifiedCurrentRuleConfiguration() throws DistSQLExceptio ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); currentRuleConfig.getBindingTableGroups().add("t_1,t_2"); DropShardingBindingTableRulesStatement sqlStatement = createSQLStatement("t_1,t_2"); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentRuleConfig); updater.updateCurrentRuleConfiguration(sqlStatement, currentRuleConfig); assertThat(currentRuleConfig.getBindingTableGroups().size(), is(1)); assertTrue(currentRuleConfig.getBindingTableGroups().contains("t_order,t_order_item")); @@ -105,7 +105,7 @@ public void assertDropRulesCurrentRuleConfigurationWithNoOrder() throws DistSQLE ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); currentRuleConfig.getBindingTableGroups().add("t_1,t_2,t_3"); DropShardingBindingTableRulesStatement sqlStatement = createSQLStatement("t_3,t_2,t_1"); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentRuleConfig); updater.updateCurrentRuleConfiguration(sqlStatement, currentRuleConfig); assertThat(currentRuleConfig.getBindingTableGroups().size(), is(1)); assertTrue(currentRuleConfig.getBindingTableGroups().contains("t_order,t_order_item")); @@ -117,7 +117,7 @@ public void assertDropRulesCurrentRuleConfigurationWithDifferentCase() throws Di ShardingRuleConfiguration currentRuleConfig = createCurrentRuleConfiguration(); currentRuleConfig.getBindingTableGroups().add("t_1,t_2,t_3"); DropShardingBindingTableRulesStatement sqlStatement = createSQLStatement("T_3,T_2,T_1"); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, sqlStatement, currentRuleConfig); updater.updateCurrentRuleConfiguration(sqlStatement, currentRuleConfig); assertThat(currentRuleConfig.getBindingTableGroups().size(), is(1)); assertTrue(currentRuleConfig.getBindingTableGroups().contains("t_order,t_order_item")); diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java index 329363b79ef50..3755173ed01f2 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingBroadcastTableRuleStatementUpdaterTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -40,24 +40,24 @@ public final class DropShardingBroadcastTableRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropShardingBroadcastTableRuleStatementUpdater updater = new DropShardingBroadcastTableRuleStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_order"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_order"), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutExistBroadcastTableRule() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_order"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_order"), new ShardingRuleConfiguration()); } @Test public void assertCheckSQLStatementWithIfExists() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(true, "t_order"), new ShardingRuleConfiguration()); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(true, "t_order"), null); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(true, "t_order"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement(true, "t_order"), null); } @Test @@ -69,7 +69,7 @@ public void assertHasAnyOneToBeDropped() { @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithBroadcastTableRuleAreNotTheSame() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_order_item"), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_order_item"), createCurrentRuleConfiguration()); } @Test diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingKeyGeneratorStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingKeyGeneratorStatementUpdaterTest.java index 09f7f44f74edb..06ab4acfcb47d 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingKeyGeneratorStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingKeyGeneratorStatementUpdaterTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; import org.apache.shardingsphere.infra.distsql.exception.rule.KeyGeneratorInUsedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredKeyGeneratorMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration; @@ -45,25 +45,25 @@ public final class DropShardingKeyGeneratorStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropShardingKeyGeneratorStatementUpdater updater = new DropShardingKeyGeneratorStatementUpdater(); @Before public void before() { - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("test"); + when(databaseMetaData.getDatabase().getName()).thenReturn("test"); } @Test(expected = RequiredKeyGeneratorMissedException.class) public void assertExecuteWithNotExist() throws DistSQLException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("uuid_key_generator"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("uuid_key_generator"), new ShardingRuleConfiguration()); } @Test public void assertExecuteWithNotExistWithIfExists() throws DistSQLException { DropShardingKeyGeneratorStatement sqlStatement = new DropShardingKeyGeneratorStatement(Collections.singletonList("uuid_key_generator")); sqlStatement.setContainsExistClause(true); - updater.checkSQLStatement(shardingSphereMetaData, sqlStatement, new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, sqlStatement, new ShardingRuleConfiguration()); } @Test @@ -79,7 +79,7 @@ public void assertExecuteWithUsed() throws DistSQLException { ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration(); currentRuleConfig.getKeyGenerators().put("uuid_key_generator", new ShardingSphereAlgorithmConfiguration("UUID", null)); currentRuleConfig.getAutoTables().add(createShardingAutoTableRuleConfiguration()); - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("uuid_key_generator"), currentRuleConfig); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("uuid_key_generator"), currentRuleConfig); } private ShardingAutoTableRuleConfiguration createShardingAutoTableRuleConfiguration() { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java index 55ab23132c937..0b0f2aba855c3 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleStatementUpdaterTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleDefinitionViolationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -51,30 +51,30 @@ public final class DropShardingTableRuleStatementUpdaterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; private final DropShardingTableRuleStatementUpdater updater = new DropShardingTableRuleStatementUpdater(); @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, new DropShardingTableRuleStatement(Collections.emptyList()), null); + updater.checkSQLStatement(databaseMetaData, new DropShardingTableRuleStatement(Collections.emptyList()), null); } @Test(expected = RequiredRuleMissedException.class) public void assertCheckSQLStatementWithoutExistedTableRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_order"), new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_order"), new ShardingRuleConfiguration()); } @Test public void assertCheckSQLStatementWithIfExists() throws RuleDefinitionViolationException { DropShardingTableRuleStatement statement = new DropShardingTableRuleStatement(true, Collections.singleton(new TableNameSegment(0, 3, new IdentifierValue("t_order_if_exists")))); - updater.checkSQLStatement(shardingSphereMetaData, statement, null); - updater.checkSQLStatement(shardingSphereMetaData, statement, new ShardingRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, statement, null); + updater.checkSQLStatement(databaseMetaData, statement, new ShardingRuleConfiguration()); } @Test(expected = RuleInUsedException.class) public void assertCheckSQLStatementWithBindingTableRule() throws RuleDefinitionViolationException { - updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement("t_order_item"), createCurrentRuleConfiguration()); + updater.checkSQLStatement(databaseMetaData, createSQLStatement("t_order_item"), createCurrentRuleConfiguration()); } @Test diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java index ccd6d2de69a3b..900acda96fe41 100644 --- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java +++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java @@ -55,7 +55,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.AnalyzeTableStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement; @@ -109,28 +109,28 @@ public final class SQLStatementContextFactory { /** * Create SQL statement context. * - * @param metaDataMap metaData map + * @param databaseMetaDataMap database meta data map * @param sqlStatement SQL statement * @param defaultDatabaseName default database name * @return SQL statement context */ - public static SQLStatementContext newInstance(final Map metaDataMap, final SQLStatement sqlStatement, final String defaultDatabaseName) { - return newInstance(metaDataMap, Collections.emptyList(), sqlStatement, defaultDatabaseName); + public static SQLStatementContext newInstance(final Map databaseMetaDataMap, final SQLStatement sqlStatement, final String defaultDatabaseName) { + return newInstance(databaseMetaDataMap, Collections.emptyList(), sqlStatement, defaultDatabaseName); } /** * Create SQL statement context. * - * @param metaDataMap metaData map + * @param databaseMetaDataMap database meta data map * @param parameters SQL parameters * @param sqlStatement SQL statement * @param defaultDatabaseName default database name * @return SQL statement context */ - public static SQLStatementContext newInstance(final Map metaDataMap, final List parameters, + public static SQLStatementContext newInstance(final Map databaseMetaDataMap, final List parameters, final SQLStatement sqlStatement, final String defaultDatabaseName) { if (sqlStatement instanceof DMLStatement) { - return getDMLStatementContext(metaDataMap, parameters, (DMLStatement) sqlStatement, defaultDatabaseName); + return getDMLStatementContext(databaseMetaDataMap, parameters, (DMLStatement) sqlStatement, defaultDatabaseName); } if (sqlStatement instanceof DDLStatement) { return getDDLStatementContext((DDLStatement) sqlStatement); @@ -144,10 +144,10 @@ public static SQLStatementContext newInstance(final Map(sqlStatement); } - private static SQLStatementContext getDMLStatementContext(final Map metaDataMap, final List parameters, + private static SQLStatementContext getDMLStatementContext(final Map databaseMetaDataMap, final List parameters, final DMLStatement sqlStatement, final String defaultDatabaseName) { if (sqlStatement instanceof SelectStatement) { - return new SelectStatementContext(metaDataMap, parameters, (SelectStatement) sqlStatement, defaultDatabaseName); + return new SelectStatementContext(databaseMetaDataMap, parameters, (SelectStatement) sqlStatement, defaultDatabaseName); } if (sqlStatement instanceof UpdateStatement) { return new UpdateStatementContext((UpdateStatement) sqlStatement); @@ -156,7 +156,7 @@ private static SQLStatementContext getDMLStatementContext(final Map columnNames; - private final Map metaDataMap; + private final Map databaseMetaDataMap; private final String defaultDatabaseName; @@ -78,32 +78,32 @@ public final class InsertStatementContext extends CommonSQLStatementContext metaDataMap, final List parameters, + public InsertStatementContext(final Map databaseMetaDataMap, final List parameters, final InsertStatement sqlStatement, final String defaultDatabaseName) { super(sqlStatement); - this.metaDataMap = metaDataMap; + this.databaseMetaDataMap = databaseMetaDataMap; this.defaultDatabaseName = defaultDatabaseName; insertColumnNames = getInsertColumnNames(); valueExpressions = getAllValueExpressions(sqlStatement); AtomicInteger parametersOffset = new AtomicInteger(0); insertValueContexts = getInsertValueContexts(parameters, parametersOffset, valueExpressions); - insertSelectContext = getInsertSelectContext(metaDataMap, parameters, parametersOffset, defaultDatabaseName).orElse(null); + insertSelectContext = getInsertSelectContext(databaseMetaDataMap, parameters, parametersOffset, defaultDatabaseName).orElse(null); onDuplicateKeyUpdateValueContext = getOnDuplicateKeyUpdateValueContext(parameters, parametersOffset).orElse(null); tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType()); - ShardingSphereSchema schema = getSchema(metaDataMap, defaultDatabaseName); + ShardingSphereSchema schema = getSchema(databaseMetaDataMap, defaultDatabaseName); columnNames = useDefaultColumns() ? schema.getAllColumnNames(sqlStatement.getTable().getTableName().getIdentifier().getValue()) : insertColumnNames; generatedKeyContext = new GeneratedKeyContextEngine(sqlStatement, schema) .createGenerateKeyContext(insertColumnNames, getAllValueExpressions(sqlStatement), parameters).orElse(null); } - private ShardingSphereSchema getSchema(final Map metaDataMap, final String defaultDatabaseName) { + private ShardingSphereSchema getSchema(final Map databaseMetaDataMap, final String defaultDatabaseName) { String databaseName = tablesContext.getDatabaseName().orElse(defaultDatabaseName); - ShardingSphereMetaData metaData = metaDataMap.get(databaseName); - if (null == metaData) { + ShardingSphereDatabaseMetaData databaseMetaData = databaseMetaDataMap.get(databaseName); + if (null == databaseMetaData) { throw new DatabaseNotExistedException(databaseName); } String defaultSchema = getDatabaseType().getDefaultSchema(databaseName); - return tablesContext.getSchemaName().map(metaData::getSchemaByName).orElseGet(() -> metaData.getSchemaByName(defaultSchema)); + return tablesContext.getSchemaName().map(optional -> databaseMetaData.getDatabase().getSchema(optional)).orElseGet(() -> databaseMetaData.getDatabase().getSchema(defaultSchema)); } private Collection getAllSimpleTableSegments() { @@ -122,13 +122,13 @@ private List getInsertValueContexts(final List param return result; } - private Optional getInsertSelectContext(final Map metaDataMap, final List parameters, + private Optional getInsertSelectContext(final Map databaseMetaDataMap, final List parameters, final AtomicInteger parametersOffset, final String defaultDatabaseName) { if (!getSqlStatement().getInsertSelect().isPresent()) { return Optional.empty(); } SubquerySegment insertSelectSegment = getSqlStatement().getInsertSelect().get(); - SelectStatementContext selectStatementContext = new SelectStatementContext(metaDataMap, parameters, insertSelectSegment.getSelect(), defaultDatabaseName); + SelectStatementContext selectStatementContext = new SelectStatementContext(databaseMetaDataMap, parameters, insertSelectSegment.getSelect(), defaultDatabaseName); InsertSelectContext insertSelectContext = new InsertSelectContext(selectStatementContext, parameters, parametersOffset.get()); parametersOffset.addAndGet(insertSelectContext.getParameterCount()); return Optional.of(insertSelectContext); @@ -271,9 +271,9 @@ private List> getAllValueExpressionsFromValues(final Col public void setUpParameters(final List parameters) { AtomicInteger parametersOffset = new AtomicInteger(0); insertValueContexts = getInsertValueContexts(parameters, parametersOffset, valueExpressions); - insertSelectContext = getInsertSelectContext(metaDataMap, parameters, parametersOffset, defaultDatabaseName).orElse(null); + insertSelectContext = getInsertSelectContext(databaseMetaDataMap, parameters, parametersOffset, defaultDatabaseName).orElse(null); onDuplicateKeyUpdateValueContext = getOnDuplicateKeyUpdateValueContext(parameters, parametersOffset).orElse(null); - ShardingSphereSchema schema = getSchema(metaDataMap, defaultDatabaseName); + ShardingSphereSchema schema = getSchema(databaseMetaDataMap, defaultDatabaseName); generatedKeyContext = new GeneratedKeyContextEngine(getSqlStatement(), schema).createGenerateKeyContext(insertColumnNames, valueExpressions, parameters).orElse(null); } } diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java index 18f0139aeb965..e13fb4cc069aa 100644 --- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java +++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java @@ -40,7 +40,7 @@ import org.apache.shardingsphere.infra.binder.type.TableAvailable; import org.apache.shardingsphere.infra.binder.type.WhereAvailable; import org.apache.shardingsphere.infra.exception.DatabaseNotExistedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType; import org.apache.shardingsphere.sql.parser.sql.common.constant.SubqueryType; @@ -102,15 +102,15 @@ public final class SelectStatementContext extends CommonSQLStatementContext metaDataMap, final List parameters, + public SelectStatementContext(final Map databaseMetaDataMap, final List parameters, final SelectStatement sqlStatement, final String defaultDatabaseName) { super(sqlStatement); extractWhereSegments(whereSegments, sqlStatement); ColumnExtractor.extractColumnSegments(columnSegments, whereSegments); - subqueryContexts = createSubqueryContexts(metaDataMap, parameters, defaultDatabaseName); + subqueryContexts = createSubqueryContexts(databaseMetaDataMap, parameters, defaultDatabaseName); tablesContext = new TablesContext(getAllTableSegments(), subqueryContexts, getDatabaseType()); String databaseName = tablesContext.getDatabaseName().orElse(defaultDatabaseName); - ShardingSphereDatabase database = getDatabase(metaDataMap, databaseName); + ShardingSphereDatabase database = getDatabase(databaseMetaDataMap, databaseName); groupByContext = new GroupByContextEngine().createGroupByContext(sqlStatement); orderByContext = new OrderByContextEngine().createOrderBy(sqlStatement, groupByContext); projectionsContext = new ProjectionsContextEngine(databaseName, database, getDatabaseType()) @@ -118,28 +118,28 @@ public SelectStatementContext(final Map metaData paginationContext = new PaginationContextEngine().createPaginationContext(sqlStatement, projectionsContext, parameters, whereSegments); } - private Map createSubqueryContexts(final Map metaDataMap, + private Map createSubqueryContexts(final Map databaseMetaDataMap, final List parameters, final String defaultDatabaseName) { Collection subquerySegments = SubqueryExtractUtil.getSubquerySegments(getSqlStatement()); Map result = new HashMap<>(subquerySegments.size(), 1); for (SubquerySegment each : subquerySegments) { - SelectStatementContext subqueryContext = new SelectStatementContext(metaDataMap, parameters, each.getSelect(), defaultDatabaseName); + SelectStatementContext subqueryContext = new SelectStatementContext(databaseMetaDataMap, parameters, each.getSelect(), defaultDatabaseName); subqueryContext.setSubqueryType(each.getSubqueryType()); result.put(each.getStartIndex(), subqueryContext); } return result; } - private ShardingSphereDatabase getDatabase(final Map metaDataMap, final String databaseName) { - ShardingSphereMetaData metaData = metaDataMap.get(databaseName); - if (null == metaData) { + private ShardingSphereDatabase getDatabase(final Map databaseMetaDataMap, final String databaseName) { + ShardingSphereDatabaseMetaData databaseMetaData = databaseMetaDataMap.get(databaseName); + if (null == databaseMetaData) { if (tablesContext.getTables().isEmpty()) { return new ShardingSphereDatabase(databaseName, Collections.emptyMap()); } else { throw new DatabaseNotExistedException(databaseName); } } - return metaData.getDatabase(); + return databaseMetaData.getDatabase(); } /** diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java index edfaf0e3e89fe..6fe45f313ae41 100644 --- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java +++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment; @@ -161,8 +161,8 @@ public void getRevisedRowCountForSQLServer() { private void getRevisedRowCount(final SelectStatement selectStatement) { selectStatement.setProjections(new ProjectionsSegment(0, 0)); - Map metaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereMetaData.class)); - SelectStatementContext selectStatementContext = new SelectStatementContext(metaDataMap, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + Map databaseMetaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabaseMetaData.class)); + SelectStatementContext selectStatementContext = new SelectStatementContext(databaseMetaDataMap, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); assertThat(new PaginationContext(getOffsetSegment(), getRowCountSegment(), getParameters()).getRevisedRowCount(selectStatementContext), is(50L)); } @@ -195,8 +195,8 @@ private void getRevisedRowCountWithMax(final SelectStatement selectStatement) { selectStatement.setProjections(new ProjectionsSegment(0, 0)); selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.DESC)))); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC)))); - Map metaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereMetaData.class)); - SelectStatementContext selectStatementContext = new SelectStatementContext(metaDataMap, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + Map databaseMetaDataMap = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabaseMetaData.class)); + SelectStatementContext selectStatementContext = new SelectStatementContext(databaseMetaDataMap, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); assertThat(new PaginationContext(getOffsetSegment(), getRowCountSegment(), getParameters()).getRevisedRowCount(selectStatementContext), is((long) Integer.MAX_VALUE)); } } diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java index 00e09c9c96a8e..09655ccd914e0 100644 --- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java +++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext; import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection; @@ -224,10 +224,10 @@ private void assertCreateProjectionsContextWithoutIndexOrderByItemSegment(final } private SelectStatementContext createSelectStatementContext(final SelectStatement selectStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - when(metaData.getDatabase()).thenReturn(mockDatabase()); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); + when(databaseMetaData.getDatabase()).thenReturn(mockDatabase()); when(schema.getAllColumnNames("t_order")).thenReturn(Arrays.asList("order_id", "content")); - return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); } private ShardingSphereDatabase mockDatabase() { diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java index edf0015dd0cfb..418b221e5f548 100644 --- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java +++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment; @@ -59,7 +59,7 @@ public void assertSQLStatementContextCreatedWhenSQLStatementInstanceOfSelectStat MySQLSelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setLimit(new LimitSegment(0, 10, null, null)); selectStatement.setProjections(projectionsSegment); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(mockMetaDataMap(), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(mockDatabaseMetaDataMap(), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); assertThat(sqlStatementContext, instanceOf(SelectStatementContext.class)); } @@ -96,17 +96,17 @@ public void assertSQLStatementContextCreatedWhenSQLStatementInstanceOfSQLServerI private void assertSQLStatementContextCreatedWhenSQLStatementInstanceOfInsertStatement(final InsertStatement insertStatement) { insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(mockMetaDataMap(), Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME); + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(mockDatabaseMetaDataMap(), Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME); assertThat(sqlStatementContext, instanceOf(InsertStatementContext.class)); } @Test public void assertSQLStatementContextCreatedWhenSQLStatementNotInstanceOfSelectStatementAndInsertStatement() { - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(mockMetaDataMap(), Collections.emptyList(), mock(MySQLStatement.class), DefaultDatabase.LOGIC_NAME); + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(mockDatabaseMetaDataMap(), Collections.emptyList(), mock(MySQLStatement.class), DefaultDatabase.LOGIC_NAME); assertThat(sqlStatementContext, instanceOf(CommonSQLStatementContext.class)); } - private Map mockMetaDataMap() { - return Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS)); + private Map mockDatabaseMetaDataMap() { + return Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS)); } } diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java index 6050582f31e24..43995628ed1ed 100644 --- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java +++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment; @@ -60,6 +60,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -102,12 +103,12 @@ private void assertInsertStatementContextWithColumnNames(final InsertStatement i } private InsertStatementContext createInsertStatementContext(final List parameters, final InsertStatement insertStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); String defaultSchemaName = insertStatement instanceof PostgreSQLStatement || insertStatement instanceof OpenGaussStatement ? "public" : DefaultDatabase.LOGIC_NAME; - when(metaData.getSchemaByName(defaultSchemaName)).thenReturn(schema); + when(databaseMetaData.getDatabase().getSchema(defaultSchemaName)).thenReturn(schema); when(schema.getAllColumnNames("tbl")).thenReturn(Arrays.asList("id", "name", "status")); - return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), parameters, insertStatement, DefaultDatabase.LOGIC_NAME); + return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), parameters, insertStatement, DefaultDatabase.LOGIC_NAME); } @Test diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java index c808386edeec4..b281d7e52218e 100644 --- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java +++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType; import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment; @@ -98,11 +98,11 @@ public void assertSetIndexForItemsByIndexOrderByForSQLServer() { } public void assertSetIndexForItemsByIndexOrderBy(final SelectStatement selectStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(INDEX_ORDER_BY)))); selectStatement.setProjections(createProjectionsSegment()); selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("table")))); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); selectStatementContext.setIndexes(Collections.emptyMap()); assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(4)); @@ -134,11 +134,11 @@ public void assertSetIndexForItemsByColumnOrderByWithOwnerForSQLServer() { } private void assertSetIndexForItemsByColumnOrderByWithOwner(final SelectStatement selectStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITH_OWNER)))); selectStatement.setProjections(createProjectionsSegment()); selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("table")))); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); selectStatementContext.setIndexes(Collections.emptyMap()); assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(1)); @@ -170,10 +170,10 @@ public void assertSetIndexForItemsByColumnOrderByWithAliasForSQLServer() { } private void assertSetIndexForItemsByColumnOrderByWithAlias(final SelectStatement selectStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITH_ALIAS)))); selectStatement.setProjections(createProjectionsSegment()); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); selectStatementContext.setIndexes(Collections.singletonMap("n", 2)); assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(2)); @@ -205,10 +205,10 @@ public void assertSetIndexForItemsByColumnOrderByWithoutAliasForSQLServer() { } private void assertSetIndexForItemsByColumnOrderByWithoutAlias(final SelectStatement selectStatement) { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITHOUT_OWNER_ALIAS)))); selectStatement.setProjections(createProjectionsSegment()); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), Collections.emptyList(), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); selectStatementContext.setIndexes(Collections.singletonMap("id", 3)); assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(3)); @@ -248,7 +248,7 @@ private void assertIsSameGroupByAndOrderByItems(final SelectStatement selectStat } private SelectStatementContext createSelectStatementContext(final SelectStatement selectStatement) { - return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereMetaData.class)), + return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabaseMetaData.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); } @@ -342,14 +342,14 @@ public void assertSetIndexWhenAggregationProjectionsPresentForSQLServer() { } private void assertSetIndexWhenAggregationProjectionsPresent(final SelectStatement selectStatement) { - final ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + final ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITHOUT_OWNER_ALIAS)))); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); AggregationProjectionSegment aggregationProjectionSegment = new AggregationProjectionSegment(0, 0, AggregationType.MAX, ""); aggregationProjectionSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue("id"))); projectionsSegment.getProjections().add(aggregationProjectionSegment); selectStatement.setProjections(projectionsSegment); - SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); selectStatementContext.setIndexes(Collections.singletonMap("id", 3)); assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(3)); @@ -383,9 +383,9 @@ public void assertSetWhereForSQLServer() { public void assertSetWhere(final SelectStatement selectStatement) { WhereSegment whereSegment = mock(WhereSegment.class); selectStatement.setWhere(whereSegment); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); selectStatement.setProjections(new ProjectionsSegment(0, 0)); - SelectStatementContext actual = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + SelectStatementContext actual = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); assertThat(actual.getTablesContext().getTableNames(), is(Collections.emptySet())); assertThat(actual.getAllTables(), is(Collections.emptyList())); @@ -435,8 +435,8 @@ private void assertContainsSubquery(final SelectStatement selectStatement, final ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(projectionSegment); selectStatement.setProjections(projectionsSegment); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - SelectStatementContext actual = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); + SelectStatementContext actual = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); assertTrue(actual.isContainsSubquery()); } @@ -482,8 +482,8 @@ private void assertContainsSubqueryWhereEmpty(final SelectStatement selectStatem ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(projectionSegment); selectStatement.setProjections(projectionsSegment); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); - SelectStatementContext actual = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); + SelectStatementContext actual = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME); assertTrue(actual.isContainsSubquery()); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/query/DistSQLResultSet.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/query/DistSQLResultSet.java index bc09677662980..3626ff61b245e 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/query/DistSQLResultSet.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/query/DistSQLResultSet.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.infra.distsql.query; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.spi.type.typed.TypedSPI; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -31,10 +31,10 @@ public interface DistSQLResultSet extends TypedSPI { /** * Initialize data. * - * @param metaData meta data for ShardingSphere + * @param databaseMetaData database meta data * @param sqlStatement SQL statement */ - void init(ShardingSphereMetaData metaData, SQLStatement sqlStatement); + void init(ShardingSphereDatabaseMetaData databaseMetaData, SQLStatement sqlStatement); /** * Get result set column names. diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RuleDefinitionUpdater.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RuleDefinitionUpdater.java index 8a6f6e4a77f55..fa5d346a73fee 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RuleDefinitionUpdater.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/RuleDefinitionUpdater.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.distsql.exception.DistSQLException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.spi.annotation.SingletonSPI; import org.apache.shardingsphere.spi.type.typed.TypedSPI; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -36,12 +36,12 @@ public interface RuleDefinitionUpdater schemaNames); + + /** + * Try Lock write for database. * * @param databaseName database name * @param timeoutMilliseconds timeout milliseconds @@ -55,6 +66,16 @@ public interface LockContext { */ boolean tryLockWrite(String databaseName, long timeoutMilliseconds); + /** + * Try lock write for schemas. + * + * @param databaseName database name + * @param schemaNames schema names + * @param timeoutMilliseconds timeout milliseconds + * @return is locked or not + */ + boolean tryLockWrite(String databaseName, Set schemaNames, long timeoutMilliseconds); + /** * Release lock write of database. * @@ -62,6 +83,14 @@ public interface LockContext { */ void releaseLockWrite(String databaseName); + /** + * Release lock write for schemas. + * + * @param databaseName database name + * @param schemaName schema name + */ + void releaseLockWrite(String databaseName, String schemaName); + /** * Is locked database. * @@ -69,4 +98,13 @@ public interface LockContext { * @return is locked database or not */ boolean isLocked(String databaseName); + + /** + * Is locked schema. + * + * @param databaseName database name + * @param schemaName schema name + * @return is locked or not + */ + boolean isLocked(String databaseName, String schemaName); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereDatabaseMetaData.java similarity index 69% rename from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereDatabaseMetaData.java index 2a7d0fd3f8924..3a07e31f9a2e2 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereDatabaseMetaData.java @@ -30,9 +30,8 @@ import org.apache.shardingsphere.infra.metadata.resource.DataSourcesMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; -import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder; +import org.apache.shardingsphere.infra.rule.builder.schema.DatabaseRulesBuilder; import javax.sql.DataSource; import java.sql.Connection; @@ -44,13 +43,13 @@ import java.util.Optional; /** - * ShardingSphere meta data. + * ShardingSphere database meta data. */ @RequiredArgsConstructor @Getter -public final class ShardingSphereMetaData { +public final class ShardingSphereDatabaseMetaData { - private final DatabaseType frontendDatabaseType; + private final DatabaseType protocolType; private final ShardingSphereResource resource; @@ -59,42 +58,42 @@ public final class ShardingSphereMetaData { private final ShardingSphereDatabase database; /** - * Create ShardingSphere meta data. + * Create database meta data. * * @param databaseName database name - * @param frontendDatabaseType frontend database type + * @param protocolType database protocol type * @param backendDatabaseType backend database type * @param databaseConfig database configuration * @param props configuration properties - * @return ShardingSphere meta data + * @return database meta data * @throws SQLException SQL exception */ - public static ShardingSphereMetaData create(final String databaseName, final DatabaseType frontendDatabaseType, final DatabaseType backendDatabaseType, - final DatabaseConfiguration databaseConfig, final ConfigurationProperties props) throws SQLException { - Collection databaseRules = SchemaRulesBuilder.buildRules(databaseName, databaseConfig, props); - ShardingSphereDatabase database = DatabaseLoader.load(databaseName, frontendDatabaseType, backendDatabaseType, databaseConfig.getDataSources(), databaseRules, props); - return create(frontendDatabaseType, databaseConfig, databaseRules, database); + public static ShardingSphereDatabaseMetaData create(final String databaseName, final DatabaseType protocolType, final DatabaseType backendDatabaseType, + final DatabaseConfiguration databaseConfig, final ConfigurationProperties props) throws SQLException { + Collection databaseRules = DatabaseRulesBuilder.build(databaseName, databaseConfig, props); + ShardingSphereDatabase database = DatabaseLoader.load(databaseName, protocolType, backendDatabaseType, databaseConfig.getDataSources(), databaseRules, props); + return create(protocolType, databaseConfig, databaseRules, database); } /** - * Create ShardingSphere meta data for system database. + * Create system database meta data. * * @param systemDatabaseName system database name - * @param frontendDatabaseType frontend database type - * @return ShardingSphere meta data + * @param protocolType protocol database type + * @return system database meta data * @throws SQLException SQL exception */ - public static ShardingSphereMetaData create(final String systemDatabaseName, final DatabaseType frontendDatabaseType) throws SQLException { - ShardingSphereDatabase systemDatabase = DatabaseLoader.load(systemDatabaseName, frontendDatabaseType); + public static ShardingSphereDatabaseMetaData create(final String systemDatabaseName, final DatabaseType protocolType) throws SQLException { + ShardingSphereDatabase systemDatabase = DatabaseLoader.load(systemDatabaseName, protocolType); DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(new LinkedHashMap<>(), new LinkedList<>()); - return create(frontendDatabaseType, databaseConfig, new LinkedList<>(), systemDatabase); + return create(protocolType, databaseConfig, new LinkedList<>(), systemDatabase); } - private static ShardingSphereMetaData create(final DatabaseType frontendDatabaseType, - final DatabaseConfiguration databaseConfig, final Collection rules, final ShardingSphereDatabase database) throws SQLException { + private static ShardingSphereDatabaseMetaData create(final DatabaseType frontendDatabaseType, final DatabaseConfiguration databaseConfig, + final Collection rules, final ShardingSphereDatabase database) throws SQLException { ShardingSphereResource resource = createResource(frontendDatabaseType, databaseConfig.getDataSources()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(databaseConfig.getRuleConfigurations(), rules); - return new ShardingSphereMetaData(frontendDatabaseType, resource, ruleMetaData, database); + return new ShardingSphereDatabaseMetaData(frontendDatabaseType, resource, ruleMetaData, database); } private static ShardingSphereResource createResource(final DatabaseType frontendDatabaseType, final Map dataSourceMap) throws SQLException { @@ -130,14 +129,4 @@ public boolean isComplete() { public boolean hasDataSource() { return !resource.getDataSources().isEmpty(); } - - /** - * Get schema by name. - * - * @param schemaName schema name - * @return ShardingSphereSchema schema - */ - public ShardingSphereSchema getSchemaByName(final String schemaName) { - return database.getSchemas().get(schemaName); - } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java index cfe35adc369d3..5a1fba5cddf4e 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java @@ -38,4 +38,14 @@ public ShardingSphereDatabase(final String name, final Map(schemas.size(), 1); schemas.forEach((key, value) -> this.schemas.put(key.toLowerCase(), value)); } + + /** + * Get schema. + * + * @param schemaName schema name + * @return ShardingSphere schema + */ + public ShardingSphereSchema getSchema(final String schemaName) { + return schemas.get(schemaName); + } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/dialect/OracleSchemaMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/dialect/OracleSchemaMetaDataLoader.java index c053bab4e9a00..e8fadb8c28ab5 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/dialect/OracleSchemaMetaDataLoader.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/dialect/OracleSchemaMetaDataLoader.java @@ -115,13 +115,13 @@ private void appendNumberDataType(final Map dataTypes) { } private ColumnMetaData loadColumnMetaData(final Map dataTypeMap, final ResultSet resultSet, final Collection primaryKeys, - final DatabaseMetaData metaData) throws SQLException { + final DatabaseMetaData databaseMetaData) throws SQLException { String columnName = resultSet.getString("COLUMN_NAME"); String dataType = getOriginalDataType(resultSet.getString("DATA_TYPE")); boolean primaryKey = primaryKeys.contains(columnName); - boolean generated = versionContainsIdentityColumn(metaData) && "YES".equals(resultSet.getString("IDENTITY_COLUMN")); + boolean generated = versionContainsIdentityColumn(databaseMetaData) && "YES".equals(resultSet.getString("IDENTITY_COLUMN")); // TODO need to support caseSensitive when version < 12.2. - boolean caseSensitive = versionContainsCollation(metaData) && resultSet.getString("COLLATION").endsWith("_CS"); + boolean caseSensitive = versionContainsCollation(databaseMetaData) && resultSet.getString("COLLATION").endsWith("_CS"); return new ColumnMetaData(columnName, dataTypeMap.get(dataType), primaryKey, generated, caseSensitive); } @@ -133,12 +133,12 @@ private String getOriginalDataType(final String dataType) { return dataType; } - private String getTableMetaDataSQL(final Collection tables, final DatabaseMetaData metaData) throws SQLException { + private String getTableMetaDataSQL(final Collection tables, final DatabaseMetaData databaseMetaData) throws SQLException { StringBuilder stringBuilder = new StringBuilder(28); - if (versionContainsIdentityColumn(metaData)) { + if (versionContainsIdentityColumn(databaseMetaData)) { stringBuilder.append(", IDENTITY_COLUMN"); } - if (versionContainsCollation(metaData)) { + if (versionContainsCollation(databaseMetaData)) { stringBuilder.append(", COLLATION"); } String collation = stringBuilder.toString(); @@ -146,12 +146,12 @@ private String getTableMetaDataSQL(final Collection tables, final Databa : String.format(TABLE_META_DATA_SQL_IN_TABLES, collation, tables.stream().map(each -> String.format("'%s'", each)).collect(Collectors.joining(","))); } - private boolean versionContainsCollation(final DatabaseMetaData metaData) throws SQLException { - return metaData.getDatabaseMajorVersion() >= COLLATION_START_MAJOR_VERSION && metaData.getDatabaseMinorVersion() >= COLLATION_START_MINOR_VERSION; + private boolean versionContainsCollation(final DatabaseMetaData databaseMetaData) throws SQLException { + return databaseMetaData.getDatabaseMajorVersion() >= COLLATION_START_MAJOR_VERSION && databaseMetaData.getDatabaseMinorVersion() >= COLLATION_START_MINOR_VERSION; } - private boolean versionContainsIdentityColumn(final DatabaseMetaData metaData) throws SQLException { - return metaData.getDatabaseMajorVersion() >= COLLATION_START_MAJOR_VERSION && metaData.getDatabaseMinorVersion() >= IDENTITY_COLUMN_START_MINOR_VERSION; + private boolean versionContainsIdentityColumn(final DatabaseMetaData databaseMetaData) throws SQLException { + return databaseMetaData.getDatabaseMajorVersion() >= COLLATION_START_MAJOR_VERSION && databaseMetaData.getDatabaseMinorVersion() >= IDENTITY_COLUMN_START_MINOR_VERSION; } private Map> loadIndexMetaData(final Connection connection, final Collection tableNames) throws SQLException { diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java index 5df3809fdfb00..b10fb39c4d2d4 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtil.java @@ -21,7 +21,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.infra.database.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.QualifiedTable; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment; @@ -79,19 +79,20 @@ public static String getGeneratedLogicIndexName(final Collection } /** - * Get table names from metadata. + * Get table names from meta data. * - * @param metaData meta data + * @param databaseMetaData database meta data * @param indexes indexes * @param databaseType database type * @return table names */ - public static Collection getTableNamesFromMetaData(final ShardingSphereMetaData metaData, final Collection indexes, final DatabaseType databaseType) { + public static Collection getTableNamesFromMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, + final Collection indexes, final DatabaseType databaseType) { Collection result = new LinkedList<>(); - String schemaName = databaseType.getDefaultSchema(metaData.getDatabase().getName()); + String schemaName = databaseType.getDefaultSchema(databaseMetaData.getDatabase().getName()); for (IndexSegment each : indexes) { String actualSchemaName = each.getOwner().map(optional -> optional.getIdentifier().getValue()).orElse(schemaName); - findLogicTableNameFromMetaData(metaData.getSchemaByName(actualSchemaName), + findLogicTableNameFromMetaData(databaseMetaData.getDatabase().getSchema(actualSchemaName), each.getIndexName().getIdentifier().getValue()).ifPresent(optional -> result.add(new QualifiedTable(actualSchemaName, optional))); } return result; diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java index 942fce4900a1b..f843da41c464c 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.rule.builder.global; import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.builder.RuleBuilder; import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; import org.apache.shardingsphere.spi.annotation.SingletonSPI; @@ -37,8 +37,8 @@ public interface GlobalRuleBuilder extends RuleBuil * Build global rule. * * @param ruleConfig rule configuration - * @param metaDataMap meta data map + * @param databaseMetaDataMap database meta data map * @return global rule */ - GlobalRule build(T ruleConfig, Map metaDataMap); + GlobalRule build(T ruleConfig, Map databaseMetaDataMap); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java index 4bc37806ec3b3..a74d46f1dad61 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java @@ -20,7 +20,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import java.util.Collection; @@ -40,14 +40,14 @@ public final class GlobalRulesBuilder { * Build rules. * * @param globalRuleConfigs global rule configurations - * @param metaDataMap meta data map + * @param databaseMetaDataMap database meta data map * @return built rules */ @SuppressWarnings({"unchecked", "rawtypes"}) - public static Collection buildRules(final Collection globalRuleConfigs, final Map metaDataMap) { + public static Collection buildRules(final Collection globalRuleConfigs, final Map databaseMetaDataMap) { Collection result = new LinkedList<>(); for (Entry entry : getRuleBuilderMap(globalRuleConfigs).entrySet()) { - result.add(entry.getValue().build(entry.getKey(), metaDataMap)); + result.add(entry.getValue().build(entry.getKey(), databaseMetaDataMap)); } return result; } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/DatabaseRulesBuilder.java similarity index 94% rename from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/DatabaseRulesBuilder.java index 2383ea89bf718..bb3cb78e7b524 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/DatabaseRulesBuilder.java @@ -36,21 +36,21 @@ import java.util.stream.Collectors; /** - * Schema rules builder. + * Database rules builder. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class SchemaRulesBuilder { +public final class DatabaseRulesBuilder { /** - * Build rules. + * Build database rules. * * @param databaseName database name - * @param databaseConfig schema configuration + * @param databaseConfig database configuration * @param props configuration properties * @return built rules */ @SuppressWarnings({"unchecked", "rawtypes"}) - public static Collection buildRules(final String databaseName, final DatabaseConfiguration databaseConfig, final ConfigurationProperties props) { + public static Collection build(final String databaseName, final DatabaseConfiguration databaseConfig, final ConfigurationProperties props) { Collection result = new LinkedList<>(); for (Entry entry : getRuleBuilderMap(databaseConfig).entrySet()) { result.add(entry.getValue().build(entry.getKey(), databaseName, databaseConfig.getDataSources(), result, props)); diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java index 36ae20fc7dade..f39126bc4e3b4 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java @@ -33,7 +33,7 @@ public final class StateContext { * Switch state. * * @param type state type - * @param on true if state type is valid, false if not + * @param on true if state type is valid, false if not */ public void switchState(final StateType type, final boolean on) { if (on) { diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereDatabaseMetaDataTest.java similarity index 82% rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereDatabaseMetaDataTest.java index 3166feab89b8a..957f443543b40 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereDatabaseMetaDataTest.java @@ -34,15 +34,14 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; -public final class ShardingSphereMetaDataTest { +public final class ShardingSphereDatabaseMetaDataTest { @Test public void assertIsComplete() { ShardingSphereResource resource = new ShardingSphereResource( Collections.singletonMap("ds", mock(DataSource.class)), mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), mock(DatabaseType.class)); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(mock(RuleConfiguration.class)), Collections.singleton(mock(ShardingSphereRule.class))); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), resource, ruleMetaData, mock(ShardingSphereDatabase.class)); - assertTrue(metaData.isComplete()); + assertTrue(new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), resource, ruleMetaData, mock(ShardingSphereDatabase.class)).isComplete()); } @Test @@ -50,15 +49,13 @@ public void assertIsNotCompleteWithoutRule() { ShardingSphereResource resource = new ShardingSphereResource( Collections.singletonMap("ds", mock(DataSource.class)), mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), mock(DatabaseType.class)); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), resource, ruleMetaData, mock(ShardingSphereDatabase.class)); - assertFalse(metaData.isComplete()); + assertFalse(new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), resource, ruleMetaData, mock(ShardingSphereDatabase.class)).isComplete()); } @Test public void assertIsNotCompleteWithoutDataSource() { ShardingSphereResource resource = new ShardingSphereResource(Collections.emptyMap(), mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), mock(DatabaseType.class)); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(mock(RuleConfiguration.class)), Collections.singleton(mock(ShardingSphereRule.class))); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), resource, ruleMetaData, mock(ShardingSphereDatabase.class)); - assertFalse(metaData.isComplete()); + assertFalse(new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), resource, ruleMetaData, mock(ShardingSphereDatabase.class)).isComplete()); } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java index 9813c3cd18ad2..c046162a91400 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -84,17 +84,17 @@ public void assertGetGeneratedLogicIndexName() { @Test public void assertGetTableNamesFromMetaData() { IndexSegment indexSegment = new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue(INDEX_NAME))); - Collection actual = IndexMetaDataUtil.getTableNamesFromMetaData(buildMetaData(), Collections.singleton(indexSegment), new MySQLDatabaseType()); + Collection actual = IndexMetaDataUtil.getTableNamesFromMetaData(buildDatabaseMetaData(), Collections.singleton(indexSegment), new MySQLDatabaseType()); assertThat(actual.size(), is(1)); assertThat(actual.iterator().next().getSchemaName(), is(DefaultDatabase.LOGIC_NAME)); assertThat(actual.iterator().next().getTableName(), is(TABLE_NAME)); } - private ShardingSphereMetaData buildMetaData() { + private ShardingSphereDatabaseMetaData buildDatabaseMetaData() { TableMetaData tableMetaData = new TableMetaData(TABLE_NAME, Collections.emptyList(), Collections.singleton(new IndexMetaData(INDEX_NAME)), Collections.emptyList()); Map tables = Collections.singletonMap(TABLE_NAME, tableMetaData); Map schemas = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new ShardingSphereSchema(tables)); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, schemas); - return new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), database); + return new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), database); } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java index 98c03ba2c8837..d382ac34a1b43 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.infra.rule.builder.fixture; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; import java.util.Map; @@ -25,7 +25,7 @@ public final class FixtureGlobalRuleBuilder implements GlobalRuleBuilder { @Override - public FixtureGlobalRule build(final FixtureGlobalRuleConfiguration ruleConfig, final Map metaDataMap) { + public FixtureGlobalRule build(final FixtureGlobalRuleConfiguration ruleConfig, final Map databaseMetaDataMap) { return new FixtureGlobalRule(); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java index 6384ce797dd2c..97133c118d1f6 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.rule.builder.global; import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import java.util.Collections; @@ -31,6 +31,7 @@ public final class GlobalRulesBuilderTest { @Test public void assertBuildRules() { - assertThat(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).size(), is(1)); + assertThat(GlobalRulesBuilder.buildRules( + Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereDatabaseMetaData.class))).size(), is(1)); } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/DatabaseRulesBuilderTest.java similarity index 93% rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/DatabaseRulesBuilderTest.java index bc89e7dd9371a..3175e47fa1926 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/DatabaseRulesBuilderTest.java @@ -33,11 +33,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; -public final class SchemaRulesBuilderTest { +public final class DatabaseRulesBuilderTest { @Test public void assertBuild() { - Iterator actual = SchemaRulesBuilder.buildRules("schema_name", + Iterator actual = DatabaseRulesBuilder.build("schema_name", new DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), Collections.singleton(new TestRuleConfiguration())), new ConfigurationProperties(new Properties())).iterator(); assertThat(actual.next(), instanceOf(TestShardingSphereRule.class)); assertThat(actual.next(), instanceOf(FixtureSchemaRule.class)); diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessor.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessor.java index 3314097b79441..7af5c57353b11 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessor.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessor.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContextBuilder; import org.apache.shardingsphere.infra.executor.sql.log.SQLLogger; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry; import org.apache.shardingsphere.infra.rewrite.engine.result.SQLRewriteResult; import org.apache.shardingsphere.infra.route.context.RouteContext; @@ -38,29 +38,30 @@ public final class KernelProcessor { * Generate execution context. * * @param logicSQL logic SQL - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param props configuration properties * @return execution context */ - public ExecutionContext generateExecutionContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ConfigurationProperties props) { - RouteContext routeContext = route(logicSQL, metaData, props); - SQLRewriteResult rewriteResult = rewrite(logicSQL, metaData, props, routeContext); - ExecutionContext result = createExecutionContext(logicSQL, metaData, routeContext, rewriteResult); + public ExecutionContext generateExecutionContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props) { + RouteContext routeContext = route(logicSQL, databaseMetaData, props); + SQLRewriteResult rewriteResult = rewrite(logicSQL, databaseMetaData, props, routeContext); + ExecutionContext result = createExecutionContext(logicSQL, databaseMetaData, routeContext, rewriteResult); logSQL(logicSQL, props, result); return result; } - private RouteContext route(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ConfigurationProperties props) { - return new SQLRouteEngine(metaData.getRuleMetaData().getRules(), props).route(logicSQL, metaData); + private RouteContext route(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props) { + return new SQLRouteEngine(databaseMetaData.getRuleMetaData().getRules(), props).route(logicSQL, databaseMetaData); } - private SQLRewriteResult rewrite(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final ConfigurationProperties props, final RouteContext routeContext) { - SQLRewriteEntry sqlRewriteEntry = new SQLRewriteEntry(metaData, props); + private SQLRewriteResult rewrite(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final RouteContext routeContext) { + SQLRewriteEntry sqlRewriteEntry = new SQLRewriteEntry(databaseMetaData, props); return sqlRewriteEntry.rewrite(logicSQL.getSql(), logicSQL.getParameters(), logicSQL.getSqlStatementContext(), routeContext); } - private ExecutionContext createExecutionContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final RouteContext routeContext, final SQLRewriteResult rewriteResult) { - return new ExecutionContext(logicSQL, ExecutionContextBuilder.build(metaData, rewriteResult, logicSQL.getSqlStatementContext()), routeContext); + private ExecutionContext createExecutionContext(final LogicSQL logicSQL, + final ShardingSphereDatabaseMetaData databaseMetaData, final RouteContext routeContext, final SQLRewriteResult rewriteResult) { + return new ExecutionContext(logicSQL, ExecutionContextBuilder.build(databaseMetaData, rewriteResult, logicSQL.getSqlStatementContext()), routeContext); } private void logSQL(final LogicSQL logicSQL, final ConfigurationProperties props, final ExecutionContext executionContext) { diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngine.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngine.java index ec4fe0e9f121e..0914a59bf192f 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngine.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngine.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import java.sql.SQLException; @@ -42,7 +42,7 @@ public final class MetaDataRefreshEngine { private static final Set> IGNORABLE_SQL_STATEMENT_CLASSES = Collections.newSetFromMap(new ConcurrentHashMap<>()); - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final FederationDatabaseMetaData federationMetaData; @@ -65,8 +65,9 @@ public void refresh(final SQLStatementContext sqlStatementContext, final Supp } Optional schemaRefresher = MetaDataRefresherFactory.findInstance(sqlStatementClass); if (schemaRefresher.isPresent()) { - String schemaName = sqlStatementContext.getTablesContext().getSchemaName().orElseGet(() -> sqlStatementContext.getDatabaseType().getDefaultSchema(metaData.getDatabase().getName())); - schemaRefresher.get().refresh(metaData, federationMetaData, optimizerPlanners, logicDataSourceNamesSupplier.get(), schemaName, sqlStatementContext.getSqlStatement(), props); + String schemaName = sqlStatementContext.getTablesContext().getSchemaName() + .orElseGet(() -> sqlStatementContext.getDatabaseType().getDefaultSchema(databaseMetaData.getDatabase().getName())); + schemaRefresher.get().refresh(databaseMetaData, federationMetaData, optimizerPlanners, logicDataSourceNamesSupplier.get(), schemaName, sqlStatementContext.getSqlStatement(), props); } else { IGNORABLE_SQL_STATEMENT_CLASSES.add(sqlStatementClass); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresher.java index 274c66dcb93ae..47721f6c2012f 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresher.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.spi.annotation.SingletonSPI; import org.apache.shardingsphere.spi.type.typed.TypedSPI; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -40,8 +40,8 @@ public interface MetaDataRefresher extends TypedSPI { /** * Refresh schema. * - * @param metaData meta data - * @param database federation database meta data + * @param databaseMetaData database meta data + * @param database federation database meta data * @param optimizerPlanners optimizer planners * @param logicDataSourceNames route data source names * @param schemaName schema name @@ -49,6 +49,6 @@ public interface MetaDataRefresher extends TypedSPI { * @param props configuration properties * @throws SQLException SQL exception */ - void refresh(ShardingSphereMetaData metaData, FederationDatabaseMetaData database, Map optimizerPlanners, + void refresh(ShardingSphereDatabaseMetaData databaseMetaData, FederationDatabaseMetaData database, Map optimizerPlanners, Collection logicDataSourceNames, String schemaName, T sqlStatement, ConfigurationProperties props) throws SQLException; } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java index dfb72cd23754b..05382661988cb 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData; @@ -45,7 +45,7 @@ public final class AlterIndexStatementSchemaRefresher implements MetaDataRefresh private static final String TYPE = AlterIndexStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final AlterIndexStatement sqlStatement, final ConfigurationProperties props) throws SQLException { Optional renameIndex = AlterIndexStatementHandler.getRenameIndexSegment(sqlStatement); if (!sqlStatement.getIndex().isPresent() || !renameIndex.isPresent()) { @@ -53,14 +53,14 @@ public void refresh(final ShardingSphereMetaData metaData, final FederationDatab } String actualSchemaName = sqlStatement.getIndex().get().getOwner().map(optional -> optional.getIdentifier().getValue()).orElse(schemaName); String indexName = sqlStatement.getIndex().get().getIndexName().getIdentifier().getValue(); - Optional logicTableName = findLogicTableName(metaData.getSchemaByName(actualSchemaName), indexName); + Optional logicTableName = findLogicTableName(databaseMetaData.getDatabase().getSchema(actualSchemaName), indexName); if (logicTableName.isPresent()) { - TableMetaData tableMetaData = metaData.getSchemaByName(actualSchemaName).get(logicTableName.get()); + TableMetaData tableMetaData = databaseMetaData.getDatabase().getSchema(actualSchemaName).get(logicTableName.get()); Preconditions.checkNotNull(tableMetaData, "Can not get the table '%s' metadata!", logicTableName.get()); tableMetaData.getIndexes().remove(indexName); String renameIndexName = renameIndex.get().getIndexName().getIdentifier().getValue(); tableMetaData.getIndexes().put(renameIndexName, new IndexMetaData(renameIndexName)); - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), actualSchemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), actualSchemaName); event.getAlteredTables().add(tableMetaData); ShardingSphereEventBus.getInstance().post(event); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterSchemaStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterSchemaStatementSchemaRefresher.java index 78013a7b2d651..98d675160b9cb 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterSchemaStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterSchemaStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.schema.event.AlterSchemaEvent; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; @@ -45,26 +45,26 @@ public final class AlterSchemaStatementSchemaRefresher implements MetaDataRefres private static final String TYPE = AlterSchemaStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final AlterSchemaStatement sqlStatement, final ConfigurationProperties props) throws SQLException { Optional renameSchemaName = AlterSchemaStatementHandler.getRenameSchema(sqlStatement); if (!renameSchemaName.isPresent()) { return; } String actualSchemaName = sqlStatement.getSchemaName().getValue(); - putSchemaMetaData(metaData, database, optimizerPlanners, actualSchemaName, renameSchemaName.get().getValue(), logicDataSourceNames); - removeSchemaMetaData(metaData, database, optimizerPlanners, actualSchemaName); - AlterSchemaEvent event = new AlterSchemaEvent(metaData.getDatabase().getName(), - actualSchemaName, renameSchemaName.get().getValue(), metaData.getSchemaByName(renameSchemaName.get().getValue())); + putSchemaMetaData(databaseMetaData, database, optimizerPlanners, actualSchemaName, renameSchemaName.get().getValue(), logicDataSourceNames); + removeSchemaMetaData(databaseMetaData, database, optimizerPlanners, actualSchemaName); + AlterSchemaEvent event = new AlterSchemaEvent(databaseMetaData.getDatabase().getName(), + actualSchemaName, renameSchemaName.get().getValue(), databaseMetaData.getDatabase().getSchema(renameSchemaName.get().getValue())); ShardingSphereEventBus.getInstance().post(event); } - private void removeSchemaMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, + private void removeSchemaMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final String schemaName) { - ShardingSphereSchema schema = metaData.getDatabase().getSchemas().remove(schemaName); + ShardingSphereSchema schema = databaseMetaData.getDatabase().getSchemas().remove(schemaName); database.removeSchemaMetadata(schemaName); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); - Collection rules = metaData.getRuleMetaData().findRules(MutableDataNodeRule.class); + Collection rules = databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class); for (String each : schema.getAllTableNames()) { removeDataNode(rules, schemaName, each); } @@ -76,15 +76,15 @@ private void removeDataNode(final Collection rules, final S } } - private void putSchemaMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + private void putSchemaMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final String schemaName, final String renameSchemaName, final Collection logicDataSourceNames) { - ShardingSphereSchema schema = metaData.getSchemaByName(schemaName); - metaData.getDatabase().getSchemas().put(renameSchemaName, schema); + ShardingSphereSchema schema = databaseMetaData.getDatabase().getSchema(schemaName); + databaseMetaData.getDatabase().getSchemas().put(renameSchemaName, schema); database.getSchemaMetadata(schemaName).ifPresent(optional -> database.putSchemaMetadata(renameSchemaName, optional)); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); - Collection rules = metaData.getRuleMetaData().findRules(MutableDataNodeRule.class); + Collection rules = databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class); for (String each : schema.getAllTableNames()) { - if (containsInImmutableDataNodeContainedRule(each, metaData)) { + if (containsInImmutableDataNodeContainedRule(each, databaseMetaData)) { continue; } putDataNode(rules, logicDataSourceNames.iterator().next(), renameSchemaName, each); @@ -97,8 +97,8 @@ private void putDataNode(final Collection rules, final Stri } } - private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() + private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() .filter(each -> !(each instanceof MutableDataNodeRule)).anyMatch(each -> each.getAllTables().contains(tableName)); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java index ca54e718c3ab4..4fa323f4901fa 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials; import org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; @@ -47,49 +47,49 @@ public final class AlterTableStatementSchemaRefresher implements MetaDataRefresh private static final String TYPE = AlterTableStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final AlterTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException { String tableName = sqlStatement.getTable().getTableName().getIdentifier().getValue(); - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); if (sqlStatement.getRenameTable().isPresent()) { String renameTable = sqlStatement.getRenameTable().get().getTableName().getIdentifier().getValue(); - putTableMetaData(metaData, database, optimizerPlanners, logicDataSourceNames, schemaName, renameTable, props); - removeTableMetaData(metaData, database, optimizerPlanners, schemaName, tableName); - event.getAlteredTables().add(metaData.getSchemaByName(schemaName).get(renameTable)); + putTableMetaData(databaseMetaData, database, optimizerPlanners, logicDataSourceNames, schemaName, renameTable, props); + removeTableMetaData(databaseMetaData, database, optimizerPlanners, schemaName, tableName); + event.getAlteredTables().add(databaseMetaData.getDatabase().getSchema(schemaName).get(renameTable)); event.getDroppedTables().add(tableName); } else { - putTableMetaData(metaData, database, optimizerPlanners, logicDataSourceNames, schemaName, tableName, props); - event.getAlteredTables().add(metaData.getSchemaByName(schemaName).get(tableName)); + putTableMetaData(databaseMetaData, database, optimizerPlanners, logicDataSourceNames, schemaName, tableName, props); + event.getAlteredTables().add(databaseMetaData.getDatabase().getSchema(schemaName).get(tableName)); } ShardingSphereEventBus.getInstance().post(event); } - private void removeTableMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, + private void removeTableMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final String schemaName, final String tableName) { - metaData.getSchemaByName(schemaName).remove(tableName); - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, tableName)); + databaseMetaData.getDatabase().getSchema(schemaName).remove(tableName); + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, tableName)); database.removeTableMetadata(schemaName, tableName); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); } - private void putTableMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + private void putTableMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final String tableName, final ConfigurationProperties props) throws SQLException { - if (!containsInImmutableDataNodeContainedRule(tableName, metaData)) { - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); + if (!containsInImmutableDataNodeContainedRule(tableName, databaseMetaData)) { + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } - SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaData.getFrontendDatabaseType(), - metaData.getResource().getDatabaseType(), metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), props, schemaName); + SchemaBuilderMaterials materials = new SchemaBuilderMaterials(databaseMetaData.getProtocolType(), + databaseMetaData.getResource().getDatabaseType(), databaseMetaData.getResource().getDataSources(), databaseMetaData.getRuleMetaData().getRules(), props, schemaName); Map metaDataMap = TableMetaDataBuilder.load(Collections.singletonList(tableName), materials); Optional actualTableMetaData = Optional.ofNullable(metaDataMap.get(schemaName)).map(optional -> optional.getTables().get(tableName)); actualTableMetaData.ifPresent(optional -> { - metaData.getSchemaByName(schemaName).put(tableName, optional); + databaseMetaData.getDatabase().getSchema(schemaName).put(tableName, optional); database.putTableMetadata(schemaName, optional); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); }); } - private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() + private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() .filter(each -> !(each instanceof MutableDataNodeRule)).anyMatch(each -> each.getAllTables().contains(tableName)); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java index a357e23873882..db4cb2bb0d972 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials; import org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; @@ -49,50 +49,50 @@ public final class AlterViewStatementSchemaRefresher implements MetaDataRefreshe private static final String TYPE = AlterViewStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final AlterViewStatement sqlStatement, final ConfigurationProperties props) throws SQLException { String viewName = sqlStatement.getView().getTableName().getIdentifier().getValue(); - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); Optional renameView = AlterViewStatementHandler.getRenameView(sqlStatement); if (renameView.isPresent()) { String renameViewName = renameView.get().getTableName().getIdentifier().getValue(); - putTableMetaData(metaData, database, optimizerPlanners, logicDataSourceNames, schemaName, renameViewName, props); - removeTableMetaData(metaData, database, optimizerPlanners, schemaName, viewName); - event.getAlteredTables().add(metaData.getSchemaByName(schemaName).get(renameViewName)); + putTableMetaData(databaseMetaData, database, optimizerPlanners, logicDataSourceNames, schemaName, renameViewName, props); + removeTableMetaData(databaseMetaData, database, optimizerPlanners, schemaName, viewName); + event.getAlteredTables().add(databaseMetaData.getDatabase().getSchema(schemaName).get(renameViewName)); event.getDroppedTables().add(viewName); } else { - putTableMetaData(metaData, database, optimizerPlanners, logicDataSourceNames, schemaName, viewName, props); - event.getAlteredTables().add(metaData.getSchemaByName(schemaName).get(viewName)); + putTableMetaData(databaseMetaData, database, optimizerPlanners, logicDataSourceNames, schemaName, viewName, props); + event.getAlteredTables().add(databaseMetaData.getDatabase().getSchema(schemaName).get(viewName)); } ShardingSphereEventBus.getInstance().post(event); } - private void removeTableMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, + private void removeTableMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final String schemaName, final String viewName) { - metaData.getSchemaByName(schemaName).remove(viewName); - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, viewName)); + databaseMetaData.getDatabase().getSchema(schemaName).remove(viewName); + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, viewName)); database.removeTableMetadata(schemaName, viewName); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); } - private void putTableMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + private void putTableMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final String viewName, final ConfigurationProperties props) throws SQLException { - if (!containsInImmutableDataNodeContainedRule(viewName, metaData)) { - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); + if (!containsInImmutableDataNodeContainedRule(viewName, databaseMetaData)) { + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } - SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaData.getFrontendDatabaseType(), - metaData.getResource().getDatabaseType(), metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), props, schemaName); + SchemaBuilderMaterials materials = new SchemaBuilderMaterials(databaseMetaData.getProtocolType(), + databaseMetaData.getResource().getDatabaseType(), databaseMetaData.getResource().getDataSources(), databaseMetaData.getRuleMetaData().getRules(), props, schemaName); Map metaDataMap = TableMetaDataBuilder.load(Collections.singletonList(viewName), materials); Optional actualViewMetaData = Optional.ofNullable(metaDataMap.get(schemaName)).map(optional -> optional.getTables().get(viewName)); actualViewMetaData.ifPresent(optional -> { - metaData.getSchemaByName(schemaName).put(viewName, optional); + databaseMetaData.getDatabase().getSchema(schemaName).put(viewName, optional); database.putTableMetadata(schemaName, optional); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); }); } - private boolean containsInImmutableDataNodeContainedRule(final String viewName, final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() + private boolean containsInImmutableDataNodeContainedRule(final String viewName, final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() .filter(each -> !(each instanceof MutableDataNodeRule)).anyMatch(each -> each.getAllTables().contains(viewName)); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java index 962542e5ecb79..b5cd8b8d3c777 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData; import org.apache.shardingsphere.infra.metadata.schema.util.IndexMetaDataUtil; @@ -41,7 +41,7 @@ public final class CreateIndexStatementSchemaRefresher implements MetaDataRefres private static final String TYPE = CreateIndexStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final CreateIndexStatement sqlStatement, final ConfigurationProperties props) throws SQLException { String indexName = null != sqlStatement.getIndex() ? sqlStatement.getIndex().getIndexName().getIdentifier().getValue() : IndexMetaDataUtil.getGeneratedLogicIndexName(sqlStatement.getColumns()); @@ -49,9 +49,9 @@ public void refresh(final ShardingSphereMetaData metaData, final FederationDatab return; } String tableName = sqlStatement.getTable().getTableName().getIdentifier().getValue(); - metaData.getSchemaByName(schemaName).get(tableName).getIndexes().put(indexName, new IndexMetaData(indexName)); - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); - event.getAlteredTables().add(metaData.getSchemaByName(schemaName).get(tableName)); + databaseMetaData.getDatabase().getSchema(schemaName).get(tableName).getIndexes().put(indexName, new IndexMetaData(indexName)); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); + event.getAlteredTables().add(databaseMetaData.getDatabase().getSchema(schemaName).get(tableName)); ShardingSphereEventBus.getInstance().post(event); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateSchemaStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateSchemaStatementSchemaRefresher.java index 80567b4fdfc49..752b27058b18c 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateSchemaStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateSchemaStatementSchemaRefresher.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.schema.event.AddSchemaEvent; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateSchemaStatement; @@ -45,17 +45,17 @@ public final class CreateSchemaStatementSchemaRefresher implements MetaDataRefre private static final String TYPE = CreateSchemaStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final CreateSchemaStatement sqlStatement, final ConfigurationProperties props) throws SQLException { Optional schema = sqlStatement.getSchemaName().isPresent() ? sqlStatement.getSchemaName() : CreateSchemaStatementHandler.getUsername(sqlStatement); if (!schema.isPresent()) { return; } String actualSchemaName = schema.get().getValue(); - metaData.getDatabase().getSchemas().put(actualSchemaName, new ShardingSphereSchema()); + databaseMetaData.getDatabase().getSchemas().put(actualSchemaName, new ShardingSphereSchema()); database.putSchemaMetadata(actualSchemaName, new FederationSchemaMetaData(actualSchemaName, new LinkedHashMap<>())); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); - AddSchemaEvent event = new AddSchemaEvent(metaData.getDatabase().getName(), actualSchemaName); + AddSchemaEvent event = new AddSchemaEvent(databaseMetaData.getDatabase().getName(), actualSchemaName); ShardingSphereEventBus.getInstance().post(event); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java index b5fa9a2789e9f..2fcd4e697d750 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials; import org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; @@ -47,28 +47,28 @@ public final class CreateTableStatementSchemaRefresher implements MetaDataRefres private static final String TYPE = CreateTableStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final CreateTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException { String tableName = sqlStatement.getTable().getTableName().getIdentifier().getValue(); - if (!containsInImmutableDataNodeContainedRule(tableName, metaData)) { - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); + if (!containsInImmutableDataNodeContainedRule(tableName, databaseMetaData)) { + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } - SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaData.getFrontendDatabaseType(), - metaData.getResource().getDatabaseType(), metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), props, schemaName); + SchemaBuilderMaterials materials = new SchemaBuilderMaterials(databaseMetaData.getProtocolType(), + databaseMetaData.getResource().getDatabaseType(), databaseMetaData.getResource().getDataSources(), databaseMetaData.getRuleMetaData().getRules(), props, schemaName); Map metaDataMap = TableMetaDataBuilder.load(Collections.singletonList(tableName), materials); Optional actualTableMetaData = Optional.ofNullable(metaDataMap.get(schemaName)).map(optional -> optional.getTables().get(tableName)); actualTableMetaData.ifPresent(optional -> { - metaData.getSchemaByName(schemaName).put(tableName, optional); + databaseMetaData.getDatabase().getSchema(schemaName).put(tableName, optional); database.putTableMetadata(schemaName, optional); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); event.getAlteredTables().add(optional); ShardingSphereEventBus.getInstance().post(event); }); } - private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() + private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() .filter(each -> !(each instanceof MutableDataNodeRule)).anyMatch(each -> each.getAllTables().contains(tableName)); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java index e16bf2a1642e9..8b80b566dd57b 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials; import org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; @@ -47,28 +47,28 @@ public final class CreateViewStatementSchemaRefresher implements MetaDataRefresh private static final String TYPE = CreateViewStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final CreateViewStatement sqlStatement, final ConfigurationProperties props) throws SQLException { String viewName = sqlStatement.getView().getTableName().getIdentifier().getValue(); - if (!containsInImmutableDataNodeContainedRule(viewName, metaData)) { - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); + if (!containsInImmutableDataNodeContainedRule(viewName, databaseMetaData)) { + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } - SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaData.getFrontendDatabaseType(), - metaData.getResource().getDatabaseType(), metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), props, schemaName); + SchemaBuilderMaterials materials = new SchemaBuilderMaterials(databaseMetaData.getProtocolType(), + databaseMetaData.getResource().getDatabaseType(), databaseMetaData.getResource().getDataSources(), databaseMetaData.getRuleMetaData().getRules(), props, schemaName); Map metaDataMap = TableMetaDataBuilder.load(Collections.singletonList(viewName), materials); Optional actualViewMetaData = Optional.ofNullable(metaDataMap.get(schemaName)).map(optional -> optional.getTables().get(viewName)); actualViewMetaData.ifPresent(optional -> { - metaData.getSchemaByName(schemaName).put(viewName, optional); + databaseMetaData.getDatabase().getSchema(schemaName).put(viewName, optional); database.putTableMetadata(schemaName, optional); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); event.getAlteredTables().add(optional); ShardingSphereEventBus.getInstance().post(event); }); } - private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() + private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() .filter(each -> !(each instanceof MutableDataNodeRule)).anyMatch(each -> each.getAllTables().contains(tableName)); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java index 45bcc91edc72f..a01c8391b2634 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.QualifiedTable; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; @@ -46,26 +46,26 @@ public final class DropIndexStatementSchemaRefresher implements MetaDataRefreshe private static final String TYPE = DropIndexStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final DropIndexStatement sqlStatement, final ConfigurationProperties props) throws SQLException { for (IndexSegment each : sqlStatement.getIndexes()) { String actualSchemaName = each.getOwner().map(optional -> optional.getIdentifier().getValue()).orElse(schemaName); - Optional logicTableName = findLogicTableName(metaData, sqlStatement, Collections.singletonList(each)); + Optional logicTableName = findLogicTableName(databaseMetaData, sqlStatement, Collections.singletonList(each)); if (!logicTableName.isPresent()) { continue; } - TableMetaData tableMetaData = metaData.getSchemaByName(actualSchemaName).get(logicTableName.get()); + TableMetaData tableMetaData = databaseMetaData.getDatabase().getSchema(actualSchemaName).get(logicTableName.get()); tableMetaData.getIndexes().remove(each.getIndexName().getIdentifier().getValue()); - post(metaData.getDatabase().getName(), actualSchemaName, tableMetaData); + post(databaseMetaData.getDatabase().getName(), actualSchemaName, tableMetaData); } } - private Optional findLogicTableName(final ShardingSphereMetaData metaData, final DropIndexStatement sqlStatement, final Collection indexSegments) { + private Optional findLogicTableName(final ShardingSphereDatabaseMetaData databaseMetaData, final DropIndexStatement sqlStatement, final Collection indexSegments) { Optional simpleTableSegment = DropIndexStatementHandler.getSimpleTableSegment(sqlStatement); if (simpleTableSegment.isPresent()) { return Optional.of(simpleTableSegment.get().getTableName().getIdentifier().getValue()); } - Collection tableNames = IndexMetaDataUtil.getTableNamesFromMetaData(metaData, indexSegments, metaData.getResource().getDatabaseType()); + Collection tableNames = IndexMetaDataUtil.getTableNamesFromMetaData(databaseMetaData, indexSegments, databaseMetaData.getResource().getDatabaseType()); return tableNames.isEmpty() ? Optional.empty() : Optional.of(tableNames.iterator().next().getTableName()); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropSchemaStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropSchemaStatementSchemaRefresher.java index bd929129ba904..19325acd14f16 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropSchemaStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropSchemaStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.event.DropSchemaEvent; import org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropSchemaStatement; @@ -44,22 +44,22 @@ public final class DropSchemaStatementSchemaRefresher implements MetaDataRefresh private static final String TYPE = DropSchemaStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final DropSchemaStatement sqlStatement, final ConfigurationProperties props) throws SQLException { Collection tobeRemovedTables = new LinkedHashSet<>(); Collection tobeRemovedSchemas = new LinkedHashSet<>(); Collection schemaNames = getSchemaNames(sqlStatement); for (String each : schemaNames) { - Optional.ofNullable(metaData.getDatabase().getSchemas().remove(each)).ifPresent(optional -> tobeRemovedTables.addAll(optional.getAllTableNames())); + Optional.ofNullable(databaseMetaData.getDatabase().getSchemas().remove(each)).ifPresent(optional -> tobeRemovedTables.addAll(optional.getAllTableNames())); tobeRemovedSchemas.add(each.toLowerCase()); database.removeSchemaMetadata(each); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); } - Collection rules = metaData.getRuleMetaData().findRules(MutableDataNodeRule.class); + Collection rules = databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class); for (String each : tobeRemovedTables) { removeDataNode(rules, each, tobeRemovedSchemas); } - ShardingSphereEventBus.getInstance().post(new DropSchemaEvent(metaData.getDatabase().getName(), schemaNames)); + ShardingSphereEventBus.getInstance().post(new DropSchemaEvent(databaseMetaData.getDatabase().getName(), schemaNames)); } private Collection getSchemaNames(final DropSchemaStatement sqlStatement) { diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java index 90bee191488c0..62107d2c40deb 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; import org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; @@ -41,16 +41,16 @@ public final class DropTableStatementSchemaRefresher implements MetaDataRefreshe private static final String TYPE = DropTableStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final DropTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException { - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); sqlStatement.getTables().forEach(each -> { - metaData.getSchemaByName(schemaName).remove(each.getTableName().getIdentifier().getValue()); + databaseMetaData.getDatabase().getSchema(schemaName).remove(each.getTableName().getIdentifier().getValue()); database.removeTableMetadata(schemaName, each.getTableName().getIdentifier().getValue()); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); event.getDroppedTables().add(each.getTableName().getIdentifier().getValue()); }); - Collection rules = metaData.getRuleMetaData().findRules(MutableDataNodeRule.class); + Collection rules = databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class); for (SimpleTableSegment each : sqlStatement.getTables()) { removeDataNode(rules, each, schemaName); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java index ac088e8c8a8d5..7ecdf2b4ac7c9 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; import org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; @@ -40,14 +40,14 @@ public final class DropViewStatementSchemaRefresher implements MetaDataRefresher private static final String TYPE = DropViewStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final DropViewStatement sqlStatement, final ConfigurationProperties props) throws SQLException { - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); sqlStatement.getViews().forEach(each -> { - metaData.getSchemaByName(schemaName).remove(each.getTableName().getIdentifier().getValue()); + databaseMetaData.getDatabase().getSchema(schemaName).remove(each.getTableName().getIdentifier().getValue()); event.getDroppedTables().add(each.getTableName().getIdentifier().getValue()); }); - Collection rules = metaData.getRuleMetaData().findRules(MutableDataNodeRule.class); + Collection rules = databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class); for (SimpleTableSegment each : sqlStatement.getViews()) { removeDataNode(rules, each, schemaName); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java index d2fafef23c88f..e2158775f9c7a 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials; import org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder; import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent; @@ -48,46 +48,46 @@ public final class RenameTableStatementSchemaRefresher implements MetaDataRefres private static final String TYPE = RenameTableStatement.class.getName(); @Override - public void refresh(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final RenameTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException { - SchemaAlteredEvent event = new SchemaAlteredEvent(metaData.getDatabase().getName(), schemaName); + SchemaAlteredEvent event = new SchemaAlteredEvent(databaseMetaData.getDatabase().getName(), schemaName); for (RenameTableDefinitionSegment each : sqlStatement.getRenameTables()) { String tableName = each.getTable().getTableName().getIdentifier().getValue(); String renameTable = each.getRenameTable().getTableName().getIdentifier().getValue(); - putTableMetaData(metaData, database, optimizerPlanners, logicDataSourceNames, schemaName, renameTable, props); - removeTableMetaData(metaData, database, optimizerPlanners, schemaName, tableName); - event.getAlteredTables().add(metaData.getSchemaByName(schemaName).get(renameTable)); + putTableMetaData(databaseMetaData, database, optimizerPlanners, logicDataSourceNames, schemaName, renameTable, props); + removeTableMetaData(databaseMetaData, database, optimizerPlanners, schemaName, tableName); + event.getAlteredTables().add(databaseMetaData.getDatabase().getSchema(schemaName).get(renameTable)); event.getDroppedTables().add(tableName); } ShardingSphereEventBus.getInstance().post(event); } - private void removeTableMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, + private void removeTableMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final String schemaName, final String tableName) { - metaData.getSchemaByName(schemaName).remove(tableName); - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, tableName)); + databaseMetaData.getDatabase().getSchema(schemaName).remove(tableName); + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, tableName)); database.removeTableMetadata(schemaName, tableName); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); } - private void putTableMetaData(final ShardingSphereMetaData metaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + private void putTableMetaData(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final String tableName, final ConfigurationProperties props) throws SQLException { - if (!containsInImmutableDataNodeContainedRule(tableName, metaData)) { - metaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); + if (!containsInImmutableDataNodeContainedRule(tableName, databaseMetaData)) { + databaseMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } - SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaData.getFrontendDatabaseType(), - metaData.getResource().getDatabaseType(), metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), props, schemaName); + SchemaBuilderMaterials materials = new SchemaBuilderMaterials(databaseMetaData.getProtocolType(), + databaseMetaData.getResource().getDatabaseType(), databaseMetaData.getResource().getDataSources(), databaseMetaData.getRuleMetaData().getRules(), props, schemaName); Map metaDataMap = TableMetaDataBuilder.load(Collections.singletonList(tableName), materials); Optional actualTableMetaData = Optional.ofNullable(metaDataMap.get(schemaName)).map(optional -> optional.getTables().get(tableName)); actualTableMetaData.ifPresent(optional -> { - metaData.getSchemaByName(schemaName).put(tableName, optional); + databaseMetaData.getDatabase().getSchema(schemaName).put(tableName, optional); database.putTableMetadata(schemaName, optional); optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database)); }); } - private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() + private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() .filter(each -> !(each instanceof MutableDataNodeRule)).anyMatch(each -> each.getAllTables().contains(tableName)); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java index 13bae4fab1ad8..75f034febcfea 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -50,10 +50,10 @@ public void assertGenerateExecutionContext() { SQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class); when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SelectStatement.class)); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "SELECT * FROM tbl", Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap())); ConfigurationProperties props = new ConfigurationProperties(createProperties()); - ExecutionContext actual = new KernelProcessor().generateExecutionContext(logicSQL, metaData, props); + ExecutionContext actual = new KernelProcessor().generateExecutionContext(logicSQL, databaseMetaData, props); assertThat(actual.getExecutionUnits().size(), is(1)); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngineTest.java b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngineTest.java index 46f8b5e53d5a8..6296b26f82ccb 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngineTest.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefreshEngineTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.segment.table.TablesContext; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropDatabaseStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement; @@ -55,11 +55,11 @@ public void assertRefreshNonIgnorableSQLStatement() throws Exception { when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DropDatabaseStatement.class)); when(sqlStatementContext.getTablesContext()).thenReturn(mock(TablesContext.class)); when(sqlStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType()); - ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(shardingSphereMetaData.getDatabase().getName()).thenReturn("database"); - Field field = metaDataRefreshEngine.getClass().getDeclaredField("metaData"); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getDatabase().getName()).thenReturn("database"); + Field field = metaDataRefreshEngine.getClass().getDeclaredField("databaseMetaData"); field.setAccessible(true); - field.set(metaDataRefreshEngine, shardingSphereMetaData); + field.set(metaDataRefreshEngine, databaseMetaData); for (int i = 0; i < dropTimes; i++) { metaDataRefreshEngine.refresh(sqlStatementContext, Collections::emptyList); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/DummyDropDatabaseMetaDataRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/DummyDropDatabaseMetaDataRefresher.java index 3e5a15e498890..39b400167e19a 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/DummyDropDatabaseMetaDataRefresher.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/DummyDropDatabaseMetaDataRefresher.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.context.refresher.MetaDataRefresher; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropDatabaseStatement; import java.util.Collection; @@ -33,7 +33,7 @@ public final class DummyDropDatabaseMetaDataRefresher implements MetaDataRefresher { @Override - public void refresh(final ShardingSphereMetaData schemaMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, + public void refresh(final ShardingSphereDatabaseMetaData databaseMetaData, final FederationDatabaseMetaData database, final Map optimizerPlanners, final Collection logicDataSourceNames, final String schemaName, final DropDatabaseStatement sqlStatement, final ConfigurationProperties props) { sqlStatement.getDatabaseName(); } diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresherTest.java b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresherTest.java index 5e3365dc38e70..a42cf719cdba7 100644 --- a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresherTest.java +++ b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresherTest.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType; import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -55,7 +55,7 @@ public final class RenameTableStatementSchemaRefresherTest { public void assertRefresh() throws SQLException { RenameTableLister listener = new RenameTableLister(2); ShardingSphereEventBus.getInstance().register(listener); - new RenameTableStatementSchemaRefresher().refresh(createShardingSphereMetaData(), new FederationDatabaseMetaData("foo_database", Collections.emptyMap()), + new RenameTableStatementSchemaRefresher().refresh(createDatabaseMetaData(), new FederationDatabaseMetaData("foo_database", Collections.emptyMap()), new HashMap<>(), Collections.singleton("foo_ds"), "foo_schema", createRenameTableStatement(), mock(ConfigurationProperties.class)); assertThat(listener.getActualCount(), is(listener.getRenameCount())); ShardingSphereEventBus.getInstance().unregister(listener); @@ -75,8 +75,8 @@ private RenameTableDefinitionSegment createRenameTableDefinitionSegment(final St return result; } - private ShardingSphereMetaData createShardingSphereMetaData() { - return new ShardingSphereMetaData(new SQL92DatabaseType(), mockShardingSphereResource(), new ShardingSphereRuleMetaData(new LinkedList<>(), new LinkedList<>()), + private ShardingSphereDatabaseMetaData createDatabaseMetaData() { + return new ShardingSphereDatabaseMetaData(new SQL92DatabaseType(), mockShardingSphereResource(), new ShardingSphereRuleMetaData(new LinkedList<>(), new LinkedList<>()), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("foo_schema", mock(ShardingSphereSchema.class)))); } diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java index 2251924d6fc48..897e5038eb362 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java @@ -19,7 +19,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -62,14 +62,14 @@ public static boolean check(final String databaseName, final Collection parameters, final Collection rules, - final String currentDatabase, final Map metaDataMap, final Grantee grantee) { + final String currentDatabase, final Map databaseMetaDataMap, final Grantee grantee) { for (Entry entry : SQLCheckerFactory.getInstance(rules).entrySet()) { - SQLCheckResult checkResult = entry.getValue().check(sqlStatement, parameters, grantee, currentDatabase, metaDataMap, entry.getKey()); + SQLCheckResult checkResult = entry.getValue().check(sqlStatement, parameters, grantee, currentDatabase, databaseMetaDataMap, entry.getKey()); if (!checkResult.isPassed()) { throw new SQLCheckException(checkResult.getErrorMessage()); } diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java index 048b5432a22a2..da649dca46977 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.infra.executor.check; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.spi.annotation.SingletonSPI; @@ -51,11 +51,11 @@ public interface SQLChecker extends OrderedSPI * @param parameters SQL parameters * @param grantee grantee * @param currentDatabase current database - * @param metaDataMap meta data map + * @param databaseMetaDataMap database meta data map * @param rule rule * @return SQL check result */ - SQLCheckResult check(SQLStatement sqlStatement, List parameters, Grantee grantee, String currentDatabase, Map metaDataMap, T rule); + SQLCheckResult check(SQLStatement sqlStatement, List parameters, Grantee grantee, String currentDatabase, Map databaseMetaDataMap, T rule); /** * Check User. diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java index d91902db7594b..bc3a25767f2f6 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java @@ -21,7 +21,7 @@ import lombok.NoArgsConstructor; import org.apache.shardingsphere.infra.binder.segment.table.TablesContext; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult; import org.apache.shardingsphere.infra.rewrite.engine.result.RouteSQLRewriteResult; import org.apache.shardingsphere.infra.rewrite.engine.result.SQLRewriteResult; @@ -46,19 +46,20 @@ public final class ExecutionContextBuilder { /** * Build execution contexts. * - * @param metaData meta data + * @param databaseMetaData database meta data * @param sqlRewriteResult SQL rewrite result * @param sqlStatementContext SQL statement context * @return execution contexts */ - public static Collection build(final ShardingSphereMetaData metaData, final SQLRewriteResult sqlRewriteResult, final SQLStatementContext sqlStatementContext) { + public static Collection build(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLRewriteResult sqlRewriteResult, final SQLStatementContext sqlStatementContext) { return sqlRewriteResult instanceof GenericSQLRewriteResult - ? build(metaData, (GenericSQLRewriteResult) sqlRewriteResult, sqlStatementContext) + ? build(databaseMetaData, (GenericSQLRewriteResult) sqlRewriteResult, sqlStatementContext) : build((RouteSQLRewriteResult) sqlRewriteResult); } - private static Collection build(final ShardingSphereMetaData metaData, final GenericSQLRewriteResult sqlRewriteResult, final SQLStatementContext sqlStatementContext) { - Collection instanceDataSourceNames = metaData.getResource().getDataSourcesMetaData().getAllInstanceDataSourceNames(); + private static Collection build(final ShardingSphereDatabaseMetaData databaseMetaData, + final GenericSQLRewriteResult sqlRewriteResult, final SQLStatementContext sqlStatementContext) { + Collection instanceDataSourceNames = databaseMetaData.getResource().getDataSourcesMetaData().getAllInstanceDataSourceNames(); if (instanceDataSourceNames.isEmpty()) { return Collections.emptyList(); } diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java index e2be7de1276f7..857b9d84c5d58 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java @@ -99,12 +99,12 @@ private T execute(final JDBCExecutionUnit jdbcExecutionUnit, final boolean isTru } } - private DataSourceMetaData getDataSourceMetaData(final DatabaseMetaData metaData) throws SQLException { - String url = metaData.getURL(); + private DataSourceMetaData getDataSourceMetaData(final DatabaseMetaData databaseMetaData) throws SQLException { + String url = databaseMetaData.getURL(); if (CACHED_DATASOURCE_METADATA.containsKey(url)) { return CACHED_DATASOURCE_METADATA.get(url); } - DataSourceMetaData result = databaseType.getDataSourceMetaData(url, metaData.getUserName()); + DataSourceMetaData result = databaseType.getDataSourceMetaData(url, databaseMetaData.getUserName()); CACHED_DATASOURCE_METADATA.put(url, result); return result; } diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/RawSQLRuntimeContext.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/RawSQLRuntimeContext.java index 93fa3e0ba3c2f..476cb064cb712 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/RawSQLRuntimeContext.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/RawSQLRuntimeContext.java @@ -20,7 +20,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.ToString; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RawGroup; /** @@ -33,7 +33,7 @@ public final class RawSQLRuntimeContext { private final String schemaName; - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final RawGroup rawGroup; diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/check/fixture/SQLCheckerFixture.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/check/fixture/SQLCheckerFixture.java index 956eead303239..c5a3bbff5aa38 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/check/fixture/SQLCheckerFixture.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/check/fixture/SQLCheckerFixture.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.executor.check.SQLCheckResult; import org.apache.shardingsphere.infra.executor.check.SQLChecker; import org.apache.shardingsphere.infra.executor.sql.fixture.FixtureRule; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -37,7 +37,7 @@ public boolean check(final String databaseName, final Grantee grantee, final Fix @Override public SQLCheckResult check(final SQLStatement sqlStatement, final List parameters, final Grantee grantee, final String currentDatabase, - final Map metaDataMap, final FixtureRule rule) { + final Map databaseMetaDataMap, final FixtureRule rule) { return null; } diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java index da9c5fec6041c..2b8e4c477eef7 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.CachedDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.DataSourcesMetaData; @@ -62,8 +62,8 @@ public void assertBuildGenericSQLRewriteResult() { when(dataSourcesMetaData.getAllInstanceDataSourceNames()).thenReturn(Arrays.asList(firstDataSourceName, "lastDataSourceName")); ShardingSphereResource resource = new ShardingSphereResource(Collections.emptyMap(), dataSourcesMetaData, mock(CachedDatabaseMetaData.class), mock(DatabaseType.class)); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), resource, ruleMetaData, buildDatabase()); - Collection actual = ExecutionContextBuilder.build(metaData, genericSQLRewriteResult, mock(SQLStatementContext.class)); + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), resource, ruleMetaData, buildDatabase()); + Collection actual = ExecutionContextBuilder.build(databaseMetaData, genericSQLRewriteResult, mock(SQLStatementContext.class)); Collection expected = Collections.singletonList(new ExecutionUnit(firstDataSourceName, new SQLUnit(sql, parameters))); assertThat(actual, is(expected)); } @@ -79,8 +79,8 @@ public void assertBuildRouteSQLRewriteResult() { sqlRewriteUnits.put(routeUnit2, sqlRewriteUnit2); ShardingSphereResource resource = new ShardingSphereResource(Collections.emptyMap(), mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), mock(DatabaseType.class)); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), resource, ruleMetaData, buildDatabase()); - Collection actual = ExecutionContextBuilder.build(metaData, new RouteSQLRewriteResult(sqlRewriteUnits), mock(SQLStatementContext.class)); + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), resource, ruleMetaData, buildDatabase()); + Collection actual = ExecutionContextBuilder.build(databaseMetaData, new RouteSQLRewriteResult(sqlRewriteUnits), mock(SQLStatementContext.class)); ExecutionUnit expectedUnit1 = new ExecutionUnit("actualName1", new SQLUnit("sql1", Collections.singletonList("parameter1"))); ExecutionUnit expectedUnit2 = new ExecutionUnit("actualName2", new SQLUnit("sql2", Collections.singletonList("parameter2"))); Collection expected = new LinkedHashSet<>(2, 1); @@ -97,8 +97,8 @@ public void assertBuildRouteSQLRewriteResultWithEmptyPrimaryKeyMeta() { sqlRewriteUnits.put(routeUnit2, sqlRewriteUnit2); ShardingSphereResource resource = new ShardingSphereResource(Collections.emptyMap(), mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), mock(DatabaseType.class)); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), resource, ruleMetaData, buildDatabaseWithoutPrimaryKey()); - Collection actual = ExecutionContextBuilder.build(metaData, new RouteSQLRewriteResult(sqlRewriteUnits), mock(SQLStatementContext.class)); + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), resource, ruleMetaData, buildDatabaseWithoutPrimaryKey()); + Collection actual = ExecutionContextBuilder.build(databaseMetaData, new RouteSQLRewriteResult(sqlRewriteUnits), mock(SQLStatementContext.class)); ExecutionUnit expectedUnit2 = new ExecutionUnit("actualName2", new SQLUnit("sql2", Collections.singletonList("parameter2"))); Collection expected = new LinkedHashSet<>(1, 1); expected.add(expectedUnit2); diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java index 3721911b98f75..277f4484257c4 100644 --- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java +++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java @@ -59,15 +59,15 @@ public final class JDBCExecutorCallbackTest { private Connection connection; @Mock - private DatabaseMetaData metaData; + private DatabaseMetaData databaseMetaData; private Collection units; @Before public void setUp() throws SQLException { when(preparedStatement.getConnection()).thenReturn(connection); - when(connection.getMetaData()).thenReturn(metaData); - when(metaData.getURL()).thenReturn("jdbc:mysql://localhost:3306/test"); + when(connection.getMetaData()).thenReturn(databaseMetaData); + when(databaseMetaData.getURL()).thenReturn("jdbc:mysql://localhost:3306/test"); units = Collections.singletonList( new JDBCExecutionUnit(new ExecutionUnit("ds", new SQLUnit("SELECT now()", Collections.emptyList())), ConnectionMode.CONNECTION_STRICTLY, preparedStatement)); } diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationContext.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationContext.java index 58bb57eed8e18..afe5dba611261 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationContext.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationContext.java @@ -21,7 +21,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.LinkedList; @@ -40,5 +40,5 @@ public final class FederationContext { private final LogicSQL logicSQL; - private final Map metaDataMap; + private final Map databaseMetaDataMap; } diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationExecutorFactory.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationExecutorFactory.java index d275078cd7a18..984e654f5c45c 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationExecutorFactory.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/FederationExecutorFactory.java @@ -35,7 +35,7 @@ public final class FederationExecutorFactory { * * @param databaseName database name * @param schemaName schema name - * @param optimizerContext filterable optimizer context + * @param optimizerContext filterable optimizer context * @param props configuration properties * @param jdbcExecutor jdbc executor * @return created instance diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java index e8a299b417478..823f701cac768 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/original/table/FilterableTableScanExecutor.java @@ -69,7 +69,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationTableMetaData; import org.apache.shardingsphere.infra.merge.MergeEngine; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -137,25 +137,25 @@ public Enumerable execute(final FederationTableMetaData tableMetaData, SqlString sqlString = createSQLString(tableMetaData, scanContext, databaseType); // TODO replace sql parse with sql convert FederationContext federationContext = executorContext.getFederationContext(); - LogicSQL logicSQL = createLogicSQL(federationContext.getMetaDataMap(), sqlString, databaseType); - ShardingSphereMetaData metaData = federationContext.getMetaDataMap().get(databaseName); - ExecutionContext context = new KernelProcessor().generateExecutionContext(logicSQL, metaData, executorContext.getProps()); + LogicSQL logicSQL = createLogicSQL(federationContext.getDatabaseMetaDataMap(), sqlString, databaseType); + ShardingSphereDatabaseMetaData databaseMetaData = federationContext.getDatabaseMetaDataMap().get(databaseName); + ExecutionContext context = new KernelProcessor().generateExecutionContext(logicSQL, databaseMetaData, executorContext.getProps()); if (federationContext.isPreview() || databaseType.getSystemSchemas().contains(schemaName)) { federationContext.getExecutionUnits().addAll(context.getExecutionUnits()); return createEmptyEnumerable(); } - return execute(schemaName, databaseType, logicSQL, metaData, context); + return execute(schemaName, databaseType, logicSQL, databaseMetaData, context); } private AbstractEnumerable execute(final String schemaName, final DatabaseType databaseType, final LogicSQL logicSQL, - final ShardingSphereMetaData metaData, final ExecutionContext context) { + final ShardingSphereDatabaseMetaData databaseMetaData, final ExecutionContext context) { try { ExecutionGroupContext executionGroupContext = prepareEngine.prepare(context.getRouteContext(), context.getExecutionUnits()); setParameters(executionGroupContext.getInputGroups()); ExecuteProcessEngine.initialize(context.getLogicSQL(), executionGroupContext, executorContext.getProps()); List queryResults = execute(executionGroupContext); ExecuteProcessEngine.finish(executionGroupContext.getExecutionID()); - MergeEngine mergeEngine = new MergeEngine(schemaName, databaseType, metaData, executorContext.getProps(), metaData.getRuleMetaData().getRules()); + MergeEngine mergeEngine = new MergeEngine(schemaName, databaseType, databaseMetaData, executorContext.getProps(), databaseMetaData.getRuleMetaData().getRules()); MergedResult mergedResult = mergeEngine.merge(queryResults, logicSQL.getSqlStatementContext()); Collection statements = getStatements(executionGroupContext.getInputGroups()); return createEnumerable(mergedResult, queryResults.get(0).getMetaData(), statements); @@ -254,13 +254,13 @@ public Enumerator enumerator() { }; } - private LogicSQL createLogicSQL(final Map metaDataMap, final SqlString sqlString, final DatabaseType databaseType) { + private LogicSQL createLogicSQL(final Map databaseMetaDataMap, final SqlString sqlString, final DatabaseType databaseType) { String sql = sqlString.getSql().replace("\n", " "); SQLStatement sqlStatement = new SQLStatementParserEngine(databaseType.getType(), optimizerContext.getSqlParserRule().getSqlStatementCache(), optimizerContext.getSqlParserRule().getParseTreeCache(), optimizerContext.getSqlParserRule().isSqlCommentParseEnabled()).parse(sql, false); List parameters = getParameters(sqlString.getDynamicParameters()); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataMap, parameters, sqlStatement, executorContext.getDatabaseName()); + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(databaseMetaDataMap, parameters, sqlStatement, executorContext.getDatabaseName()); return new LogicSQL(sqlStatementContext, sql, parameters); } diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/OptimizerContextFactory.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/OptimizerContextFactory.java index ee73dbdc63201..1d1b756c53f7c 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/OptimizerContextFactory.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/OptimizerContextFactory.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.parser.rule.SQLParserRule; @@ -39,13 +39,13 @@ public final class OptimizerContextFactory { /** * Create optimize context. * - * @param metaDataMap meta data map + * @param databaseMetaDataMap database meta data map * @param globalRuleMetaData global rule meta data * @return created optimizer context */ - public static OptimizerContext create(final Map metaDataMap, final ShardingSphereRuleMetaData globalRuleMetaData) { - FederationMetaData federationMetaData = new FederationMetaData(metaDataMap); - Map parserContexts = OptimizerParserContextFactory.create(metaDataMap); + public static OptimizerContext create(final Map databaseMetaDataMap, final ShardingSphereRuleMetaData globalRuleMetaData) { + FederationMetaData federationMetaData = new FederationMetaData(databaseMetaDataMap); + Map parserContexts = OptimizerParserContextFactory.create(databaseMetaDataMap); Map plannerContexts = OptimizerPlannerContextFactory.create(federationMetaData); SQLParserRule sqlParserRule = globalRuleMetaData.findSingleRule(SQLParserRule.class).orElse(null); return new OptimizerContext(sqlParserRule, federationMetaData, parserContexts, plannerContexts); diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java index 24a00e244fa2f..9dc8576ecd250 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java @@ -21,7 +21,7 @@ import lombok.RequiredArgsConstructor; import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.shardingsphere.infra.database.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.federation.optimizer.context.parser.dialect.OptimizerSQLDialectBuilderFactory; import java.util.HashMap; @@ -39,12 +39,12 @@ public final class OptimizerParserContextFactory { /** * Create optimizer parser context map. * - * @param metaDataMap meta data map + * @param databaseMetaDataMap meta data map * @return created optimizer parser context map */ - public static Map create(final Map metaDataMap) { + public static Map create(final Map databaseMetaDataMap) { Map result = new HashMap<>(); - for (Entry entry : metaDataMap.entrySet()) { + for (Entry entry : databaseMetaDataMap.entrySet()) { DatabaseType databaseType = entry.getValue().getResource().getDatabaseType(); result.put(entry.getKey(), new OptimizerParserContext(databaseType, createSQLDialectProperties(databaseType))); } diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/FederationMetaData.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/FederationMetaData.java index 96b0f83638525..1f0cd0fd4b1da 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/FederationMetaData.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/FederationMetaData.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.federation.optimizer.metadata; import lombok.Getter; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.LinkedHashMap; import java.util.Map; @@ -32,9 +32,9 @@ public final class FederationMetaData { private final Map databases; - public FederationMetaData(final Map metaDataMap) { - databases = new LinkedHashMap<>(metaDataMap.size(), 1); - for (Entry entry : metaDataMap.entrySet()) { + public FederationMetaData(final Map databaseMetaDataMap) { + databases = new LinkedHashMap<>(databaseMetaDataMap.size(), 1); + for (Entry entry : databaseMetaDataMap.entrySet()) { databases.put(entry.getKey().toLowerCase(), new FederationDatabaseMetaData(entry.getKey(), entry.getValue().getDatabase().getSchemas())); } } diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/ShardingSphereOptimizerTest.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/ShardingSphereOptimizerTest.java index 0520d94380e8f..1ce2c64029035 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/ShardingSphereOptimizerTest.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/ShardingSphereOptimizerTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine; import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContextFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -109,9 +109,9 @@ public void init() throws Exception { Map tableMetaDataMap = new HashMap<>(2, 1); tableMetaDataMap.put("t_order_federate", createOrderTableMetaData()); tableMetaDataMap.put("t_user_info", createUserInfoTableMetaData()); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( new H2DatabaseType(), mockResource(), null, new ShardingSphereDatabase(databaseName, Collections.singletonMap(schemaName, new ShardingSphereSchema(tableMetaDataMap)))); - optimizer = new ShardingSphereOptimizer(OptimizerContextFactory.create(Collections.singletonMap(databaseName, metaData), createGlobalRuleMetaData())); + optimizer = new ShardingSphereOptimizer(OptimizerContextFactory.create(Collections.singletonMap(databaseName, databaseMetaData), createGlobalRuleMetaData())); } private ShardingSphereRuleMetaData createGlobalRuleMetaData() { diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java index 1bc39368e6610..33ffd275f42fc 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.merge.engine.merger.ResultMergerEngine; import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import java.sql.SQLException; @@ -48,18 +48,18 @@ public final class MergeEngine { private final DatabaseType databaseType; - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final ConfigurationProperties props; @SuppressWarnings("rawtypes") private final Map engines; - public MergeEngine(final String databaseName, final DatabaseType databaseType, final ShardingSphereMetaData metaData, + public MergeEngine(final String databaseName, final DatabaseType databaseType, final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props, final Collection rules) { this.databaseName = databaseName; this.databaseType = databaseType; - this.metaData = metaData; + this.databaseMetaData = databaseMetaData; this.props = props; engines = ResultProcessEngineFactory.getInstances(rules); } @@ -83,7 +83,7 @@ private Optional executeMerge(final List queryResults for (Entry entry : engines.entrySet()) { if (entry.getValue() instanceof ResultMergerEngine) { ResultMerger resultMerger = ((ResultMergerEngine) entry.getValue()).newInstance(databaseName, databaseType, entry.getKey(), props, sqlStatementContext); - return Optional.of(resultMerger.merge(queryResults, sqlStatementContext, metaData)); + return Optional.of(resultMerger.merge(queryResults, sqlStatementContext, databaseMetaData)); } } return Optional.empty(); @@ -94,7 +94,7 @@ private MergedResult decorate(final MergedResult mergedResult, final SQLStatemen MergedResult result = null; for (Entry entry : engines.entrySet()) { if (entry.getValue() instanceof ResultDecoratorEngine) { - ResultDecorator resultDecorator = ((ResultDecoratorEngine) entry.getValue()).newInstance(databaseType, databaseName, metaData, entry.getKey(), props, sqlStatementContext); + ResultDecorator resultDecorator = ((ResultDecoratorEngine) entry.getValue()).newInstance(databaseType, databaseName, databaseMetaData, entry.getKey(), props, sqlStatementContext); result = null == result ? resultDecorator.decorate(mergedResult, sqlStatementContext, entry.getKey()) : resultDecorator.decorate(result, sqlStatementContext, entry.getKey()); } } @@ -106,7 +106,7 @@ private Optional decorate(final QueryResult queryResult, final SQL MergedResult result = null; for (Entry entry : engines.entrySet()) { if (entry.getValue() instanceof ResultDecoratorEngine) { - ResultDecorator resultDecorator = ((ResultDecoratorEngine) entry.getValue()).newInstance(databaseType, databaseName, metaData, entry.getKey(), props, sqlStatementContext); + ResultDecorator resultDecorator = ((ResultDecoratorEngine) entry.getValue()).newInstance(databaseType, databaseName, databaseMetaData, entry.getKey(), props, sqlStatementContext); result = null == result ? resultDecorator.decorate(queryResult, sqlStatementContext, entry.getKey()) : resultDecorator.decorate(result, sqlStatementContext, entry.getKey()); } } diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/decorator/ResultDecoratorEngine.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/decorator/ResultDecoratorEngine.java index ec16eb1a1caf5..2c2000652f68e 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/decorator/ResultDecoratorEngine.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/decorator/ResultDecoratorEngine.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.merge.engine.ResultProcessEngine; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; /** @@ -36,11 +36,12 @@ public interface ResultDecoratorEngine extends Res * * @param databaseType database type * @param databaseName database name - * @param metaData ShardingSphere metaData + * @param databaseMetaData database meta data * @param rule rule - * @param props ShardingSphere properties + * @param props configuration properties * @param sqlStatementContext SQL statement context * @return created instance */ - ResultDecorator newInstance(DatabaseType databaseType, String databaseName, ShardingSphereMetaData metaData, T rule, ConfigurationProperties props, SQLStatementContext sqlStatementContext); + ResultDecorator newInstance(DatabaseType databaseType, String databaseName, + ShardingSphereDatabaseMetaData databaseMetaData, T rule, ConfigurationProperties props, SQLStatementContext sqlStatementContext); } diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/ResultMerger.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/ResultMerger.java index f12a93371fa4c..2cd6fcbab794f 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/ResultMerger.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/ResultMerger.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.sql.SQLException; import java.util.List; @@ -35,9 +35,9 @@ public interface ResultMerger { * * @param queryResults query results * @param sqlStatementContext SQL statement context - * @param metaData ShardingSphere metaData + * @param databaseMetaData database meta data * @return merged result * @throws SQLException SQL exception */ - MergedResult merge(List queryResults, SQLStatementContext sqlStatementContext, ShardingSphereMetaData metaData) throws SQLException; + MergedResult merge(List queryResults, SQLStatementContext sqlStatementContext, ShardingSphereDatabaseMetaData databaseMetaData) throws SQLException; } diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMerger.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMerger.java index f35fc1bdfaf3a..f4a6ad18fd22e 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMerger.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMerger.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.merge.engine.merger.ResultMerger; import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.List; @@ -32,7 +32,7 @@ public final class TransparentResultMerger implements ResultMerger { @Override - public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereMetaData metaData) { + public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereDatabaseMetaData databaseMetaData) { return new TransparentMergedResult(queryResults.get(0)); } } diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java index cf889bc7b51b7..31edd793edd9e 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/MergeEngineTest.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.merge.fixture.rule.IndependentRuleFixture; import org.apache.shardingsphere.infra.merge.fixture.rule.MergerRuleFixture; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,7 +47,7 @@ public final class MergeEngineTest { private DatabaseType databaseType; @Mock - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ConfigurationProperties props; @@ -61,28 +61,28 @@ public final class MergeEngineTest { @Test public void assertMergeWithIndependentRule() throws SQLException { when(queryResult.getValue(1, String.class)).thenReturn("test"); - MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, metaData, props, Collections.singletonList(new IndependentRuleFixture())); + MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, databaseMetaData, props, Collections.singletonList(new IndependentRuleFixture())); MergedResult actual = mergeEngine.merge(Collections.singletonList(queryResult), sqlStatementContext); assertThat(actual.getValue(1, String.class), is("test")); } @Test public void assertMergeWithMergerRuleOnly() throws SQLException { - MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, metaData, props, Collections.singletonList(new MergerRuleFixture())); + MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, databaseMetaData, props, Collections.singletonList(new MergerRuleFixture())); MergedResult actual = mergeEngine.merge(Collections.singletonList(queryResult), sqlStatementContext); assertThat(actual.getValue(1, String.class), is("merged_value")); } @Test public void assertMergeWithDecoratorRuleOnly() throws SQLException { - MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, metaData, props, Collections.singletonList(new DecoratorRuleFixture())); + MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, databaseMetaData, props, Collections.singletonList(new DecoratorRuleFixture())); MergedResult actual = mergeEngine.merge(Collections.singletonList(queryResult), sqlStatementContext); assertThat(actual.getValue(1, String.class), is("decorated_value")); } @Test public void assertMergeWithMergerRuleAndDecoratorRuleTogether() throws SQLException { - MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, metaData, props, Arrays.asList(new MergerRuleFixture(), new DecoratorRuleFixture())); + MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseType, databaseMetaData, props, Arrays.asList(new MergerRuleFixture(), new DecoratorRuleFixture())); MergedResult actual = mergeEngine.merge(Collections.singletonList(queryResult), sqlStatementContext); assertThat(actual.getValue(1, String.class), is("decorated_merged_value")); } diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMergerTest.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMergerTest.java index 3a62ce1a8f4d1..3f4df1a8fea3d 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMergerTest.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/engine/merger/impl/TransparentResultMergerTest.java @@ -19,8 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; -import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.junit.Test; import java.sql.SQLException; @@ -36,8 +35,6 @@ public final class TransparentResultMergerTest { public void assertMerge() throws SQLException { QueryResult queryResult = mock(QueryResult.class); when(queryResult.next()).thenReturn(true); - TransparentResultMerger merger = new TransparentResultMerger(); - MergedResult actual = merger.merge(Collections.singletonList(queryResult), mock(SQLStatementContext.class), mock(ShardingSphereMetaData.class)); - assertTrue(actual.next()); + assertTrue(new TransparentResultMerger().merge(Collections.singletonList(queryResult), mock(SQLStatementContext.class), mock(ShardingSphereDatabaseMetaData.class)).next()); } } diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/decorator/ResultDecoratorEngineFixture.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/decorator/ResultDecoratorEngineFixture.java index 5e0bd0ea2c651..ccab90ee40a97 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/decorator/ResultDecoratorEngineFixture.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/decorator/ResultDecoratorEngineFixture.java @@ -23,12 +23,12 @@ import org.apache.shardingsphere.infra.merge.engine.decorator.ResultDecorator; import org.apache.shardingsphere.infra.merge.engine.decorator.ResultDecoratorEngine; import org.apache.shardingsphere.infra.merge.fixture.rule.DecoratorRuleFixture; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; public final class ResultDecoratorEngineFixture implements ResultDecoratorEngine { @Override - public ResultDecorator newInstance(final DatabaseType databaseType, final String databaseName, final ShardingSphereMetaData metaData, + public ResultDecorator newInstance(final DatabaseType databaseType, final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final DecoratorRuleFixture rule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext) { return new ResultDecoratorFixture(); } diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/merger/ResultMergerFixture.java b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/merger/ResultMergerFixture.java index 9fac94a792e4a..1397f514285c4 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/merger/ResultMergerFixture.java +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/merger/ResultMergerFixture.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.merge.engine.merger.ResultMerger; import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; @@ -35,7 +35,7 @@ public final class ResultMergerFixture implements ResultMerger { @Override - public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereMetaData metaData) throws SQLException { + public MergedResult merge(final List queryResults, final SQLStatementContext sqlStatementContext, final ShardingSphereDatabaseMetaData databaseMetaData) throws SQLException { ResultSet resultSet = mock(ResultSet.class); when(resultSet.getString(1)).thenReturn("merged_value"); QueryResult queryResult = new JDBCStreamQueryResult(resultSet); diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java index 3afa56732d1f5..94ed143533a5a 100644 --- a/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java +++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator; import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecoratorFactory; @@ -41,17 +41,17 @@ */ public final class SQLRewriteEntry { - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final ConfigurationProperties props; @SuppressWarnings("rawtypes") private final Map decorators; - public SQLRewriteEntry(final ShardingSphereMetaData metaData, final ConfigurationProperties props) { - this.metaData = metaData; + public SQLRewriteEntry(final ShardingSphereDatabaseMetaData databaseMetaData, final ConfigurationProperties props) { + this.databaseMetaData = databaseMetaData; this.props = props; - decorators = SQLRewriteContextDecoratorFactory.getInstance(metaData.getRuleMetaData().getRules()); + decorators = SQLRewriteContextDecoratorFactory.getInstance(databaseMetaData.getRuleMetaData().getRules()); } /** @@ -65,16 +65,16 @@ public SQLRewriteEntry(final ShardingSphereMetaData metaData, final Configuratio */ public SQLRewriteResult rewrite(final String sql, final List parameters, final SQLStatementContext sqlStatementContext, final RouteContext routeContext) { SQLRewriteContext sqlRewriteContext = createSQLRewriteContext(sql, parameters, sqlStatementContext, routeContext); - SQLTranslatorRule rule = metaData.getRuleMetaData().findSingleRule(SQLTranslatorRule.class).orElse(new SQLTranslatorRule(new SQLTranslatorRuleConfiguration())); - DatabaseType frontendDatabaseType = metaData.getFrontendDatabaseType(); - DatabaseType backendDatabaseType = metaData.getResource().getDatabaseType(); + SQLTranslatorRule rule = databaseMetaData.getRuleMetaData().findSingleRule(SQLTranslatorRule.class).orElse(new SQLTranslatorRule(new SQLTranslatorRuleConfiguration())); + DatabaseType frontendDatabaseType = databaseMetaData.getProtocolType(); + DatabaseType backendDatabaseType = databaseMetaData.getResource().getDatabaseType(); return routeContext.getRouteUnits().isEmpty() ? new GenericSQLRewriteEngine(rule, frontendDatabaseType, backendDatabaseType).rewrite(sqlRewriteContext) : new RouteSQLRewriteEngine(rule, frontendDatabaseType, backendDatabaseType).rewrite(sqlRewriteContext, routeContext); } private SQLRewriteContext createSQLRewriteContext(final String sql, final List parameters, final SQLStatementContext sqlStatementContext, final RouteContext routeContext) { - SQLRewriteContext result = new SQLRewriteContext(metaData.getDatabase().getName(), metaData.getDatabase().getSchemas(), sqlStatementContext, sql, parameters); + SQLRewriteContext result = new SQLRewriteContext(databaseMetaData.getDatabase().getName(), databaseMetaData.getDatabase().getSchemas(), sqlStatementContext, sql, parameters); decorate(decorators, result, routeContext); result.generateSQLTokens(); return result; diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java index 07c669b2a5e45..cddd11635c4f5 100644 --- a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java +++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -49,9 +49,9 @@ public final class SQLRewriteEntryTest { @Test public void assertRewriteForGenericSQLRewriteResult() { - ShardingSphereMetaData metaData = new ShardingSphereMetaData(DatabaseTypeFactory.getInstance("H2"), + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(DatabaseTypeFactory.getInstance("H2"), mockResource(), mockRuleMetaData(), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("test", mock(ShardingSphereSchema.class)))); - SQLRewriteEntry sqlRewriteEntry = new SQLRewriteEntry(metaData, new ConfigurationProperties(new Properties())); + SQLRewriteEntry sqlRewriteEntry = new SQLRewriteEntry(databaseMetaData, new ConfigurationProperties(new Properties())); RouteContext routeContext = new RouteContext(); GenericSQLRewriteResult sqlRewriteResult = (GenericSQLRewriteResult) sqlRewriteEntry.rewrite("SELECT ?", Collections.singletonList(1), mock(SQLStatementContext.class), routeContext); assertThat(sqlRewriteResult.getSqlRewriteUnit().getSql(), is("SELECT ?")); @@ -60,9 +60,9 @@ public void assertRewriteForGenericSQLRewriteResult() { @Test public void assertRewriteForRouteSQLRewriteResult() { - ShardingSphereMetaData metaData = new ShardingSphereMetaData(DatabaseTypeFactory.getInstance("H2"), + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(DatabaseTypeFactory.getInstance("H2"), mockResource(), mockRuleMetaData(), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.singletonMap("test", mock(ShardingSphereSchema.class)))); - SQLRewriteEntry sqlRewriteEntry = new SQLRewriteEntry(metaData, new ConfigurationProperties(new Properties())); + SQLRewriteEntry sqlRewriteEntry = new SQLRewriteEntry(databaseMetaData, new ConfigurationProperties(new Properties())); RouteContext routeContext = new RouteContext(); RouteUnit firstRouteUnit = mock(RouteUnit.class); when(firstRouteUnit.getDataSourceMapper()).thenReturn(new RouteMapper("ds", "ds_0")); diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SQLRouter.java b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SQLRouter.java index bd0050f610de7..ac03d9af21ea9 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SQLRouter.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/SQLRouter.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.spi.annotation.SingletonSPI; @@ -37,21 +37,21 @@ public interface SQLRouter extends OrderedSPI { * Create route context. * * @param logicSQL logic SQL - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param rule rule * @param props configuration properties * @return route context */ - RouteContext createRouteContext(LogicSQL logicSQL, ShardingSphereMetaData metaData, T rule, ConfigurationProperties props); + RouteContext createRouteContext(LogicSQL logicSQL, ShardingSphereDatabaseMetaData databaseMetaData, T rule, ConfigurationProperties props); /** * Decorate route context. * * @param routeContext route context * @param logicSQL logic SQL - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param rule rule * @param props configuration properties */ - void decorateRouteContext(RouteContext routeContext, LogicSQL logicSQL, ShardingSphereMetaData metaData, T rule, ConfigurationProperties props); + void decorateRouteContext(RouteContext routeContext, LogicSQL logicSQL, ShardingSphereDatabaseMetaData databaseMetaData, T rule, ConfigurationProperties props); } diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngine.java b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngine.java index d77133816c2d8..d4ca74d133aa3 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngine.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngine.java @@ -20,7 +20,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.engine.impl.AllSQLRouteExecutor; import org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor; @@ -45,12 +45,12 @@ public final class SQLRouteEngine { * Route SQL. * * @param logicSQL logic SQL - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @return route context */ - public RouteContext route(final LogicSQL logicSQL, final ShardingSphereMetaData metaData) { + public RouteContext route(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData) { SQLRouteExecutor executor = isNeedAllSchemas(logicSQL.getSqlStatementContext().getSqlStatement()) ? new AllSQLRouteExecutor() : new PartialSQLRouteExecutor(rules, props); - return executor.route(logicSQL, metaData); + return executor.route(logicSQL, databaseMetaData); } // TODO use dynamic config to judge UnconfiguredSchema diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteExecutor.java b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteExecutor.java index 154a2b864a33c..4160ff7802155 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteExecutor.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/SQLRouteExecutor.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.route.context.RouteContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; /** * SQL route executor. @@ -30,8 +30,8 @@ public interface SQLRouteExecutor { * Route. * * @param logicSQL logic SQL - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @return route context */ - RouteContext route(LogicSQL logicSQL, ShardingSphereMetaData metaData); + RouteContext route(LogicSQL logicSQL, ShardingSphereDatabaseMetaData databaseMetaData); } diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java index 422081511661a..f9fbec0bdae16 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/AllSQLRouteExecutor.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.route.engine.impl; import org.apache.shardingsphere.infra.binder.LogicSQL; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; @@ -32,9 +32,9 @@ public final class AllSQLRouteExecutor implements SQLRouteExecutor { @Override - public RouteContext route(final LogicSQL logicSQL, final ShardingSphereMetaData metaData) { + public RouteContext route(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData) { RouteContext result = new RouteContext(); - for (String each : metaData.getResource().getDataSources().keySet()) { + for (String each : databaseMetaData.getResource().getDataSources().keySet()) { result.getRouteUnits().add(new RouteUnit(new RouteMapper(each, each), Collections.emptyList())); } return result; diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java index a39e48f589e25..f73cae26ae319 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; import org.apache.shardingsphere.infra.hint.HintManager; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.SQLRouter; import org.apache.shardingsphere.infra.route.SQLRouterFactory; import org.apache.shardingsphere.infra.route.context.RouteContext; @@ -56,22 +56,22 @@ public PartialSQLRouteExecutor(final Collection rules, final @Override @SuppressWarnings({"unchecked", "rawtypes"}) - public RouteContext route(final LogicSQL logicSQL, final ShardingSphereMetaData metaData) { + public RouteContext route(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData) { RouteContext result = new RouteContext(); - Optional dataSourceName = findDataSourceByHint(logicSQL.getSqlStatementContext(), metaData.getResource().getDataSources()); + Optional dataSourceName = findDataSourceByHint(logicSQL.getSqlStatementContext(), databaseMetaData.getResource().getDataSources()); if (dataSourceName.isPresent()) { result.getRouteUnits().add(new RouteUnit(new RouteMapper(dataSourceName.get(), dataSourceName.get()), Collections.emptyList())); return result; } for (Entry entry : routers.entrySet()) { if (result.getRouteUnits().isEmpty()) { - result = entry.getValue().createRouteContext(logicSQL, metaData, entry.getKey(), props); + result = entry.getValue().createRouteContext(logicSQL, databaseMetaData, entry.getKey(), props); } else { - entry.getValue().decorateRouteContext(result, logicSQL, metaData, entry.getKey(), props); + entry.getValue().decorateRouteContext(result, logicSQL, databaseMetaData, entry.getKey(), props); } } - if (result.getRouteUnits().isEmpty() && 1 == metaData.getResource().getDataSources().size()) { - String singleDataSourceName = metaData.getResource().getDataSources().keySet().iterator().next(); + if (result.getRouteUnits().isEmpty() && 1 == databaseMetaData.getResource().getDataSources().size()) { + String singleDataSourceName = databaseMetaData.getResource().getDataSources().keySet().iterator().next(); result.getRouteUnits().add(new RouteUnit(new RouteMapper(singleDataSourceName, singleDataSourceName), Collections.emptyList())); } return result; diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java index 31c9b540e8c7a..effcd7ce614db 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/AllSQLRouteExecutorTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.route.engine; import org.apache.shardingsphere.infra.binder.LogicSQL; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteUnit; import org.apache.shardingsphere.infra.route.engine.impl.AllSQLRouteExecutor; @@ -42,10 +42,10 @@ public final class AllSQLRouteExecutorTest { @Test public void assertRouteSuccess() { String name = "test"; - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getResource().getDataSources().keySet()).thenReturn(Stream.of(name).collect(Collectors.toSet())); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getResource().getDataSources().keySet()).thenReturn(Stream.of(name).collect(Collectors.toSet())); AllSQLRouteExecutor allSQLRouteExecutor = new AllSQLRouteExecutor(); - RouteContext actual = allSQLRouteExecutor.route(mock(LogicSQL.class), metaData); + RouteContext actual = allSQLRouteExecutor.route(mock(LogicSQL.class), databaseMetaData); assertThat(actual.getRouteUnits().size(), is(1)); RouteUnit routeUnit = actual.getRouteUnits().iterator().next(); assertThat(routeUnit.getDataSourceMapper().getLogicName(), is(name)); diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/PartialSQLRouteExecutorTest.java b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/PartialSQLRouteExecutorTest.java index 9fb205ccd23d3..da71c312fd2bb 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/PartialSQLRouteExecutorTest.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/PartialSQLRouteExecutorTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.exception.ShardingSphereException; import org.apache.shardingsphere.infra.hint.HintManager; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor; import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement; @@ -50,7 +50,7 @@ public final class PartialSQLRouteExecutorTest { private final PartialSQLRouteExecutor partialSQLRouteExecutor = new PartialSQLRouteExecutor(Collections.emptyList(), new ConfigurationProperties(new Properties())); @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData shardingSphereMetaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private CommonSQLStatementContext commonSQLStatementContext; @@ -60,14 +60,14 @@ public void setup() { Map dataSourceMap = new HashMap<>(); dataSourceMap.put("ds_0", null); dataSourceMap.put("ds_1", null); - when(shardingSphereMetaData.getResource().getDataSources()).thenReturn(dataSourceMap); + when(databaseMetaData.getResource().getDataSources()).thenReturn(dataSourceMap); } @Test public void assertRouteBySQLCommentHint() { when(commonSQLStatementContext.findHintDataSourceName()).thenReturn(Optional.of("ds_1")); LogicSQL logicSQL = new LogicSQL(commonSQLStatementContext, "", Collections.emptyList()); - RouteContext routeContext = partialSQLRouteExecutor.route(logicSQL, shardingSphereMetaData); + RouteContext routeContext = partialSQLRouteExecutor.route(logicSQL, databaseMetaData); assertThat(routeContext.getRouteUnits().size(), is(1)); assertThat(routeContext.getRouteUnits().iterator().next().getDataSourceMapper().getActualName(), is("ds_1")); } @@ -77,7 +77,7 @@ public void assertRouteByHintManagerHint() { try (HintManager hintManager = HintManager.getInstance()) { hintManager.setDataSourceName("ds_1"); LogicSQL logicSQL = new LogicSQL(commonSQLStatementContext, "", Collections.emptyList()); - RouteContext routeContext = partialSQLRouteExecutor.route(logicSQL, shardingSphereMetaData); + RouteContext routeContext = partialSQLRouteExecutor.route(logicSQL, databaseMetaData); assertThat(routeContext.getRouteUnits().size(), is(1)); assertThat(routeContext.getRouteUnits().iterator().next().getDataSourceMapper().getActualName(), is("ds_1")); } @@ -87,7 +87,7 @@ public void assertRouteByHintManagerHint() { public void assertRouteBySQLCommentHintWithException() { when(commonSQLStatementContext.findHintDataSourceName()).thenReturn(Optional.of("ds_3")); LogicSQL logicSQL = new LogicSQL(commonSQLStatementContext, "", Collections.emptyList()); - partialSQLRouteExecutor.route(logicSQL, shardingSphereMetaData); + partialSQLRouteExecutor.route(logicSQL, databaseMetaData); } @Test(expected = ShardingSphereException.class) @@ -95,7 +95,7 @@ public void assertRouteByHintManagerHintWithException() { try (HintManager hintManager = HintManager.getInstance()) { hintManager.setDataSourceName("ds-3"); LogicSQL logicSQL = new LogicSQL(commonSQLStatementContext, "", Collections.emptyList()); - partialSQLRouteExecutor.route(logicSQL, shardingSphereMetaData); + partialSQLRouteExecutor.route(logicSQL, databaseMetaData); } } } diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java index d3b415b8d2b71..7b57558b86143 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -52,10 +52,10 @@ public final class SQLRouteEngineTest { public void assertRouteSuccess() { LogicSQL logicSQL = new LogicSQL(mock(CommonSQLStatementContext.class), "SELECT 1", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(new RouteRuleFixture())); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase("logic_schema", Collections.emptyMap())); SQLRouteEngine sqlRouteEngine = new SQLRouteEngine(Collections.singleton(new RouteRuleFixture()), props); - RouteContext actual = sqlRouteEngine.route(logicSQL, metaData); + RouteContext actual = sqlRouteEngine.route(logicSQL, databaseMetaData); assertThat(actual.getRouteUnits().size(), is(1)); RouteUnit routeUnit = actual.getRouteUnits().iterator().next(); assertThat(routeUnit.getDataSourceMapper().getLogicName(), is("ds")); @@ -67,9 +67,9 @@ public void assertRouteSuccess() { public void assertRouteFailure() { LogicSQL logicSQL = new LogicSQL(mock(CommonSQLStatementContext.class), "SELECT 1", Collections.emptyList()); ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(new RouteRuleFixture())); - ShardingSphereMetaData metaData = new ShardingSphereMetaData( + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS), ruleMetaData, new ShardingSphereDatabase("logic_schema", Collections.emptyMap())); SQLRouteEngine sqlRouteEngine = new SQLRouteEngine(Collections.singleton(new RouteFailureRuleFixture()), props); - sqlRouteEngine.route(logicSQL, metaData); + sqlRouteEngine.route(logicSQL, databaseMetaData); } } diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFailureFixture.java b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFailureFixture.java index 29ad3e67a088f..f79774683946f 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFailureFixture.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFailureFixture.java @@ -21,19 +21,19 @@ import org.apache.shardingsphere.infra.route.SQLRouter; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.fixture.rule.RouteFailureRuleFixture; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.binder.LogicSQL; public final class SQLRouterFailureFixture implements SQLRouter { @Override - public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final RouteFailureRuleFixture rule, final ConfigurationProperties props) { + public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final RouteFailureRuleFixture rule, final ConfigurationProperties props) { throw new UnsupportedOperationException("Route failure."); } @Override public void decorateRouteContext(final RouteContext routeContext, - final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final RouteFailureRuleFixture rule, final ConfigurationProperties props) { + final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final RouteFailureRuleFixture rule, final ConfigurationProperties props) { throw new UnsupportedOperationException("Route failure."); } diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java index adb745048698d..af6b9584efb52 100644 --- a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java +++ b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; import org.apache.shardingsphere.infra.route.fixture.rule.RouteRuleFixture; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.binder.LogicSQL; import java.util.Collections; @@ -31,7 +31,7 @@ public final class SQLRouterFixture implements SQLRouter { @Override - public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final RouteRuleFixture rule, final ConfigurationProperties props) { + public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final RouteRuleFixture rule, final ConfigurationProperties props) { RouteContext result = new RouteContext(); result.getRouteUnits().add(new RouteUnit(new RouteMapper("ds", "ds_0"), Collections.emptyList())); return result; @@ -39,7 +39,7 @@ public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSp @Override public void decorateRouteContext(final RouteContext routeContext, - final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final RouteRuleFixture rule, final ConfigurationProperties props) { + final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final RouteRuleFixture rule, final ConfigurationProperties props) { routeContext.getRouteUnits().add(new RouteUnit(new RouteMapper("ds", "ds_0"), Collections.emptyList())); } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java index a9e3e234733b2..66648949a91ba 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java @@ -20,6 +20,7 @@ import lombok.Getter; import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.infra.database.type.DatabaseType; +import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor; import org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawExecutor; import org.apache.shardingsphere.infra.federation.executor.FederationExecutor; @@ -45,10 +46,11 @@ public final class DriverExecutor implements AutoCloseable { public DriverExecutor(final ShardingSphereConnection connection) { MetaDataContexts metaDataContexts = connection.getContextManager().getMetaDataContexts(); - JDBCExecutor jdbcExecutor = new JDBCExecutor(metaDataContexts.getExecutorEngine(), connection.isHoldTransaction()); + ExecutorEngine executorEngine = connection.getContextManager().getExecutorEngine(); + JDBCExecutor jdbcExecutor = new JDBCExecutor(executorEngine, connection.isHoldTransaction()); regularExecutor = new DriverJDBCExecutor(connection.getDatabaseName(), metaDataContexts, jdbcExecutor); - rawExecutor = new RawExecutor(metaDataContexts.getExecutorEngine(), connection.isHoldTransaction(), metaDataContexts.getProps()); - DatabaseType databaseType = metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(); + rawExecutor = new RawExecutor(executorEngine, connection.isHoldTransaction(), metaDataContexts.getProps()); + DatabaseType databaseType = metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(); String schemaName = databaseType.getDefaultSchema(connection.getDatabaseName()); federationExecutor = FederationExecutorFactory.newInstance(connection.getDatabaseName(), schemaName, metaDataContexts.getOptimizerContext(), metaDataContexts.getProps(), jdbcExecutor); trafficExecutor = new TrafficExecutor(); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java index eab6ca895da0b..b623b0b65b2b4 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java @@ -57,7 +57,7 @@ public DriverJDBCExecutor(final String databaseName, final MetaDataContexts meta this.databaseName = databaseName; this.metaDataContexts = metaDataContexts; this.jdbcExecutor = jdbcExecutor; - metadataRefreshEngine = new MetaDataRefreshEngine(metaDataContexts.getMetaData(databaseName), + metadataRefreshEngine = new MetaDataRefreshEngine(metaDataContexts.getDatabaseMetaData(databaseName), metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName), metaDataContexts.getOptimizerContext().getPlannerContexts(), metaDataContexts.getProps()); } @@ -99,7 +99,7 @@ public int executeUpdate(final ExecutionGroupContext executio ExecuteProcessEngine.initialize(logicSQL, executionGroupContext, metaDataContexts.getProps()); SQLStatementContext sqlStatementContext = logicSQL.getSqlStatementContext(); List results = doExecute(executionGroupContext, sqlStatementContext, routeUnits, callback); - int result = isNeedAccumulate(metaDataContexts.getMetaData(databaseName).getRuleMetaData().getRules(), sqlStatementContext) ? accumulate(results) : results.get(0); + int result = isNeedAccumulate(metaDataContexts.getDatabaseMetaData(databaseName).getRuleMetaData().getRules(), sqlStatementContext) ? accumulate(results) : results.get(0); ExecuteProcessEngine.finish(executionGroupContext.getExecutionID()); return result; } finally { diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java index adef45c1ef444..3b91f2e417e6a 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java @@ -134,7 +134,7 @@ private void handleNewBatchExecutionUnits(final Collection n public int[] executeBatch(final SQLStatementContext sqlStatementContext) throws SQLException { boolean isExceptionThrown = SQLExecutorExceptionHandler.isExceptionThrown(); JDBCExecutorCallback callback = new JDBCExecutorCallback( - metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType(), sqlStatementContext.getSqlStatement(), isExceptionThrown) { + metaDataContexts.getDatabaseMetaData(databaseName).getResource().getDatabaseType(), sqlStatementContext.getSqlStatement(), isExceptionThrown) { @Override protected int[] executeSQL(final String sql, final Statement statement, final ConnectionMode connectionMode) throws SQLException { @@ -155,7 +155,7 @@ protected Optional getSaneResult(final SQLStatement sqlStatement) { } private boolean isNeedAccumulate(final SQLStatementContext sqlStatementContext) { - for (ShardingSphereRule each : metaDataContexts.getMetaData(databaseName).getRuleMetaData().getRules()) { + for (ShardingSphereRule each : metaDataContexts.getDatabaseMetaData(databaseName).getRuleMetaData().getRules()) { if (each instanceof DataNodeContainedRule && ((DataNodeContainedRule) each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) { return true; } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractResultSetAdapter.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractResultSetAdapter.java index ea43422492dd5..ae3a5fabb8777 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractResultSetAdapter.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractResultSetAdapter.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement; import org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationResultSet; import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.sql.ResultSet; import java.sql.ResultSetMetaData; @@ -62,14 +62,14 @@ protected AbstractResultSetAdapter(final List resultSets, final State @Override public final ResultSetMetaData getMetaData() throws SQLException { - return new ShardingSphereResultSetMetaData(resultSets.get(0).getMetaData(), getShardingSphereMetaData(), executionContext.getSqlStatementContext()); + return new ShardingSphereResultSetMetaData(resultSets.get(0).getMetaData(), getDatabaseMetaData(), executionContext.getSqlStatementContext()); } - private ShardingSphereMetaData getShardingSphereMetaData() { + private ShardingSphereDatabaseMetaData getDatabaseMetaData() { ShardingSphereConnection connection = statement instanceof ShardingSpherePreparedStatement ? ((ShardingSpherePreparedStatement) statement).getConnection() : ((ShardingSphereStatement) statement).getConnection(); - return connection.getContextManager().getMetaDataContexts().getMetaData(connection.getDatabaseName()); + return connection.getContextManager().getMetaDataContexts().getDatabaseMetaData(connection.getDatabaseName()); } @Override diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java index 6618c0769b56c..03f6707612ef4 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java @@ -195,7 +195,7 @@ public final void close() throws SQLException { protected final void handleExceptionInTransaction(final ShardingSphereConnection connection, final MetaDataContexts metaDataContexts) { if (connection.getConnectionManager().getConnectionTransaction().isInTransaction()) { - DatabaseType databaseType = metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(); + DatabaseType databaseType = metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(); if (databaseType instanceof PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType) { connection.getConnectionManager().getConnectionTransaction().setRollbackOnly(true); } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java index 8ea67961f72e9..37412811a6b42 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java @@ -84,7 +84,7 @@ public ConnectionManager(final String databaseName, final ContextManager context private Map getTrafficDataSourceMap(final String schema, final ContextManager contextManager) { Optional trafficRule = contextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TrafficRule.class); - Optional metaDataPersistService = contextManager.getMetaDataContexts().getMetaDataPersistService(); + Optional metaDataPersistService = contextManager.getMetaDataContexts().getPersistService(); if (!trafficRule.isPresent() || trafficRule.get().getStrategyRules().isEmpty() || !metaDataPersistService.isPresent()) { return Collections.emptyMap(); } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java index 53c472f3264e0..e5e7d215078d6 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java @@ -51,10 +51,10 @@ public final class ShardingSphereDatabaseMetaData extends AdaptedDatabaseMetaDat private DatabaseMetaData currentDatabaseMetaData; public ShardingSphereDatabaseMetaData(final ShardingSphereConnection connection) { - super(connection.getContextManager().getMetaDataContexts().getMetaData(connection.getDatabaseName()).getResource().getCachedDatabaseMetaData()); + super(connection.getContextManager().getMetaDataContexts().getDatabaseMetaData(connection.getDatabaseName()).getResource().getCachedDatabaseMetaData()); this.connection = connection; - rules = connection.getContextManager().getMetaDataContexts().getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules(); - dataSourcesMetaData = connection.getContextManager().getMetaDataContexts().getMetaData(connection.getDatabaseName()).getResource().getDataSourcesMetaData(); + rules = connection.getContextManager().getMetaDataContexts().getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules(); + dataSourcesMetaData = connection.getContextManager().getMetaDataContexts().getDatabaseMetaData(connection.getDatabaseName()).getResource().getDataSourcesMetaData(); } @Override diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java index bb6ff68fd73b4..8af9e1b45e3e9 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; @@ -44,7 +44,7 @@ public final class ShardingSphereResultSetMetaData extends WrapperAdapter implem private final ResultSetMetaData resultSetMetaData; - private final ShardingSphereMetaData shardingSphereMetaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final SQLStatementContext sqlStatementContext; @@ -151,7 +151,7 @@ public int getScale(final int column) throws SQLException { @Override public String getTableName(final int column) throws SQLException { String actualTableName = resultSetMetaData.getTableName(column); - Optional rule = shardingSphereMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataNodeContainedRule).findFirst(); + Optional rule = databaseMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataNodeContainedRule).findFirst(); return rule.isPresent() ? ((DataNodeContainedRule) rule.get()).findLogicTableByActualTable(actualTableName).orElse(actualTableName) : actualTableName; } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java index 0c7a29cde4575..45f13907d06b8 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java @@ -69,7 +69,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.merge.MergeEngine; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; @@ -176,16 +176,16 @@ private ShardingSpherePreparedStatement(final ShardingSphereConnection connectio Optional sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class); Preconditions.checkState(sqlParserRule.isPresent()); ShardingSphereSQLParserEngine sqlParserEngine = new ShardingSphereSQLParserEngine(DatabaseTypeEngine.getTrunkDatabaseTypeName( - metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration()); + metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration()); sqlStatement = sqlParserEngine.parse(sql, true); - sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), sqlStatement, connection.getDatabaseName()); + sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getDatabaseMetaDataMap(), sqlStatement, connection.getDatabaseName()); parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement); statementOption = returnGeneratedKeys ? new StatementOption(true) : new StatementOption(resultSetType, resultSetConcurrency, resultSetHoldability); executor = new DriverExecutor(connection); - JDBCExecutor jdbcExecutor = new JDBCExecutor(metaDataContexts.getExecutorEngine(), connection.isHoldTransaction()); + JDBCExecutor jdbcExecutor = new JDBCExecutor(connection.getContextManager().getExecutorEngine(), connection.isHoldTransaction()); batchPreparedStatementExecutor = new BatchPreparedStatementExecutor(metaDataContexts, jdbcExecutor, connection.getDatabaseName()); kernelProcessor = new KernelProcessor(); - statementsCacheable = isStatementsCacheable(metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getConfigurations()); + statementsCacheable = isStatementsCacheable(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getConfigurations()); trafficRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(TrafficRule.class).orElse(null); statementManager = new StatementManager(); } @@ -276,21 +276,21 @@ private List executeQuery0() throws SQLException { ExecutionGroupContext executionGroupContext = createExecutionGroupContext(); cacheStatements(executionGroupContext.getInputGroups()); return executor.getRegularExecutor().executeQuery(executionGroupContext, executionContext.getLogicSQL(), - new PreparedStatementExecuteQueryCallback(metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, + new PreparedStatementExecuteQueryCallback(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, SQLExecutorExceptionHandler.isExceptionThrown())); } private ResultSet executeFederationQuery(final LogicSQL logicSQL) throws SQLException { - PreparedStatementExecuteQueryCallback callback = new PreparedStatementExecuteQueryCallback(metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), + PreparedStatementExecuteQueryCallback callback = new PreparedStatementExecuteQueryCallback(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, SQLExecutorExceptionHandler.isExceptionThrown()); - FederationContext context = new FederationContext(false, logicSQL, metaDataContexts.getMetaDataMap()); + FederationContext context = new FederationContext(false, logicSQL, metaDataContexts.getDatabaseMetaDataMap()); return executor.getFederationExecutor().executeQuery(createDriverExecutionPrepareEngine(), callback, context); } private DriverExecutionPrepareEngine createDriverExecutionPrepareEngine() { int maxConnectionsSizePerQuery = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); return new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT, maxConnectionsSizePerQuery, connection.getConnectionManager(), statementManager, - statementOption, metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()); + statementOption, metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()); } @Override @@ -334,7 +334,7 @@ private int accumulate(final Collection results) { private JDBCExecutorCallback createExecuteUpdateCallback() { boolean isExceptionThrown = SQLExecutorExceptionHandler.isExceptionThrown(); - return new JDBCExecutorCallback(metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, isExceptionThrown) { + return new JDBCExecutorCallback(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, isExceptionThrown) { @Override protected Integer executeSQL(final String sql, final Statement statement, final ConnectionMode connectionMode) throws SQLException { @@ -385,7 +385,7 @@ public boolean execute() throws SQLException { } private boolean hasRawExecutionRule() { - for (ShardingSphereRule each : metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()) { + for (ShardingSphereRule each : metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()) { if (each instanceof RawExecutionRule) { return true; } @@ -395,7 +395,7 @@ private boolean hasRawExecutionRule() { private ExecutionGroupContext createRawExecutionGroupContext() throws SQLException { int maxConnectionsSizePerQuery = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); - return new RawExecutionPrepareEngine(maxConnectionsSizePerQuery, metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()) + return new RawExecutionPrepareEngine(maxConnectionsSizePerQuery, metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()) .prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits()); } @@ -406,7 +406,7 @@ private ExecutionGroupContext createExecutionGroupContext() t private JDBCExecutorCallback createExecuteCallback() { boolean isExceptionThrown = SQLExecutorExceptionHandler.isExceptionThrown(); - return new JDBCExecutorCallback(metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, isExceptionThrown) { + return new JDBCExecutorCallback(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, isExceptionThrown) { @Override protected Boolean executeSQL(final String sql, final Statement statement, final ConnectionMode connectionMode) throws SQLException { @@ -467,8 +467,8 @@ private List getQueryResults(final List resultSets) thro private ExecutionContext createExecutionContext(final LogicSQL logicSQL) { SQLCheckEngine.check(logicSQL.getSqlStatementContext().getSqlStatement(), logicSQL.getParameters(), - metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules(), connection.getDatabaseName(), metaDataContexts.getMetaDataMap(), null); - ExecutionContext result = kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getMetaData(connection.getDatabaseName()), metaDataContexts.getProps()); + metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules(), connection.getDatabaseName(), metaDataContexts.getDatabaseMetaDataMap(), null); + ExecutionContext result = kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()), metaDataContexts.getProps()); findGeneratedKey(result).ifPresent(generatedKey -> generatedValues.addAll(generatedKey.getGeneratedValues())); return result; } @@ -482,9 +482,9 @@ private LogicSQL createLogicSQL() { } private MergedResult mergeQuery(final List queryResults) throws SQLException { - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(connection.getDatabaseName()); - MergeEngine mergeEngine = new MergeEngine(connection.getDatabaseName(), metaData.getResource().getDatabaseType(), metaData, - metaDataContexts.getProps(), metaData.getRuleMetaData().getRules()); + ShardingSphereDatabaseMetaData databaseMetaData = metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()); + MergeEngine mergeEngine = new MergeEngine(connection.getDatabaseName(), databaseMetaData.getResource().getDatabaseType(), databaseMetaData, + metaDataContexts.getProps(), databaseMetaData.getRuleMetaData().getRules()); return mergeEngine.merge(queryResults, executionContext.getSqlStatementContext()); } @@ -569,7 +569,7 @@ public int[] executeBatch() throws SQLException { private void initBatchPreparedStatementExecutor() throws SQLException { DriverExecutionPrepareEngine prepareEngine = new DriverExecutionPrepareEngine<>( JDBCDriverType.PREPARED_STATEMENT, metaDataContexts.getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), - connection.getConnectionManager(), statementManager, statementOption, metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()); + connection.getConnectionManager(), statementManager, statementOption, metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()); List executionUnits = new ArrayList<>(batchPreparedStatementExecutor.getBatchExecutionUnits().size()); for (BatchExecutionUnit each : batchPreparedStatementExecutor.getBatchExecutionUnits()) { ExecutionUnit executionUnit = each.getExecutionUnit(); @@ -615,7 +615,7 @@ public int getResultSetHoldability() { @Override public boolean isAccumulate() { - return metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream() + return metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream() .anyMatch(each -> each instanceof DataNodeContainedRule && ((DataNodeContainedRule) each) .isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames())); } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java index ba3598ba4745c..cdb42e37f267d 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java @@ -65,7 +65,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.merge.MergeEngine; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; import org.apache.shardingsphere.infra.route.context.RouteUnit; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; @@ -194,28 +194,28 @@ private List getShardingSphereResultSets() { } private List executeQuery0() throws SQLException { - if (metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { + if (metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { return executor.getRawExecutor().execute(createRawExecutionContext(), executionContext.getLogicSQL(), new RawSQLExecutorCallback()).stream().map(each -> (QueryResult) each).collect(Collectors.toList()); } ExecutionGroupContext executionGroupContext = createExecutionContext(); cacheStatements(executionGroupContext.getInputGroups()); - StatementExecuteQueryCallback callback = new StatementExecuteQueryCallback(metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), + StatementExecuteQueryCallback callback = new StatementExecuteQueryCallback(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), executionContext.getSqlStatementContext().getSqlStatement(), SQLExecutorExceptionHandler.isExceptionThrown()); return executor.getRegularExecutor().executeQuery(executionGroupContext, executionContext.getLogicSQL(), callback); } private ResultSet executeFederationQuery(final LogicSQL logicSQL) throws SQLException { - StatementExecuteQueryCallback callback = new StatementExecuteQueryCallback(metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), + StatementExecuteQueryCallback callback = new StatementExecuteQueryCallback(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), executionContext.getSqlStatementContext().getSqlStatement(), SQLExecutorExceptionHandler.isExceptionThrown()); - FederationContext context = new FederationContext(false, logicSQL, metaDataContexts.getMetaDataMap()); + FederationContext context = new FederationContext(false, logicSQL, metaDataContexts.getDatabaseMetaDataMap()); return executor.getFederationExecutor().executeQuery(createDriverExecutionPrepareEngine(), callback, context); } private DriverExecutionPrepareEngine createDriverExecutionPrepareEngine() { int maxConnectionsSizePerQuery = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, connection.getConnectionManager(), statementManager, - statementOption, metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()); + statementOption, metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()); } @Override @@ -228,7 +228,7 @@ public int executeUpdate(final String sql) throws SQLException { return executor.getTrafficExecutor().execute(executionUnit, Statement::executeUpdate); } executionContext = createExecutionContext(logicSQL); - if (metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { + if (metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { return accumulate(executor.getRawExecutor().execute(createRawExecutionContext(), executionContext.getLogicSQL(), new RawSQLExecutorCallback())); } ExecutionGroupContext executionGroupContext = createExecutionContext(); @@ -256,7 +256,7 @@ public int executeUpdate(final String sql, final int autoGeneratedKeys) throws S return executor.getTrafficExecutor().execute(executionUnit, (statement, actualSQL) -> statement.executeUpdate(actualSQL, autoGeneratedKeys)); } executionContext = createExecutionContext(logicSQL); - if (metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { + if (metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { return accumulate(executor.getRawExecutor().execute(createRawExecutionContext(), executionContext.getLogicSQL(), new RawSQLExecutorCallback())); } ExecutionGroupContext executionGroupContext = createExecutionContext(); @@ -282,7 +282,7 @@ public int executeUpdate(final String sql, final int[] columnIndexes) throws SQL return executor.getTrafficExecutor().execute(executionUnit, (statement, actualSQL) -> statement.executeUpdate(actualSQL, columnIndexes)); } executionContext = createExecutionContext(logicSQL); - if (metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { + if (metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { return accumulate(executor.getRawExecutor().execute(createRawExecutionContext(), executionContext.getLogicSQL(), new RawSQLExecutorCallback())); } ExecutionGroupContext executionGroups = createExecutionContext(); @@ -308,7 +308,7 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ return executor.getTrafficExecutor().execute(executionUnit, (statement, actualSQL) -> statement.executeUpdate(actualSQL, columnNames)); } executionContext = createExecutionContext(logicSQL); - if (metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { + if (metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { return accumulate(executor.getRawExecutor().execute(createRawExecutionContext(), executionContext.getLogicSQL(), new RawSQLExecutorCallback())); } ExecutionGroupContext executionGroupContext = createExecutionContext(); @@ -327,7 +327,7 @@ private int executeUpdate(final ExecutionGroupContext executi final SQLStatementContext sqlStatementContext, final Collection routeUnits) throws SQLException { boolean isExceptionThrown = SQLExecutorExceptionHandler.isExceptionThrown(); JDBCExecutorCallback callback = new JDBCExecutorCallback( - metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatementContext.getSqlStatement(), isExceptionThrown) { + metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatementContext.getSqlStatement(), isExceptionThrown) { @Override protected Integer executeSQL(final String sql, final Statement statement, final ConnectionMode connectionMode) throws SQLException { @@ -399,7 +399,7 @@ private boolean execute(final ExecutionGroupContext execution final SQLStatement sqlStatement, final Collection routeUnits) throws SQLException { boolean isExceptionThrown = SQLExecutorExceptionHandler.isExceptionThrown(); JDBCExecutorCallback jdbcExecutorCallback = new JDBCExecutorCallback( - metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, isExceptionThrown) { + metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType(), sqlStatement, isExceptionThrown) { @Override protected Boolean executeSQL(final String sql, final Statement statement, final ConnectionMode connectionMode) throws SQLException { @@ -423,7 +423,7 @@ private boolean execute0(final String sql, final ExecuteCallback callback) throw return executor.getTrafficExecutor().execute(executionUnit, (statement, actualSQL) -> callback.execute(actualSQL, statement)); } executionContext = createExecutionContext(logicSQL); - if (metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { + if (metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream().anyMatch(each -> each instanceof RawExecutionRule)) { // TODO process getStatement Collection results = executor.getRawExecutor().execute(createRawExecutionContext(), executionContext.getLogicSQL(), new RawSQLExecutorCallback()); return results.iterator().next() instanceof QueryResult; @@ -458,9 +458,9 @@ private void clearStatements() throws SQLException { private LogicSQL createLogicSQL(final String sql) { SQLParserRule sqlParserRule = findSQLParserRule(); ShardingSphereSQLParserEngine sqlParserEngine = new ShardingSphereSQLParserEngine( - DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(connection.getDatabaseName()).getResource().getDatabaseType()), sqlParserRule.toParserConfiguration()); + DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType()), sqlParserRule.toParserConfiguration()); SQLStatement sqlStatement = sqlParserEngine.parse(sql, false); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), sqlStatement, connection.getDatabaseName()); + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getDatabaseMetaDataMap(), sqlStatement, connection.getDatabaseName()); return new LogicSQL(sqlStatementContext, sql, Collections.emptyList()); } @@ -473,8 +473,8 @@ private SQLParserRule findSQLParserRule() { private ExecutionContext createExecutionContext(final LogicSQL logicSQL) throws SQLException { clearStatements(); SQLCheckEngine.check(logicSQL.getSqlStatementContext().getSqlStatement(), logicSQL.getParameters(), - metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules(), connection.getDatabaseName(), metaDataContexts.getMetaDataMap(), null); - return kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getMetaData(connection.getDatabaseName()), metaDataContexts.getProps()); + metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules(), connection.getDatabaseName(), metaDataContexts.getDatabaseMetaDataMap(), null); + return kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()), metaDataContexts.getProps()); } private ExecutionGroupContext createExecutionContext() throws SQLException { @@ -484,7 +484,7 @@ private ExecutionGroupContext createExecutionContext() throws private ExecutionGroupContext createRawExecutionContext() throws SQLException { int maxConnectionsSizePerQuery = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); - return new RawExecutionPrepareEngine(maxConnectionsSizePerQuery, metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()) + return new RawExecutionPrepareEngine(maxConnectionsSizePerQuery, metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules()) .prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits()); } @@ -547,9 +547,9 @@ private List getQueryResults(final List resultSets) thro } private MergedResult mergeQuery(final List queryResults) throws SQLException { - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(connection.getDatabaseName()); - MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, metaData.getResource().getDatabaseType(), metaData, - metaDataContexts.getProps(), metaData.getRuleMetaData().getRules()); + ShardingSphereDatabaseMetaData databaseMetaData = metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()); + MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, databaseMetaData.getResource().getDatabaseType(), databaseMetaData, + metaDataContexts.getProps(), databaseMetaData.getRuleMetaData().getRules()); return mergeEngine.merge(queryResults, executionContext.getSqlStatementContext()); } @@ -572,7 +572,7 @@ public int getResultSetHoldability() { @Override public boolean isAccumulate() { - return metaDataContexts.getMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream() + return metaDataContexts.getDatabaseMetaData(connection.getDatabaseName()).getRuleMetaData().getRules().stream() .anyMatch(each -> each instanceof DataNodeContainedRule && ((DataNodeContainedRule) each) .isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames())); } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java index c942e0164e7f4..c20c79926637b 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java @@ -86,9 +86,9 @@ private Map mockDataSourceMap() { private MetaDataContexts mockMetaDataContexts() { MetaDataContexts result = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS); - when(result.getMetaData(DefaultDatabase.LOGIC_NAME).getResource().getDatabaseType()).thenReturn(DatabaseTypeFactory.getInstance("H2")); + when(result.getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getResource().getDatabaseType()).thenReturn(DatabaseTypeFactory.getInstance("H2")); ShardingRule shardingRule = mockShardingRule(); - when(result.getMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules()).thenReturn(Collections.singletonList(shardingRule)); + when(result.getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules()).thenReturn(Collections.singletonList(shardingRule)); return result; } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java index af5aa82e25031..fa6df680e2bf6 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java @@ -64,7 +64,7 @@ public final class PreparedStatementAdapterTest { public void setUp() throws SQLException { ShardingSphereConnection connection = mock(ShardingSphereConnection.class, RETURNS_DEEP_STUBS); when(connection.getDatabaseName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(connection.getContextManager().getMetaDataContexts().getMetaData(connection.getDatabaseName()).getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); + when(connection.getContextManager().getMetaDataContexts().getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); when(connection.getContextManager().getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(SQLParserRule.class)).thenReturn(Optional.of(sqlParserRule)); when(connection.getContextManager().getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TrafficRule.class)).thenReturn(Optional.of(trafficRule)); shardingSpherePreparedStatement = new ShardingSpherePreparedStatement(connection, "SELECT 1"); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java index 5816ef18da730..fd629139eb43a 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java @@ -234,7 +234,7 @@ private ShardingSphereStatement mockShardingSphereStatementWithNeedAccumulate(fi ShardingSphereConnection connection = mock(ShardingSphereConnection.class, RETURNS_DEEP_STUBS); DataNodeContainedRule rule = mock(DataNodeContainedRule.class); when(rule.isNeedAccumulate(any())).thenReturn(true); - when(connection.getContextManager().getMetaDataContexts().getMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules()).thenReturn(Collections.singletonList(rule)); + when(connection.getContextManager().getMetaDataContexts().getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules()).thenReturn(Collections.singletonList(rule)); TrafficRule trafficRule = new TrafficRule(new DefaultTrafficRuleConfigurationBuilder().build()); when(connection.getContextManager().getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TrafficRule.class)).thenReturn(Optional.of(trafficRule)); ShardingSphereStatement result = new ShardingSphereStatement(connection); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java index d4d06ed96c575..fa1fd9ef9b971 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java @@ -89,7 +89,7 @@ private ContextManager mockContextManager() throws SQLException { TrafficRule trafficRule = mockTrafficRule(); MetaDataPersistService metaDataPersistService = mockMetaDataPersistService(); when(result.getDataSourceMap(DefaultDatabase.LOGIC_NAME)).thenReturn(dataSourceMap); - when(result.getMetaDataContexts().getMetaDataPersistService()).thenReturn(Optional.of(metaDataPersistService)); + when(result.getMetaDataContexts().getPersistService()).thenReturn(Optional.of(metaDataPersistService)); when(result.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TransactionRule.class)).thenReturn(Optional.empty()); when(result.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TrafficRule.class)).thenReturn(Optional.of(trafficRule)); when(result.getInstanceContext().getComputeNodeInstanceIds(InstanceType.PROXY, Arrays.asList("OLTP", "OLAP"))).thenReturn(Collections.singletonList(new InstanceId("127.0.0.1@3307"))); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java index 04c7e4f794093..1ef4d5bbeb6fd 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java @@ -53,7 +53,7 @@ public void tearDown() { public void assertNewConstructorWithModeConfigurationOnly() throws SQLException { ShardingSphereDataSource actual = new ShardingSphereDataSource(DefaultDatabase.LOGIC_NAME, null); assertThat(actual.getDatabaseName(), is(DefaultDatabase.LOGIC_NAME)); - assertTrue(actual.getContextManager().getMetaDataContexts().getMetaDataMap().containsKey(DefaultDatabase.LOGIC_NAME)); + assertTrue(actual.getContextManager().getMetaDataContexts().getDatabaseMetaDataMap().containsKey(DefaultDatabase.LOGIC_NAME)); assertTrue(actual.getContextManager().getTransactionContexts().getEngines().containsKey(DefaultDatabase.LOGIC_NAME)); assertThat(actual.getContextManager().getInstanceContext().getInstance().getState().getCurrentState(), is(StateType.OK)); assertTrue(actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).isEmpty()); @@ -65,7 +65,7 @@ public void assertNewConstructorWithAllArguments() throws SQLException { when(connection.getMetaData().getURL()).thenReturn("jdbc:mock://127.0.0.1/foo_ds"); ShardingSphereDataSource actual = createShardingSphereDataSource(new MockedDataSource(connection)); assertThat(actual.getDatabaseName(), is(DefaultDatabase.LOGIC_NAME)); - assertTrue(actual.getContextManager().getMetaDataContexts().getMetaDataMap().containsKey(DefaultDatabase.LOGIC_NAME)); + assertTrue(actual.getContextManager().getMetaDataContexts().getDatabaseMetaDataMap().containsKey(DefaultDatabase.LOGIC_NAME)); assertTrue(actual.getContextManager().getTransactionContexts().getEngines().containsKey(DefaultDatabase.LOGIC_NAME)); assertThat(actual.getContextManager().getInstanceContext().getInstance().getState().getCurrentState(), is(StateType.OK)); assertThat(actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).size(), is(1)); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java index 9c3986bde231c..6f597f781a87c 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.driver.jdbc.core.resultset.DatabaseMetaDataResultSet; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.CachedDatabaseMetaData; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -79,7 +79,7 @@ public final class ShardingSphereDatabaseMetaDataTest { private final Map dataSourceMap = new HashMap<>(); - private ShardingSphereDatabaseMetaData shardingSphereDatabaseMetaData; + private org.apache.shardingsphere.driver.jdbc.core.datasource.metadata.ShardingSphereDatabaseMetaData shardingSphereDatabaseMetaData; @Before public void setUp() throws SQLException { @@ -93,12 +93,12 @@ public void setUp() throws SQLException { when(shardingSphereConnection.getContextManager().getMetaDataContexts()).thenReturn(metaDataContexts); when(shardingSphereConnection.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME)).thenReturn(dataSourceMap); when(shardingSphereConnection.getDatabaseName()).thenReturn(DefaultDatabase.LOGIC_NAME); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaDataContexts.getMetaData(shardingSphereConnection.getDatabaseName())).thenReturn(metaData); - when(metaData.getResource().getCachedDatabaseMetaData()).thenReturn(cachedDatabaseMetaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(metaDataContexts.getDatabaseMetaData(shardingSphereConnection.getDatabaseName())).thenReturn(databaseMetaData); + when(databaseMetaData.getResource().getCachedDatabaseMetaData()).thenReturn(cachedDatabaseMetaData); ShardingRule shardingRule = mockShardingRule(); - when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.singleton(shardingRule)); - shardingSphereDatabaseMetaData = new ShardingSphereDatabaseMetaData(shardingSphereConnection); + when(databaseMetaData.getRuleMetaData().getRules()).thenReturn(Collections.singleton(shardingRule)); + shardingSphereDatabaseMetaData = new org.apache.shardingsphere.driver.jdbc.core.datasource.metadata.ShardingSphereDatabaseMetaData(shardingSphereConnection); } private ShardingRule mockShardingRule() { diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java index 9cc55f06db34b..df754853e1a10 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java @@ -50,7 +50,7 @@ public final class UnsupportedOperationPreparedStatementTest { public void setUp() throws SQLException { ShardingSphereConnection connection = mock(ShardingSphereConnection.class, RETURNS_DEEP_STUBS); when(connection.getDatabaseName()).thenReturn(DefaultDatabase.LOGIC_NAME); - when(connection.getContextManager().getMetaDataContexts().getMetaData(connection.getDatabaseName()).getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); + when(connection.getContextManager().getMetaDataContexts().getDatabaseMetaData(connection.getDatabaseName()).getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); when(connection.getContextManager().getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(SQLParserRule.class)).thenReturn(Optional.of(sqlParserRule)); when(connection.getContextManager().getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TrafficRule.class)).thenReturn(Optional.of(trafficRule)); shardingSpherePreparedStatement = new ShardingSpherePreparedStatement(connection, "SELECT 1"); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java index 326dfa4fd4767..e70841b3a47bb 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java @@ -21,9 +21,8 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; -import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.state.StateContext; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -53,17 +52,17 @@ public final class DriverStateContextTest { @Before public void setUp() { - Map metaDataMap = mockMetaDataMap(); - when(contextManager.getMetaDataContexts()).thenReturn(new MetaDataContexts(mock(MetaDataPersistService.class), metaDataMap, - mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), mock(ConfigurationProperties.class))); + Map databaseMetaDataMap = mockDatabaseMetaDataMap(); + when(contextManager.getMetaDataContexts()).thenReturn(new MetaDataContexts( + mock(MetaDataPersistService.class), databaseMetaDataMap, mock(ShardingSphereRuleMetaData.class), mock(OptimizerContext.class), mock(ConfigurationProperties.class))); when(contextManager.getInstanceContext().getInstance().getState()).thenReturn(new StateContext()); } - private Map mockMetaDataMap() { - Map result = new LinkedHashMap<>(); - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, Answers.RETURNS_DEEP_STUBS); - when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); - result.put(DefaultDatabase.LOGIC_NAME, metaData); + private Map mockDatabaseMetaDataMap() { + Map result = new LinkedHashMap<>(); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, Answers.RETURNS_DEEP_STUBS); + when(databaseMetaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); + result.put(DefaultDatabase.LOGIC_NAME, databaseMetaData); return result; } diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java index 32d79c1fd085f..7b86dd4465378 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java @@ -70,7 +70,7 @@ public class SpringBootStarterTest { @Test public void assertDataSources() { - Map dataSources = dataSource.getContextManager().getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources(); + Map dataSources = dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources(); assertThat(dataSources.size(), is(2)); assertTrue(dataSources.containsKey("ds0")); assertTrue(dataSources.containsKey("ds1")); @@ -78,7 +78,7 @@ public void assertDataSources() { @Test public void assertRules() { - Collection rules = dataSource.getContextManager().getMetaDataContexts().getMetaData("foo_db").getRuleMetaData().getRules(); + Collection rules = dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData("foo_db").getRuleMetaData().getRules(); assertThat(rules.size(), is(5)); for (ShardingSphereRule each : rules) { if (each instanceof ShardingRule) { diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java index eec492a3ee37a..36d0919f6c2a7 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java @@ -55,7 +55,7 @@ public static void setUp() { @Test public void assertDataSources() { - Map dataSources = dataSource.getContextManager().getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources(); + Map dataSources = dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources(); assertThat(dataSources.size(), is(2)); assertTrue(dataSources.containsKey("ds0")); assertTrue(dataSources.containsKey("ds1")); diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java index 1a58e1a5bbe5c..2880ddda61418 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java @@ -49,8 +49,8 @@ public abstract class AbstractSpringNamespaceTest extends AbstractJUnit4SpringCo @Test public void assertShardingSphereDataSource() { - assertDataSources(dataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultDatabase.LOGIC_NAME).getResource().getDataSources()); - assertSchemaRules(dataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules()); + assertDataSources(dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getResource().getDataSources()); + assertSchemaRules(dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules()); assertGlobalRules(dataSource.getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules()); } diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProviderAlgorithm.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProviderAlgorithm.java index 1f91b53db0f01..c4d6dac606d16 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProviderAlgorithm.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProviderAlgorithm.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.authority.model.AuthorityRegistry; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import java.util.Collection; @@ -33,9 +33,9 @@ public interface AuthorityProviderAlgorithm extends ShardingSphereAlgorithm { /** * Build authority registry. * - * @param metaDataMap meta data map + * @param databaseMetaDataMap database meta data map * @param users users * @return built authority registry */ - AuthorityRegistry buildAuthorityRegistry(Map metaDataMap, Collection users); + AuthorityRegistry buildAuthorityRegistry(Map databaseMetaDataMap, Collection users); } diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java index b9af0ccb2997c..8a1281fd05e9f 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule; import org.apache.shardingsphere.infra.executor.check.SQLCheckResult; import org.apache.shardingsphere.infra.executor.check.SQLChecker; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -65,7 +65,7 @@ public boolean check(final String databaseName, final Grantee grantee, final Aut @Override public SQLCheckResult check(final SQLStatement sqlStatement, final List parameters, final Grantee grantee, - final String currentDatabase, final Map metaDataMap, final AuthorityRule authorityRule) { + final String currentDatabase, final Map databaseMetaDataMap, final AuthorityRule authorityRule) { if (null == grantee) { return new SQLCheckResult(true, ""); } diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java index 82ad14af27c2b..8c0e07d36707d 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeBuilder; import org.apache.shardingsphere.authority.registry.UserPrivilegeMapAuthorityRegistry; import org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import java.util.Collection; @@ -47,8 +47,8 @@ public void init(final Properties props) { } @Override - public AuthorityRegistry buildAuthorityRegistry(final Map metaDataMap, final Collection users) { - return new UserPrivilegeMapAuthorityRegistry(StoragePrivilegeBuilder.build(new LinkedList<>(metaDataMap.values()), users)); + public AuthorityRegistry buildAuthorityRegistry(final Map databaseMetaDataMap, final Collection users) { + return new UserPrivilegeMapAuthorityRegistry(StoragePrivilegeBuilder.build(new LinkedList<>(databaseMetaDataMap.values()), users)); } @Override diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilder.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilder.java index b06bd5e37eea3..3f52b34fde1b5 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilder.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilder.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine; import org.apache.shardingsphere.infra.exception.ShardingSphereException; import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import javax.sql.DataSource; @@ -54,12 +54,12 @@ public final class StoragePrivilegeBuilder { /** * Build privileges. * - * @param metaDataList meta data list + * @param databaseMetaDataList database meta data list * @param users users * @return privileges */ - public static Map build(final Collection metaDataList, final Collection users) { - return metaDataList.isEmpty() ? buildPrivilegesInCache(users) : buildPrivilegesInStorage(metaDataList, users); + public static Map build(final Collection databaseMetaDataList, final Collection users) { + return databaseMetaDataList.isEmpty() ? buildPrivilegesInCache(users) : buildPrivilegesInStorage(databaseMetaDataList, users); } private static Map buildPrivilegesInCache(final Collection users) { @@ -70,22 +70,23 @@ private static Map buildPrivilegesInCache( return result; } - private static Map buildPrivilegesInStorage(final Collection metaDataList, final Collection users) { + private static Map buildPrivilegesInStorage(final Collection databaseMetaDataList, + final Collection users) { Map result = new LinkedHashMap<>(users.size(), 1); - metaDataList.stream().map(each -> buildPrivilegesInStorage(each, users)).forEach(result::putAll); + databaseMetaDataList.stream().map(each -> buildPrivilegesInStorage(each, users)).forEach(result::putAll); return result; } - private static Map buildPrivilegesInStorage(final ShardingSphereMetaData metaData, final Collection users) { - DatabaseType databaseType = DatabaseTypeEngine.getDatabaseType(metaData.getResource().getAllInstanceDataSources()); + private static Map buildPrivilegesInStorage(final ShardingSphereDatabaseMetaData databaseMetaData, final Collection users) { + DatabaseType databaseType = DatabaseTypeEngine.getDatabaseType(databaseMetaData.getResource().getAllInstanceDataSources()); Optional handler = StoragePrivilegeHandlerFactory.findInstance(databaseType.getType()); if (!handler.isPresent()) { return buildPrivilegesInCache(users); } - save(metaData.getResource().getAllInstanceDataSources(), users, handler.get()); - Map> result = load(metaData.getResource().getAllInstanceDataSources(), users, handler.get()); + save(databaseMetaData.getResource().getAllInstanceDataSources(), users, handler.get()); + Map> result = load(databaseMetaData.getResource().getAllInstanceDataSources(), users, handler.get()); checkConsistent(result); - return StoragePrivilegeMerger.merge(result, metaData.getDatabase().getName(), metaData.getRuleMetaData().getRules()); + return StoragePrivilegeMerger.merge(result, databaseMetaData.getDatabase().getName(), databaseMetaData.getRuleMetaData().getRules()); } private static void save(final Collection dataSources, diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/schema/SchemaPermittedPrivilegesProviderAlgorithm.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/schema/SchemaPermittedPrivilegesProviderAlgorithm.java index 33ff8cbd7c012..0b2e94a6fb458 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/schema/SchemaPermittedPrivilegesProviderAlgorithm.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/schema/SchemaPermittedPrivilegesProviderAlgorithm.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.authority.provider.schema.builder.SchemaPrivilegeBuilder; import org.apache.shardingsphere.authority.registry.UserPrivilegeMapAuthorityRegistry; import org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import java.util.Collection; @@ -46,7 +46,7 @@ public void init(final Properties props) { } @Override - public AuthorityRegistry buildAuthorityRegistry(final Map metaDataMap, final Collection users) { + public AuthorityRegistry buildAuthorityRegistry(final Map databaseMetaDataMap, final Collection users) { return new UserPrivilegeMapAuthorityRegistry(SchemaPrivilegeBuilder.build(users, props)); } diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedPrivilegesProviderAlgorithm.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedPrivilegesProviderAlgorithm.java index b0b87d3089434..cebc9d3af598c 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedPrivilegesProviderAlgorithm.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedPrivilegesProviderAlgorithm.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.authority.model.AuthorityRegistry; import org.apache.shardingsphere.authority.registry.AllPermittedAuthorityRegistry; import org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import java.util.Collection; @@ -43,7 +43,7 @@ public void init(final Properties props) { } @Override - public AuthorityRegistry buildAuthorityRegistry(final Map metaDataMap, final Collection users) { + public AuthorityRegistry buildAuthorityRegistry(final Map databaseMetaDataMap, final Collection users) { return new AllPermittedAuthorityRegistry(); } diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java index de45655d15867..2f6d11b28e696 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.authority.model.AuthorityRegistry; import org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm; import org.apache.shardingsphere.authority.factory.AuthorityProviderAlgorithmFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; @@ -42,10 +42,10 @@ public final class AuthorityRule implements GlobalRule { private volatile AuthorityRegistry authorityRegistry; - public AuthorityRule(final AuthorityRuleConfiguration config, final Map metaDataMap) { + public AuthorityRule(final AuthorityRuleConfiguration config, final Map databaseMetaDataMap) { users = config.getUsers(); provider = AuthorityProviderAlgorithmFactory.newInstance(config.getProvider()); - authorityRegistry = provider.buildAuthorityRegistry(metaDataMap, config.getUsers()); + authorityRegistry = provider.buildAuthorityRegistry(databaseMetaDataMap, config.getUsers()); } /** @@ -70,11 +70,11 @@ public Optional findPrivileges(final Grantee grantee) /** * Refresh authority. * - * @param metaDataMap meta data map + * @param databaseMetaDataMap database meta data map * @param users users */ - public synchronized void refresh(final Map metaDataMap, final Collection users) { - authorityRegistry = provider.buildAuthorityRegistry(metaDataMap, users); + public synchronized void refresh(final Map databaseMetaDataMap, final Collection users) { + authorityRegistry = provider.buildAuthorityRegistry(databaseMetaDataMap, users); } @Override diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java index 17592004b5e6c..5aa60901c17ff 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration; import org.apache.shardingsphere.authority.constant.AuthorityOrder; import org.apache.shardingsphere.authority.rule.AuthorityRule; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; import java.util.Map; @@ -31,8 +31,8 @@ public final class AuthorityRuleBuilder implements GlobalRuleBuilder { @Override - public AuthorityRule build(final AuthorityRuleConfiguration ruleConfig, final Map metaDataMap) { - return new AuthorityRule(ruleConfig, metaDataMap); + public AuthorityRule build(final AuthorityRuleConfiguration ruleConfig, final Map databaseMetaDataMap) { + return new AuthorityRule(ruleConfig, databaseMetaDataMap); } @Override diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java index d75c1a1d72d82..f649b07a4f0af 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; import org.apache.shardingsphere.infra.executor.check.SQLChecker; import org.apache.shardingsphere.infra.executor.check.SQLCheckerFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement; @@ -54,7 +54,7 @@ public final class AuthorityCheckerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @SuppressWarnings("unchecked") @Test @@ -75,7 +75,7 @@ public void assertCheckSchemaByNative() throws SQLException { ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost"); users.add(root); AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties())); - AuthorityRule rule = new AuthorityRule(ruleConfig, createMetaDataMap(users)); + AuthorityRule rule = new AuthorityRule(ruleConfig, createDatabaseMetaDataMap(users)); SQLChecker sqlChecker = SQLCheckerFactory.getInstance(Collections.singleton(rule)).get(rule); assertTrue(sqlChecker.check("db0", new Grantee("root", "localhost"), rule)); assertFalse(sqlChecker.check("db1", new Grantee("root", "localhost"), rule)); @@ -113,12 +113,12 @@ public void assertCheckSQLStatement() { assertTrue(sqlChecker.check(createTableStatement, Collections.emptyList(), new Grantee("root", "localhost"), "db0", Collections.emptyMap(), rule).isPassed()); } - private Map createMetaDataMap(final Collection users) throws SQLException { - when(metaData.getDatabase().getName()).thenReturn("db0"); + private Map createDatabaseMetaDataMap(final Collection users) throws SQLException { + when(databaseMetaData.getDatabase().getName()).thenReturn("db0"); DataSource dataSource = mockDataSourceForPrivileges(users); - when(metaData.getResource().getAllInstanceDataSources()).thenReturn(Collections.singletonList(dataSource)); - when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.emptyList()); - return Collections.singletonMap("db0", metaData); + when(databaseMetaData.getResource().getAllInstanceDataSources()).thenReturn(Collections.singletonList(dataSource)); + when(databaseMetaData.getRuleMetaData().getRules()).thenReturn(Collections.emptyList()); + return Collections.singletonMap("db0", databaseMetaData); } private DataSource mockDataSourceForPrivileges(final Collection users) throws SQLException { diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithmTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithmTest.java index 01f7e8b5ea561..8cdd45d28e78d 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithmTest.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithmTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.authority.model.AuthorityRegistry; import org.apache.shardingsphere.authority.model.PrivilegeType; import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.junit.Test; @@ -47,8 +47,8 @@ public void assertFindPrivileges() throws SQLException { Collection users = new LinkedList<>(); ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost"); users.add(root); - ShardingSphereMetaData metaData = mockShardingSphereMetaData(users); - AuthorityRegistry authorityRegistry = algorithm.buildAuthorityRegistry(Collections.singletonMap("db0", metaData), users); + ShardingSphereDatabaseMetaData databaseMetaData = mockDatabaseMetaData(users); + AuthorityRegistry authorityRegistry = algorithm.buildAuthorityRegistry(Collections.singletonMap("db0", databaseMetaData), users); Optional privileges = authorityRegistry.findPrivileges(new Grantee("root", "localhost")); assertTrue(privileges.isPresent()); assertPrivilege(privileges.get()); @@ -65,8 +65,8 @@ private void assertPrivilege(final ShardingSpherePrivileges privileges) { assertTrue(privileges.hasPrivileges(expected)); } - private ShardingSphereMetaData mockShardingSphereMetaData(final Collection users) throws SQLException { - ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + private ShardingSphereDatabaseMetaData mockDatabaseMetaData(final Collection users) throws SQLException { + ShardingSphereDatabaseMetaData result = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); DataSource dataSource = mockDataSourceForPrivileges(users); when(result.getResource().getAllInstanceDataSources()).thenReturn(Collections.singletonList(dataSource)); when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList()); diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java index c003ead4604b9..f0b65d732f7d2 100644 --- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java +++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.authority.model.PrivilegeType; import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.junit.Test; @@ -43,11 +43,11 @@ public final class StoragePrivilegeBuilderTest { @Test public void assertBuildInCache() { - Collection metaDataList = new LinkedList<>(); + Collection databaseMetaDataList = new LinkedList<>(); Collection users = new LinkedList<>(); ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost"); users.add(root); - Map result = StoragePrivilegeBuilder.build(metaDataList, users); + Map result = StoragePrivilegeBuilder.build(databaseMetaDataList, users); assertThat(result.size(), is(1)); assertTrue(result.get(root).hasPrivileges(Collections.singletonList(PrivilegeType.SUPER))); } @@ -57,8 +57,8 @@ public void assertBuildPrivilegesInStorage() throws SQLException { Collection users = new LinkedList<>(); ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost"); users.add(root); - ShardingSphereMetaData metaData = mockShardingSphereMetaData(users); - Map result = StoragePrivilegeBuilder.build(Collections.singletonList(metaData), users); + ShardingSphereDatabaseMetaData databaseMetaData = mockDatabaseMetaData(users); + Map result = StoragePrivilegeBuilder.build(Collections.singletonList(databaseMetaData), users); assertThat(result.size(), is(1)); Collection expected = new LinkedList<>(); expected.add(PrivilegeType.SUPER); @@ -70,8 +70,8 @@ public void assertBuildPrivilegesInStorage() throws SQLException { assertTrue(result.get(root).hasPrivileges(expected)); } - private ShardingSphereMetaData mockShardingSphereMetaData(final Collection users) throws SQLException { - ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + private ShardingSphereDatabaseMetaData mockDatabaseMetaData(final Collection users) throws SQLException { + ShardingSphereDatabaseMetaData result = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); DataSource dataSource = mockDataSourceForPrivileges(users); when(result.getResource().getAllInstanceDataSources()).thenReturn(Collections.singleton(dataSource)); when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList()); diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/config/ingest/InventoryDumperConfiguration.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/config/ingest/InventoryDumperConfiguration.java index 1d5635aec6ceb..c1f33e2cc54b1 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/config/ingest/InventoryDumperConfiguration.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/config/ingest/InventoryDumperConfiguration.java @@ -35,8 +35,7 @@ public final class InventoryDumperConfiguration extends DumperConfiguration { private String logicTableName; - // TODO rename to uniqueKey - private String primaryKey; + private String uniqueKey; private Integer uniqueKeyDataType; diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/Column.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/Column.java index b1417b4b814e8..24a25b8a76548 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/Column.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/Column.java @@ -38,10 +38,10 @@ public final class Column { private final boolean updated; - private final boolean primaryKey; + private final boolean uniqueKey; - public Column(final String name, final Object value, final boolean updated, final boolean primaryKey) { - this(name, null, value, updated, primaryKey); + public Column(final String name, final Object value, final boolean updated, final boolean uniqueKey) { + this(name, null, value, updated, uniqueKey); } @Override diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/DataRecord.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/DataRecord.java index 19ad081cc5d35..126b8ee17e9b4 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/DataRecord.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/api/ingest/record/DataRecord.java @@ -33,15 +33,15 @@ */ @Getter @Setter -@EqualsAndHashCode(of = {"tableName", "primaryKeyValue"}, callSuper = false) +@EqualsAndHashCode(of = {"tableName", "uniqueKeyValue"}, callSuper = false) @ToString public final class DataRecord extends Record { private final List columns; - private final List primaryKeyValue = new LinkedList<>(); + private final List uniqueKeyValue = new LinkedList<>(); - private final List oldPrimaryKeyValues = new ArrayList<>(); + private final List oldUniqueKeyValues = new ArrayList<>(); private String type; @@ -59,9 +59,9 @@ public DataRecord(final IngestPosition position, final int columnCount) { */ public void addColumn(final Column data) { columns.add(data); - if (data.isPrimaryKey()) { - primaryKeyValue.add(data.getValue()); - oldPrimaryKeyValues.add(data.getOldValue()); + if (data.isUniqueKey()) { + uniqueKeyValue.add(data.getValue()); + oldUniqueKeyValues.add(data.getOldValue()); } } @@ -90,7 +90,7 @@ public Column getColumn(final int index) { * @return key */ public Key getKey() { - return new Key(tableName, primaryKeyValue); + return new Key(tableName, uniqueKeyValue); } /** @@ -99,7 +99,7 @@ public Key getKey() { * @return key */ public Key getOldKey() { - return new Key(tableName, oldPrimaryKeyValues); + return new Key(tableName, oldUniqueKeyValues); } @EqualsAndHashCode @@ -108,6 +108,6 @@ public static class Key { private final String tableName; - private final List primaryKeyValues; + private final List uniqueKeyValues; } } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java index 595fc6209d1fe..4e1da7e835de6 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java @@ -49,12 +49,11 @@ public final class PipelineAPIFactory { @Override protected GovernanceRepositoryAPI initialize() { - Optional persistServiceOptional = PipelineContext.getContextManager().getMetaDataContexts().getMetaDataPersistService(); - if (!persistServiceOptional.isPresent()) { + Optional persistService = PipelineContext.getContextManager().getMetaDataContexts().getPersistService(); + if (!persistService.isPresent()) { throw new RuntimeException("persistService is not present"); } - ClusterPersistRepository repository = (ClusterPersistRepository) persistServiceOptional.get().getRepository(); - return new GovernanceRepositoryAPIImpl(repository); + return new GovernanceRepositoryAPIImpl((ClusterPersistRepository) persistService.get().getRepository()); } }; diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyChecker.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyChecker.java index 490b02f882898..df50886da0f52 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyChecker.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/DataConsistencyChecker.java @@ -38,7 +38,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorThreadFactoryBuilder; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -79,8 +79,8 @@ public final class DataConsistencyChecker { public DataConsistencyChecker(final RuleAlteredJobConfiguration jobConfig) { this.jobConfig = jobConfig; logicTableNames = jobConfig.splitLogicTableNames(); - ShardingSphereMetaData metaData = PipelineContext.getContextManager().getMetaDataContexts().getMetaData(jobConfig.getDatabaseName()); - tableNameSchemaNameMapping = new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(metaData.getDatabase().getSchemas())); + ShardingSphereDatabaseMetaData databaseMetaData = PipelineContext.getContextManager().getMetaDataContexts().getDatabaseMetaData(jobConfig.getDatabaseName()); + tableNameSchemaNameMapping = new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(databaseMetaData.getDatabase().getSchemas())); } /** @@ -225,12 +225,12 @@ private void addMySQLDataSourceConfig(final PipelineDataSourceConfiguration data private TableMetaData getTableMetaData(final String databaseName, final String logicTableName) { ContextManager contextManager = PipelineContext.getContextManager(); Preconditions.checkNotNull(contextManager, "ContextManager null"); - ShardingSphereMetaData metaData = contextManager.getMetaDataContexts().getMetaData(databaseName); - if (null == metaData) { + ShardingSphereDatabaseMetaData databaseMetaData = contextManager.getMetaDataContexts().getDatabaseMetaData(databaseName); + if (null == databaseMetaData) { throw new RuntimeException("Can not get meta data by database name " + databaseName); } String schemaName = tableNameSchemaNameMapping.getSchemaName(logicTableName); - ShardingSphereSchema schema = metaData.getSchemaByName(schemaName); + ShardingSphereSchema schema = databaseMetaData.getDatabase().getSchema(schemaName); if (null == schema) { throw new RuntimeException("Can not get schema by schema name " + schemaName + ", logicTableName=" + logicTableName); } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/AbstractImporter.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/AbstractImporter.java index 7b8cd297293c3..c606d4ef103f9 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/AbstractImporter.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/AbstractImporter.java @@ -189,7 +189,7 @@ private void executeUpdate(final Connection connection, final DataRecord record) } for (int i = 0; i < conditionColumns.size(); i++) { Column keyColumn = conditionColumns.get(i); - ps.setObject(updatedColumns.size() + i + 1, (keyColumn.isPrimaryKey() && keyColumn.isUpdated()) ? keyColumn.getOldValue() : keyColumn.getValue()); + ps.setObject(updatedColumns.size() + i + 1, (keyColumn.isUniqueKey() && keyColumn.isUpdated()) ? keyColumn.getOldValue() : keyColumn.getValue()); } int updateCount = ps.executeUpdate(); if (1 != updateCount) { diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java index 5418794d6fc7b..632a482fe5b9f 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/importer/DataRecordMerger.java @@ -129,11 +129,11 @@ private void mergeDelete(final DataRecord dataRecord, final Map position = dumperConfig.getPosition(); log.info("inventory dump, uniqueKeyDataType={}, firstSQL={}, laterSQL={}, position={}", uniqueKeyDataType, firstSQL, laterSQL, position); if (position instanceof FinishedPosition) { @@ -167,12 +167,12 @@ private Optional dump0(final Connection conn, final String sql, final in record.setType(IngestDataChangeType.INSERT); record.setTableName(logicTableName); for (int i = 1; i <= metaData.getColumnCount(); i++) { - boolean isPrimaryKey = tableMetaData.isPrimaryKey(i - 1); + boolean isUniqueKey = tableMetaData.isUniqueKey(i - 1); Object value = readValue(resultSet, i); - if (isPrimaryKey) { + if (isUniqueKey) { maxUniqueKeyValue = value; } - record.addColumn(new Column(metaData.getColumnName(i), value, true, isPrimaryKey)); + record.addColumn(new Column(metaData.getColumnName(i), value, true, isUniqueKey)); } pushRecord(record); rowCount++; @@ -198,8 +198,8 @@ private Object getPositionEndValue(final IngestPosition position) { } private IngestPosition newPosition(final ResultSet rs) throws SQLException { - return null == dumperConfig.getPrimaryKey() ? new PlaceholderPosition() - : PrimaryKeyPositionFactory.newInstance(rs.getObject(dumperConfig.getPrimaryKey()), ((PrimaryKeyPosition) dumperConfig.getPosition()).getEndValue()); + return null == dumperConfig.getUniqueKey() ? new PlaceholderPosition() + : PrimaryKeyPositionFactory.newInstance(rs.getObject(dumperConfig.getUniqueKey()), ((PrimaryKeyPosition) dumperConfig.getPosition()).getEndValue()); } protected abstract PreparedStatement createPreparedStatement(Connection connection, String sql) throws SQLException; diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java index ddfd926fd48a1..1ef10aaf11a00 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java @@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.datanode.DataNodes; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.data.pipeline.spi.ddlgenerator.DialectDDLSQLGeneratorFactory; import org.apache.shardingsphere.infra.metadata.schema.util.IndexMetaDataUtil; import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; @@ -73,12 +73,12 @@ public final class PipelineDDLGenerator { */ @SneakyThrows public String generateLogicDDLSQL(final DatabaseType databaseType, final String databaseName, final String schemaName, final String tableName) { - ShardingSphereMetaData metaData = contextManager.getMetaDataContexts().getMetaData(databaseName); - String sql = generateActualDDLSQL(databaseType, schemaName, tableName, metaData); + ShardingSphereDatabaseMetaData databaseMetaData = contextManager.getMetaDataContexts().getDatabaseMetaData(databaseName); + String sql = generateActualDDLSQL(databaseType, schemaName, tableName, databaseMetaData); StringBuilder result = new StringBuilder(); for (String each : sql.split(DELIMITER)) { if (!each.trim().isEmpty()) { - result.append(decorateActualSQL(each.trim(), metaData, databaseType, databaseName)).append(DELIMITER).append(System.lineSeparator()); + result.append(decorateActualSQL(each.trim(), databaseMetaData, databaseType, databaseName)).append(DELIMITER).append(System.lineSeparator()); } } return result.toString(); @@ -105,40 +105,42 @@ public String replaceTableNameWithPrefix(final String sql, final String prefix, return sql; } - private String generateActualDDLSQL(final DatabaseType databaseType, final String schemaName, final String tableName, final ShardingSphereMetaData metaData) throws SQLException { - DataNodes dataNodes = new DataNodes(metaData.getRuleMetaData().getRules()); - Optional optional = dataNodes.getDataNodes(tableName).stream().filter(dataNode -> metaData.getResource().getDataSources().containsKey(dataNode.getDataSourceName().contains(".") - ? dataNode.getDataSourceName().split("\\.")[0] - : dataNode.getDataSourceName())).findFirst(); - String dataSourceName = optional.map(DataNode::getDataSourceName).orElseGet(() -> metaData.getResource().getDataSources().keySet().iterator().next()); + private String generateActualDDLSQL(final DatabaseType databaseType, final String schemaName, final String tableName, final ShardingSphereDatabaseMetaData databaseMetaData) throws SQLException { + DataNodes dataNodes = new DataNodes(databaseMetaData.getRuleMetaData().getRules()); + Optional optional = dataNodes.getDataNodes(tableName).stream() + .filter(dataNode -> databaseMetaData.getResource().getDataSources().containsKey(dataNode.getDataSourceName().contains(".") + ? dataNode.getDataSourceName().split("\\.")[0] + : dataNode.getDataSourceName())) + .findFirst(); + String dataSourceName = optional.map(DataNode::getDataSourceName).orElseGet(() -> databaseMetaData.getResource().getDataSources().keySet().iterator().next()); String actualTable = optional.map(DataNode::getTableName).orElse(tableName); return DialectDDLSQLGeneratorFactory.findInstance(databaseType).orElseThrow(() -> new ShardingSphereException("Failed to get dialect ddl sql generator")) - .generateDDLSQL(actualTable, schemaName, metaData.getResource().getDataSources().get(dataSourceName)); + .generateDDLSQL(actualTable, schemaName, databaseMetaData.getResource().getDataSources().get(dataSourceName)); } - private String decorateActualSQL(final String sql, final ShardingSphereMetaData metaData, final DatabaseType databaseType, final String databaseName) { + private String decorateActualSQL(final String sql, final ShardingSphereDatabaseMetaData databaseMetaData, final DatabaseType databaseType, final String databaseName) { LogicSQL logicSQL = getLogicSQL(sql, databaseType, databaseName); String result = logicSQL.getSql(); SQLStatementContext sqlStatementContext = logicSQL.getSqlStatementContext(); if (sqlStatementContext instanceof CreateTableStatementContext) { - result = decorateIndexAndConstraint(metaData, result, sqlStatementContext); - result = decorateTable(metaData, result, (TableAvailable) sqlStatementContext); + result = decorateIndexAndConstraint(databaseMetaData, result, sqlStatementContext); + result = decorateTable(databaseMetaData, result, (TableAvailable) sqlStatementContext); } if (sqlStatementContext instanceof CommentStatementContext) { - result = decorateTable(metaData, result, (TableAvailable) sqlStatementContext); + result = decorateTable(databaseMetaData, result, (TableAvailable) sqlStatementContext); } if (sqlStatementContext instanceof CreateIndexStatementContext) { - result = decorateTable(metaData, result, (TableAvailable) sqlStatementContext); - result = decorateIndexAndConstraint(metaData, result, sqlStatementContext); + result = decorateTable(databaseMetaData, result, (TableAvailable) sqlStatementContext); + result = decorateIndexAndConstraint(databaseMetaData, result, sqlStatementContext); } return result; } - private String decorateTable(final ShardingSphereMetaData metaData, final String sql, final TableAvailable sqlStatementContext) { + private String decorateTable(final ShardingSphereDatabaseMetaData databaseMetaData, final String sql, final TableAvailable sqlStatementContext) { String result = sql; for (SimpleTableSegment each : sqlStatementContext.getAllTables()) { - String logicTable = findLogicTable(each.getTableName(), metaData); + String logicTable = findLogicTable(each.getTableName(), databaseMetaData); if (!logicTable.equals(each.getTableName().getIdentifier().getValue())) { result = replace(result, each.getTableName(), logicTable); } @@ -146,13 +148,13 @@ private String decorateTable(final ShardingSphereMetaData metaData, final String return result; } - private String decorateIndexAndConstraint(final ShardingSphereMetaData metaData, final String sql, final SQLStatementContext sqlStatementContext) { + private String decorateIndexAndConstraint(final ShardingSphereDatabaseMetaData databaseMetaData, final String sql, final SQLStatementContext sqlStatementContext) { if (!(sqlStatementContext instanceof TableAvailable) || ((TableAvailable) sqlStatementContext).getTablesContext().getTables().isEmpty()) { return sql; } String result = sql; TableNameSegment tableNameSegment = ((TableAvailable) sqlStatementContext).getTablesContext().getTables().iterator().next().getTableName(); - String logicTable = findLogicTable(tableNameSegment, metaData); + String logicTable = findLogicTable(tableNameSegment, databaseMetaData); if (!tableNameSegment.getIdentifier().getValue().equals(logicTable)) { if (sqlStatementContext instanceof IndexAvailable) { result = decorateIndex((IndexAvailable) sqlStatementContext, result, tableNameSegment); @@ -160,7 +162,6 @@ private String decorateIndexAndConstraint(final ShardingSphereMetaData metaData, if (sqlStatementContext instanceof ConstraintAvailable) { result = decorateConstraint((ConstraintAvailable) sqlStatementContext, result, tableNameSegment); } - } return result; } @@ -193,9 +194,9 @@ private String replace(final String sql, final SQLSegment sqlSegment, final Stri return result; } - private String findLogicTable(final TableNameSegment tableNameSegment, final ShardingSphereMetaData metaData) { + private String findLogicTable(final TableNameSegment tableNameSegment, final ShardingSphereDatabaseMetaData databaseMetaData) { String actualTable = tableNameSegment.getIdentifier().getValue(); - return metaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataNodeContainedRule) + return databaseMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataNodeContainedRule) .map(each -> ((DataNodeContainedRule) each).findLogicTableByActualTable(actualTable).orElse(null)).filter(Objects::nonNull).findFirst().orElse(actualTable); } @@ -203,7 +204,7 @@ private LogicSQL getLogicSQL(final String sql, final DatabaseType databaseType, Optional sqlParserRule = contextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(SQLParserRule.class); Preconditions.checkState(sqlParserRule.isPresent()); SQLStatement sqlStatement = new ShardingSphereSQLParserEngine(databaseType.getType(), sqlParserRule.get().toParserConfiguration()).parse(sql, false); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(contextManager.getMetaDataContexts().getMetaDataMap(), + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(contextManager.getMetaDataContexts().getDatabaseMetaDataMap(), sqlStatement, databaseName); return new LogicSQL(sqlStatementContext, sql, Collections.emptyList()); } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/loader/PipelineTableMetaDataLoader.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/loader/PipelineTableMetaDataLoader.java index e70dd8dd566be..75c762edbd921 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/loader/PipelineTableMetaDataLoader.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/loader/PipelineTableMetaDataLoader.java @@ -22,17 +22,22 @@ import org.apache.shardingsphere.data.pipeline.api.datasource.PipelineDataSourceWrapper; import org.apache.shardingsphere.data.pipeline.api.metadata.TableName; import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineColumnMetaData; +import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineIndexMetaData; import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineTableMetaData; import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; /** @@ -49,13 +54,30 @@ public final class PipelineTableMetaDataLoader { private final Map tableMetaDataMap = new ConcurrentHashMap<>(); /** - * Load table metadata. + * Get table metadata, load if it does not exist. * - * @param schemaName schema name - * @param tableNamePattern table name pattern - * @throws SQLException if loading failure + * @param schemaName schema name. nullable + * @param tableName dedicated table name, not table name pattern + * @return table metadata */ - public void loadTableMetaData(final String schemaName, final String tableNamePattern) throws SQLException { + public PipelineTableMetaData getTableMetaData(final String schemaName, final String tableName) { + PipelineTableMetaData result = tableMetaDataMap.get(new TableName(tableName)); + if (null != result) { + return result; + } + try { + loadTableMetaData(schemaName, tableName); + } catch (final SQLException ex) { + throw new RuntimeException(String.format("Load metadata for table '%s' failed", tableName), ex); + } + result = tableMetaDataMap.get(new TableName(tableName)); + if (null == result) { + log.warn("getTableMetaData, can not load metadata for table '{}'", tableName); + } + return result; + } + + private void loadTableMetaData(final String schemaName, final String tableNamePattern) throws SQLException { try (Connection connection = dataSource.getConnection()) { long startMillis = System.currentTimeMillis(); String schemaNameFinal = isSchemaAvailable() ? schemaName : null; @@ -91,17 +113,36 @@ private Map loadTableMetaData0(final Connectio throw ex; } boolean primaryKey = primaryKeys.contains(columnName); - PipelineColumnMetaData columnMetaData = new PipelineColumnMetaData(ordinalPosition, columnName, dataType, dataTypeName, primaryKey); + boolean isNullable = "YES".equals(resultSet.getString("IS_NULLABLE")); + PipelineColumnMetaData columnMetaData = new PipelineColumnMetaData(ordinalPosition, columnName, dataType, dataTypeName, isNullable, primaryKey); columnMetaDataMap.put(columnName, columnMetaData); } } Map result = new LinkedHashMap<>(); for (Entry> entry : tablePipelineColumnMetaDataMap.entrySet()) { - result.put(new TableName(entry.getKey()), new PipelineTableMetaData(entry.getKey(), entry.getValue())); + String tableName = entry.getKey(); + result.put(new TableName(tableName), new PipelineTableMetaData(tableName, entry.getValue(), loadIndexesOfTable(connection, schemaName, entry.getValue(), tableName))); } return result; } + private Collection loadIndexesOfTable(final Connection connection, final String schemaName, final Map columns, + final String tableName) throws SQLException { + Map result = new LinkedHashMap<>(); + Map> orderedColumnsOfIndexes = new LinkedHashMap<>(); + try (ResultSet resultSet = connection.getMetaData().getIndexInfo(connection.getCatalog(), schemaName, tableName, true, false)) { + while (resultSet.next()) { + String indexName = resultSet.getString("INDEX_NAME"); + result.computeIfAbsent(indexName, unused -> new PipelineIndexMetaData(indexName, new LinkedList<>())); + orderedColumnsOfIndexes.computeIfAbsent(indexName, unused -> new TreeMap<>()).put(resultSet.getShort("ORDINAL_POSITION"), resultSet.getString("COLUMN_NAME")); + } + } + for (PipelineIndexMetaData each : result.values()) { + orderedColumnsOfIndexes.get(each.getName()).values().stream().map(columns::get).forEach(each.getColumns()::add); + } + return result.values(); + } + private Set loadPrimaryKeys(final Connection connection, final String schemaName, final String tableName) throws SQLException { Set result = new LinkedHashSet<>(); // TODO order primary keys @@ -112,28 +153,4 @@ private Set loadPrimaryKeys(final Connection connection, final String sc } return result; } - - /** - * Get table metadata, load if it does not exist. - * - * @param schemaName schema name. nullable - * @param tableName dedicated table name, not table name pattern - * @return table metadata - */ - public PipelineTableMetaData getTableMetaData(final String schemaName, final String tableName) { - PipelineTableMetaData result = tableMetaDataMap.get(new TableName(tableName)); - if (null != result) { - return result; - } - try { - loadTableMetaData(schemaName, tableName); - } catch (final SQLException ex) { - throw new RuntimeException(String.format("Load metadata for table '%s' failed", tableName), ex); - } - result = tableMetaDataMap.get(new TableName(tableName)); - if (null == result) { - log.warn("getTableMetaData, can not load metadata for table '{}'", tableName); - } - return result; - } } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineColumnMetaData.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineColumnMetaData.java index 6d6e5cd1b7319..3202dbdbeeb37 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineColumnMetaData.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineColumnMetaData.java @@ -41,6 +41,8 @@ public final class PipelineColumnMetaData implements Comparable columns; +} diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineTableMetaData.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineTableMetaData.java index d63aedbb955f2..86c99c7ea2a4d 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineTableMetaData.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/model/PipelineTableMetaData.java @@ -23,6 +23,7 @@ import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -30,7 +31,7 @@ import java.util.stream.Collectors; /** - * Pipelien table meta data. + * Pipeline table meta data. */ @Slf4j @ToString @@ -47,7 +48,10 @@ public final class PipelineTableMetaData { @Getter private final List primaryKeyColumns; - public PipelineTableMetaData(final String name, final Map columnMetaDataMap) { + @Getter + private final Collection uniqueIndexes; + + public PipelineTableMetaData(final String name, final Map columnMetaDataMap, final Collection uniqueIndexes) { this.name = name; this.columnMetaDataMap = columnMetaDataMap; List columnMetaDataList = new ArrayList<>(columnMetaDataMap.values()); @@ -55,6 +59,7 @@ public PipelineTableMetaData(final String name, final Map= columnNames.size()) { + return false; + } + String columnName = columnNames.get(columnIndex); + return columnMetaDataMap.get(columnName).isPrimaryKey() || (columnName.equals(uniqueIndexes.iterator().next().getColumns().get(0).getName())); } @Override diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/record/RecordUtil.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/record/RecordUtil.java index f623da6f196dd..02d8146909a9f 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/record/RecordUtil.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/record/RecordUtil.java @@ -41,7 +41,7 @@ public final class RecordUtil { public static List extractPrimaryColumns(final DataRecord dataRecord) { List result = new ArrayList<>(dataRecord.getColumns().size()); for (Column each : dataRecord.getColumns()) { - if (each.isPrimaryKey()) { + if (each.isUniqueKey()) { result.add(each); } } @@ -58,7 +58,7 @@ public static List extractPrimaryColumns(final DataRecord dataRecord) { public static List extractConditionColumns(final DataRecord dataRecord, final Set shardingColumns) { List result = new ArrayList<>(dataRecord.getColumns().size()); for (Column each : dataRecord.getColumns()) { - if (each.isPrimaryKey() || shardingColumns.contains(each.getName())) { + if (each.isUniqueKey() || shardingColumns.contains(each.getName())) { result.add(each); } } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/prepare/InventoryTaskSplitter.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/prepare/InventoryTaskSplitter.java index 593e3b479791d..fe243a135e4df 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/prepare/InventoryTaskSplitter.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/prepare/InventoryTaskSplitter.java @@ -35,6 +35,8 @@ import org.apache.shardingsphere.data.pipeline.core.exception.PipelineJobPrepareFailedException; import org.apache.shardingsphere.data.pipeline.core.execute.ExecuteEngine; import org.apache.shardingsphere.data.pipeline.core.metadata.loader.PipelineTableMetaDataLoader; +import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineColumnMetaData; +import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineIndexMetaData; import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineTableMetaData; import org.apache.shardingsphere.data.pipeline.core.sqlbuilder.PipelineSQLBuilderFactory; import org.apache.shardingsphere.data.pipeline.core.task.InventoryTask; @@ -118,7 +120,7 @@ private Collection splitByPrimaryKey(final RuleAlt splitDumperConfig.setShardingItem(i++); splitDumperConfig.setActualTableName(dumperConfig.getActualTableName()); splitDumperConfig.setLogicTableName(dumperConfig.getLogicTableName()); - splitDumperConfig.setPrimaryKey(dumperConfig.getPrimaryKey()); + splitDumperConfig.setUniqueKey(dumperConfig.getUniqueKey()); splitDumperConfig.setUniqueKeyDataType(dumperConfig.getUniqueKeyDataType()); splitDumperConfig.setBatchSize(batchSize); splitDumperConfig.setRateLimitAlgorithm(rateLimitAlgorithm); @@ -133,51 +135,61 @@ private Collection> getInventoryPositions(final RuleAlteredJob String schemaName = dumperConfig.getSchemaName(new LogicTableName(dumperConfig.getLogicTableName())); String actualTableName = dumperConfig.getActualTableName(); PipelineTableMetaData tableMetaData = metaDataLoader.getTableMetaData(schemaName, actualTableName); + PipelineColumnMetaData uniqueKeyColumn = mustGetAnAppropriateUniqueKeyColumn(tableMetaData, actualTableName); if (null != initProgress && initProgress.getStatus() != JobStatus.PREPARING_FAILURE) { Collection> result = initProgress.getInventoryPosition(dumperConfig.getActualTableName()).values(); for (IngestPosition each : result) { if (each instanceof PrimaryKeyPosition) { - String primaryKey = tableMetaData.getPrimaryKeyColumns().get(0); - dumperConfig.setPrimaryKey(primaryKey); - dumperConfig.setUniqueKeyDataType(tableMetaData.getColumnMetaData(primaryKey).getDataType()); + dumperConfig.setUniqueKey(uniqueKeyColumn.getName()); + dumperConfig.setUniqueKeyDataType(uniqueKeyColumn.getDataType()); break; } } // Do NOT filter FinishedPosition here, since whole inventory tasks are required in job progress when persisting to register center. return result; } - checkPrimaryKey(tableMetaData, actualTableName); - String primaryKey = tableMetaData.getPrimaryKeyColumns().get(0); - dumperConfig.setPrimaryKey(primaryKey); - int primaryKeyDataType = tableMetaData.getColumnMetaData(primaryKey).getDataType(); - dumperConfig.setUniqueKeyDataType(primaryKeyDataType); - if (PipelineJdbcUtils.isIntegerColumn(primaryKeyDataType)) { + dumperConfig.setUniqueKey(uniqueKeyColumn.getName()); + int uniqueKeyDataType = uniqueKeyColumn.getDataType(); + dumperConfig.setUniqueKeyDataType(uniqueKeyDataType); + if (PipelineJdbcUtils.isIntegerColumn(uniqueKeyDataType)) { return getPositionByIntegerPrimaryKeyRange(jobContext, dataSource, dumperConfig); - } else if (PipelineJdbcUtils.isStringColumn(primaryKeyDataType)) { + } else if (PipelineJdbcUtils.isStringColumn(uniqueKeyDataType)) { return getPositionByStringPrimaryKeyRange(); } else { throw new PipelineJobCreationException(String.format("Can not split range for table %s, reason: primary key is not integer or string type", actualTableName)); } } - private void checkPrimaryKey(final PipelineTableMetaData tableMetaData, final String tableName) { + private PipelineColumnMetaData mustGetAnAppropriateUniqueKeyColumn(final PipelineTableMetaData tableMetaData, final String tableName) { if (null == tableMetaData) { throw new PipelineJobCreationException(String.format("Can not split range for table %s, reason: can not get table metadata ", tableName)); } List primaryKeys = tableMetaData.getPrimaryKeyColumns(); - if (null == primaryKeys || primaryKeys.isEmpty()) { - throw new PipelineJobCreationException(String.format("Can not split range for table %s, reason: no primary key", tableName)); - } if (primaryKeys.size() > 1) { throw new PipelineJobCreationException(String.format("Can not split range for table %s, reason: primary key is union primary", tableName)); } + if (1 == primaryKeys.size()) { + return tableMetaData.getColumnMetaData(tableMetaData.getPrimaryKeyColumns().get(0)); + } + Collection uniqueIndexes = tableMetaData.getUniqueIndexes(); + if (uniqueIndexes.isEmpty()) { + throw new PipelineJobCreationException(String.format("Can not split range for table %s, reason: no primary key or unique index", tableName)); + } + if (1 == uniqueIndexes.size() && 1 == uniqueIndexes.iterator().next().getColumns().size()) { + PipelineColumnMetaData column = uniqueIndexes.iterator().next().getColumns().get(0); + if (!column.isNullable()) { + return column; + } + } + throw new PipelineJobCreationException( + String.format("Can not split range for table %s, reason: table contains multiple unique index or unique index contains nullable/multiple column(s)", tableName)); } private Collection> getPositionByIntegerPrimaryKeyRange(final RuleAlteredJobContext jobContext, final DataSource dataSource, final InventoryDumperConfiguration dumperConfig) { Collection> result = new LinkedList<>(); RuleAlteredJobConfiguration jobConfig = jobContext.getJobConfig(); String sql = PipelineSQLBuilderFactory.getInstance(jobConfig.getSourceDatabaseType()) - .buildSplitByPrimaryKeyRangeSQL(dumperConfig.getSchemaName(new LogicTableName(dumperConfig.getLogicTableName())), dumperConfig.getActualTableName(), dumperConfig.getPrimaryKey()); + .buildSplitByPrimaryKeyRangeSQL(dumperConfig.getSchemaName(new LogicTableName(dumperConfig.getLogicTableName())), dumperConfig.getActualTableName(), dumperConfig.getUniqueKey()); int shardingSize = jobContext.getRuleAlteredContext().getOnRuleAlteredActionConfig().getInput().getShardingSize(); try ( Connection connection = dataSource.getConnection(); @@ -194,7 +206,7 @@ private Collection> getPositionByIntegerPrimaryKeyRange(final } long endId = rs.getLong(1); if (endId == 0) { - log.info("getPositionByPrimaryKeyRange, endId is 0, break, tableName={}, primaryKey={}, beginId={}", dumperConfig.getActualTableName(), dumperConfig.getPrimaryKey(), beginId); + log.info("getPositionByPrimaryKeyRange, endId is 0, break, tableName={}, primaryKey={}, beginId={}", dumperConfig.getActualTableName(), dumperConfig.getUniqueKey(), beginId); break; } result.add(new IntegerPrimaryKeyPosition(beginId, endId)); @@ -206,7 +218,7 @@ private Collection> getPositionByIntegerPrimaryKeyRange(final result.add(new IntegerPrimaryKeyPosition(0, 0)); } } catch (final SQLException ex) { - throw new PipelineJobPrepareFailedException(String.format("Split task for table %s by primary key %s error", dumperConfig.getActualTableName(), dumperConfig.getPrimaryKey()), ex); + throw new PipelineJobPrepareFailedException(String.format("Split task for table %s by primary key %s error", dumperConfig.getActualTableName(), dumperConfig.getUniqueKey()), ex); } return result; } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/scaling/core/job/environment/ScalingEnvironmentManager.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/scaling/core/job/environment/ScalingEnvironmentManager.java index b3743020deba5..f525ea9f7afbd 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/scaling/core/job/environment/ScalingEnvironmentManager.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/scaling/core/job/environment/ScalingEnvironmentManager.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceFactory; import org.apache.shardingsphere.data.pipeline.core.sqlbuilder.PipelineSQLBuilderFactory; import org.apache.shardingsphere.data.pipeline.spi.sqlbuilder.PipelineSQLBuilder; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.sql.Connection; import java.sql.PreparedStatement; @@ -52,8 +52,8 @@ public void cleanupTargetTables(final RuleAlteredJobConfiguration jobConfig) thr log.info("cleanupTargetTables, tables={}", tables); PipelineDataSourceConfiguration target = jobConfig.getTarget(); PipelineSQLBuilder pipelineSQLBuilder = PipelineSQLBuilderFactory.getInstance(jobConfig.getTargetDatabaseType()); - ShardingSphereMetaData metaData = PipelineContext.getContextManager().getMetaDataContexts().getMetaData(jobConfig.getDatabaseName()); - TableNameSchemaNameMapping tableNameSchemaNameMapping = new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(metaData.getDatabase().getSchemas())); + ShardingSphereDatabaseMetaData databaseMetaData = PipelineContext.getContextManager().getMetaDataContexts().getDatabaseMetaData(jobConfig.getDatabaseName()); + TableNameSchemaNameMapping tableNameSchemaNameMapping = new TableNameSchemaNameMapping(TableNameSchemaNameMapping.convert(databaseMetaData.getDatabase().getSchemas())); try ( PipelineDataSourceWrapper dataSource = PipelineDataSourceFactory.newInstance(PipelineDataSourceConfigurationFactory.newInstance(target.getType(), target.getParameter())); Connection connection = dataSource.getConnection()) { diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumper.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumper.java index 65ab8bc84fbe1..1adf68bc2012d 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumper.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumper.java @@ -131,7 +131,7 @@ private void handleWriteRowsEvent(final WriteRowsEvent event) { record.setType(IngestDataChangeType.INSERT); for (int i = 0; i < each.length; i++) { PipelineColumnMetaData columnMetaData = tableMetaData.getColumnMetaData(i); - record.addColumn(new Column(columnMetaData.getName(), handleValue(columnMetaData, each[i]), true, columnMetaData.isPrimaryKey())); + record.addColumn(new Column(columnMetaData.getName(), handleValue(columnMetaData, each[i]), true, tableMetaData.isUniqueKey(i))); } pushRecord(record); } @@ -168,7 +168,7 @@ private void handleDeleteRowsEvent(final DeleteRowsEvent event) { record.setType(IngestDataChangeType.DELETE); for (int i = 0, length = each.length; i < length; i++) { PipelineColumnMetaData columnMetaData = tableMetaData.getColumnMetaData(i); - record.addColumn(new Column(columnMetaData.getName(), handleValue(columnMetaData, each[i]), true, columnMetaData.isPrimaryKey())); + record.addColumn(new Column(columnMetaData.getName(), handleValue(columnMetaData, each[i]), true, tableMetaData.isUniqueKey(i))); } pushRecord(record); } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java index a50a48c28a4b7..870f676e3ff52 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java @@ -50,7 +50,7 @@ private String buildDuplicateUpdateSQL(final DataRecord dataRecord, final Map extractUpdatedColumns(final DataRecord record, final Map> shardingColumnsMap) { - return record.getColumns().stream().filter(each -> !(each.isPrimaryKey() || isShardingColumn(shardingColumnsMap, record.getTableName(), each.getName()))).collect(Collectors.toList()); + return record.getColumns().stream().filter(each -> !(each.isUniqueKey() || isShardingColumn(shardingColumnsMap, record.getTableName(), each.getName()))).collect(Collectors.toList()); } private String buildConflictSQL(final Map> shardingColumnsMap) { diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverter.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverter.java index e3403ae306135..cc9e26117d403 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverter.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverter.java @@ -110,6 +110,7 @@ private DataRecord handleDeleteRowsEvent(final DeleteRowEvent event) { // TODO completion columns DataRecord result = createDataRecord(event, event.getPrimaryKeys().size()); result.setType(IngestDataChangeType.DELETE); + // TODO Unique key may be a column within unique index List primaryKeyColumns = getPipelineTableMetaData(event.getTableName()).getPrimaryKeyColumns(); for (int i = 0; i < event.getPrimaryKeys().size(); i++) { result.addColumn(new Column(primaryKeyColumns.get(i), event.getPrimaryKeys().get(i), true, true)); @@ -125,9 +126,9 @@ private DataRecord createDataRecord(final AbstractRowEvent rowsEvent, final int private void putColumnsIntoDataRecord(final DataRecord dataRecord, final PipelineTableMetaData tableMetaData, final List values) { for (int i = 0, count = values.size(); i < count; i++) { - boolean isPrimaryKey = tableMetaData.isPrimaryKey(i); - Object primaryKeyOldValue = isPrimaryKey ? values.get(i) : null; - Column column = new Column(tableMetaData.getColumnMetaData(i).getName(), primaryKeyOldValue, values.get(i), true, isPrimaryKey); + boolean isUniqueKey = tableMetaData.isUniqueKey(i); + Object uniqueKeyOldValue = isUniqueKey ? values.get(i) : null; + Column column = new Column(tableMetaData.getColumnMetaData(i).getName(), uniqueKeyOldValue, values.get(i), true, isUniqueKey); dataRecord.addColumn(column); } } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java index 52d8986985b59..3b9a258e30b47 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPlugin.java @@ -85,7 +85,6 @@ private AbstractRowEvent readTableEvent(final ByteBuffer data) { private AbstractRowEvent readWriteRowEvent(final ByteBuffer data) { WriteRowEvent result = new WriteRowEvent(); List afterColumns = new LinkedList<>(); - while (data.hasRemaining()) { afterColumns.add(readColumn(data)); } @@ -96,7 +95,6 @@ private AbstractRowEvent readWriteRowEvent(final ByteBuffer data) { private AbstractRowEvent readUpdateRowEvent(final ByteBuffer data) { UpdateRowEvent result = new UpdateRowEvent(); List afterColumns = new LinkedList<>(); - while (data.hasRemaining()) { afterColumns.add(readColumn(data)); } @@ -107,7 +105,6 @@ private AbstractRowEvent readUpdateRowEvent(final ByteBuffer data) { private AbstractRowEvent readDeleteRowEvent(final ByteBuffer data) { DeleteRowEvent result = new DeleteRowEvent(); List afterColumns = new LinkedList<>(); - while (data.hasRemaining()) { afterColumns.add(readColumn(data)); } diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java index 937bb5bf0703e..e7fda9f2e84f2 100644 --- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java +++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java @@ -61,7 +61,7 @@ private String buildConflictSQL(final DataRecord dataRecord, final Map { @Override - public SQLParserRule build(final SQLParserRuleConfiguration ruleConfig, final Map metaDataMap) { + public SQLParserRule build(final SQLParserRuleConfiguration ruleConfig, final Map databaseMetaDataMap) { return new SQLParserRule(ruleConfig); } diff --git a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java index 0079385d49429..1790d7aced7e5 100644 --- a/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java +++ b/shardingsphere-kernel/shardingsphere-schedule/shardingsphere-schedule-core/src/main/java/org/apache/shardingsphere/schedule/core/api/ModeScheduleContextFactory.java @@ -50,14 +50,14 @@ public void init(final String instanceId, final ModeConfiguration modeConfig) { /** * Get mode schedule context of current instance. * + * @param instanceId instance id * @return mode schedule context */ - public Optional get() { - // TODO get by instance id + public Optional get(final String instanceId) { if (modeScheduleContexts.values().isEmpty()) { return Optional.empty(); } - return Optional.ofNullable(modeScheduleContexts.values().iterator().next()); + return Optional.ofNullable(modeScheduleContexts.get(instanceId)); } /** diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java index 7c1358cb7afac..18509a35fbf37 100644 --- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java +++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouter.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.database.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.QualifiedTable; import org.apache.shardingsphere.infra.metadata.schema.util.IndexMetaDataUtil; import org.apache.shardingsphere.infra.route.SQLRouter; @@ -52,15 +52,15 @@ public final class SingleTableSQLRouter implements SQLRouter { @SuppressWarnings({"rawtypes", "unchecked"}) @Override - public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final SingleTableRule rule, final ConfigurationProperties props) { - if (1 == metaData.getResource().getDataSources().size()) { - return createSingleDataSourceRouteContext(rule, metaData); + public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final SingleTableRule rule, final ConfigurationProperties props) { + if (1 == databaseMetaData.getResource().getDataSources().size()) { + return createSingleDataSourceRouteContext(rule, databaseMetaData); } RouteContext result = new RouteContext(); SQLStatementContext sqlStatementContext = logicSQL.getSqlStatementContext(); Optional validator = SingleTableMetadataValidatorFactory.newInstance(sqlStatementContext.getSqlStatement()); - validator.ifPresent(optional -> optional.validate(rule, sqlStatementContext, metaData)); - Collection singleTableNames = getSingleTableNames(sqlStatementContext, metaData, rule, result); + validator.ifPresent(optional -> optional.validate(rule, sqlStatementContext, databaseMetaData)); + Collection singleTableNames = getSingleTableNames(sqlStatementContext, databaseMetaData, rule, result); if (!singleTableNames.isEmpty()) { validateSameDataSource(sqlStatementContext, rule, props, singleTableNames, result); } @@ -69,10 +69,10 @@ public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSp } @Override - public void decorateRouteContext(final RouteContext routeContext, final LogicSQL logicSQL, final ShardingSphereMetaData metaData, + public void decorateRouteContext(final RouteContext routeContext, final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final SingleTableRule rule, final ConfigurationProperties props) { SQLStatementContext sqlStatementContext = logicSQL.getSqlStatementContext(); - Collection singleTableNames = getSingleTableNames(sqlStatementContext, metaData, rule, routeContext); + Collection singleTableNames = getSingleTableNames(sqlStatementContext, databaseMetaData, rule, routeContext); if (singleTableNames.isEmpty()) { return; } @@ -80,27 +80,28 @@ public void decorateRouteContext(final RouteContext routeContext, final LogicSQL SingleTableRouteEngineFactory.newInstance(singleTableNames, sqlStatementContext.getSqlStatement()).ifPresent(optional -> optional.route(routeContext, rule)); } - private RouteContext createSingleDataSourceRouteContext(final SingleTableRule rule, final ShardingSphereMetaData metaData) { + private RouteContext createSingleDataSourceRouteContext(final SingleTableRule rule, final ShardingSphereDatabaseMetaData databaseMetaData) { String logicDataSource = rule.getDataSourceNames().iterator().next(); - String actualDataSource = metaData.getResource().getDataSources().keySet().iterator().next(); + String actualDataSource = databaseMetaData.getResource().getDataSources().keySet().iterator().next(); RouteContext result = new RouteContext(); result.getRouteUnits().add(new RouteUnit(new RouteMapper(logicDataSource, actualDataSource), Collections.emptyList())); return result; } - private static Collection getSingleTableNames(final SQLStatementContext sqlStatementContext, final ShardingSphereMetaData metaData, + private static Collection getSingleTableNames(final SQLStatementContext sqlStatementContext, final ShardingSphereDatabaseMetaData databaseMetaData, final SingleTableRule rule, final RouteContext routeContext) { DatabaseType databaseType = sqlStatementContext.getDatabaseType(); - Collection result = getQualifiedTables(metaData, sqlStatementContext.getTablesContext().getTables(), databaseType); + Collection result = getQualifiedTables(databaseMetaData, sqlStatementContext.getTablesContext().getTables(), databaseType); if (result.isEmpty() && sqlStatementContext instanceof IndexAvailable) { - result = IndexMetaDataUtil.getTableNamesFromMetaData(metaData, ((IndexAvailable) sqlStatementContext).getIndexes(), databaseType); + result = IndexMetaDataUtil.getTableNamesFromMetaData(databaseMetaData, ((IndexAvailable) sqlStatementContext).getIndexes(), databaseType); } return routeContext.getRouteUnits().isEmpty() && sqlStatementContext.getSqlStatement() instanceof CreateTableStatement ? result : rule.getSingleTableNames(result); } - private static Collection getQualifiedTables(final ShardingSphereMetaData metaData, final Collection tableSegments, final DatabaseType databaseType) { + private static Collection getQualifiedTables(final ShardingSphereDatabaseMetaData databaseMetaData, + final Collection tableSegments, final DatabaseType databaseType) { Collection result = new LinkedList<>(); - String schemaName = databaseType.getDefaultSchema(metaData.getDatabase().getName()); + String schemaName = databaseType.getDefaultSchema(databaseMetaData.getDatabase().getName()); for (SimpleTableSegment each : tableSegments) { String actualSchemaName = each.getOwner().map(optional -> optional.getIdentifier().getValue()).orElse(schemaName); result.add(new QualifiedTable(actualSchemaName, each.getTableName().getIdentifier().getValue())); diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/engine/SingleTableRouteEngine.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/engine/SingleTableRouteEngine.java index e9293cd9379ea..4e4d6c4cd85ab 100644 --- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/engine/SingleTableRouteEngine.java +++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/engine/SingleTableRouteEngine.java @@ -28,7 +28,7 @@ public interface SingleTableRouteEngine { /** * Route. * - * @param routeContext route context + * @param routeContext route context * @param singleTableRule single table rule */ void route(RouteContext routeContext, SingleTableRule singleTableRule); diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/SingleTableMetadataValidator.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/SingleTableMetadataValidator.java index eb2dc31d57412..9d9b421748ac6 100644 --- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/SingleTableMetadataValidator.java +++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/SingleTableMetadataValidator.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.singletable.route.validator; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.singletable.rule.SingleTableRule; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -34,7 +34,7 @@ public interface SingleTableMetadataValidator { * * @param rule single table rule * @param sqlStatementContext SQL statement context - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data */ - void validate(SingleTableRule rule, SQLStatementContext sqlStatementContext, ShardingSphereMetaData metaData); + void validate(SingleTableRule rule, SQLStatementContext sqlStatementContext, ShardingSphereDatabaseMetaData databaseMetaData); } diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java index 8cc6397809de0..93ba31b8b3cbd 100644 --- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java +++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; import org.apache.shardingsphere.singletable.route.validator.SingleTableMetadataValidator; import org.apache.shardingsphere.singletable.rule.SingleTableRule; @@ -33,11 +33,11 @@ public final class SingleTableDropSchemaMetadataValidator implements SingleTableMetadataValidator { @Override - public void validate(final SingleTableRule rule, final SQLStatementContext sqlStatementContext, final ShardingSphereMetaData metaData) { + public void validate(final SingleTableRule rule, final SQLStatementContext sqlStatementContext, final ShardingSphereDatabaseMetaData databaseMetaData) { boolean containsCascade = DropSchemaStatementHandler.isContainsCascade(sqlStatementContext.getSqlStatement()); for (IdentifierValue each : sqlStatementContext.getSqlStatement().getSchemaNames()) { String schemaName = each.getValue(); - ShardingSphereSchema schema = metaData.getSchemaByName(schemaName); + ShardingSphereSchema schema = databaseMetaData.getDatabase().getSchema(schemaName); if (null == schema) { throw new ShardingSphereException("Schema %s does not exist.", schemaName); } diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java index eccadb7f0e3b1..6ed5b86373a5d 100644 --- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java +++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; @@ -61,8 +61,8 @@ public void assertCreateRouteContextWithSingleDataSource() { SingleTableRule singleTableRule = new SingleTableRule(new SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), createSingleDataSourceMap(), Collections.emptyList(), new ConfigurationProperties(new Properties())); singleTableRule.getSingleTableDataNodes().put("t_order", Collections.singletonList(mockDataNode("ds_0"))); - ShardingSphereMetaData metaData = mockSingleDataSourceMetaData(); - RouteContext actual = new SingleTableSQLRouter().createRouteContext(createLogicSQL(), metaData, singleTableRule, new ConfigurationProperties(new Properties())); + ShardingSphereDatabaseMetaData databaseMetaData = mockSingleDataSourceMetaData(); + RouteContext actual = new SingleTableSQLRouter().createRouteContext(createLogicSQL(), databaseMetaData, singleTableRule, new ConfigurationProperties(new Properties())); List routeUnits = new ArrayList<>(actual.getRouteUnits()); assertThat(actual.getRouteUnits().size(), is(1)); assertThat(routeUnits.get(0).getDataSourceMapper().getLogicName(), is("ds_0")); @@ -76,8 +76,8 @@ public void assertCreateRouteContextWithReadwriteSplittingDataSource() { SingleTableRule singleTableRule = new SingleTableRule(new SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), createReadwriteSplittingDataSourceMap(), Collections.emptyList(), new ConfigurationProperties(new Properties())); singleTableRule.getSingleTableDataNodes().put("t_order", Collections.singletonList(mockDataNode("write_ds"))); - ShardingSphereMetaData metaData = mockReadwriteSplittingDataSourceMetaData(); - RouteContext actual = new SingleTableSQLRouter().createRouteContext(createLogicSQL(), metaData, singleTableRule, new ConfigurationProperties(new Properties())); + ShardingSphereDatabaseMetaData databaseMetaData = mockReadwriteSplittingDataSourceMetaData(); + RouteContext actual = new SingleTableSQLRouter().createRouteContext(createLogicSQL(), databaseMetaData, singleTableRule, new ConfigurationProperties(new Properties())); List routeUnits = new ArrayList<>(actual.getRouteUnits()); assertThat(actual.getRouteUnits().size(), is(1)); assertThat(routeUnits.get(0).getDataSourceMapper().getLogicName(), is("readwrite_ds")); @@ -91,8 +91,8 @@ public void assertCreateRouteContextWithMultiDataSource() { SingleTableRule singleTableRule = new SingleTableRule(new SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), createMultiDataSourceMap(), Collections.emptyList(), new ConfigurationProperties(new Properties())); singleTableRule.getSingleTableDataNodes().put("t_order", Collections.singletonList(mockDataNode("ds_0"))); - ShardingSphereMetaData metaData = mockMultiDataSourceMetaData(); - RouteContext actual = new SingleTableSQLRouter().createRouteContext(createLogicSQL(), metaData, singleTableRule, new ConfigurationProperties(new Properties())); + ShardingSphereDatabaseMetaData databaseMetaData = mockMultiDataSourceMetaData(); + RouteContext actual = new SingleTableSQLRouter().createRouteContext(createLogicSQL(), databaseMetaData, singleTableRule, new ConfigurationProperties(new Properties())); List routeUnits = new ArrayList<>(actual.getRouteUnits()); assertThat(actual.getRouteUnits().size(), is(1)); assertThat(routeUnits.get(0).getDataSourceMapper().getLogicName(), is("ds_0")); @@ -110,24 +110,24 @@ private DataNode mockDataNode(final String dataSourceName) { return result; } - private ShardingSphereMetaData mockSingleDataSourceMetaData() { - ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + private ShardingSphereDatabaseMetaData mockSingleDataSourceMetaData() { + ShardingSphereDatabaseMetaData result = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); Map dataSourceMap = new HashMap<>(2, 1); dataSourceMap.put("ds_0", mock(DataSource.class, RETURNS_DEEP_STUBS)); when(result.getResource().getDataSources()).thenReturn(dataSourceMap); return result; } - private ShardingSphereMetaData mockReadwriteSplittingDataSourceMetaData() { - ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + private ShardingSphereDatabaseMetaData mockReadwriteSplittingDataSourceMetaData() { + ShardingSphereDatabaseMetaData result = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); Map dataSourceMap = new HashMap<>(2, 1); dataSourceMap.put("write_ds", mock(DataSource.class, RETURNS_DEEP_STUBS)); when(result.getResource().getDataSources()).thenReturn(dataSourceMap); return result; } - private ShardingSphereMetaData mockMultiDataSourceMetaData() { - ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); + private ShardingSphereDatabaseMetaData mockMultiDataSourceMetaData() { + ShardingSphereDatabaseMetaData result = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); Map dataSourceMap = new HashMap<>(2, 1); dataSourceMap.put("ds_0", mock(DataSource.class, RETURNS_DEEP_STUBS)); dataSourceMap.put("ds_1", mock(DataSource.class, RETURNS_DEEP_STUBS)); diff --git a/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java b/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java index 92737b176fc1c..d4af047bdcbeb 100644 --- a/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java +++ b/shardingsphere-kernel/shardingsphere-sql-translator/shardingsphere-sql-translator-core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.sqltranslator.rule.builder; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration; import org.apache.shardingsphere.sqltranslator.constant.SQLTranslatorOrder; @@ -31,7 +31,7 @@ public final class SQLTranslatorRuleBuilder implements GlobalRuleBuilder { @Override - public SQLTranslatorRule build(final SQLTranslatorRuleConfiguration ruleConfig, final Map metaDataMap) { + public SQLTranslatorRule build(final SQLTranslatorRuleConfiguration ruleConfig, final Map databaseMetaDataMap) { return new SQLTranslatorRule(ruleConfig); } diff --git a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java index 145a58c416423..72bf193f2b59d 100644 --- a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java +++ b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.traffic.rule.builder; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration; @@ -32,7 +32,7 @@ public final class TrafficRuleBuilder implements GlobalRuleBuilder { @Override - public GlobalRule build(final TrafficRuleConfiguration ruleConfig, final Map mataDataMap) { + public GlobalRule build(final TrafficRuleConfiguration ruleConfig, final Map databaseMetaDataMap) { return new TrafficRule(ruleConfig); } diff --git a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java index 56f4a8ff1fe8c..0f3b704885cbd 100644 --- a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java +++ b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement; @@ -87,7 +87,7 @@ private LogicSQL createLogicSQL(final boolean includeComments) { when(sqlStatement.getCommentSegments()).thenReturn(includeComments ? Collections.singleton(new CommentSegment("/* ShardingSphere hint: useTraffic=true */", 0, 0)) : Collections.emptyList()); when(sqlStatement.getProjections()).thenReturn(new ProjectionsSegment(0, 0)); SQLStatementContext statementContext = new SelectStatementContext( - Collections.singletonMap("sharding_db", mock(ShardingSphereMetaData.class)), Collections.emptyList(), sqlStatement, "sharding_db"); + Collections.singletonMap("sharding_db", mock(ShardingSphereDatabaseMetaData.class)), Collections.emptyList(), sqlStatement, "sharding_db"); when(result.getSqlStatementContext()).thenReturn(statementContext); return result; } diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java index 90459c9236796..e5e50debd8308 100644 --- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java +++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.transaction.context; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine; @@ -36,7 +36,7 @@ @RequiredArgsConstructor public final class TransactionContextsBuilder { - private final Map metaDataMap; + private final Map databaseMetaData; private final Collection globalRules; @@ -46,11 +46,11 @@ public final class TransactionContextsBuilder { * @return transaction contexts */ public TransactionContexts build() { - Map engines = new HashMap<>(metaDataMap.keySet().size(), 1); + Map engines = new HashMap<>(databaseMetaData.keySet().size(), 1); TransactionRule transactionRule = getTransactionRule(); - for (String each : metaDataMap.keySet()) { + for (String each : databaseMetaData.keySet()) { ShardingSphereTransactionManagerEngine engine = new ShardingSphereTransactionManagerEngine(); - ShardingSphereResource resource = metaDataMap.get(each).getResource(); + ShardingSphereResource resource = databaseMetaData.get(each).getResource(); engine.init(resource.getDatabaseType(), resource.getDataSources(), transactionRule); engines.put(each, engine); } diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java index add5e7605b676..8560ab5b5981b 100644 --- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java +++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.transaction.rule.builder; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; import org.apache.shardingsphere.transaction.constant.TransactionOrder; @@ -31,7 +31,7 @@ public final class TransactionRuleBuilder implements GlobalRuleBuilder { @Override - public TransactionRule build(final TransactionRuleConfiguration ruleConfig, final Map metaDataMap) { + public TransactionRule build(final TransactionRuleConfiguration ruleConfig, final Map databaseMetaDataMap) { return new TransactionRule(ruleConfig); } diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilderTest.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilderTest.java index 008e838e84f79..ec8f61c47d0d1 100644 --- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilderTest.java +++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilderTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.transaction.context; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine; import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; @@ -50,10 +50,10 @@ public void assertNewInstanceWithEmptyEngines() { @Test public void assertGetDefaultTransactionManagerEngine() { - ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS); - when(metaData.getResource().getDataSources()).thenReturn(createDataSourceMap()); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS); + when(databaseMetaData.getResource().getDataSources()).thenReturn(createDataSourceMap()); Collection globalRules = Collections.singleton(new TransactionRule(new TransactionRuleConfiguration(TransactionType.LOCAL.name(), null, new Properties()))); - TransactionContexts transactionContexts = new TransactionContextsBuilder(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), globalRules).build(); + TransactionContexts transactionContexts = new TransactionContextsBuilder(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), globalRules).build(); Map engines = transactionContexts.getEngines(); assertThat(engines.size(), is(1)); assertNotNull(transactionContexts.getEngines().get(DefaultDatabase.LOGIC_NAME)); diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java index 38a92d6cf6a84..433e2bdf906d8 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java @@ -17,22 +17,23 @@ package org.apache.shardingsphere.mode.manager; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration; import org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine; import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator; +import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContextFactory; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; import org.apache.shardingsphere.infra.instance.InstanceContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; @@ -44,7 +45,7 @@ import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; -import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder; +import org.apache.shardingsphere.infra.rule.builder.schema.DatabaseRulesBuilder; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -74,7 +75,6 @@ /** * Context manager. */ -@AllArgsConstructor @Getter @Slf4j public final class ContextManager implements AutoCloseable { @@ -85,14 +85,13 @@ public final class ContextManager implements AutoCloseable { private final InstanceContext instanceContext; - /** - * Get data source map. - * - * @param databaseName database name - * @return data source map - */ - public Map getDataSourceMap(final String databaseName) { - return metaDataContexts.getMetaData(databaseName).getResource().getDataSources(); + private final ExecutorEngine executorEngine; + + public ContextManager(final MetaDataContexts metaDataContexts, final TransactionContexts transactionContexts, final InstanceContext instanceContext) { + this.metaDataContexts = metaDataContexts; + this.transactionContexts = transactionContexts; + this.instanceContext = instanceContext; + executorEngine = ExecutorEngine.createExecutorEngineWithSize(metaDataContexts.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)); } /** @@ -113,6 +112,16 @@ public synchronized void renewTransactionContexts(final TransactionContexts tran this.transactionContexts = transactionContexts; } + /** + * Get data source map. + * + * @param databaseName database name + * @return data source map + */ + public Map getDataSourceMap(final String databaseName) { + return metaDataContexts.getDatabaseMetaData(databaseName).getResource().getDataSources(); + } + /** * Add database. * @@ -120,18 +129,25 @@ public synchronized void renewTransactionContexts(final TransactionContexts tran * @throws SQLException SQL exception */ public void addDatabase(final String databaseName) throws SQLException { - if (metaDataContexts.getMetaDataMap().containsKey(databaseName)) { + if (metaDataContexts.getDatabaseMetaDataMap().containsKey(databaseName)) { return; } - MetaDataContexts newMetaDataContexts = buildNewMetaDataContext(databaseName); - FederationDatabaseMetaData databaseMetaData = newMetaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); - metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().put(databaseName, databaseMetaData); - metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(databaseMetaData)); - metaDataContexts.getMetaDataMap().put(databaseName, newMetaDataContexts.getMetaData(databaseName)); + MetaDataContexts newMetaDataContexts = createMetaDataContext(databaseName); + FederationDatabaseMetaData federationDatabaseMetaData = newMetaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); + metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().put(databaseName, federationDatabaseMetaData); + metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(federationDatabaseMetaData)); + metaDataContexts.getDatabaseMetaDataMap().put(databaseName, newMetaDataContexts.getDatabaseMetaData(databaseName)); persistMetaData(metaDataContexts); renewAllTransactionContext(); } + private MetaDataContexts createMetaDataContext(final String databaseName) throws SQLException { + MetaDataContextsBuilder builder = new MetaDataContextsBuilder( + Collections.singletonMap(databaseName, new DataSourceProvidedDatabaseConfiguration(new HashMap<>(), new LinkedList<>())), + metaDataContexts.getGlobalRuleMetaData().getConfigurations(), metaDataContexts.getProps()); + return builder.build(metaDataContexts.getPersistService().orElse(null)); + } + /** * Add schema. * @@ -139,13 +155,13 @@ public void addDatabase(final String databaseName) throws SQLException { * @param schemaName schema name */ public void addSchema(final String databaseName, final String schemaName) { - if (null != metaDataContexts.getMetaData(databaseName).getSchemaByName(schemaName)) { + if (null != metaDataContexts.getDatabaseMetaData(databaseName).getDatabase().getSchema(schemaName)) { return; } FederationDatabaseMetaData federationDatabaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); federationDatabaseMetaData.putTableMetadata(schemaName, new TableMetaData()); metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(federationDatabaseMetaData)); - metaDataContexts.getMetaDataMap().get(databaseName).getDatabase().getSchemas().put(schemaName, new ShardingSphereSchema()); + metaDataContexts.getDatabaseMetaDataMap().get(databaseName).getDatabase().getSchemas().put(schemaName, new ShardingSphereSchema()); } /** @@ -155,9 +171,10 @@ public void addSchema(final String databaseName, final String schemaName) { * @param schemas schemas */ public void alterSchemas(final String databaseName, final Map schemas) { - ShardingSphereMetaData alteredMetaData = new ShardingSphereMetaData(metaDataContexts.getMetaData(databaseName).getFrontendDatabaseType(), - metaDataContexts.getMetaData(databaseName).getResource(), metaDataContexts.getMetaData(databaseName).getRuleMetaData(), new ShardingSphereDatabase(databaseName, schemas)); - Map alteredMetaDataMap = new HashMap<>(metaDataContexts.getMetaDataMap()); + ShardingSphereDatabaseMetaData alteredMetaData = new ShardingSphereDatabaseMetaData(metaDataContexts.getDatabaseMetaData(databaseName).getProtocolType(), + metaDataContexts.getDatabaseMetaData(databaseName).getResource(), metaDataContexts.getDatabaseMetaData(databaseName).getRuleMetaData(), + new ShardingSphereDatabase(databaseName, schemas)); + Map alteredMetaDataMap = new HashMap<>(metaDataContexts.getDatabaseMetaDataMap()); alteredMetaDataMap.put(databaseName, alteredMetaData); FederationDatabaseMetaData alteredDatabaseMetaData = new FederationDatabaseMetaData(databaseName, schemas); metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().put(databaseName, alteredDatabaseMetaData); @@ -174,54 +191,54 @@ public void alterSchemas(final String databaseName, final Map alterTableSchema(databaseName, schemaName, optional)); Optional.ofNullable(deletedTable).ifPresent(optional -> deleteTable(databaseName, schemaName, optional)); } } private void persistMetaData(final MetaDataContexts metaDataContexts) { - metaDataContexts.getMetaDataMap().forEach((databaseName, schemas) -> schemas.getDatabase().getSchemas().forEach((schemaName, tables) -> { + metaDataContexts.getDatabaseMetaDataMap().forEach((databaseName, schemas) -> schemas.getDatabase().getSchemas().forEach((schemaName, tables) -> { if (tables.getTables().isEmpty()) { - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistSchema(databaseName, schemaName)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistSchema(databaseName, schemaName)); } else { - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistTables(databaseName, schemaName, tables)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistTables(databaseName, schemaName, tables)); } })); } private void alterTableSchema(final String databaseName, final String schemaName, final TableMetaData changedTableMetaData) { - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName); - alterSingleTableDataNodes(databaseName, metaData, changedTableMetaData); - FederationDatabaseMetaData databaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); - metaData.getSchemaByName(schemaName).put(changedTableMetaData.getName(), changedTableMetaData); - databaseMetaData.putTableMetadata(schemaName, changedTableMetaData); - metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(databaseMetaData)); + ShardingSphereDatabaseMetaData databaseMetaDataFromMetaDataContexts = metaDataContexts.getDatabaseMetaData(databaseName); + alterSingleTableDataNodes(databaseName, databaseMetaDataFromMetaDataContexts, changedTableMetaData); + FederationDatabaseMetaData databaseMetaDataFromOptimizerContext = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); + databaseMetaDataFromMetaDataContexts.getDatabase().getSchema(schemaName).put(changedTableMetaData.getName(), changedTableMetaData); + databaseMetaDataFromOptimizerContext.putTableMetadata(schemaName, changedTableMetaData); + metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(databaseMetaDataFromOptimizerContext)); } - private void alterSingleTableDataNodes(final String databaseName, final ShardingSphereMetaData metaData, final TableMetaData changedTableMetaData) { - if (!containsInImmutableDataNodeContainedRule(changedTableMetaData.getName(), metaData)) { - refreshRules(databaseName, metaData); + private void alterSingleTableDataNodes(final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final TableMetaData changedTableMetaData) { + if (!containsInImmutableDataNodeContainedRule(changedTableMetaData.getName(), databaseMetaData)) { + refreshRules(databaseName, databaseMetaData); } } - private void refreshRules(final String databaseName, final ShardingSphereMetaData metaData) { - Collection rules = SchemaRulesBuilder.buildRules(databaseName, new DataSourceProvidedDatabaseConfiguration(metaData.getResource().getDataSources(), - metaData.getRuleMetaData().getConfigurations()), new ConfigurationProperties(metaDataContexts.getProps().getProps())); - metaData.getRuleMetaData().getRules().clear(); - metaData.getRuleMetaData().getRules().addAll(rules); + private void refreshRules(final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData) { + Collection databaseRules = DatabaseRulesBuilder.build(databaseName, new DataSourceProvidedDatabaseConfiguration(databaseMetaData.getResource().getDataSources(), + databaseMetaData.getRuleMetaData().getConfigurations()), new ConfigurationProperties(metaDataContexts.getProps().getProps())); + databaseMetaData.getRuleMetaData().getRules().clear(); + databaseMetaData.getRuleMetaData().getRules().addAll(databaseRules); } private void deleteTable(final String databaseName, final String schemaName, final String deletedTable) { - if (null != metaDataContexts.getMetaData(databaseName).getSchemaByName(schemaName)) { - metaDataContexts.getMetaData(databaseName).getSchemaByName(schemaName).remove(deletedTable); + if (null != metaDataContexts.getDatabaseMetaData(databaseName).getDatabase().getSchema(schemaName)) { + metaDataContexts.getDatabaseMetaData(databaseName).getDatabase().getSchema(schemaName).remove(deletedTable); FederationDatabaseMetaData databaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); databaseMetaData.removeTableMetadata(schemaName, deletedTable); metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(databaseMetaData)); } } - private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereMetaData schemaMetaData) { + private boolean containsInImmutableDataNodeContainedRule(final String tableName, final ShardingSphereDatabaseMetaData schemaMetaData) { return schemaMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream() .filter(each -> !(each instanceof MutableDataNodeRule)).anyMatch(each -> each.getAllTables().contains(tableName)); } @@ -232,14 +249,14 @@ private boolean containsInImmutableDataNodeContainedRule(final String tableName, * @param databaseName database name */ public void deleteDatabase(final String databaseName) { - if (metaDataContexts.getMetaDataMap().containsKey(databaseName)) { + if (metaDataContexts.getDatabaseMetaDataMap().containsKey(databaseName)) { metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().remove(databaseName); metaDataContexts.getOptimizerContext().getParserContexts().remove(databaseName); metaDataContexts.getOptimizerContext().getPlannerContexts().remove(databaseName); - ShardingSphereMetaData removeMetaData = metaDataContexts.getMetaDataMap().remove(databaseName); + ShardingSphereDatabaseMetaData removeMetaData = metaDataContexts.getDatabaseMetaDataMap().remove(databaseName); closeDataSources(removeMetaData); removeAndCloseTransactionEngine(databaseName); - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().deleteDatabase(databaseName)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().deleteDatabase(databaseName)); } } @@ -250,13 +267,13 @@ public void deleteDatabase(final String databaseName) { * @param schemaName schema name */ public void dropSchema(final String databaseName, final String schemaName) { - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName); - if (null == metaData || null == metaData.getSchemaByName(schemaName)) { + ShardingSphereDatabaseMetaData databaseMetaDataFromMetaDataContexts = metaDataContexts.getDatabaseMetaData(databaseName); + if (null == databaseMetaDataFromMetaDataContexts || null == databaseMetaDataFromMetaDataContexts.getDatabase().getSchema(schemaName)) { return; } - FederationDatabaseMetaData databaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); - databaseMetaData.removeSchemaMetadata(schemaName); - metaData.getDatabase().getSchemas().remove(schemaName); + FederationDatabaseMetaData databaseMetaDataFromOptimizerContext = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName); + databaseMetaDataFromOptimizerContext.removeSchemaMetadata(schemaName); + databaseMetaDataFromMetaDataContexts.getDatabase().getSchemas().remove(schemaName); } /** @@ -268,7 +285,7 @@ public void dropSchema(final String databaseName, final String schemaName) { */ public void addResource(final String databaseName, final Map dataSourcePropsMap) throws SQLException { refreshMetaDataContext(databaseName, dataSourcePropsMap); - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, dataSourcePropsMap)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, dataSourcePropsMap)); } /** @@ -280,7 +297,7 @@ public void addResource(final String databaseName, final Map dataSourcePropsMap) throws SQLException { refreshMetaDataContext(databaseName, dataSourcePropsMap); - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, dataSourcePropsMap)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, dataSourcePropsMap)); } /** @@ -290,8 +307,8 @@ public void alterResource(final String databaseName, final Map toBeDroppedResourceNames) { - toBeDroppedResourceNames.forEach(metaDataContexts.getMetaData(databaseName).getResource().getDataSources()::remove); - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().drop(databaseName, toBeDroppedResourceNames)); + toBeDroppedResourceNames.forEach(metaDataContexts.getDatabaseMetaData(databaseName).getResource().getDataSources()::remove); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getDataSourceService().drop(databaseName, toBeDroppedResourceNames)); } /** @@ -302,11 +319,11 @@ public void dropResource(final String databaseName, final Collection toB */ public void alterRuleConfiguration(final String databaseName, final Collection ruleConfigs) { try { - MetaDataContexts changedMetaDataContexts = buildChangedMetaDataContext(metaDataContexts.getMetaDataMap().get(databaseName), ruleConfigs); + MetaDataContexts changedMetaDataContexts = buildChangedMetaDataContext(metaDataContexts.getDatabaseMetaDataMap().get(databaseName), ruleConfigs); metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().putAll(changedMetaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases()); - Map metaDataMap = new HashMap<>(metaDataContexts.getMetaDataMap()); - metaDataMap.putAll(changedMetaDataContexts.getMetaDataMap()); - renewMetaDataContexts(rebuildMetaDataContexts(metaDataMap)); + Map databaseMetaDataMap = new HashMap<>(metaDataContexts.getDatabaseMetaDataMap()); + databaseMetaDataMap.putAll(changedMetaDataContexts.getDatabaseMetaDataMap()); + renewMetaDataContexts(rebuildMetaDataContexts(databaseMetaDataMap)); } catch (final SQLException ex) { log.error("Alter database:{} rule configuration failed", databaseName, ex); } @@ -320,7 +337,7 @@ public void alterRuleConfiguration(final String databaseName, final Collection dataSourcePropsMap) { try { - MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSource(metaDataContexts.getMetaDataMap().get(databaseName), dataSourcePropsMap); + MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSource(metaDataContexts.getDatabaseMetaDataMap().get(databaseName), dataSourcePropsMap); refreshMetaDataContext(databaseName, changedMetaDataContext, dataSourcePropsMap); } catch (final SQLException ex) { log.error("Alter database:{} data source configuration failed", databaseName, ex); @@ -336,7 +353,8 @@ public void alterDataSourceConfiguration(final String databaseName, final Map dataSourcePropsMap, final Collection ruleConfigs) { try { - MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSourceAndRule(metaDataContexts.getMetaDataMap().get(databaseName), dataSourcePropsMap, ruleConfigs); + MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSourceAndRule( + metaDataContexts.getDatabaseMetaDataMap().get(databaseName), dataSourcePropsMap, ruleConfigs); refreshMetaDataContext(databaseName, changedMetaDataContext, dataSourcePropsMap); } catch (SQLException ex) { log.error("Alter database:{} data source and rule configuration failed", databaseName, ex); @@ -351,7 +369,7 @@ public void alterDataSourceAndRuleConfiguration(final String databaseName, final public void alterGlobalRuleConfiguration(final Collection ruleConfigs) { if (!ruleConfigs.isEmpty()) { boolean needRenewTransaction = isNeedRenewTransactionContext(ruleConfigs); - ShardingSphereRuleMetaData newGlobalRuleMetaData = new ShardingSphereRuleMetaData(ruleConfigs, GlobalRulesBuilder.buildRules(ruleConfigs, metaDataContexts.getMetaDataMap())); + ShardingSphereRuleMetaData newGlobalRuleMetaData = new ShardingSphereRuleMetaData(ruleConfigs, GlobalRulesBuilder.buildRules(ruleConfigs, metaDataContexts.getDatabaseMetaDataMap())); renewMetaDataContexts(rebuildMetaDataContexts(newGlobalRuleMetaData)); if (needRenewTransaction) { renewAllTransactionContext(); @@ -385,7 +403,7 @@ public void reloadMetaData(final String databaseName, final String schemaName) { Map schemas = loadActualSchema(databaseName, schemaName); alterSchemas(databaseName, schemas); for (ShardingSphereSchema each : schemas.values()) { - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistTables(databaseName, schemaName, each)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistTables(databaseName, schemaName, each)); } } catch (final SQLException ex) { log.error("Reload database:{} meta data of schema:{} failed", databaseName, schemaName, ex); @@ -401,9 +419,9 @@ public void reloadMetaData(final String databaseName, final String schemaName) { */ public void reloadMetaData(final String databaseName, final String schemaName, final String tableName) { try { - SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaDataContexts.getMetaData(databaseName).getFrontendDatabaseType(), - metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType(), metaDataContexts.getMetaData(databaseName).getResource().getDataSources(), - metaDataContexts.getMetaData(databaseName).getRuleMetaData().getRules(), metaDataContexts.getProps(), schemaName); + SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaDataContexts.getDatabaseMetaData(databaseName).getProtocolType(), + metaDataContexts.getDatabaseMetaData(databaseName).getResource().getDatabaseType(), metaDataContexts.getDatabaseMetaData(databaseName).getResource().getDataSources(), + metaDataContexts.getDatabaseMetaData(databaseName).getRuleMetaData().getRules(), metaDataContexts.getProps(), schemaName); loadTableMetaData(databaseName, schemaName, tableName, materials); } catch (final SQLException ex) { log.error("Reload table:{} meta data of database:{} schema:{} failed", tableName, databaseName, schemaName, ex); @@ -420,10 +438,10 @@ public void reloadMetaData(final String databaseName, final String schemaName, f */ public void reloadMetaData(final String databaseName, final String schemaName, final String tableName, final String dataSourceName) { try { - SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaDataContexts.getMetaData(databaseName).getFrontendDatabaseType(), - metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType(), Collections.singletonMap(dataSourceName, - metaDataContexts.getMetaData(databaseName).getResource().getDataSources().get(dataSourceName)), - metaDataContexts.getMetaData(databaseName).getRuleMetaData().getRules(), metaDataContexts.getProps(), schemaName); + SchemaBuilderMaterials materials = new SchemaBuilderMaterials(metaDataContexts.getDatabaseMetaData(databaseName).getProtocolType(), + metaDataContexts.getDatabaseMetaData(databaseName).getResource().getDatabaseType(), Collections.singletonMap(dataSourceName, + metaDataContexts.getDatabaseMetaData(databaseName).getResource().getDataSources().get(dataSourceName)), + metaDataContexts.getDatabaseMetaData(databaseName).getRuleMetaData().getRules(), metaDataContexts.getProps(), schemaName); loadTableMetaData(databaseName, schemaName, tableName, materials); } catch (final SQLException ex) { log.error("Reload table:{} meta data of database:{} schema:{} with data source:{} failed", tableName, databaseName, schemaName, dataSourceName, ex); @@ -433,39 +451,39 @@ public void reloadMetaData(final String databaseName, final String schemaName, f private void loadTableMetaData(final String databaseName, final String schemaName, final String tableName, final SchemaBuilderMaterials materials) throws SQLException { SchemaMetaData schemaMetaData = TableMetaDataBuilder.load(Collections.singletonList(tableName), materials).getOrDefault(schemaName, new SchemaMetaData("", Collections.emptyMap())); if (schemaMetaData.getTables().containsKey(tableName)) { - metaDataContexts.getMetaData(databaseName).getSchemaByName(schemaName).put(tableName, schemaMetaData.getTables().get(tableName)); - metaDataContexts.getMetaDataPersistService() - .ifPresent(optional -> optional.getSchemaMetaDataService().persistTables(databaseName, schemaName, metaDataContexts.getMetaData(databaseName).getSchemaByName(schemaName))); + metaDataContexts.getDatabaseMetaData(databaseName).getDatabase().getSchema(schemaName).put(tableName, schemaMetaData.getTables().get(tableName)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getSchemaMetaDataService() + .persistTables(databaseName, schemaName, metaDataContexts.getDatabaseMetaData(databaseName).getDatabase().getSchema(schemaName))); } } private Map loadActualSchema(final String databaseName, final String schemaName) throws SQLException { - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName); - Map dataSourceMap = metaData.getResource().getDataSources(); - Collection rules = metaDataContexts.getMetaDataMap().get(databaseName).getRuleMetaData().getRules(); + ShardingSphereDatabaseMetaData databaseMetaData = metaDataContexts.getDatabaseMetaData(databaseName); + Map dataSourceMap = databaseMetaData.getResource().getDataSources(); + Collection rules = metaDataContexts.getDatabaseMetaDataMap().get(databaseName).getRuleMetaData().getRules(); DatabaseType databaseType = DatabaseTypeEngine.getDatabaseType(dataSourceMap.values()); - return SchemaLoader.load(schemaName, metaData.getFrontendDatabaseType(), databaseType, dataSourceMap, rules, metaDataContexts.getProps()); + return SchemaLoader.load(schemaName, databaseMetaData.getProtocolType(), databaseType, dataSourceMap, rules, metaDataContexts.getProps()); } private Collection getPendingClosedDataSources(final String databaseName, final Map dataSourcePropsMap) { Collection result = new LinkedList<>(); - result.addAll(getDeletedDataSources(metaDataContexts.getMetaData(databaseName), dataSourcePropsMap).values()); - result.addAll(getChangedDataSources(metaDataContexts.getMetaData(databaseName), dataSourcePropsMap).values()); + result.addAll(getDeletedDataSources(metaDataContexts.getDatabaseMetaData(databaseName), dataSourcePropsMap).values()); + result.addAll(getChangedDataSources(metaDataContexts.getDatabaseMetaData(databaseName), dataSourcePropsMap).values()); return result; } - private Map getDeletedDataSources(final ShardingSphereMetaData originalMetaData, final Map newDataSourcePropsMap) { + private Map getDeletedDataSources(final ShardingSphereDatabaseMetaData originalMetaData, final Map newDataSourcePropsMap) { return originalMetaData.getResource().getDataSources().entrySet().stream().filter(entry -> !newDataSourcePropsMap.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private Map getChangedDataSources(final ShardingSphereMetaData originalMetaData, final Map newDataSourcePropsMap) { + private Map getChangedDataSources(final ShardingSphereDatabaseMetaData originalMetaData, final Map newDataSourcePropsMap) { Collection changedDataSourceNames = getChangedDataSourceConfiguration(originalMetaData, newDataSourcePropsMap).keySet(); return originalMetaData.getResource().getDataSources().entrySet().stream().filter(entry -> changedDataSourceNames.contains(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private Map getChangedDataSourceConfiguration(final ShardingSphereMetaData originalMetaData, + private Map getChangedDataSourceConfiguration(final ShardingSphereDatabaseMetaData originalMetaData, final Map dataSourcePropsMap) { return dataSourcePropsMap.entrySet().stream() .filter(entry -> isModifiedDataSource(originalMetaData.getResource().getDataSources(), entry.getKey(), entry.getValue())) @@ -476,51 +494,51 @@ private boolean isModifiedDataSource(final Map originalDataS return originalDataSources.containsKey(dataSourceName) && !dataSourceProps.equals(DataSourcePropertiesCreator.create(originalDataSources.get(dataSourceName))); } - private MetaDataContexts rebuildMetaDataContexts(final Map schemaMetaData) { - return new MetaDataContexts(metaDataContexts.getMetaDataPersistService().orElse(null), - schemaMetaData, metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(), + private MetaDataContexts rebuildMetaDataContexts(final Map schemaMetaData) { + return new MetaDataContexts(metaDataContexts.getPersistService().orElse(null), + schemaMetaData, metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getOptimizerContext(), metaDataContexts.getProps()); } private MetaDataContexts rebuildMetaDataContexts(final ShardingSphereRuleMetaData globalRuleMetaData) { - return new MetaDataContexts(metaDataContexts.getMetaDataPersistService().orElse(null), - metaDataContexts.getMetaDataMap(), globalRuleMetaData, metaDataContexts.getExecutorEngine(), metaDataContexts.getOptimizerContext(), metaDataContexts.getProps()); + return new MetaDataContexts(metaDataContexts.getPersistService().orElse(null), + metaDataContexts.getDatabaseMetaDataMap(), globalRuleMetaData, metaDataContexts.getOptimizerContext(), metaDataContexts.getProps()); } private MetaDataContexts rebuildMetaDataContexts(final ConfigurationProperties props) { - return new MetaDataContexts(metaDataContexts.getMetaDataPersistService().orElse(null), - metaDataContexts.getMetaDataMap(), metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(), metaDataContexts.getOptimizerContext(), props); + return new MetaDataContexts(metaDataContexts.getPersistService().orElse(null), + metaDataContexts.getDatabaseMetaDataMap(), metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getOptimizerContext(), props); } private void refreshMetaDataContext(final String databaseName, final Map dataSourceProps) throws SQLException { - MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithAddedDataSource(metaDataContexts.getMetaDataMap().get(databaseName), dataSourceProps); - metaDataContexts.getMetaDataMap().putAll(changedMetaDataContext.getMetaDataMap()); + MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithAddedDataSource(metaDataContexts.getDatabaseMetaDataMap().get(databaseName), dataSourceProps); + metaDataContexts.getDatabaseMetaDataMap().putAll(changedMetaDataContext.getDatabaseMetaDataMap()); metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().putAll(changedMetaDataContext.getOptimizerContext().getFederationMetaData().getDatabases()); metaDataContexts.getOptimizerContext().getParserContexts().putAll(changedMetaDataContext.getOptimizerContext().getParserContexts()); metaDataContexts.getOptimizerContext().getPlannerContexts().putAll(changedMetaDataContext.getOptimizerContext().getPlannerContexts()); - renewTransactionContext(databaseName, metaDataContexts.getMetaData(databaseName).getResource()); + renewTransactionContext(databaseName, metaDataContexts.getDatabaseMetaData(databaseName).getResource()); } private void refreshMetaDataContext(final String databaseName, final MetaDataContexts changedMetaDataContext, final Map dataSourcePropsMap) { metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().putAll(changedMetaDataContext.getOptimizerContext().getFederationMetaData().getDatabases()); - Map metaDataMap = new HashMap<>(metaDataContexts.getMetaDataMap()); - metaDataMap.putAll(changedMetaDataContext.getMetaDataMap()); + Map databaseMetaDataMap = new HashMap<>(metaDataContexts.getDatabaseMetaDataMap()); + databaseMetaDataMap.putAll(changedMetaDataContext.getDatabaseMetaDataMap()); Collection pendingClosedDataSources = getPendingClosedDataSources(databaseName, dataSourcePropsMap); - renewMetaDataContexts(rebuildMetaDataContexts(metaDataMap)); - renewTransactionContext(databaseName, metaDataContexts.getMetaData(databaseName).getResource()); + renewMetaDataContexts(rebuildMetaDataContexts(databaseMetaDataMap)); + renewTransactionContext(databaseName, metaDataContexts.getDatabaseMetaData(databaseName).getResource()); closeDataSources(databaseName, pendingClosedDataSources); } - private MetaDataContexts buildChangedMetaDataContextWithAddedDataSource(final ShardingSphereMetaData originalMetaData, + private MetaDataContexts buildChangedMetaDataContextWithAddedDataSource(final ShardingSphereDatabaseMetaData originalMetaData, final Map addedDataSourceProps) throws SQLException { Map dataSourceMap = new HashMap<>(originalMetaData.getResource().getDataSources()); dataSourceMap.putAll(DataSourcePoolCreator.create(addedDataSourceProps)); DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(dataSourceMap, originalMetaData.getRuleMetaData().getConfigurations()); - Optional metaDataPersistService = metaDataContexts.getMetaDataPersistService(); + Optional metaDataPersistService = metaDataContexts.getPersistService(); metaDataPersistService.ifPresent(optional -> persistTransactionConfiguration(databaseConfig, optional)); MetaDataContextsBuilder builder = new MetaDataContextsBuilder( Collections.singletonMap(originalMetaData.getDatabase().getName(), databaseConfig), metaDataContexts.getGlobalRuleMetaData().getConfigurations(), metaDataContexts.getProps()); - MetaDataContexts result = builder.build(metaDataContexts.getMetaDataPersistService().orElse(null)); + MetaDataContexts result = builder.build(metaDataContexts.getPersistService().orElse(null)); persistMetaData(result); return result; } @@ -531,16 +549,16 @@ private void persistTransactionConfiguration(final DatabaseConfiguration databas optional.getTransactionProps(getTransactionRule().getProps(), databaseConfig, instanceContext.getModeConfiguration().getType()), true)); } - private MetaDataContexts buildChangedMetaDataContext(final ShardingSphereMetaData originalMetaData, final Collection ruleConfigs) throws SQLException { + private MetaDataContexts buildChangedMetaDataContext(final ShardingSphereDatabaseMetaData originalMetaData, final Collection ruleConfigs) throws SQLException { MetaDataContextsBuilder builder = new MetaDataContextsBuilder( Collections.singletonMap(originalMetaData.getDatabase().getName(), new DataSourceProvidedDatabaseConfiguration(originalMetaData.getResource().getDataSources(), ruleConfigs)), metaDataContexts.getGlobalRuleMetaData().getConfigurations(), metaDataContexts.getProps()); - MetaDataContexts result = builder.build(metaDataContexts.getMetaDataPersistService().orElse(null)); + MetaDataContexts result = builder.build(metaDataContexts.getPersistService().orElse(null)); persistMetaData(result); return result; } - private MetaDataContexts buildChangedMetaDataContextWithChangedDataSource(final ShardingSphereMetaData originalMetaData, + private MetaDataContexts buildChangedMetaDataContextWithChangedDataSource(final ShardingSphereDatabaseMetaData originalMetaData, final Map newDataSourceProps) throws SQLException { Collection deletedDataSources = getDeletedDataSources(originalMetaData, newDataSourceProps).keySet(); Map changedDataSources = buildChangedDataSources(originalMetaData, newDataSourceProps); @@ -549,12 +567,12 @@ private MetaDataContexts buildChangedMetaDataContextWithChangedDataSource(final originalMetaData.getRuleMetaData().getConfigurations()); MetaDataContextsBuilder builder = new MetaDataContextsBuilder(Collections.singletonMap(originalMetaData.getDatabase().getName(), databaseConfig), metaDataContexts.getGlobalRuleMetaData().getConfigurations(), metaDataContexts.getProps()); - MetaDataContexts result = builder.build(metaDataContexts.getMetaDataPersistService().orElse(null)); + MetaDataContexts result = builder.build(metaDataContexts.getPersistService().orElse(null)); persistMetaData(result); return result; } - private MetaDataContexts buildChangedMetaDataContextWithChangedDataSourceAndRule(final ShardingSphereMetaData originalMetaData, final Map newDataSourceProps, + private MetaDataContexts buildChangedMetaDataContextWithChangedDataSourceAndRule(final ShardingSphereDatabaseMetaData originalMetaData, final Map newDataSourceProps, final Collection ruleConfigs) throws SQLException { Collection deletedDataSources = getDeletedDataSources(originalMetaData, newDataSourceProps).keySet(); Map changedDataSources = buildChangedDataSources(originalMetaData, newDataSourceProps); @@ -562,7 +580,7 @@ private MetaDataContexts buildChangedMetaDataContextWithChangedDataSourceAndRule getAddedDataSources(originalMetaData, newDataSourceProps), changedDataSources, deletedDataSources), ruleConfigs); MetaDataContextsBuilder builder = new MetaDataContextsBuilder( Collections.singletonMap(originalMetaData.getDatabase().getName(), databaseConfig), metaDataContexts.getGlobalRuleMetaData().getConfigurations(), metaDataContexts.getProps()); - MetaDataContexts result = builder.build(metaDataContexts.getMetaDataPersistService().orElse(null)); + MetaDataContexts result = builder.build(metaDataContexts.getPersistService().orElse(null)); persistMetaData(result); return result; } @@ -576,12 +594,12 @@ private Map getNewDataSources(final Map return result; } - private Map getAddedDataSources(final ShardingSphereMetaData originalMetaData, final Map newDataSourcePropsMap) { + private Map getAddedDataSources(final ShardingSphereDatabaseMetaData originalMetaData, final Map newDataSourcePropsMap) { return DataSourcePoolCreator.create(newDataSourcePropsMap.entrySet().stream() .filter(entry -> !originalMetaData.getResource().getDataSources().containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue))); } - private Map buildChangedDataSources(final ShardingSphereMetaData originalMetaData, final Map newDataSourcePropsMap) { + private Map buildChangedDataSources(final ShardingSphereDatabaseMetaData originalMetaData, final Map newDataSourcePropsMap) { return DataSourcePoolCreator.create(getChangedDataSourceConfiguration(originalMetaData, newDataSourcePropsMap)); } @@ -589,7 +607,7 @@ private Map buildChangedDataSources(final ShardingSphereMeta * Reload all transaction context. */ public void renewAllTransactionContext() { - for (Entry entry : metaDataContexts.getMetaDataMap().entrySet()) { + for (Entry entry : metaDataContexts.getDatabaseMetaDataMap().entrySet()) { renewTransactionContext(entry.getKey(), entry.getValue().getResource()); } } @@ -616,21 +634,14 @@ private TransactionRule getTransactionRule() { return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build())); } - private MetaDataContexts buildNewMetaDataContext(final String databaseName) throws SQLException { - MetaDataContextsBuilder builder = new MetaDataContextsBuilder( - Collections.singletonMap(databaseName, new DataSourceProvidedDatabaseConfiguration(new HashMap<>(), new LinkedList<>())), - metaDataContexts.getGlobalRuleMetaData().getConfigurations(), metaDataContexts.getProps()); - return builder.build(metaDataContexts.getMetaDataPersistService().orElse(null)); - } - - private void closeDataSources(final ShardingSphereMetaData removeMetaData) { + private void closeDataSources(final ShardingSphereDatabaseMetaData removeMetaData) { if (null != removeMetaData.getResource()) { removeMetaData.getResource().getDataSources().values().forEach(each -> removeMetaData.getResource().close(each)); } } private void closeDataSources(final String databaseName, final Collection dataSources) { - ShardingSphereResource resource = metaDataContexts.getMetaData(databaseName).getResource(); + ShardingSphereResource resource = metaDataContexts.getDatabaseMetaData(databaseName).getResource(); dataSources.forEach(resource::close); } @@ -653,6 +664,7 @@ private void closeTransactionEngine(final ShardingSphereTransactionManagerEngine @Override public void close() throws Exception { + executorEngine.close(); metaDataContexts.close(); } } diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java index d9af36a1a431f..99bb0a869b476 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java @@ -20,10 +20,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContextFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -42,20 +41,18 @@ @Getter public final class MetaDataContexts implements AutoCloseable { - private final MetaDataPersistService metaDataPersistService; + private final MetaDataPersistService persistService; - private final Map metaDataMap; + private final Map databaseMetaDataMap; private final ShardingSphereRuleMetaData globalRuleMetaData; - private final ExecutorEngine executorEngine; - private final OptimizerContext optimizerContext; private final ConfigurationProperties props; - public MetaDataContexts(final MetaDataPersistService metaDataPersistService) { - this(metaDataPersistService, new LinkedHashMap<>(), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()), null, + public MetaDataContexts(final MetaDataPersistService persistService) { + this(persistService, new LinkedHashMap<>(), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()), OptimizerContextFactory.create(new HashMap<>(), new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList())), new ConfigurationProperties(new Properties())); } @@ -64,8 +61,8 @@ public MetaDataContexts(final MetaDataPersistService metaDataPersistService) { * * @return persist service */ - public Optional getMetaDataPersistService() { - return Optional.ofNullable(metaDataPersistService); + public Optional getPersistService() { + return Optional.ofNullable(persistService); } /** @@ -74,24 +71,23 @@ public Optional getMetaDataPersistService() { * @return all database names */ public Collection getAllDatabaseNames() { - return metaDataMap.keySet(); + return databaseMetaDataMap.keySet(); } /** - * Get meta data. + * Get database meta data. * * @param databaseName database name - * @return meta data + * @return database meta data */ - public ShardingSphereMetaData getMetaData(final String databaseName) { - return metaDataMap.get(databaseName); + public ShardingSphereDatabaseMetaData getDatabaseMetaData(final String databaseName) { + return databaseMetaDataMap.get(databaseName); } @Override public void close() throws Exception { - executorEngine.close(); - if (null != metaDataPersistService) { - metaDataPersistService.getRepository().close(); + if (null != persistService) { + persistService.getRepository().close(); } } } diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java index 078eede934391..af2e5b143b997 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilder.java @@ -21,12 +21,10 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine; -import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContextFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -59,34 +57,33 @@ public final class MetaDataContextsBuilder { public MetaDataContexts build(final MetaDataPersistService metaDataPersistService) throws SQLException { DatabaseType frontendDatabaseType = DatabaseTypeEngine.getFrontendDatabaseType(databaseConfigMap, props); DatabaseType backendDatabaseType = DatabaseTypeEngine.getBackendDatabaseType(databaseConfigMap); - Map databaseMetaDataMap = getDatabaseMetaDataMap(frontendDatabaseType, backendDatabaseType); + Map databaseMetaDataMap = getDatabaseMetaDataMap(frontendDatabaseType, backendDatabaseType); ShardingSphereRuleMetaData globalMetaData = new ShardingSphereRuleMetaData(globalRuleConfigs, GlobalRulesBuilder.buildRules(globalRuleConfigs, databaseMetaDataMap)); - ExecutorEngine executorEngine = ExecutorEngine.createExecutorEngineWithSize(props.getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)); - return new MetaDataContexts(metaDataPersistService, databaseMetaDataMap, globalMetaData, executorEngine, OptimizerContextFactory.create(databaseMetaDataMap, globalMetaData), props); + return new MetaDataContexts(metaDataPersistService, databaseMetaDataMap, globalMetaData, OptimizerContextFactory.create(databaseMetaDataMap, globalMetaData), props); } - private Map getDatabaseMetaDataMap(final DatabaseType frontendDatabaseType, final DatabaseType backendDatabaseType) throws SQLException { - Map result = new HashMap<>(databaseConfigMap.size() + frontendDatabaseType.getSystemDatabaseSchemaMap().size(), 1); + private Map getDatabaseMetaDataMap(final DatabaseType frontendDatabaseType, final DatabaseType backendDatabaseType) throws SQLException { + Map result = new HashMap<>(databaseConfigMap.size() + frontendDatabaseType.getSystemDatabaseSchemaMap().size(), 1); result.putAll(getGenericDatabaseMetaDataMap(frontendDatabaseType, backendDatabaseType)); result.putAll(getSystemDatabaseMetaDataMap(frontendDatabaseType)); return result; } - private Map getGenericDatabaseMetaDataMap(final DatabaseType frontendDatabaseType, final DatabaseType backendDatabaseType) throws SQLException { - Map result = new HashMap<>(databaseConfigMap.size(), 1); + private Map getGenericDatabaseMetaDataMap(final DatabaseType frontendDatabaseType, final DatabaseType backendDatabaseType) throws SQLException { + Map result = new HashMap<>(databaseConfigMap.size(), 1); for (Entry entry : databaseConfigMap.entrySet()) { String databaseName = entry.getKey(); if (!frontendDatabaseType.getSystemSchemas().contains(databaseName)) { - result.put(databaseName, ShardingSphereMetaData.create(databaseName, frontendDatabaseType, backendDatabaseType, entry.getValue(), props)); + result.put(databaseName, ShardingSphereDatabaseMetaData.create(databaseName, frontendDatabaseType, backendDatabaseType, entry.getValue(), props)); } } return result; } - private Map getSystemDatabaseMetaDataMap(final DatabaseType frontendDatabaseType) throws SQLException { - Map result = new HashMap<>(frontendDatabaseType.getSystemDatabaseSchemaMap().size(), 1); + private Map getSystemDatabaseMetaDataMap(final DatabaseType frontendDatabaseType) throws SQLException { + Map result = new HashMap<>(frontendDatabaseType.getSystemDatabaseSchemaMap().size(), 1); for (String each : frontendDatabaseType.getSystemDatabaseSchemaMap().keySet()) { - result.put(each, ShardingSphereMetaData.create(each, frontendDatabaseType)); + result.put(each, ShardingSphereDatabaseMetaData.create(each, frontendDatabaseType)); } return result; } diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java index 1aaf6d73d338c..1280cc0c3b31e 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java @@ -48,7 +48,7 @@ public final class DatabaseMetaDataNode { * Get meta data data source path. * * @param databaseName database name - * @param version data source version + * @param version data source version * @return data source path */ public static String getMetaDataDataSourcePath(final String databaseName, final String version) { @@ -78,7 +78,7 @@ public static String getDatabaseNamePath(final String databaseName) { * Get rule path. * * @param databaseName database name - * @param version rule version + * @param version rule version * @return rule path */ public static String getRulePath(final String databaseName, final String version) { diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java index eff0b5fcbdf09..20f6a29c26148 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.List; import java.util.Optional; /** @@ -47,7 +46,7 @@ public final class ComputeNodePersistService { * * @param instanceId instance id * @param labels collection of label - * @param isOverwrite whether overwrite registry center's configuration if existed + * @param isOverwrite whether overwrite registry center's configuration if existed */ public void persistInstanceLabels(final String instanceId, final Collection labels, final boolean isOverwrite) { if (null != labels && !labels.isEmpty() && (isOverwrite || !isExisted(instanceId))) { @@ -96,6 +95,7 @@ public void persistInstanceXaRecoveryId(final String instanceId, final String xa * @param instanceId instance id * @return labels */ + @SuppressWarnings("unchecked") public Collection loadInstanceLabels(final String instanceId) { String yamlContent = repository.get(ComputeNode.getInstanceLabelsNodePath(instanceId)); return Strings.isNullOrEmpty(yamlContent) ? new ArrayList<>() : YamlEngine.unmarshal(yamlContent, Collection.class); @@ -107,6 +107,7 @@ public Collection loadInstanceLabels(final String instanceId) { * @param instanceId instance id * @return status */ + @SuppressWarnings("unchecked") public Collection loadInstanceStatus(final String instanceId) { String yamlContent = repository.get(ComputeNode.getInstanceStatusNodePath(instanceId)); return Strings.isNullOrEmpty(yamlContent) ? new ArrayList<>() : YamlEngine.unmarshal(yamlContent, Collection.class); @@ -138,29 +139,6 @@ public Optional loadXaRecoveryId(final String instanceId) { return Optional.ofNullable(repository.get(ComputeNode.getInstanceXaRecoveryIdNodePath(instanceId))); } - /** - * Load compute node instances by instance type and labels. - * - * @param instanceType instance type - * @param labels collection of contained label - * @return compute node instances - */ - public Collection loadComputeNodeInstances(final InstanceType instanceType, final Collection labels) { - Collection onlineComputeNodes = repository.getChildrenKeys(ComputeNode.getOnlineNodePath(instanceType)); - List result = new ArrayList<>(onlineComputeNodes.size()); - onlineComputeNodes.forEach(each -> { - Collection actualLabels = loadInstanceLabels(each); - if (actualLabels.stream().anyMatch(labels::contains)) { - ComputeNodeInstance instance = new ComputeNodeInstance(new InstanceDefinition(instanceType, each)); - instance.setLabels(actualLabels); - instance.switchState(loadInstanceStatus(each)); - loadInstanceWorkerId(each).ifPresent(instance::setWorkerId); - result.add(instance); - } - }); - return result; - } - /** * Load all compute node instances. * diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index 8e12183b61bf7..4c45418547a50 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; @@ -28,7 +29,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData; import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData; import org.apache.shardingsphere.infra.instance.InstanceContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.CachedDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.DataSourcesMetaData; @@ -81,20 +82,21 @@ public final class ContextManagerTest { @Before public void setUp() throws SQLException { + when(metaDataContexts.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(1); contextManager = new ContextManager(metaDataContexts, mock(TransactionContexts.class), mock(InstanceContext.class)); when(metaDataContexts.getGlobalRuleMetaData().getRules()).thenReturn(Collections.emptyList()); when(metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases()).thenReturn(new LinkedHashMap<>()); when(metaDataContexts.getProps()).thenReturn(new ConfigurationProperties(new Properties())); - when(metaDataContexts.getMetaData("foo_db").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); - when(metaDataContexts.getMetaData("foo_db").getFrontendDatabaseType()).thenReturn(new MySQLDatabaseType()); + when(metaDataContexts.getDatabaseMetaData("foo_db").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType()); + when(metaDataContexts.getDatabaseMetaData("foo_db").getProtocolType()).thenReturn(new MySQLDatabaseType()); } @Test public void assertGetDataSourceMap() { ShardingSphereResource resource = new ShardingSphereResource( Collections.singletonMap("foo_ds", new MockedDataSource()), mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), mock(DatabaseType.class)); - when(metaDataContexts.getMetaData(DefaultDatabase.LOGIC_NAME)).thenReturn( - new ShardingSphereMetaData(mock(DatabaseType.class), resource, mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase("foo_db", Collections.emptyMap()))); + when(metaDataContexts.getDatabaseMetaData(DefaultDatabase.LOGIC_NAME)).thenReturn( + new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), resource, mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase("foo_db", Collections.emptyMap()))); assertThat(contextManager.getDataSourceMap(DefaultDatabase.LOGIC_NAME).size(), is(1)); } @@ -114,9 +116,9 @@ public void assertRenewTransactionContexts() { @Test public void assertAddDatabase() throws SQLException { - when(metaDataContexts.getMetaDataMap()).thenReturn(new LinkedHashMap<>()); + when(metaDataContexts.getDatabaseMetaDataMap()).thenReturn(new LinkedHashMap<>()); contextManager.addDatabase("foo_db"); - assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().containsKey("foo_db")); + assertTrue(contextManager.getMetaDataContexts().getDatabaseMetaDataMap().containsKey("foo_db")); assertTrue(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_db")); } @@ -124,7 +126,7 @@ public void assertAddDatabase() throws SQLException { public void assertAlterSchemas() { contextManager.alterSchemas("foo_db", Collections.singletonMap("foo_db", new ShardingSphereSchema(Collections.singletonMap("foo_table", new TableMetaData("foo_table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()))))); - assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getSchemaByName("foo_db").containsTable("foo_table")); + assertTrue(contextManager.getMetaDataContexts().getDatabaseMetaDataMap().get("foo_db").getDatabase().getSchema("foo_db").containsTable("foo_table")); assertTrue(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_db")); Map schemas = contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().get("foo_db").getSchemas(); assertTrue(schemas.get("foo_db").getTables().containsKey("foo_table")); @@ -132,12 +134,12 @@ public void assertAlterSchemas() { @Test public void assertDeleteDatabase() { - when(metaDataContexts.getMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(ShardingSphereMetaData.class)))); + when(metaDataContexts.getDatabaseMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(ShardingSphereDatabaseMetaData.class)))); when(metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(FederationDatabaseMetaData.class)))); when(metaDataContexts.getOptimizerContext().getParserContexts()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(OptimizerParserContext.class)))); when(metaDataContexts.getOptimizerContext().getPlannerContexts()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(OptimizerPlannerContext.class)))); contextManager.deleteDatabase("foo_db"); - assertFalse(contextManager.getMetaDataContexts().getMetaDataMap().containsKey("foo_db")); + assertFalse(contextManager.getMetaDataContexts().getDatabaseMetaDataMap().containsKey("foo_db")); assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_db")); assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getParserContexts().containsKey("foo_db")); assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getPlannerContexts().containsKey("foo_db")); @@ -146,10 +148,10 @@ public void assertDeleteDatabase() { @Test public void assertAddResource() throws SQLException { ShardingSphereResource resource = mock(ShardingSphereResource.class); - when(metaDataContexts.getMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", new ShardingSphereMetaData(new MySQLDatabaseType(), resource, + when(metaDataContexts.getDatabaseMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", new ShardingSphereDatabaseMetaData(new MySQLDatabaseType(), resource, new ShardingSphereRuleMetaData(new LinkedList<>(), new LinkedList<>()), new ShardingSphereDatabase("foo_db", Collections.emptyMap()))))); contextManager.addResource("foo_db", createToBeAddedDataSourceProperties()); - assertAddedDataSources(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getResource().getDataSources()); + assertAddedDataSources(contextManager.getMetaDataContexts().getDatabaseMetaDataMap().get("foo_db").getResource().getDataSources()); } private Map createToBeAddedDataSourceProperties() { @@ -173,18 +175,18 @@ private void assertAddedDataSource(final MockedDataSource actual) { @Test public void assertAlterResource() throws SQLException { - Map originalMetaDataMap = new HashMap<>(Collections.singletonMap("foo_db", createOriginalMetaData())); - when(metaDataContexts.getMetaDataMap()).thenReturn(originalMetaDataMap); + Map originalDatabaseMetaDataMap = new HashMap<>(Collections.singletonMap("foo_db", createOriginalDatabaseMetaData())); + when(metaDataContexts.getDatabaseMetaDataMap()).thenReturn(originalDatabaseMetaDataMap); contextManager.alterResource("foo_db", Collections.singletonMap("bar_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties("test", "test")))); - assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getResource().getDataSources().get("bar_ds")); + assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getDatabaseMetaDataMap().get("foo_db").getResource().getDataSources().get("bar_ds")); } - private ShardingSphereMetaData createOriginalMetaData() { + private ShardingSphereDatabaseMetaData createOriginalDatabaseMetaData() { ShardingSphereResource resource = mock(ShardingSphereResource.class); when(resource.getDataSources()).thenReturn(Collections.singletonMap("foo_db", new MockedDataSource())); ShardingSphereRuleMetaData ruleMetaData = mock(ShardingSphereRuleMetaData.class); when(ruleMetaData.getConfigurations()).thenReturn(new LinkedList<>()); - return new ShardingSphereMetaData(new MySQLDatabaseType(), resource, ruleMetaData, new ShardingSphereDatabase("foo_db", Collections.emptyMap())); + return new ShardingSphereDatabaseMetaData(new MySQLDatabaseType(), resource, ruleMetaData, new ShardingSphereDatabase("foo_db", Collections.emptyMap())); } private void assertAlteredDataSource(final MockedDataSource actual) { @@ -195,31 +197,31 @@ private void assertAlteredDataSource(final MockedDataSource actual) { @Test public void assertDropResource() { - when(metaDataContexts.getMetaData("foo_db").getResource().getDataSources()).thenReturn(new HashMap<>(Collections.singletonMap("foo_ds", new MockedDataSource()))); + when(metaDataContexts.getDatabaseMetaData("foo_db").getResource().getDataSources()).thenReturn(new HashMap<>(Collections.singletonMap("foo_ds", new MockedDataSource()))); contextManager.dropResource("foo_db", Collections.singleton("foo_ds")); - assertTrue(contextManager.getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources().isEmpty()); + assertTrue(contextManager.getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources().isEmpty()); } @Test public void assertAlterRuleConfiguration() { ShardingSphereResource resource = mock(ShardingSphereResource.class); - when(metaDataContexts.getMetaDataMap()).thenReturn(Collections.singletonMap("foo_db", - new ShardingSphereMetaData(new MySQLDatabaseType(), resource, mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase("foo_db", Collections.emptyMap())))); - when(metaDataContexts.getMetaDataPersistService()).thenReturn(Optional.of(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS))); + when(metaDataContexts.getDatabaseMetaDataMap()).thenReturn(Collections.singletonMap("foo_db", + new ShardingSphereDatabaseMetaData(new MySQLDatabaseType(), resource, mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase("foo_db", Collections.emptyMap())))); + when(metaDataContexts.getPersistService()).thenReturn(Optional.of(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS))); RuleConfiguration ruleConfig = mock(RuleConfiguration.class); contextManager.alterRuleConfiguration("foo_db", Collections.singleton(ruleConfig)); - assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getRuleMetaData().getConfigurations().contains(ruleConfig)); + assertTrue(contextManager.getMetaDataContexts().getDatabaseMetaDataMap().get("foo_db").getRuleMetaData().getConfigurations().contains(ruleConfig)); } @Test public void assertAlterDataSourceConfiguration() { - ShardingSphereMetaData originalMetaData = new ShardingSphereMetaData(new MySQLDatabaseType(), + ShardingSphereDatabaseMetaData originalDatabaseMetaData = new ShardingSphereDatabaseMetaData(new MySQLDatabaseType(), createOriginalResource(), createOriginalRuleMetaData(), new ShardingSphereDatabase("foo_db", Collections.emptyMap())); - when(metaDataContexts.getMetaData("foo_db")).thenReturn(originalMetaData); - when(metaDataContexts.getMetaDataMap()).thenReturn(Collections.singletonMap("foo_db", originalMetaData)); + when(metaDataContexts.getDatabaseMetaData("foo_db")).thenReturn(originalDatabaseMetaData); + when(metaDataContexts.getDatabaseMetaDataMap()).thenReturn(Collections.singletonMap("foo_db", originalDatabaseMetaData)); contextManager.alterDataSourceConfiguration("foo_db", Collections.singletonMap("foo_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties("test", "test")))); - assertThat(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getResource().getDataSources().size(), is(1)); - assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources().get("foo_ds")); + assertThat(contextManager.getMetaDataContexts().getDatabaseMetaDataMap().get("foo_db").getResource().getDataSources().size(), is(1)); + assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources().get("foo_ds")); } private ShardingSphereResource createOriginalResource() { @@ -254,16 +256,16 @@ public void assertAlterProperties() { @Test public void assertReloadMetaData() { - when(metaDataContexts.getMetaData("foo_db").getResource().getDataSources()).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource())); + when(metaDataContexts.getDatabaseMetaData("foo_db").getResource().getDataSources()).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource())); SchemaMetaDataPersistService schemaMetaDataPersistService = mock(SchemaMetaDataPersistService.class, RETURNS_DEEP_STUBS); MetaDataPersistService metaDataPersistService = mock(MetaDataPersistService.class); when(metaDataPersistService.getSchemaMetaDataService()).thenReturn(schemaMetaDataPersistService); - when(metaDataContexts.getMetaDataPersistService()).thenReturn(Optional.of(metaDataPersistService)); + when(metaDataContexts.getPersistService()).thenReturn(Optional.of(metaDataPersistService)); contextManager.reloadMetaData("foo_db", "foo_schema"); verify(schemaMetaDataPersistService, times(1)).persistTables(eq("foo_db"), eq("foo_schema"), any(ShardingSphereSchema.class)); contextManager.reloadMetaData("foo_db", "foo_schema", "foo_table"); - assertNotNull(contextManager.getMetaDataContexts().getMetaData("foo_db").getSchemaByName("foo_schema")); - assertTrue(contextManager.getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources().containsKey("foo_ds")); + assertNotNull(contextManager.getMetaDataContexts().getDatabaseMetaData("foo_db").getDatabase().getSchema("foo_schema")); + assertTrue(contextManager.getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources().containsKey("foo_ds")); } private Map createProperties(final String username, final String password) { diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilderTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilderTest.java index de5af32b0b5a1..0a7139466e601 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilderTest.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsBuilderTest.java @@ -59,13 +59,13 @@ public void assertBuildWithAuthorityRuleConfigurations() throws SQLException { MetaDataContexts actual = new MetaDataContextsBuilder( Collections.singletonMap("logic_db", databaseConfig), Collections.singleton(authorityRuleConfig), new ConfigurationProperties(props)).build(mock(MetaDataPersistService.class)); assertRules(actual); - assertTrue(actual.getMetaData("logic_db").getResource().getDataSources().isEmpty()); + assertTrue(actual.getDatabaseMetaData("logic_db").getResource().getDataSources().isEmpty()); assertThat(actual.getProps().getProps().size(), is(1)); assertThat(actual.getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE), is(1)); } private void assertRules(final MetaDataContexts actual) { - Collection rules = actual.getMetaData("logic_db").getRuleMetaData().getRules(); + Collection rules = actual.getDatabaseMetaData("logic_db").getRuleMetaData().getRules(); assertThat(rules.size(), is(1)); assertThat(rules.iterator().next(), instanceOf(FixtureRule.class)); } @@ -85,14 +85,14 @@ public void assertBuildWithoutGlobalRuleConfigurations() throws SQLException { public void assertBuildWithEmptyRuleConfigurations() throws SQLException { MetaDataContexts actual = new MetaDataContextsBuilder( Collections.emptyMap(), Collections.emptyList(), new ConfigurationProperties(new Properties())).build(mock(MetaDataPersistService.class)); - assertThat(actual.getMetaDataMap().size(), is(4)); - assertTrue(actual.getMetaDataMap().containsKey("information_schema")); - assertTrue(actual.getMetaDataMap().containsKey("performance_schema")); - assertTrue(actual.getMetaDataMap().containsKey("mysql")); - assertTrue(actual.getMetaDataMap().containsKey("sys")); - assertThat(actual.getMetaDataMap().get("information_schema").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); - assertThat(actual.getMetaDataMap().get("performance_schema").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); - assertThat(actual.getMetaDataMap().get("mysql").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); - assertThat(actual.getMetaDataMap().get("sys").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); + assertThat(actual.getDatabaseMetaDataMap().size(), is(4)); + assertTrue(actual.getDatabaseMetaDataMap().containsKey("information_schema")); + assertTrue(actual.getDatabaseMetaDataMap().containsKey("performance_schema")); + assertTrue(actual.getDatabaseMetaDataMap().containsKey("mysql")); + assertTrue(actual.getDatabaseMetaDataMap().containsKey("sys")); + assertThat(actual.getDatabaseMetaDataMap().get("information_schema").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); + assertThat(actual.getDatabaseMetaDataMap().get("performance_schema").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); + assertThat(actual.getDatabaseMetaDataMap().get("mysql").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); + assertThat(actual.getDatabaseMetaDataMap().get("sys").getRuleMetaData().getRules(), instanceOf(LinkedList.class)); } } diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java index 80609b3840914..deddee29edfc2 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.DefaultDatabase; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -43,12 +43,12 @@ public final class MetaDataContextsTest { private OptimizerContext optimizerContext; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Test public void assertGetDefaultMetaData() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, metaData), - mock(ShardingSphereRuleMetaData.class), null, optimizerContext, new ConfigurationProperties(new Properties())); - assertThat(metaDataContexts.getMetaData(DefaultDatabase.LOGIC_NAME), is(metaData)); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseMetaData), + mock(ShardingSphereRuleMetaData.class), optimizerContext, new ConfigurationProperties(new Properties())); + assertThat(metaDataContexts.getDatabaseMetaData(DefaultDatabase.LOGIC_NAME), is(databaseMetaData)); } } diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistServiceTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistServiceTest.java index 832efedeb2928..d83ecb188b777 100644 --- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistServiceTest.java +++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistServiceTest.java @@ -102,13 +102,6 @@ public void assertLoadInstanceXaRecoveryId() { verify(repository).get(ComputeNode.getInstanceXaRecoveryIdNodePath(instanceId)); } - @Test - public void assertLoadComputeNodeInstances() { - InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307); - new ComputeNodePersistService(repository).loadComputeNodeInstances(instanceDefinition.getInstanceType(), Collections.singletonList("test")); - verify(repository).getChildrenKeys(ComputeNode.getOnlineNodePath(instanceDefinition.getInstanceType())); - } - @Test public void assertLoadAllComputeNodeInstances() { when(repository.getChildrenKeys("/nodes/compute_nodes/online/proxy")).thenReturn(Collections.singletonList("127.0.0.1@3307")); diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index 3be5c0709a15b..c6d6326731867 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition; import org.apache.shardingsphere.infra.instance.definition.InstanceType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.ContextManagerBuilder; import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter; @@ -106,9 +106,9 @@ private Properties getTransactionProperties(final MetaDataContexts metaDataConte if (!databaseName.isPresent() || !fileGenerator.isPresent()) { return transactionRule.isPresent() ? transactionRule.get().getProps() : new Properties(); } - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName.get()); + ShardingSphereDatabaseMetaData databaseMetaData = metaDataContexts.getDatabaseMetaData(databaseName.get()); Properties result = fileGenerator.get().getTransactionProps(transactionRule.get().getProps(), - new DataSourceProvidedDatabaseConfiguration(metaData.getResource().getDataSources(), metaData.getRuleMetaData().getConfigurations()), getType()); + new DataSourceProvidedDatabaseConfiguration(databaseMetaData.getResource().getDataSources(), databaseMetaData.getRuleMetaData().getConfigurations()), getType()); Optional transactionRuleConfig = metaDataContexts.getGlobalRuleMetaData().findSingleRuleConfiguration(TransactionRuleConfiguration.class); Preconditions.checkState(transactionRuleConfig.isPresent()); transactionRuleConfig.get().getProps().clear(); @@ -143,11 +143,11 @@ private DatabaseConfiguration createDatabaseConfiguration(final String databaseN } private void persistMetaData(final MetaDataContexts metaDataContexts) { - metaDataContexts.getMetaDataMap().forEach((databaseName, schemas) -> schemas.getDatabase().getSchemas().forEach((schemaName, tables) -> { + metaDataContexts.getDatabaseMetaDataMap().forEach((databaseName, schemas) -> schemas.getDatabase().getSchemas().forEach((schemaName, tables) -> { if (tables.getTables().isEmpty()) { - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistSchema(databaseName, schemaName)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistSchema(databaseName, schemaName)); } else { - metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistTables(databaseName, schemaName, tables)); + metaDataContexts.getPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persistTables(databaseName, schemaName, tables)); } })); } @@ -162,7 +162,7 @@ private ContextManager createContextManager(final ClusterPersistRepository repos instanceContext.initLockContext(); repository.watchSessionConnection(instanceContext); generateTransactionConfigurationFile(instanceContext, metaDataContexts, transactionProps); - TransactionContexts transactionContexts = new TransactionContextsBuilder(metaDataContexts.getMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); + TransactionContexts transactionContexts = new TransactionContextsBuilder(metaDataContexts.getDatabaseMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); return new ContextManager(metaDataContexts, transactionContexts, instanceContext); } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java index e9ba8b4f9fa07..adec775c50281 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java @@ -180,7 +180,7 @@ public synchronized void renew(final DataSourceChangedEvent event) { @Subscribe public synchronized void renew(final DisabledStateChangedEvent event) { QualifiedDatabase qualifiedDatabase = event.getQualifiedSchema(); - contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedDatabase.getDatabaseName()).getRuleMetaData().getRules() + contextManager.getMetaDataContexts().getDatabaseMetaDataMap().get(qualifiedDatabase.getDatabaseName()).getRuleMetaData().getRules() .stream().filter(each -> each instanceof StatusContainedRule) .forEach(each -> ((StatusContainedRule) each).updateStatus(new DataSourceNameDisabledEvent(qualifiedDatabase, event.isDisabled()))); } @@ -193,7 +193,7 @@ public synchronized void renew(final DisabledStateChangedEvent event) { @Subscribe public synchronized void renew(final PrimaryStateChangedEvent event) { QualifiedDatabase qualifiedDatabase = event.getQualifiedDatabase(); - contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedDatabase.getDatabaseName()).getRuleMetaData().getRules() + contextManager.getMetaDataContexts().getDatabaseMetaDataMap().get(qualifiedDatabase.getDatabaseName()).getRuleMetaData().getRules() .stream() .filter(each -> each instanceof StatusContainedRule) .forEach(each -> ((StatusContainedRule) each) @@ -323,7 +323,7 @@ public synchronized void completeUnitShowProcessList(final ShowProcessListUnitCo } private void buildSpecialRules() { - contextManager.getMetaDataContexts().getMetaDataMap().forEach((key, value) -> value.getRuleMetaData().getRules().forEach(each -> { + contextManager.getMetaDataContexts().getDatabaseMetaDataMap().forEach((key, value) -> value.getRuleMetaData().getRules().forEach(each -> { if (each instanceof StatusContainedRule) { disableDataSources((StatusContainedRule) each); } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeService.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeService.java index c3a83aa961088..bb69177579f58 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeService.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeService.java @@ -30,7 +30,7 @@ public abstract class AbstractDistributeLockNodeService implements LockNodeServi @Override public String getLocksNodePath() { - return PATH_DELIMITER + LOCK_ROOT + PATH_DELIMITER + getLockLevel() + PATH_DELIMITER + LOCKS_NODE; + return PATH_DELIMITER + LOCK_ROOT + PATH_DELIMITER + getLockTypeName() + PATH_DELIMITER + LOCKS_NODE; } @Override @@ -57,5 +57,5 @@ public Optional parseLocksAckNodePath(final String nodePath) { return matcher.find() ? Optional.of(matcher.group(2)) : Optional.empty(); } - protected abstract String getLockLevel(); + protected abstract String getLockTypeName(); } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java index 088517264595f..7f2be2102aba1 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java @@ -27,6 +27,8 @@ import org.apache.shardingsphere.spi.ShardingSphereServiceLoader; import org.apache.shardingsphere.spi.type.required.RequiredSPIRegistry; +import java.util.Set; + /** * Distribute lock context. */ @@ -51,28 +53,48 @@ private void loadLockManager(final ShardingSphereInterMutexLockHolder lockHolder lockManager.init(lockHolder); } + @Override + public ShardingSphereLock getMutexLock() { + return lockManager.getMutexLock(); + } + @Override public boolean lockWrite(final String databaseName) { return lockManager.lockWrite(databaseName); } + @Override + public boolean lockWrite(final String databaseName, final Set schemaNames) { + return lockManager.lockWrite(databaseName, schemaNames); + } + @Override public boolean tryLockWrite(final String databaseName, final long timeoutMilliseconds) { return lockManager.tryLockWrite(databaseName, timeoutMilliseconds); } + @Override + public boolean tryLockWrite(final String databaseName, final Set schemaNames, final long timeoutMilliseconds) { + return lockManager.tryLockWrite(databaseName, schemaNames, timeoutMilliseconds); + } + @Override public void releaseLockWrite(final String databaseName) { lockManager.releaseLockWrite(databaseName); } + @Override + public void releaseLockWrite(final String databaseName, final String schemaName) { + lockManager.releaseLockWrite(databaseName, schemaName); + } + @Override public boolean isLocked(final String databaseName) { return lockManager.isLocked(databaseName); } @Override - public ShardingSphereLock getMutexLock() { - return lockManager.getMutexLock(); + public boolean isLocked(final String databaseName, final String schema) { + return lockManager.isLocked(databaseName, schema); } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java index eb6cf7423c648..0498e8627bcbe 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java @@ -27,11 +27,11 @@ public final class DatabaseLockNodeService extends AbstractDistributeLockNodeSer @Override public String getSequenceNodePath() { - return PATH_DELIMITER + LOCK_ROOT + PATH_DELIMITER + getLockLevel() + PATH_DELIMITER + "sequence"; + return PATH_DELIMITER + LOCK_ROOT + PATH_DELIMITER + getLockTypeName() + PATH_DELIMITER + "sequence"; } @Override - protected String getLockLevel() { + protected String getLockTypeName() { return "database"; } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/watcher/DatabaseLockChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/watcher/DatabaseLockChangedWatcher.java index bdfad78849c34..f2f8df1b67951 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/watcher/DatabaseLockChangedWatcher.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/watcher/DatabaseLockChangedWatcher.java @@ -44,8 +44,8 @@ public Collection getWatchingKeys() { } @Override - public Collection getWatchingTypes() { - return Arrays.asList(DataChangedEvent.Type.ADDED, DataChangedEvent.Type.DELETED); + public Collection getWatchingTypes() { + return Arrays.asList(Type.ADDED, Type.DELETED); } @Override @@ -71,9 +71,9 @@ private Optional handleDatabaseLocksEvent(final Type eventType, } private Optional handleDatabaseLocksAckEvent(final Type eventType, final String ackLockedName) { - if (DataChangedEvent.Type.ADDED == eventType) { + if (Type.ADDED == eventType) { return Optional.of(new DatabaseAckLockedEvent(ackLockedName)); - } else if (DataChangedEvent.Type.DELETED == eventType) { + } else if (Type.DELETED == eventType) { return Optional.of(new DatabaseAckLockReleasedEvent(ackLockedName)); } return Optional.empty(); diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributeLockManager.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributeLockManager.java index c1a4d79a63cc9..94af0556a102c 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributeLockManager.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributeLockManager.java @@ -55,11 +55,11 @@ public boolean lockWrite(final String databaseName) { @Override public boolean tryLockWrite(final String databaseName, final long timeoutMilliseconds) { - return innerTryLock(databaseName, timeoutMilliseconds); + return innerDatabaseTryLock(databaseName, timeoutMilliseconds); } - private synchronized boolean innerTryLock(final String databaseName, final long timeoutMilliseconds) { - Preconditions.checkNotNull(databaseName, "Try Lock write for databaseName args database name can not be null."); + private synchronized boolean innerDatabaseTryLock(final String databaseName, final long timeoutMilliseconds) { + Preconditions.checkNotNull(databaseName, "Try Lock write for database args database name can not be null."); if (!sequencedLock.tryLock(TimeoutMilliseconds.DEFAULT_REGISTRY)) { return false; } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java index 290c854163121..11918dbef5b0c 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java @@ -22,6 +22,8 @@ import org.apache.shardingsphere.spi.annotation.SingletonSPI; import org.apache.shardingsphere.spi.type.required.RequiredSPI; +import java.util.Set; + /** * Lock manager of ShardingSphere. */ @@ -43,13 +45,24 @@ public interface ShardingSphereLockManager extends RequiredSPI { ShardingSphereLock getMutexLock(); /** - * Lock write. + * Lock write for database. * * @param databaseName database name * @return is locked or not */ boolean lockWrite(String databaseName); + /** + * Lock write for schemas. + * + * @param databaseName database name + * @param schemaNames schema names + * @return is locked or not + */ + default boolean lockWrite(String databaseName, Set schemaNames) { + throw new UnsupportedOperationException(); + } + /** * Try lock write for database. * @@ -59,6 +72,18 @@ public interface ShardingSphereLockManager extends RequiredSPI { */ boolean tryLockWrite(String databaseName, long timeoutMilliseconds); + /** + * Try lock write for schemas. + * + * @param databaseName database name + * @param schemaNames schema names + * @param timeoutMilliseconds timeout milliseconds + * @return is locked or not + */ + default boolean tryLockWrite(String databaseName, Set schemaNames, long timeoutMilliseconds) { + throw new UnsupportedOperationException(); + } + /** * Release lock write for database. * @@ -66,6 +91,16 @@ public interface ShardingSphereLockManager extends RequiredSPI { */ void releaseLockWrite(String databaseName); + /** + * Try lock write for schemas. + * + * @param databaseName database name + * @param schemaName schema name + */ + default void releaseLockWrite(String databaseName, String schemaName) { + throw new UnsupportedOperationException(); + } + /** * Is locked database. * @@ -73,4 +108,15 @@ public interface ShardingSphereLockManager extends RequiredSPI { * @return is locked or not */ boolean isLocked(String databaseName); + + /** + * Is locked schema. + * + * @param databaseName database name + * @param schemaName schema name + * @return is locked or not + */ + default boolean isLocked(String databaseName, String schemaName) { + throw new UnsupportedOperationException(); + } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeService.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeService.java index efc87054d33b5..3ebd045ae90ab 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeService.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeService.java @@ -27,11 +27,11 @@ public final class MutexLockNodeService extends AbstractDistributeLockNodeServic @Override public String getSequenceNodePath() { - return PATH_DELIMITER + LOCK_ROOT + PATH_DELIMITER + getLockLevel() + PATH_DELIMITER + "sequence"; + return PATH_DELIMITER + LOCK_ROOT + PATH_DELIMITER + getLockTypeName() + PATH_DELIMITER + "sequence"; } @Override - protected String getLockLevel() { + protected String getLockTypeName() { return "mutex"; } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeUtil.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeUtil.java index 76bf438b35da2..74eb4f7f780a3 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeUtil.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeUtil.java @@ -26,7 +26,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class LockNodeUtil { - private static final String LOCK_DELIMITER = "#@#"; + private static final String LOCK_NAME_DELIMITER = "#@#"; /** * Generate Lock leases node path. @@ -56,7 +56,7 @@ public static String generateAckPathName(final String lockName) { * @return ack locked name */ public static String generateAckLockedName(final String lockName, final String instanceId) { - return lockName + LOCK_DELIMITER + instanceId; + return lockName + LOCK_NAME_DELIMITER + instanceId; } /** @@ -66,7 +66,7 @@ public static String generateAckLockedName(final String lockName, final String i * @return string array of locked name and instance id */ public static String[] parseAckLockName(final String ackLockedName) { - return ackLockedName.trim().split(LOCK_DELIMITER); + return ackLockedName.trim().split(LOCK_NAME_DELIMITER); } /** diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java index 9e37e77c33c98..daa0001fb8d7d 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.watcher; +import com.google.common.base.Preconditions; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; @@ -71,13 +72,16 @@ public Collection getWatchingTypes() { public Optional createGovernanceEvent(final DataChangedEvent event) { // TODO Maybe can reduce once regular if (isLogicDatabaseChanged(event)) { - return buildLogicDatabaseChangedEvent(event); - } else if (isLogicSchemaChanged(event)) { - return buildLogicSchemaChangedEvent(event); - } else if (isTableMetaDataChanged(event)) { - return buildTableMetaDataChangedEvent(event); - } else if (Type.UPDATED == event.getType()) { - return buildGovernanceEvent(event); + return createLogicDatabaseChangedEvent(event); + } + if (isLogicSchemaChanged(event)) { + return createLogicSchemaChangedEvent(event); + } + if (isTableMetaDataChanged(event)) { + return createSchemaChangedEvent(event); + } + if (Type.UPDATED == event.getType()) { + return createUpdateGovernanceEvent(event); } return Optional.empty(); } @@ -98,30 +102,33 @@ private boolean isTableMetaDataChanged(final DataChangedEvent event) { && !SystemSchemaBuilderRule.isSystemTable(databaseName.get(), tableName.get()) && !Strings.isNullOrEmpty(event.getValue()); } - private Optional buildLogicDatabaseChangedEvent(final DataChangedEvent event) { - String databaseName = DatabaseMetaDataNode.getDatabaseName(event.getKey()).get(); + private Optional createLogicDatabaseChangedEvent(final DataChangedEvent event) { + Optional databaseName = DatabaseMetaDataNode.getDatabaseName(event.getKey()); + Preconditions.checkState(databaseName.isPresent()); if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) { - return Optional.of(new DatabaseAddedEvent(databaseName)); + return Optional.of(new DatabaseAddedEvent(databaseName.get())); } if (Type.DELETED == event.getType()) { - return Optional.of(new DatabaseDeletedEvent(databaseName)); + return Optional.of(new DatabaseDeletedEvent(databaseName.get())); } return Optional.empty(); } - private Optional buildLogicSchemaChangedEvent(final DataChangedEvent event) { - String databaseName = DatabaseMetaDataNode.getDatabaseNameByDatabasePath(event.getKey()).get(); - String schemaName = DatabaseMetaDataNode.getSchemaName(event.getKey()).get(); + private Optional createLogicSchemaChangedEvent(final DataChangedEvent event) { + Optional databaseName = DatabaseMetaDataNode.getDatabaseNameByDatabasePath(event.getKey()); + Preconditions.checkState(databaseName.isPresent()); + Optional schemaName = DatabaseMetaDataNode.getSchemaName(event.getKey()); + Preconditions.checkState(schemaName.isPresent()); if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) { - return Optional.of(new SchemaAddedEvent(databaseName, schemaName)); + return Optional.of(new SchemaAddedEvent(databaseName.get(), schemaName.get())); } if (Type.DELETED == event.getType()) { - return Optional.of(new SchemaDeletedEvent(databaseName, schemaName)); + return Optional.of(new SchemaDeletedEvent(databaseName.get(), schemaName.get())); } return Optional.empty(); } - private Optional buildGovernanceEvent(final DataChangedEvent event) { + private Optional createUpdateGovernanceEvent(final DataChangedEvent event) { Optional databaseName = DatabaseMetaDataNode.getDatabaseNameByDatabasePath(event.getKey()); if (!databaseName.isPresent() || Strings.isNullOrEmpty(event.getValue())) { return Optional.empty(); @@ -133,11 +140,7 @@ private Optional buildGovernanceEvent(final DataChangedEvent ev if (schemaVersion.isPresent()) { return Optional.of(createDataSourceChangedEvent(databaseName.get(), schemaVersion.get(), event)); } - schemaVersion = DatabaseMetaDataNode.getVersionByRulesPath(event.getKey()); - if (schemaVersion.isPresent()) { - return Optional.of(createRuleChangedEvent(databaseName.get(), schemaVersion.get(), event)); - } - return Optional.empty(); + return DatabaseMetaDataNode.getVersionByRulesPath(event.getKey()).map(optional -> new RuleConfigurationsChangedEvent(databaseName.get(), optional, getRuleConfigurations(event.getValue()))); } @SuppressWarnings("unchecked") @@ -150,25 +153,25 @@ private DataSourceChangedEvent createDataSourceChangedEvent(final String databas return new DataSourceChangedEvent(databaseName, schemaVersion, dataSourcePropertiesMap); } - private GovernanceEvent createRuleChangedEvent(final String databaseName, final String schemaVersion, final DataChangedEvent event) { - return new RuleConfigurationsChangedEvent(databaseName, schemaVersion, getRuleConfigurations(event.getValue())); - } - @SuppressWarnings("unchecked") private Collection getRuleConfigurations(final String yamlContent) { - Collection rules = Strings.isNullOrEmpty(yamlContent) - ? new LinkedList<>() - : YamlEngine.unmarshal(yamlContent, Collection.class, true); + Collection rules = Strings.isNullOrEmpty(yamlContent) ? new LinkedList<>() : YamlEngine.unmarshal(yamlContent, Collection.class, true); return new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(rules); } - private Optional buildTableMetaDataChangedEvent(final DataChangedEvent event) { - String databaseName = DatabaseMetaDataNode.getDatabaseNameByDatabasePath(event.getKey()).get(); - String schemaName = DatabaseMetaDataNode.getSchemaNameBySchemaPath(event.getKey()).get(); - String tableName = DatabaseMetaDataNode.getTableName(event.getKey()).get(); - if (Type.DELETED == event.getType()) { - return Optional.of(new SchemaChangedEvent(databaseName, schemaName, null, tableName)); - } - return Optional.of(new SchemaChangedEvent(databaseName, schemaName, new TableMetaDataYamlSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlTableMetaData.class)), null)); + private Optional createSchemaChangedEvent(final DataChangedEvent event) { + Optional databaseName = DatabaseMetaDataNode.getDatabaseNameByDatabasePath(event.getKey()); + Preconditions.checkState(databaseName.isPresent()); + Optional schemaName = DatabaseMetaDataNode.getSchemaNameBySchemaPath(event.getKey()); + Preconditions.checkState(schemaName.isPresent()); + Optional tableName = DatabaseMetaDataNode.getTableName(event.getKey()); + Preconditions.checkState(tableName.isPresent()); + return Optional.of(createSchemaChangedEvent(event, databaseName.get(), schemaName.get(), tableName.get())); + } + + private SchemaChangedEvent createSchemaChangedEvent(final DataChangedEvent event, final String databaseName, final String schemaName, final String tableName) { + return Type.DELETED == event.getType() + ? new SchemaChangedEvent(databaseName, schemaName, null, tableName) + : new SchemaChangedEvent(databaseName, schemaName, new TableMetaDataYamlSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlTableMetaData.class)), null); } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java index 61d7a3c159d2f..d7ee8741981eb 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java @@ -28,7 +28,6 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator; -import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessContext; import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessContext; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext; @@ -36,7 +35,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition; import org.apache.shardingsphere.infra.instance.definition.InstanceType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.resource.CachedDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.resource.DataSourcesMetaData; @@ -129,7 +128,7 @@ public final class ClusterContextManagerCoordinatorTest { private MetaDataPersistService metaDataPersistService; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereMetaData metaData; + private ShardingSphereDatabaseMetaData databaseMetaData; @Mock private ShardingSphereRuleMetaData globalRuleMetaData; @@ -139,23 +138,23 @@ public void setUp() throws SQLException { ModeConfiguration modeConfig = new ModeConfiguration("Cluster", new ClusterPersistRepositoryConfiguration("FIXTURE", "", "", new Properties()), false); contextManager = new ClusterContextManagerBuilder().build(ContextManagerBuilderParameter.builder().modeConfig(modeConfig).databaseConfigs(Collections.emptyMap()) .globalRuleConfigs(Collections.emptyList()).props(new Properties()).instanceDefinition(new InstanceDefinition(InstanceType.PROXY, 3307)).build()); - assertTrue(contextManager.getMetaDataContexts().getMetaDataPersistService().isPresent()); - contextManager.renewMetaDataContexts(new MetaDataContexts(contextManager.getMetaDataContexts().getMetaDataPersistService().get(), createMetaDataMap(), globalRuleMetaData, - mock(ExecutorEngine.class), createOptimizerContext(), new ConfigurationProperties(new Properties()))); + assertTrue(contextManager.getMetaDataContexts().getPersistService().isPresent()); + contextManager.renewMetaDataContexts(new MetaDataContexts(contextManager.getMetaDataContexts().getPersistService().get(), createDatabaseMetaDataMap(), globalRuleMetaData, + createOptimizerContext(), new ConfigurationProperties(new Properties()))); contextManager.renewTransactionContexts(mock(TransactionContexts.class, RETURNS_DEEP_STUBS)); coordinator = new ClusterContextManagerCoordinator(metaDataPersistService, contextManager, new RegistryCenter(mock(ClusterPersistRepository.class))); } - private Map createMetaDataMap() { - when(metaData.getDatabase().getName()).thenReturn("db"); + private Map createDatabaseMetaDataMap() { + when(databaseMetaData.getDatabase().getName()).thenReturn("db"); ShardingSphereResource resource = mock(ShardingSphereResource.class); when(resource.getDatabaseType()).thenReturn(new MySQLDatabaseType()); - when(metaData.getResource()).thenReturn(resource); - when(metaData.getFrontendDatabaseType()).thenReturn(new MySQLDatabaseType()); - when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); - when(metaData.getRuleMetaData().getRules()).thenReturn(new LinkedList<>()); - when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); - return new HashMap<>(Collections.singletonMap("db", metaData)); + when(databaseMetaData.getResource()).thenReturn(resource); + when(databaseMetaData.getProtocolType()).thenReturn(new MySQLDatabaseType()); + when(databaseMetaData.getDatabase().getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class)); + when(databaseMetaData.getRuleMetaData().getRules()).thenReturn(new LinkedList<>()); + when(databaseMetaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList()); + return new HashMap<>(Collections.singletonMap("db", databaseMetaData)); } private OptimizerContext createOptimizerContext() { @@ -169,7 +168,7 @@ public void assertDatabaseAdd() throws SQLException { when(metaDataPersistService.getDataSourceService().load("db_add")).thenReturn(getDataSourcePropertiesMap()); when(metaDataPersistService.getDatabaseRulePersistService().load("db_add")).thenReturn(Collections.emptyList()); coordinator.renew(new DatabaseAddedEvent("db_add")); - assertNotNull(contextManager.getMetaDataContexts().getMetaData("db_add").getResource().getDataSources()); + assertNotNull(contextManager.getMetaDataContexts().getDatabaseMetaData("db_add").getResource().getDataSources()); } private Map getDataSourcePropertiesMap() { @@ -184,7 +183,7 @@ private Map getDataSourcePropertiesMap() { @Test public void assertSchemaDelete() { coordinator.renew(new DatabaseDeletedEvent("db")); - assertNull(contextManager.getMetaDataContexts().getMetaData("db")); + assertNull(contextManager.getMetaDataContexts().getDatabaseMetaData("db")); } @Test @@ -201,21 +200,21 @@ public void assertSchemaChanged() { SchemaChangedEvent event = new SchemaChangedEvent("db", "db", changedTableMetaData, null); coordinator.renew(event); assertTrue(contextManager.getMetaDataContexts().getAllDatabaseNames().contains("db")); - verify(contextManager.getMetaDataContexts().getMetaData("db").getSchemaByName("db")).put("t_order", event.getChangedTableMetaData()); + verify(contextManager.getMetaDataContexts().getDatabaseMetaData("db").getDatabase().getSchema("db")).put("t_order", event.getChangedTableMetaData()); } @Test public void assertRuleConfigurationsChanged() { when(metaDataPersistService.getDatabaseVersionPersistService().isActiveVersion("db", "0")).thenReturn(true); - assertThat(contextManager.getMetaDataContexts().getMetaData("db"), is(metaData)); + assertThat(contextManager.getMetaDataContexts().getDatabaseMetaData("db"), is(databaseMetaData)); coordinator.renew(new RuleConfigurationsChangedEvent("db", "0", Collections.emptyList())); - assertThat(contextManager.getMetaDataContexts().getMetaData("db"), not(metaData)); + assertThat(contextManager.getMetaDataContexts().getDatabaseMetaData("db"), not(databaseMetaData)); } @Test public void assertDisableStateChanged() { StatusContainedRule statusContainedRule = mock(StatusContainedRule.class); - when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.singletonList(statusContainedRule)); + when(databaseMetaData.getRuleMetaData().getRules()).thenReturn(Collections.singletonList(statusContainedRule)); DisabledStateChangedEvent event = new DisabledStateChangedEvent(new QualifiedDatabase("db.readwrite_ds.ds_0"), true); coordinator.renew(event); verify(statusContainedRule, times(1)).updateStatus(argThat( @@ -226,7 +225,7 @@ public void assertDisableStateChanged() { public void assertDataSourceChanged() { when(metaDataPersistService.getDatabaseVersionPersistService().isActiveVersion("db", "0")).thenReturn(true); coordinator.renew(new DataSourceChangedEvent("db", "0", getChangedDataSourcePropertiesMap())); - assertTrue(contextManager.getMetaDataContexts().getMetaData("db").getResource().getDataSources().containsKey("ds_2")); + assertTrue(contextManager.getMetaDataContexts().getDatabaseMetaData("db").getResource().getDataSources().containsKey("ds_2")); } private Map getChangedDataSourcePropertiesMap() { @@ -268,9 +267,9 @@ public void assertRenewPrimaryDataSourceName() { StatusContainedRule mockStatusContainedRule = mock(StatusContainedRule.class); rules.add(mockStatusContainedRule); ShardingSphereRuleMetaData mockShardingSphereRuleMetaData = new ShardingSphereRuleMetaData(new LinkedList<>(), rules); - ShardingSphereMetaData mockShardingSphereMetaData = mock(ShardingSphereMetaData.class); - when(mockShardingSphereMetaData.getRuleMetaData()).thenReturn(mockShardingSphereRuleMetaData); - contextManager.getMetaDataContexts().getMetaDataMap().put("db", mockShardingSphereMetaData); + ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class); + when(databaseMetaData.getRuleMetaData()).thenReturn(mockShardingSphereRuleMetaData); + contextManager.getMetaDataContexts().getDatabaseMetaDataMap().put("db", databaseMetaData); PrimaryStateChangedEvent mockPrimaryStateChangedEvent = new PrimaryStateChangedEvent(new QualifiedDatabase("db.readwrite_ds.test_ds")); coordinator.renew(mockPrimaryStateChangedEvent); verify(mockStatusContainedRule).updateStatus(any()); @@ -391,9 +390,9 @@ private void lockAndAwaitDefaultTime(final ShowProcessListSimpleLock lock) { private Map initContextManager() { Map result = getDataSourceMap(); ShardingSphereResource resource = new ShardingSphereResource(result, mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), new MySQLDatabaseType()); - ShardingSphereMetaData mockedMetaData = new ShardingSphereMetaData(new MySQLDatabaseType(), resource, - mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase("db", Collections.emptyMap())); - contextManager.getMetaDataContexts().getMetaDataMap().put("db", mockedMetaData); + ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData( + new MySQLDatabaseType(), resource, mock(ShardingSphereRuleMetaData.class), new ShardingSphereDatabase("db", Collections.emptyMap())); + contextManager.getMetaDataContexts().getDatabaseMetaDataMap().put("db", databaseMetaData); return result; } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeServiceTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeServiceTest.java index cf8a78975d913..b7f24c91b0952 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeServiceTest.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeServiceTest.java @@ -33,6 +33,6 @@ public void assertGetSequenceNodePath() { @Test public void assertGetLockLevel() { - assertThat(SERVICE.getLockLevel(), is("database")); + assertThat(SERVICE.getLockTypeName(), is("database")); } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeServiceTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeServiceTest.java index d4f158736717c..1e9b42100b07b 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeServiceTest.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeServiceTest.java @@ -33,6 +33,6 @@ public void assertGetSequenceNodePath() { @Test public void assertGetLockLevel() { - assertThat(SERVICE.getLockLevel(), is("mutex")); + assertThat(SERVICE.getLockTypeName(), is("mutex")); } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java index 0c107d990dcda..156811e7b7fd2 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java @@ -49,7 +49,7 @@ public ContextManager build(final ContextManagerBuilderParameter parameter) thro parameter.getDatabaseConfigs(), parameter.getGlobalRuleConfigs(), new ConfigurationProperties(parameter.getProps())).build(null); InstanceContext instanceContext = buildInstanceContext(parameter); generateTransactionConfigurationFile(instanceContext, metaDataContexts); - TransactionContexts transactionContexts = new TransactionContextsBuilder(metaDataContexts.getMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); + TransactionContexts transactionContexts = new TransactionContextsBuilder(metaDataContexts.getDatabaseMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); ContextManager result = new ContextManager(metaDataContexts, transactionContexts, buildInstanceContext(parameter)); setInstanceContext(result); return result; @@ -71,7 +71,7 @@ private void generateTransactionConfigurationFile(final InstanceContext instance } private void setInstanceContext(final ContextManager contextManager) { - contextManager.getMetaDataContexts().getMetaDataMap().forEach((key, value) -> value.getRuleMetaData().getRules().stream().filter(each -> each instanceof InstanceAwareRule) + contextManager.getMetaDataContexts().getDatabaseMetaDataMap().forEach((key, value) -> value.getRuleMetaData().getRules().stream().filter(each -> each instanceof InstanceAwareRule) .forEach(each -> ((InstanceAwareRule) each).setInstanceContext(contextManager.getInstanceContext()))); } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java index 90054bf535a07..7422ad1934136 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java @@ -21,6 +21,8 @@ import org.apache.shardingsphere.infra.lock.LockContext; import org.apache.shardingsphere.infra.lock.ShardingSphereLock; +import java.util.Set; + /** * Memory lock context. */ @@ -43,18 +45,42 @@ public boolean lockWrite(final String databaseName) { return mutexLock.tryLock(databaseName); } + @Override + public boolean lockWrite(final String databaseName, final Set schemaNames) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } + @Override public boolean tryLockWrite(final String databaseName, final long timeoutMilliseconds) { return mutexLock.tryLock(databaseName, timeoutMilliseconds); } + @Override + public boolean tryLockWrite(final String databaseName, final Set schemaNames, final long timeoutMilliseconds) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } + @Override public void releaseLockWrite(final String databaseName) { mutexLock.releaseLock(databaseName); } + @Override + public void releaseLockWrite(final String databaseName, final String schemaName) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } + @Override public boolean isLocked(final String databaseName) { return mutexLock.isLocked(databaseName); } + + @Override + public boolean isLocked(final String databaseName, final String schemaName) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java index 7b974089f43e8..c939beb5a3f55 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java @@ -93,7 +93,7 @@ private ContextManager createContextManager(final MetaDataPersistService metaDat InstanceContext instanceContext = new InstanceContext(metaDataPersistService.getComputeNodePersistService().loadComputeNodeInstance(parameter.getInstanceDefinition()), new StandaloneWorkerIdGenerator(), parameter.getModeConfig(), new StandaloneLockContext()); generateTransactionConfigurationFile(instanceContext, metaDataContexts); - TransactionContexts transactionContexts = new TransactionContextsBuilder(metaDataContexts.getMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); + TransactionContexts transactionContexts = new TransactionContextsBuilder(metaDataContexts.getDatabaseMetaDataMap(), metaDataContexts.getGlobalRuleMetaData().getRules()).build(); ContextManager result = new ContextManager(metaDataContexts, transactionContexts, instanceContext); setInstanceContext(result); return result; @@ -109,7 +109,7 @@ private void generateTransactionConfigurationFile(final InstanceContext instance } private void setInstanceContext(final ContextManager contextManager) { - contextManager.getMetaDataContexts().getMetaDataMap().forEach((key, value) -> value.getRuleMetaData().getRules().stream().filter(each -> each instanceof InstanceAwareRule) + contextManager.getMetaDataContexts().getDatabaseMetaDataMap().forEach((key, value) -> value.getRuleMetaData().getRules().stream().filter(each -> each instanceof InstanceAwareRule) .forEach(each -> ((InstanceAwareRule) each).setInstanceContext(contextManager.getInstanceContext()))); } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java index 755bec938eba9..8ed502c06c8c2 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java @@ -21,6 +21,8 @@ import org.apache.shardingsphere.infra.lock.LockContext; import org.apache.shardingsphere.infra.lock.ShardingSphereLock; +import java.util.Set; + /** * Standalone lock context. */ @@ -43,18 +45,42 @@ public boolean lockWrite(final String databaseName) { return mutexLock.tryLock(databaseName); } + @Override + public boolean lockWrite(final String databaseName, final Set schemaNames) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } + @Override public boolean tryLockWrite(final String databaseName, final long timeoutMilliseconds) { return mutexLock.tryLock(databaseName, timeoutMilliseconds); } + @Override + public boolean tryLockWrite(final String databaseName, final Set schemaNames, final long timeoutMilliseconds) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } + @Override public void releaseLockWrite(final String databaseName) { mutexLock.releaseLock(databaseName); } + @Override + public void releaseLockWrite(final String databaseName, final String schemaName) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } + @Override public boolean isLocked(final String databaseName) { return mutexLock.isLocked(databaseName); } + + @Override + public boolean isLocked(final String databaseName, final String schemaName) { + // TODO when the lock structure adjustment is completed + throw new UnsupportedOperationException(); + } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java index e897d7fafcef9..17144188ea008 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java @@ -47,10 +47,9 @@ public void assertBuild() throws SQLException { new DataSourceProvidedDatabaseConfiguration(Collections.singletonMap("foo_ds", new MockedDataSource()), Collections.singleton(mock(RuleConfiguration.class))))) .globalRuleConfigs(Collections.singleton(mock(RuleConfiguration.class))).props(new Properties()) .instanceDefinition(new InstanceDefinition(InstanceType.PROXY, 3307)).build()); - assertNotNull(actual.getMetaDataContexts().getMetaDataMap().get("foo_schema")); - assertNotNull(actual.getMetaDataContexts().getExecutorEngine()); - assertTrue(actual.getMetaDataContexts().getMetaDataPersistService().isPresent()); - PersistRepository repository = actual.getMetaDataContexts().getMetaDataPersistService().get().getRepository(); + assertNotNull(actual.getMetaDataContexts().getDatabaseMetaDataMap().get("foo_schema")); + assertTrue(actual.getMetaDataContexts().getPersistService().isPresent()); + PersistRepository repository = actual.getMetaDataContexts().getPersistService().get().getRepository(); assertNotNull(repository.get(GlobalNode.getGlobalRuleNode())); assertNotNull(repository.get(DatabaseMetaDataNode.getMetaDataDataSourcePath("foo_schema", "0"))); assertNotNull(repository.get(DatabaseMetaDataNode.getRulePath("foo_schema", "0"))); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java index 2099172fe1025..3da88140304c6 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java @@ -34,7 +34,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType; import org.apache.shardingsphere.infra.merge.MergeEngine; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -69,7 +69,7 @@ public abstract class DatabaseCommunicationEngine { private final String driverType; - private final ShardingSphereMetaData metaData; + private final ShardingSphereDatabaseMetaData databaseMetaData; private final LogicSQL logicSQL; @@ -83,13 +83,13 @@ public abstract class DatabaseCommunicationEngine { private final BackendConnection backendConnection; - public DatabaseCommunicationEngine(final String driverType, final ShardingSphereMetaData metaData, final LogicSQL logicSQL, final BackendConnection backendConnection) { + public DatabaseCommunicationEngine(final String driverType, final ShardingSphereDatabaseMetaData databaseMetaData, final LogicSQL logicSQL, final BackendConnection backendConnection) { this.driverType = driverType; - this.metaData = metaData; + this.databaseMetaData = databaseMetaData; this.logicSQL = logicSQL; this.backendConnection = backendConnection; String databaseName = backendConnection.getConnectionSession().getDatabaseName(); - metadataRefreshEngine = new MetaDataRefreshEngine(metaData, + metadataRefreshEngine = new MetaDataRefreshEngine(databaseMetaData, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName), ProxyContext.getInstance().getContextManager().getMetaDataContexts().getOptimizerContext().getPlannerContexts(), ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps()); @@ -116,29 +116,30 @@ protected QueryResponseHeader processExecuteQuery(final ExecutionContext executi protected List createQueryHeaders(final ExecutionContext executionContext, final QueryResult queryResultSample) throws SQLException { int columnCount = getColumnCount(executionContext, queryResultSample); List result = new ArrayList<>(columnCount); - LazyInitializer dataNodeContainedRule = getDataNodeContainedRuleLazyInitializer(metaData); - QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(metaData.getFrontendDatabaseType()); + LazyInitializer dataNodeContainedRule = getDataNodeContainedRuleLazyInitializer(databaseMetaData); + QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(databaseMetaData.getProtocolType()); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { - result.add(createQueryHeader(queryHeaderBuilderEngine, executionContext, queryResultSample, metaData, columnIndex, dataNodeContainedRule)); + result.add(createQueryHeader(queryHeaderBuilderEngine, executionContext, queryResultSample, databaseMetaData, columnIndex, dataNodeContainedRule)); } return result; } - protected LazyInitializer getDataNodeContainedRuleLazyInitializer(final ShardingSphereMetaData metaData) { + protected LazyInitializer getDataNodeContainedRuleLazyInitializer(final ShardingSphereDatabaseMetaData databaseMetaData) { return new LazyInitializer() { @Override protected DataNodeContainedRule initialize() { - return null != metaData ? metaData.getRuleMetaData().findSingleRule(DataNodeContainedRule.class).orElse(null) : null; + return null != databaseMetaData ? databaseMetaData.getRuleMetaData().findSingleRule(DataNodeContainedRule.class).orElse(null) : null; } }; } protected QueryHeader createQueryHeader(final QueryHeaderBuilderEngine queryHeaderBuilderEngine, final ExecutionContext executionContext, final QueryResult queryResultSample, - final ShardingSphereMetaData metaData, final int columnIndex, final LazyInitializer dataNodeContainedRule) throws SQLException { + final ShardingSphereDatabaseMetaData databaseMetaData, final int columnIndex, + final LazyInitializer dataNodeContainedRule) throws SQLException { return hasSelectExpandProjections(executionContext.getSqlStatementContext()) ? queryHeaderBuilderEngine.build( - ((SelectStatementContext) executionContext.getSqlStatementContext()).getProjectionsContext(), queryResultSample.getMetaData(), metaData, columnIndex, dataNodeContainedRule) - : queryHeaderBuilderEngine.build(queryResultSample.getMetaData(), metaData, columnIndex, dataNodeContainedRule); + ((SelectStatementContext) executionContext.getSqlStatementContext()).getProjectionsContext(), queryResultSample.getMetaData(), databaseMetaData, columnIndex, dataNodeContainedRule) + : queryHeaderBuilderEngine.build(queryResultSample.getMetaData(), databaseMetaData, columnIndex, dataNodeContainedRule); } protected int getColumnCount(final ExecutionContext executionContext, final QueryResult queryResultSample) throws SQLException { @@ -153,8 +154,8 @@ protected boolean hasSelectExpandProjections(final SQLStatementContext sqlSta protected MergedResult mergeQuery(final SQLStatementContext sqlStatementContext, final List queryResults) throws SQLException { MergeEngine mergeEngine = new MergeEngine(DefaultDatabase.LOGIC_NAME, - ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(metaData.getDatabase().getName()).getResource().getDatabaseType(), - metaData, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps(), metaData.getRuleMetaData().getRules()); + ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseMetaData.getDatabase().getName()).getResource().getDatabaseType(), + databaseMetaData, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps(), databaseMetaData.getRuleMetaData().getRules()); return mergeEngine.merge(queryResults, sqlStatementContext); } @@ -176,7 +177,7 @@ protected boolean isNeedAccumulate(final SQLStatementContext sqlStatementCont } private Optional findDataNodeContainedRule() { - for (ShardingSphereRule each : metaData.getRuleMetaData().getRules()) { + for (ShardingSphereRule each : databaseMetaData.getRuleMetaData().getRules()) { if (each instanceof DataNodeContainedRule) { return Optional.of((DataNodeContainedRule) each); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java index 785269e73b3f1..24acdfee3cd16 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine; import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection; import org.apache.shardingsphere.proxy.backend.communication.vertx.VertxBackendConnection; @@ -60,16 +60,16 @@ public static DatabaseCommunicationEngineFactory getInstance() { * @return created instance */ public T newTextProtocolInstance(final SQLStatementContext sqlStatementContext, final String sql, final BackendConnection backendConnection) { - ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName()); + ShardingSphereDatabaseMetaData databaseMetaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName()); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, Collections.emptyList()); T result; if (backendConnection instanceof JDBCBackendConnection) { JDBCBackendConnection jdbcBackendConnection = (JDBCBackendConnection) backendConnection; - result = (T) new JDBCDatabaseCommunicationEngine(JDBCDriverType.STATEMENT, metaData, logicSQL, jdbcBackendConnection); + result = (T) new JDBCDatabaseCommunicationEngine(JDBCDriverType.STATEMENT, databaseMetaData, logicSQL, jdbcBackendConnection); jdbcBackendConnection.add((JDBCDatabaseCommunicationEngine) result); } else { VertxBackendConnection vertxBackendConnection = (VertxBackendConnection) backendConnection; - result = (T) new VertxDatabaseCommunicationEngine(metaData, logicSQL, vertxBackendConnection); + result = (T) new VertxDatabaseCommunicationEngine(databaseMetaData, logicSQL, vertxBackendConnection); } return result; } @@ -86,16 +86,16 @@ public T newTextProtocolInstance(final S */ public T newBinaryProtocolInstance(final SQLStatementContext sqlStatementContext, final String sql, final List parameters, final BackendConnection backendConnection) { - ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName()); + ShardingSphereDatabaseMetaData databaseMetaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName()); LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, parameters); T result; if (backendConnection instanceof JDBCBackendConnection) { JDBCBackendConnection jdbcBackendConnection = (JDBCBackendConnection) backendConnection; - result = (T) new JDBCDatabaseCommunicationEngine(JDBCDriverType.PREPARED_STATEMENT, metaData, logicSQL, jdbcBackendConnection); + result = (T) new JDBCDatabaseCommunicationEngine(JDBCDriverType.PREPARED_STATEMENT, databaseMetaData, logicSQL, jdbcBackendConnection); jdbcBackendConnection.add((JDBCDatabaseCommunicationEngine) result); } else { VertxBackendConnection vertxBackendConnection = (VertxBackendConnection) backendConnection; - result = (T) new VertxDatabaseCommunicationEngine(metaData, logicSQL, vertxBackendConnection); + result = (T) new VertxDatabaseCommunicationEngine(databaseMetaData, logicSQL, vertxBackendConnection); } return result; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java index 3d2310d7d31b3..bc9bbdf01c540 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java @@ -113,7 +113,7 @@ private boolean isExecuteDDLInPostgreSQLOpenGaussTransaction(final SQLStatement */ public List execute(final ExecutionContext executionContext) throws SQLException { String databaseName = backendConnection.getConnectionSession().getDatabaseName(); - Collection rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules(); + Collection rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getRuleMetaData().getRules(); int maxConnectionsSizePerQuery = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); boolean isReturnGeneratedKeys = executionContext.getSqlStatementContext().getSqlStatement() instanceof MySQLInsertStatement; return execute(executionContext, rules, maxConnectionsSizePerQuery, isReturnGeneratedKeys); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java index 897a857e6ba07..e0b51bb1557c1 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java @@ -97,7 +97,7 @@ private boolean isExecuteDDLInPostgreSQLOpenGaussTransaction(final SQLStatement */ public Future> execute(final ExecutionContext executionContext) throws SQLException { String databaseName = backendConnection.getConnectionSession().getDatabaseName(); - Collection rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules(); + Collection rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getRuleMetaData().getRules(); int maxConnectionsSizePerQuery = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); return useDriverToExecute(executionContext, rules, maxConnectionsSizePerQuery); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java index 09360ad1827d4..e46046afdb0e8 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java @@ -36,7 +36,7 @@ import org.apache.shardingsphere.infra.federation.executor.FederationContext; import org.apache.shardingsphere.infra.federation.executor.FederationExecutor; import org.apache.shardingsphere.infra.federation.executor.FederationExecutorFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.util.SystemSchemaUtil; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -81,8 +81,8 @@ public final class JDBCDatabaseCommunicationEngine extends DatabaseCommunication private final JDBCBackendConnection backendConnection; - public JDBCDatabaseCommunicationEngine(final String driverType, final ShardingSphereMetaData metaData, final LogicSQL logicSQL, final JDBCBackendConnection backendConnection) { - super(driverType, metaData, logicSQL, backendConnection); + public JDBCDatabaseCommunicationEngine(final String driverType, final ShardingSphereDatabaseMetaData databaseMetaData, final LogicSQL logicSQL, final JDBCBackendConnection backendConnection) { + super(driverType, databaseMetaData, logicSQL, backendConnection); proxySQLExecutor = new ProxySQLExecutor(driverType, backendConnection, this); this.backendConnection = backendConnection; MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); @@ -121,7 +121,7 @@ public void add(final ResultSet resultSet) { public ResponseHeader execute() { LogicSQL logicSQL = getLogicSQL(); ExecutionContext executionContext = getKernelProcessor().generateExecutionContext( - logicSQL, getMetaData(), ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps()); + logicSQL, getDatabaseMetaData(), ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps()); // TODO move federation route logic to binder SQLStatementContext sqlStatementContext = logicSQL.getSqlStatementContext(); String defaultDatabaseName = backendConnection.getConnectionSession().getDatabaseName(); @@ -146,12 +146,12 @@ public ResponseHeader execute() { private ResultSet doExecuteFederation(final LogicSQL logicSQL, final MetaDataContexts metaDataContexts) throws SQLException { boolean isReturnGeneratedKeys = logicSQL.getSqlStatementContext().getSqlStatement() instanceof MySQLInsertStatement; - DatabaseType databaseType = metaDataContexts.getMetaData(backendConnection.getConnectionSession().getDatabaseName()).getResource().getDatabaseType(); + DatabaseType databaseType = metaDataContexts.getDatabaseMetaData(backendConnection.getConnectionSession().getDatabaseName()).getResource().getDatabaseType(); ProxyJDBCExecutorCallback callback = ProxyJDBCExecutorCallbackFactory.newInstance(getDriverType(), databaseType, logicSQL.getSqlStatementContext().getSqlStatement(), this, isReturnGeneratedKeys, SQLExecutorExceptionHandler.isExceptionThrown(), true); backendConnection.setFederationExecutor(federationExecutor); DriverExecutionPrepareEngine prepareEngine = createDriverExecutionPrepareEngine(isReturnGeneratedKeys, metaDataContexts); - FederationContext context = new FederationContext(false, logicSQL, metaDataContexts.getMetaDataMap()); + FederationContext context = new FederationContext(false, logicSQL, metaDataContexts.getDatabaseMetaDataMap()); return federationExecutor.executeQuery(prepareEngine, callback, context); } @@ -159,17 +159,17 @@ private DriverExecutionPrepareEngine createDriver int maxConnectionsSizePerQuery = metaData.getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); JDBCBackendStatement statementManager = (JDBCBackendStatement) backendConnection.getConnectionSession().getStatementManager(); return new DriverExecutionPrepareEngine<>(getDriverType(), maxConnectionsSizePerQuery, backendConnection, statementManager, - new StatementOption(isReturnGeneratedKeys), metaData.getMetaData(backendConnection.getConnectionSession().getDatabaseName()).getRuleMetaData().getRules()); + new StatementOption(isReturnGeneratedKeys), metaData.getDatabaseMetaData(backendConnection.getConnectionSession().getDatabaseName()).getRuleMetaData().getRules()); } private ResponseHeader processExecuteFederation(final ResultSet resultSet, final MetaDataContexts metaDataContexts) throws SQLException { int columnCount = resultSet.getMetaData().getColumnCount(); setQueryHeaders(new ArrayList<>(columnCount)); - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(backendConnection.getConnectionSession().getDatabaseName()); - LazyInitializer dataNodeContainedRule = getDataNodeContainedRuleLazyInitializer(metaData); - QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(null == metaData ? null : metaData.getFrontendDatabaseType()); + ShardingSphereDatabaseMetaData databaseMetaData = metaDataContexts.getDatabaseMetaData(backendConnection.getConnectionSession().getDatabaseName()); + LazyInitializer dataNodeContainedRule = getDataNodeContainedRuleLazyInitializer(databaseMetaData); + QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(null == databaseMetaData ? null : databaseMetaData.getProtocolType()); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { - getQueryHeaders().add(queryHeaderBuilderEngine.build(new JDBCQueryResultMetaData(resultSet.getMetaData()), metaData, columnIndex, dataNodeContainedRule)); + getQueryHeaders().add(queryHeaderBuilderEngine.build(new JDBCQueryResultMetaData(resultSet.getMetaData()), databaseMetaData, columnIndex, dataNodeContainedRule)); } setMergedResult(new IteratorStreamMergedResult(Collections.singletonList(new JDBCStreamQueryResult(resultSet)))); return new QueryResponseHeader(getQueryHeaders()); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSource.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSource.java index 9f2dd4668ca18..7ba85c6766476 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSource.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSource.java @@ -68,7 +68,7 @@ public List getConnections(final String databaseName, final String d @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") 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(databaseName).getResource().getDataSources().get(dataSourceName); + DataSource dataSource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getResource().getDataSources().get(dataSourceName); if (dataSourceName.contains(".")) { String dataSourceStr = dataSourceName.split("\\.")[0]; if (GlobalDataSourceRegistry.getInstance().getCachedDataSourceDataSources().containsKey(dataSourceStr)) { diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java index 7bbc939e423e7..ff5b1cd052e3e 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java @@ -65,7 +65,7 @@ public List execute(final LogicSQL logicSQL, final ExecutionGroup final boolean isReturnGeneratedKeys, final boolean isExceptionThrown) throws SQLException { try { MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); - DatabaseType databaseType = metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getResource().getDatabaseType(); + DatabaseType databaseType = metaDataContexts.getDatabaseMetaData(connectionSession.getDatabaseName()).getResource().getDatabaseType(); ExecuteProcessEngine.initialize(logicSQL, executionGroupContext, metaDataContexts.getProps()); SQLStatementContext context = logicSQL.getSqlStatementContext(); List result = jdbcExecutor.execute(executionGroupContext, diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java index 82889892f4dac..2d757233eb80a 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java @@ -114,7 +114,7 @@ private DatabaseType getFrontendDatabaseType() { return DatabaseTypeEngine.getTrunkDatabaseType("MySQL"); } String schemaName = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getAllDatabaseNames().iterator().next(); - return ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource().getDatabaseType(); + return ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(schemaName).getResource().getDatabaseType(); } private static Optional findConfiguredDatabaseType() { diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java index 7fd10a17e0d65..830c3b73437ff 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java @@ -77,7 +77,7 @@ public Statement createStorageResource(final ExecutionUnit executionUnit, final private void setFetchSize(final Statement statement) throws SQLException { DatabaseType databaseType = ProxyContext.getInstance().getContextManager().getMetaDataContexts() - .getMetaData(null == databaseName ? SQLStatementDatabaseHolder.get() : databaseName).getResource().getDatabaseType(); + .getDatabaseMetaData(null == databaseName ? SQLStatementDatabaseHolder.get() : databaseName).getResource().getDatabaseType(); Optional fetchSizeSetter = StatementMemoryStrictlyFetchSizeSetterFactory.findInstance(databaseType.getType()); if (fetchSizeSetter.isPresent()) { fetchSizeSetter.get().setFetchSize(statement); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendDataSource.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendDataSource.java index 77b8143d8a3b7..7b3b3fa15b5fe 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendDataSource.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendDataSource.java @@ -127,7 +127,7 @@ public Pool getPool(final String schemaName, final String dataSourceName) { } private Pool createPoolFromSchemaDataSource(final String schemaName, final String dataSourceName) { - DataSource dataSource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource().getDataSources().get(dataSourceName); + DataSource dataSource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(schemaName).getResource().getDataSources().get(dataSourceName); Preconditions.checkNotNull(dataSource, "Can not get connection from datasource %s.", dataSourceName); HikariDataSource value = (HikariDataSource) dataSource; URI uri = URI.create(value.getJdbcUrl().replace("jdbc:", "")); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxDatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxDatabaseCommunicationEngine.java index 4f89fd9eaef77..22305f6faa304 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxDatabaseCommunicationEngine.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxDatabaseCommunicationEngine.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine; import org.apache.shardingsphere.proxy.backend.communication.ReactiveProxySQLExecutor; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -39,8 +39,8 @@ public final class VertxDatabaseCommunicationEngine extends DatabaseCommunicatio private final ReactiveProxySQLExecutor reactiveProxySQLExecutor; - public VertxDatabaseCommunicationEngine(final ShardingSphereMetaData metaData, final LogicSQL logicSQL, final VertxBackendConnection vertxBackendConnection) { - super("Vert.x", metaData, logicSQL, vertxBackendConnection); + public VertxDatabaseCommunicationEngine(final ShardingSphereDatabaseMetaData databaseMetaData, final LogicSQL logicSQL, final VertxBackendConnection vertxBackendConnection) { + super("Vert.x", databaseMetaData, logicSQL, vertxBackendConnection); reactiveProxySQLExecutor = new ReactiveProxySQLExecutor(vertxBackendConnection); } @@ -54,7 +54,7 @@ public VertxDatabaseCommunicationEngine(final ShardingSphereMetaData metaData, f public Future execute() { try { ExecutionContext executionContext = getKernelProcessor() - .generateExecutionContext(getLogicSQL(), getMetaData(), ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps()); + .generateExecutionContext(getLogicSQL(), getDatabaseMetaData(), ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps()); if (executionContext.getRouteContext().isFederated()) { return Future.failedFuture(new UnsupportedOperationException("Executing federated query by Vert.x is not supported yet.")); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java index 0d98f9a741eff..4fc0617de4b01 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java @@ -21,7 +21,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.state.StateContext; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -79,11 +79,11 @@ public boolean databaseExists(final String databaseName) { * @param databaseName database name * @return ShardingSphere meta data */ - public ShardingSphereMetaData getMetaData(final String databaseName) { + public ShardingSphereDatabaseMetaData getMetaData(final String databaseName) { if (Strings.isNullOrEmpty(databaseName) || !contextManager.getMetaDataContexts().getAllDatabaseNames().contains(databaseName)) { throw new NoDatabaseSelectedException(); } - return contextManager.getMetaDataContexts().getMetaData(databaseName); + return contextManager.getMetaDataContexts().getDatabaseMetaData(databaseName); } /** @@ -114,7 +114,7 @@ public Optional getStateContext() { public Collection getRules(final String databaseName) { Collection result = new LinkedList<>(); if (!Strings.isNullOrEmpty(databaseName) && databaseExists(databaseName)) { - result.addAll(contextManager.getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules()); + result.addAll(contextManager.getMetaDataContexts().getDatabaseMetaData(databaseName).getRuleMetaData().getRules()); } result.addAll(contextManager.getMetaDataContexts().getGlobalRuleMetaData().getRules()); return result; diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java index af88a1c95bdce..4f6340baf8f47 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java @@ -19,7 +19,7 @@ import org.apache.commons.lang3.concurrent.LazyInitializer; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.spi.annotation.SingletonSPI; import org.apache.shardingsphere.spi.type.required.RequiredSPI; @@ -37,7 +37,7 @@ public interface QueryHeaderBuilder extends TypedSPI, RequiredSPI { * Build query header. * * @param queryResultMetaData query result meta data - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param columnName column name * @param columnLabel column label * @param columnIndex column index @@ -45,6 +45,6 @@ public interface QueryHeaderBuilder extends TypedSPI, RequiredSPI { * @return query header * @throws SQLException SQL exception */ - QueryHeader build(QueryResultMetaData queryResultMetaData, ShardingSphereMetaData metaData, + QueryHeader build(QueryResultMetaData queryResultMetaData, ShardingSphereDatabaseMetaData databaseMetaData, String columnName, String columnLabel, int columnIndex, LazyInitializer dataNodeContainedRule) throws SQLException; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java index ac634acfc1744..f56aa35dcd6e3 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import java.sql.SQLException; @@ -42,17 +42,17 @@ public final class QueryHeaderBuilderEngine { * Build query header builder. * * @param queryResultMetaData query result meta data - * @param metaData ShardingSphere meta data - * @param columnIndex column index + * @param databaseMetaData database meta data + * @param columnIndex column index * @param dataNodeContainedRule data node contained rule * @return query header * @throws SQLException SQL exception */ - public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereMetaData metaData, + public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereDatabaseMetaData databaseMetaData, final int columnIndex, final LazyInitializer dataNodeContainedRule) throws SQLException { String columnName = queryResultMetaData.getColumnName(columnIndex); String columnLabel = queryResultMetaData.getColumnLabel(columnIndex); - return QueryHeaderBuilderFactory.getInstance(databaseType).build(queryResultMetaData, metaData, columnName, columnLabel, columnIndex, dataNodeContainedRule); + return QueryHeaderBuilderFactory.getInstance(databaseType).build(queryResultMetaData, databaseMetaData, columnName, columnLabel, columnIndex, dataNodeContainedRule); } /** @@ -60,17 +60,17 @@ public QueryHeader build(final QueryResultMetaData queryResultMetaData, final Sh * * @param projectionsContext projections context * @param queryResultMetaData query result meta data - * @param metaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param columnIndex column index * @param dataNodeContainedRule data node contained rule * @return query header * @throws SQLException SQL exception */ public QueryHeader build(final ProjectionsContext projectionsContext, final QueryResultMetaData queryResultMetaData, - final ShardingSphereMetaData metaData, final int columnIndex, final LazyInitializer dataNodeContainedRule) throws SQLException { + final ShardingSphereDatabaseMetaData databaseMetaData, final int columnIndex, final LazyInitializer dataNodeContainedRule) throws SQLException { String columnName = getColumnName(projectionsContext, queryResultMetaData, columnIndex); String columnLabel = getColumnLabel(projectionsContext, queryResultMetaData, columnIndex); - return QueryHeaderBuilderFactory.getInstance(databaseType).build(queryResultMetaData, metaData, columnName, columnLabel, columnIndex, dataNodeContainedRule); + return QueryHeaderBuilderFactory.getInstance(databaseType).build(queryResultMetaData, databaseMetaData, columnName, columnLabel, columnIndex, dataNodeContainedRule); } private String getColumnLabel(final ProjectionsContext projectionsContext, final QueryResultMetaData queryResultMetaData, final int columnIndex) throws SQLException { diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/MySQLQueryHeaderBuilder.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/MySQLQueryHeaderBuilder.java index 8238c381e4d8b..8058d8d190ccf 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/MySQLQueryHeaderBuilder.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/MySQLQueryHeaderBuilder.java @@ -21,7 +21,7 @@ import org.apache.commons.lang3.concurrent.ConcurrentException; import org.apache.commons.lang3.concurrent.LazyInitializer; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData; import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; @@ -38,15 +38,15 @@ public final class MySQLQueryHeaderBuilder implements QueryHeaderBuilder { @SneakyThrows(ConcurrentException.class) @Override - public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereMetaData metaData, final String columnName, final String columnLabel, + public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereDatabaseMetaData databaseMetaData, final String columnName, final String columnLabel, final int columnIndex, final LazyInitializer dataNodeContainedRule) throws SQLException { - String schemaName = null == metaData ? "" : metaData.getDatabase().getName(); + String schemaName = null == databaseMetaData ? "" : databaseMetaData.getDatabase().getName(); String actualTableName = queryResultMetaData.getTableName(columnIndex); String tableName; boolean primaryKey; if (null != actualTableName && null != dataNodeContainedRule.get()) { tableName = dataNodeContainedRule.get().findLogicTableByActualTable(actualTableName).orElse(""); - TableMetaData tableMetaData = metaData.getSchemaByName(schemaName).get(tableName); + TableMetaData tableMetaData = databaseMetaData.getDatabase().getSchema(schemaName).get(tableName); primaryKey = null != tableMetaData && Optional.ofNullable(tableMetaData.getColumns().get(columnName.toLowerCase())).map(ColumnMetaData::isPrimaryKey).orElse(false); } else { tableName = actualTableName; diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/OpenGaussQueryHeaderBuilder.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/OpenGaussQueryHeaderBuilder.java index f20e9fa388683..a92b131022dc3 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/OpenGaussQueryHeaderBuilder.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/OpenGaussQueryHeaderBuilder.java @@ -19,7 +19,7 @@ import org.apache.commons.lang3.concurrent.LazyInitializer; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeaderBuilder; @@ -34,9 +34,9 @@ public final class OpenGaussQueryHeaderBuilder implements QueryHeaderBuilder { private final PostgreSQLQueryHeaderBuilder delegated = new PostgreSQLQueryHeaderBuilder(); @Override - public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereMetaData metaData, final String columnName, final String columnLabel, + public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereDatabaseMetaData databaseMetaData, final String columnName, final String columnLabel, final int columnIndex, final LazyInitializer dataNodeContainedRule) throws SQLException { - return delegated.build(queryResultMetaData, metaData, columnName, columnLabel, columnIndex, dataNodeContainedRule); + return delegated.build(queryResultMetaData, databaseMetaData, columnName, columnLabel, columnIndex, dataNodeContainedRule); } @Override diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/PostgreSQLQueryHeaderBuilder.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/PostgreSQLQueryHeaderBuilder.java index 5063559f919c1..f94c585645059 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/PostgreSQLQueryHeaderBuilder.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/impl/PostgreSQLQueryHeaderBuilder.java @@ -19,7 +19,7 @@ import org.apache.commons.lang3.concurrent.LazyInitializer; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeaderBuilder; @@ -38,7 +38,7 @@ public final class PostgreSQLQueryHeaderBuilder implements QueryHeaderBuilder { private static final boolean UNUSED_BOOLEAN_FIELD = false; @Override - public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereMetaData metaData, final String columnName, final String columnLabel, + public QueryHeader build(final QueryResultMetaData queryResultMetaData, final ShardingSphereDatabaseMetaData databaseMetaData, final String columnName, final String columnLabel, final int columnIndex, final LazyInitializer unused) throws SQLException { int columnType = queryResultMetaData.getColumnType(columnIndex); String columnTypeName = queryResultMetaData.getColumnTypeName(columnIndex); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java index c6190ce8509a0..d9e3442554b8b 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java @@ -101,7 +101,7 @@ public static TextProtocolBackendHandler newInstance(final DatabaseType database } return DistSQLBackendHandlerFactory.newInstance(databaseType, (DistSQLStatement) sqlStatement, connectionSession); } - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaDataMap(), sqlStatement, connectionSession.getDefaultDatabaseName()); Optional backendHandler = DatabaseAdminBackendHandlerFactory.newInstance(databaseType, sqlStatementContext, connectionSession, sql); if (backendHandler.isPresent()) { @@ -123,7 +123,7 @@ public static TextProtocolBackendHandler newInstance(final DatabaseType database ? sqlStatementContext.getTablesContext().getDatabaseName().get() : connectionSession.getDatabaseName(); SQLCheckEngine.check(sqlStatement, Collections.emptyList(), - getRules(databaseName), databaseName, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), connectionSession.getGrantee()); + getRules(databaseName), databaseName, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaDataMap(), connectionSession.getGrantee()); if (sqlStatement instanceof TCLStatement) { return TransactionBackendHandlerFactory.newInstance((SQLStatementContext) sqlStatementContext, sql, connectionSession); } @@ -135,7 +135,7 @@ private static DatabaseType getFrontendDatabaseType(final DatabaseType defaultDa String databaseName = connectionSession.getDatabaseName(); return Strings.isNullOrEmpty(databaseName) || !ProxyContext.getInstance().databaseExists(databaseName) ? defaultDatabaseType - : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getFrontendDatabaseType(); + : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getProtocolType(); } private static Optional findExtraTextProtocolBackendHandler(final SQLStatement sqlStatement) { @@ -160,7 +160,7 @@ private static Collection getRules(final String databaseName return contexts.getGlobalRuleMetaData().getRules(); } Collection result; - result = new LinkedList<>(contexts.getMetaData(databaseName).getRuleMetaData().getRules()); + result = new LinkedList<>(contexts.getDatabaseMetaData(databaseName).getRuleMetaData().getRules()); result.addAll(contexts.getGlobalRuleMetaData().getRules()); return result; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java index 9c4054a966085..254819165a6b1 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; @@ -63,23 +63,23 @@ public ResponseHeader execute() throws SQLException { private List createResponseHeader() throws SQLException { List result = new ArrayList<>(queryResultMetaData.getColumnCount()); - ShardingSphereMetaData metaData = null == connectionSession.getDatabaseName() ? null : ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()); - DatabaseType databaseType = null == metaData ? connectionSession.getDatabaseType() - : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(metaData.getDatabase().getName()).getResource().getDatabaseType(); + ShardingSphereDatabaseMetaData databaseMetaData = null == connectionSession.getDatabaseName() ? null : ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()); + DatabaseType databaseType = null == databaseMetaData ? connectionSession.getDatabaseType() + : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseMetaData.getDatabase().getName()).getResource().getDatabaseType(); QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(databaseType); - LazyInitializer dataNodeContainedRule = getDataNodeContainedRuleLazyInitializer(metaData); + LazyInitializer dataNodeContainedRule = getDataNodeContainedRuleLazyInitializer(databaseMetaData); for (int columnIndex = 1; columnIndex <= queryResultMetaData.getColumnCount(); columnIndex++) { - result.add(queryHeaderBuilderEngine.build(queryResultMetaData, metaData, columnIndex, dataNodeContainedRule)); + result.add(queryHeaderBuilderEngine.build(queryResultMetaData, databaseMetaData, columnIndex, dataNodeContainedRule)); } return result; } - private LazyInitializer getDataNodeContainedRuleLazyInitializer(final ShardingSphereMetaData metaData) { + private LazyInitializer getDataNodeContainedRuleLazyInitializer(final ShardingSphereDatabaseMetaData databaseMetaData) { return new LazyInitializer() { @Override protected DataNodeContainedRule initialize() { - return null == metaData ? null : metaData.getRuleMetaData().findSingleRule(DataNodeContainedRule.class).orElse(null); + return null == databaseMetaData ? null : databaseMetaData.getRuleMetaData().findSingleRule(DataNodeContainedRule.class).orElse(null); } }; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java index cdd15719b2ea4..46f61f2bce68f 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java @@ -168,7 +168,7 @@ protected static boolean hasAuthority(final String databaseName, final Grantee g private static Collection getRules(final String databaseName) { Collection result; - result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules()); + result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getRuleMetaData().getRules()); result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules()); return result; } @@ -210,7 +210,7 @@ protected List getDatabaseNames(final ConnectionSession connectionSessio */ @Override protected void getSourceData(final String databaseName, final FunctionWithException callback) throws SQLException { - ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource(); + ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getResource(); Optional> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst(); log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(ResourceNotExistedException::new).getKey(), sql); try ( diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorCreator.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorCreator.java index 1ef5bd478afc1..f4ac85c9c60b8 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorCreator.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorCreator.java @@ -159,14 +159,12 @@ private boolean isQuerySpecialSchema(final SelectStatement sqlStatement, final S private DatabaseAdminExecutor mockExecutor(final String schemaName, final SelectStatement sqlStatement, final String sql) { boolean isNotUseSchema = !Optional.ofNullable(schemaName).isPresent() && sqlStatement.getFrom() == null; + if (!hasDatabases() || !hasResources()) { + return new NoResourceShowExecutor(sqlStatement); + } + String driverType = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.PROXY_BACKEND_DRIVER_TYPE); if (isNotUseSchema) { - if (!hasDatabases() || !hasResources()) { - return new NoResourceShowExecutor(sqlStatement); - } else { - // TODO Avoid accessing database here, consider using `org.apache.shardingsphere.proxy.backend.text.data.DatabaseBackendHandler` - String driverType = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.PROXY_BACKEND_DRIVER_TYPE); - return "ExperimentalVertx".equals(driverType) ? null : new UnicastResourceShowExecutor(sqlStatement, sql); - } + return "ExperimentalVertx".equals(driverType) ? null : new UnicastResourceShowExecutor(sqlStatement, sql); } return null; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java index 222daf1a28f91..c3b390d0ecee4 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java @@ -74,7 +74,7 @@ private boolean checkLikePattern(final String schemaName) { private Collection getRules(final String schemaName) { Collection result; - result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules()); + result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(schemaName).getRuleMetaData().getRules()); result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules()); return result; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java index 083e5cd11e7ae..bccc817e25b6b 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java @@ -81,8 +81,8 @@ private QueryResult getQueryResult(final String databaseName) { } private Collection getAllTableNames(final String databaseName) { - Collection result = ProxyContext.getInstance().getMetaData(databaseName) - .getSchemaByName(databaseName).getTables().values().stream().map(TableMetaData::getName).collect(Collectors.toList()); + Collection result = ProxyContext.getInstance().getMetaData(databaseName).getDatabase() + .getSchema(databaseName).getTables().values().stream().map(TableMetaData::getName).collect(Collectors.toList()); if (showTablesStatement.getFilter().isPresent()) { Optional pattern = showTablesStatement.getFilter().get().getLike().map(optional -> SQLUtil.convertLikePatternToRegex(optional.getPattern())); return pattern.isPresent() ? result.stream().filter(each -> RegularUtil.matchesCaseInsensitive(pattern.get(), each)).collect(Collectors.toList()) : result; diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java index 54d1c30ec2137..9a9db85f72073 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java @@ -78,7 +78,7 @@ public void execute(final ConnectionSession connectionSession) throws SQLExcepti } try { connectionSession.setCurrentDatabase(databaseName); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaDataMap(), sqlStatement, connectionSession.getDefaultDatabaseName()); databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection()); responseHeader = databaseCommunicationEngine.execute(); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java index 3b7e2c64de117..90d760e8150fb 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java @@ -51,7 +51,8 @@ public void execute(final ConnectionSession connectionSession) { private Collection getRules(final String schemaName) { Collection result = new LinkedList<>(); - Optional.ofNullable(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName)).ifPresent(optional -> result.addAll(optional.getRuleMetaData().getRules())); + Optional.ofNullable( + ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(schemaName)).ifPresent(optional -> result.addAll(optional.getRuleMetaData().getRules())); result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules()); return result; } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java index b678cfb823331..5670ee7436e44 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java @@ -94,7 +94,7 @@ protected List getDatabaseNames(final ConnectionSession connectionSessio @Override protected void rowPostProcessing(final String databaseName, final Map rowMap, final Map aliasMap) { - ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource(); + ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getResource(); Set catalogs = resource.getDataSources().keySet().stream().map(each -> resource.getDataSourcesMetaData().getDataSourceMetaData(each).getCatalog()).collect(Collectors.toSet()); schemaNameAlias = aliasMap.getOrDefault(SCHEMA_NAME, ""); String rowValue = rowMap.getOrDefault(schemaNameAlias, "").toString(); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java index 352c85ac9837d..e10828e09602c 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java @@ -87,7 +87,7 @@ protected List getDatabaseNames(final ConnectionSession connectionSessio @Override protected void rowPostProcessing(final String databaseName, final Map rowMap, final Map aliasMap) { buildColumnNames(aliasMap); - ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource(); + ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getResource(); Set catalogs = resource.getDataSources().keySet().stream().map(each -> resource.getDataSourcesMetaData().getDataSourceMetaData(each).getCatalog()).collect(Collectors.toSet()); databaseNameAlias = aliasMap.getOrDefault(DATABASE_NAME, aliasMap.getOrDefault(DATNAME, aliasMap.getOrDefault(NAME, ""))); String rowValue = rowMap.getOrDefault(databaseNameAlias, "").toString(); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java index d1ce755fdfa61..84e0ef4a4264d 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.proxy.backend.text.admin.executor.AbstractDatabaseMetadataExecutor; @@ -53,9 +53,9 @@ public SelectTableExecutor(final String sql) { @Override protected void initDatabaseData(final String databaseName) { - ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(databaseName); - String schema = metaData.getResource().getDatabaseType().getDefaultSchema(databaseName); - tableNames = new ArrayList<>(metaData.getSchemaByName(schema).getAllTableNames()); + ShardingSphereDatabaseMetaData databaseMetaData = ProxyContext.getInstance().getMetaData(databaseName); + String schema = databaseMetaData.getResource().getDatabaseType().getDefaultSchema(databaseName); + tableNames = new ArrayList<>(databaseMetaData.getDatabase().getSchema(schema).getAllTableNames()); } @Override diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java index e8068051f001f..c90f8d2186464 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java @@ -20,7 +20,7 @@ import com.google.common.base.Strings; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.executor.check.SQLCheckEngine; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -71,9 +71,9 @@ private boolean isDropCurrentDatabase(final String databaseName) { private static Collection getRules(final String schemaName) { Collection result = new LinkedList<>(); - ShardingSphereMetaData metaData = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName); - if (null != metaData && null != metaData.getRuleMetaData()) { - result.addAll(metaData.getRuleMetaData().getRules()); + ShardingSphereDatabaseMetaData databaseMetaData = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(schemaName); + if (null != databaseMetaData && null != databaseMetaData.getRuleMetaData()) { + result.addAll(databaseMetaData.getRuleMetaData().getRules()); } result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules()); return result; diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java index 223666092e1fd..15bb0a5262650 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java @@ -80,6 +80,6 @@ private static DatabaseType getBackendDatabaseType(final DatabaseType defaultDat String databaseName = connectionSession.getDatabaseName(); return Strings.isNullOrEmpty(databaseName) || !ProxyContext.getInstance().databaseExists(databaseName) ? defaultDatabaseType - : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource().getDatabaseType(); + : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(databaseName).getResource().getDatabaseType(); } } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java index a76c854cc1e36..1fa02897269f9 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java @@ -44,7 +44,7 @@ import org.apache.shardingsphere.infra.federation.executor.FederationContext; import org.apache.shardingsphere.infra.federation.executor.FederationExecutor; import org.apache.shardingsphere.infra.federation.executor.FederationExecutorFactory; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -99,21 +99,21 @@ protected Collection getColumnNames() { protected Collection> getRows(final ContextManager contextManager) throws SQLException { MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); String databaseName = getDatabaseName(); - String databaseType = DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(databaseName).getFrontendDatabaseType()); + String databaseType = DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getDatabaseMetaData(databaseName).getProtocolType()); Optional sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class); Preconditions.checkState(sqlParserRule.isPresent()); SQLStatement previewedStatement = new ShardingSphereSQLParserEngine(databaseType, sqlParserRule.get().toParserConfiguration()).parse(sqlStatement.getSql(), false); - SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), previewedStatement, databaseName); + SQLStatementContext sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getDatabaseMetaDataMap(), previewedStatement, databaseName); // TODO optimize SQLStatementDatabaseHolder if (sqlStatementContext instanceof TableAvailable) { ((TableAvailable) sqlStatementContext).getTablesContext().getDatabaseName().ifPresent(SQLStatementDatabaseHolder::set); } - ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()); - if (!metaData.isComplete()) { + ShardingSphereDatabaseMetaData databaseMetaData = ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()); + if (!databaseMetaData.isComplete()) { throw new RuleNotExistedException(); } LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sqlStatement.getSql(), Collections.emptyList()); - ExecutionContext executionContext = kernelProcessor.generateExecutionContext(logicSQL, metaData, metaDataContexts.getProps()); + ExecutionContext executionContext = kernelProcessor.generateExecutionContext(logicSQL, databaseMetaData, metaDataContexts.getProps()); Collection executionUnits = executionContext.getRouteContext().isFederated() ? getFederationExecutionUnits(logicSQL, databaseName, metaDataContexts) : executionContext.getExecutionUnits(); @@ -128,8 +128,8 @@ private Collection getFederationExecutionUnits(final LogicSQL log SQLStatement sqlStatement = logicSQL.getSqlStatementContext().getSqlStatement(); boolean isReturnGeneratedKeys = sqlStatement instanceof MySQLInsertStatement; DriverExecutionPrepareEngine prepareEngine = createDriverExecutionPrepareEngine(isReturnGeneratedKeys, metaDataContexts); - FederationContext context = new FederationContext(true, logicSQL, metaDataContexts.getMetaDataMap()); - DatabaseType databaseType = metaDataContexts.getMetaData(getDatabaseName()).getResource().getDatabaseType(); + FederationContext context = new FederationContext(true, logicSQL, metaDataContexts.getDatabaseMetaDataMap()); + DatabaseType databaseType = metaDataContexts.getDatabaseMetaData(getDatabaseName()).getResource().getDatabaseType(); String schemaName = logicSQL.getSqlStatementContext().getTablesContext().getSchemaName().orElse(databaseType.getDefaultSchema(databaseName)); FederationExecutor executor = FederationExecutorFactory.newInstance(databaseName, schemaName, metaDataContexts.getOptimizerContext(), metaDataContexts.getProps(), new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), false)); @@ -155,7 +155,8 @@ protected Optional getSaneResult(final SQLStatement sqlStatement) private DriverExecutionPrepareEngine createDriverExecutionPrepareEngine(final boolean isReturnGeneratedKeys, final MetaDataContexts metaData) { int maxConnectionsSizePerQuery = metaData.getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, (JDBCBackendConnection) connectionSession.getBackendConnection(), - (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(isReturnGeneratedKeys), metaData.getMetaData(getDatabaseName()).getRuleMetaData().getRules()); + (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(isReturnGeneratedKeys), + metaData.getDatabaseMetaData(getDatabaseName()).getRuleMetaData().getRules()); } private String getDatabaseName() { diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java index f1c5ae843e0c1..ed6eec397612b 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/DatabaseDiscoveryRuleConfigurationImportChecker.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import java.util.Collection; import java.util.LinkedHashSet; @@ -40,23 +40,23 @@ public final class DatabaseDiscoveryRuleConfigurationImportChecker { /** * Check database discovery rule configuration. * - * @param shardingSphereMetaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param currentRuleConfig current rule configuration * @throws DistSQLException definition violation exception */ - public void check(final ShardingSphereMetaData shardingSphereMetaData, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - if (null == shardingSphereMetaData || null == currentRuleConfig) { + public void check(final ShardingSphereDatabaseMetaData databaseMetaData, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { + if (null == databaseMetaData || null == currentRuleConfig) { return; } - String databaseName = shardingSphereMetaData.getDatabase().getName(); - checkResources(databaseName, shardingSphereMetaData, currentRuleConfig); + String databaseName = databaseMetaData.getDatabase().getName(); + checkResources(databaseName, databaseMetaData, currentRuleConfig); checkDiscoverTypeAndHeartbeat(databaseName, currentRuleConfig); } - private void checkResources(final String databaseName, final ShardingSphereMetaData shardingSphereMetaData, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { + private void checkResources(final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { Collection requireResources = new LinkedHashSet<>(); currentRuleConfig.getDataSources().forEach(each -> requireResources.addAll(each.getDataSourceNames())); - Collection notExistResources = shardingSphereMetaData.getResource().getNotExistedResources(requireResources); + Collection notExistResources = databaseMetaData.getResource().getNotExistedResources(requireResources); DistSQLException.predictionThrow(notExistResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistResources)); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java index c240e85958b48..04d9a32e3a377 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.expr.InlineExpressionParser; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.factory.ReplicaLoadBalanceAlgorithmFactory; @@ -39,20 +39,20 @@ public final class ReadwriteSplittingRuleConfigurationImportChecker { /** * Check readwrite-splitting rule configuration. * - * @param shardingSphereMetaData ShardingSphere meta data + * @param databaseMetaData database meta data * @param currentRuleConfig current rule configuration * @throws DistSQLException definition violation exception */ - public void check(final ShardingSphereMetaData shardingSphereMetaData, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws DistSQLException { - if (null == shardingSphereMetaData || null == currentRuleConfig) { + public void check(final ShardingSphereDatabaseMetaData databaseMetaData, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws DistSQLException { + if (null == databaseMetaData || null == currentRuleConfig) { return; } - String databaseName = shardingSphereMetaData.getDatabase().getName(); - checkResources(databaseName, shardingSphereMetaData, currentRuleConfig); + String databaseName = databaseMetaData.getDatabase().getName(); + checkResources(databaseName, databaseMetaData, currentRuleConfig); checkLoadBalancers(currentRuleConfig); } - private void checkResources(final String databaseName, final ShardingSphereMetaData shardingSphereMetaData, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws DistSQLException { + private void checkResources(final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final ReadwriteSplittingRuleConfiguration currentRuleConfig) throws DistSQLException { Collection requireResources = new LinkedHashSet<>(); Collection requireDiscoverableResources = new LinkedHashSet<>(); currentRuleConfig.getDataSources().forEach(each -> { @@ -66,15 +66,15 @@ private void checkResources(final String databaseName, final ShardingSphereMetaD requireResources.addAll(new InlineExpressionParser(each.getReadDataSourceNames().get()).splitAndEvaluate()); } }); - Collection notExistResources = shardingSphereMetaData.getResource().getNotExistedResources(requireResources); + Collection notExistResources = databaseMetaData.getResource().getNotExistedResources(requireResources); DistSQLException.predictionThrow(notExistResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistResources)); - Collection logicResources = getLogicResources(shardingSphereMetaData); + Collection logicResources = getLogicResources(databaseMetaData); Collection notExistLogicResources = requireDiscoverableResources.stream().filter(each -> !logicResources.contains(each)).collect(Collectors.toSet()); DistSQLException.predictionThrow(notExistLogicResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistLogicResources)); } - private Collection getLogicResources(final ShardingSphereMetaData shardingSphereMetaData) { - return shardingSphereMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataSourceContainedRule) + private Collection getLogicResources(final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataSourceContainedRule) .map(each -> ((DataSourceContainedRule) each).getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new)); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java index 61e222938abbf..bfafdcb963e7e 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.expr.InlineExpressionParser; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; @@ -63,17 +63,17 @@ public final class ShardingRuleConfigurationImportChecker { /** * Check sharding rule configuration. * - * @param shardingSphereMetaData ShardingSphere meta data + * @param databaseMetaData meta data * @param currentRuleConfig current rule configuration * @throws DistSQLException definition violation exception */ - public void check(final ShardingSphereMetaData shardingSphereMetaData, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { - if (null == shardingSphereMetaData || null == currentRuleConfig) { + public void check(final ShardingSphereDatabaseMetaData databaseMetaData, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { + if (null == databaseMetaData || null == currentRuleConfig) { return; } - String databaseName = shardingSphereMetaData.getDatabase().getName(); + String databaseName = databaseMetaData.getDatabase().getName(); checkLogicTables(databaseName, currentRuleConfig); - checkResources(databaseName, shardingSphereMetaData, currentRuleConfig); + checkResources(databaseName, databaseMetaData, currentRuleConfig); checkKeyGenerators(currentRuleConfig); checkShardingAlgorithms(currentRuleConfig); } @@ -121,16 +121,16 @@ private Collection getDataSourceNames(final ShardingTableRuleConfigurati return actualDataNodes.stream().map(each -> new DataNode(each).getDataSourceName()).collect(Collectors.toList()); } - private void checkResources(final String databaseName, final ShardingSphereMetaData shardingSphereMetaData, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { + private void checkResources(final String databaseName, final ShardingSphereDatabaseMetaData databaseMetaData, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException { Collection requiredResource = getRequiredResources(currentRuleConfig); - Collection notExistedResources = shardingSphereMetaData.getResource().getNotExistedResources(requiredResource); - Collection logicResources = getLogicResources(shardingSphereMetaData); + Collection notExistedResources = databaseMetaData.getResource().getNotExistedResources(requiredResource); + Collection logicResources = getLogicResources(databaseMetaData); notExistedResources.removeIf(logicResources::contains); DistSQLException.predictionThrow(notExistedResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, notExistedResources)); } - private Collection getLogicResources(final ShardingSphereMetaData shardingSphereMetaData) { - return shardingSphereMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataSourceContainedRule) + private Collection getLogicResources(final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof DataSourceContainedRule) .map(each -> ((DataSourceContainedRule) each).getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new)); } } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java index ba13d1bd49edf..9c4c49d542c74 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java @@ -20,7 +20,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.hint.HintManager; import org.apache.shardingsphere.infra.merge.result.MergedResult; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.exception.RuleNotExistedException; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader; @@ -59,12 +59,12 @@ protected List createQueryHeaders() { @Override protected MergedResult createMergedResult() { Map results = new HashMap<>(); - ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()); - if (!metaData.isComplete()) { + ShardingSphereDatabaseMetaData databaseMetaData = ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()); + if (!databaseMetaData.isComplete()) { throw new RuleNotExistedException(); } String schemaName = connectionSession.getDatabaseType().getDefaultSchema(connectionSession.getDatabaseName()); - Collection tableNames = metaData.getSchemaByName(schemaName).getAllTableNames(); + Collection tableNames = databaseMetaData.getDatabase().getSchema(schemaName).getAllTableNames(); for (String each : tableNames) { if (HintManager.isDatabaseShardingOnly()) { fillShardingValues(results, each, HintManager.getDatabaseShardingValues(), Collections.emptyList()); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java index 1f1189fdd109d..4da2d5c20a6ae 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration; import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler; @@ -79,14 +79,14 @@ protected Collection> getRows(final ContextManager contextManager) return dataMap.values(); } - private void addSchemaData(final Map> dataMap, final ShardingSphereMetaData metaData) { + private void addSchemaData(final Map> dataMap, final ShardingSphereDatabaseMetaData databaseMetaData) { initData(dataMap); - Collection singleTableRules = metaData.getRuleMetaData().findRules(SingleTableRule.class); + Collection singleTableRules = databaseMetaData.getRuleMetaData().findRules(SingleTableRule.class); if (!singleTableRules.isEmpty()) { addSingleTableData(dataMap, singleTableRules); } - if (hasRuleConfiguration(metaData)) { - addConfigurationData(dataMap, metaData.getRuleMetaData().getConfigurations()); + if (hasRuleConfiguration(databaseMetaData)) { + addConfigurationData(dataMap, databaseMetaData.getRuleMetaData().getConfigurations()); } } @@ -96,8 +96,8 @@ private void addSingleTableData(final Map> dataMap, final C dataMap.compute(SINGLE_TABLE, (key, value) -> buildRow(value, SINGLE_TABLE, count.orElse(DEFAULT_COUNT))); } - private boolean hasRuleConfiguration(final ShardingSphereMetaData metaData) { - Collection configs = metaData.getRuleMetaData().getConfigurations(); + private boolean hasRuleConfiguration(final ShardingSphereDatabaseMetaData databaseMetaData) { + Collection configs = databaseMetaData.getRuleMetaData().getConfigurations(); return null != configs && !configs.isEmpty(); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java index 4a18d918e3a3e..902756e622da1 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator; import org.apache.shardingsphere.infra.exception.DatabaseNotExistedException; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.yaml.engine.YamlEngine; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -114,11 +114,11 @@ protected Collection getColumnNames() { @Override protected Collection> getRows(final ContextManager contextManager) { String databaseName = getDatabaseName(); - ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(databaseName); + ShardingSphereDatabaseMetaData databaseMetaData = ProxyContext.getInstance().getMetaData(databaseName); StringBuilder result = new StringBuilder(); configItem(ZERO, "databaseName", databaseName, result); - getDataSourcesConfig(metaData, result); - getRuleConfigurations(metaData.getRuleMetaData().getConfigurations(), result); + getDataSourcesConfig(databaseMetaData, result); + getRuleConfigurations(databaseMetaData.getRuleMetaData().getConfigurations(), result); if (!sqlStatement.getFilePath().isPresent()) { return Collections.singleton(Collections.singletonList(result.toString())); } @@ -135,12 +135,12 @@ protected Collection> getRows(final ContextManager contextManager) return Collections.singleton(Collections.singletonList(String.format("Successfully exported to:'%s'", sqlStatement.getFilePath().get()))); } - private void getDataSourcesConfig(final ShardingSphereMetaData metaData, final StringBuilder result) { - if (null == metaData.getResource().getDataSources() || metaData.getResource().getDataSources().isEmpty()) { + private void getDataSourcesConfig(final ShardingSphereDatabaseMetaData databaseMetaData, final StringBuilder result) { + if (null == databaseMetaData.getResource().getDataSources() || databaseMetaData.getResource().getDataSources().isEmpty()) { return; } configItem(ZERO, "dataSources", result); - for (Entry each : metaData.getResource().getDataSources().entrySet()) { + for (Entry each : databaseMetaData.getResource().getDataSources().entrySet()) { configItem(ONE, each.getKey(), result); DataSourceProperties dataSourceProps = DataSourcePropertiesCreator.create(each.getValue()); dataSourceProps.getConnectionPropertySynonyms().getStandardProperties().forEach((key, value) -> configItem(TWO, key, value, result)); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java index 0115119bbe922..fd5fbed544c76 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java @@ -20,7 +20,7 @@ import com.google.common.base.Strings; import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants; import org.apache.shardingsphere.infra.exception.DatabaseNotExistedException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase; import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule; import org.apache.shardingsphere.mode.metadata.storage.StorageNodeDataSource; @@ -76,9 +76,9 @@ protected Collection getColumnNames() { protected Collection> getRows(final ContextManager contextManager) { String databaseName = getDatabaseName(); MetaDataContexts metaDataContexts = contextManager.getMetaDataContexts(); - ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName); - Collection allReadResources = getAllReadResources(metaData); - Map persistentReadResources = getPersistentReadResources(databaseName, metaDataContexts.getMetaDataPersistService().orElse(null)); + ShardingSphereDatabaseMetaData databaseMetaData = metaDataContexts.getDatabaseMetaData(databaseName); + Collection allReadResources = getAllReadResources(databaseMetaData); + Map persistentReadResources = getPersistentReadResources(databaseName, metaDataContexts.getPersistService().orElse(null)); return buildRows(allReadResources, persistentReadResources); } @@ -93,9 +93,9 @@ private String getDatabaseName() { return result; } - private Collection getAllReadResources(final ShardingSphereMetaData metaData) { + private Collection getAllReadResources(final ShardingSphereDatabaseMetaData databaseMetaData) { Collection result = new LinkedHashSet<>(); - Map> readResourceData = getReadResourceData(metaData); + Map> readResourceData = getReadResourceData(databaseMetaData); readResourceData.forEach((key, value) -> { String resources = value.getOrDefault(ExportableConstants.REPLICA_DATA_SOURCE_NAMES, ""); result.addAll(deconstructString(resources)); @@ -103,8 +103,8 @@ private Collection getAllReadResources(final ShardingSphereMetaData meta return result; } - private Map> getReadResourceData(final ShardingSphereMetaData metaData) { - return metaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof ExportableRule) + private Map> getReadResourceData(final ShardingSphereDatabaseMetaData databaseMetaData) { + return databaseMetaData.getRuleMetaData().getRules().stream().filter(each -> each instanceof ExportableRule) .map(each -> ((ExportableRule) each).export(ExportableConstants.EXPORTABLE_KEY_DATA_SOURCE)) .map(each -> (Map>) each.orElse(Collections.emptyMap())) .map(Map::entrySet).flatMap(Collection::stream).filter(entry -> !entry.getValue().isEmpty()) diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java index 94bc758f6f474..e18b951fe73e8 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java @@ -65,7 +65,7 @@ protected Collection getColumnNames() { protected Collection> getRows(final ContextManager contextManager) { String databaseName = getDatabaseName(); String defaultSchema = connectionSession.getDatabaseType().getDefaultSchema(connectionSession.getDatabaseName()); - ShardingSphereSchema schema = ProxyContext.getInstance().getMetaData(databaseName).getSchemaByName(defaultSchema); + ShardingSphereSchema schema = ProxyContext.getInstance().getMetaData(databaseName).getDatabase().getSchema(defaultSchema); return schema.getAllTableNames().stream().filter(each -> sqlStatement.getTableNames().contains(each)) .map(each -> buildTableRows(databaseName, schema, each)).flatMap(Collection::stream).collect(Collectors.toList()); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterInstanceHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterInstanceHandler.java index 7ed2ea2659388..0bd8e33016e67 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterInstanceHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterInstanceHandler.java @@ -45,7 +45,7 @@ protected void update(final ContextManager contextManager, final AlterInstanceSt } private void setXaRecoveryId(final ContextManager contextManager, final AlterInstanceStatement sqlStatement) { - Optional persistService = contextManager.getMetaDataContexts().getMetaDataPersistService(); + Optional persistService = contextManager.getMetaDataContexts().getPersistService(); if (!persistService.isPresent()) { throw new UnsupportedOperationException(String.format("No persistence configuration found, unable to set '%s'", sqlStatement.getKey())); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java index f674cbe2770e1..4b69509a6b580 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java @@ -66,7 +66,7 @@ private CacheOption createCacheOption(final CacheOption cacheOption, final Cache } private void persistNewRuleConfigurations(final Collection globalRuleConfigs) { - Optional metaDataPersistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService(); + Optional metaDataPersistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getPersistService(); if (metaDataPersistService.isPresent() && null != metaDataPersistService.get().getGlobalRuleService()) { metaDataPersistService.get().getGlobalRuleService().persist(globalRuleConfigs, true); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java index d1e3775e62685..475669fabf577 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java @@ -86,7 +86,7 @@ private void persistNewRuleConfigurations(final TrafficRuleConfiguration toBeAlt currentConfig.getLoadBalancers().putAll(toBeAlteredConfig.getLoadBalancers()); getUnusedLoadBalancer(currentConfig).forEach(each -> currentConfig.getLoadBalancers().remove(each)); MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); - Optional metaDataPersistService = metaDataContexts.getMetaDataPersistService(); + Optional metaDataPersistService = metaDataContexts.getPersistService(); metaDataPersistService.ifPresent(optional -> optional.getGlobalRuleService().persist(metaDataContexts.getGlobalRuleMetaData().getConfigurations(), true)); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java index 9fa2f12d10461..573014f049853 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java @@ -50,7 +50,7 @@ protected void update(final ContextManager contextManager, final AlterTransactio globalRules.add(new TransactionRule(toBeAlteredRuleConfig)); globalRuleConfigs.add(toBeAlteredRuleConfig); ProxyContext.getInstance().getContextManager().renewAllTransactionContext(); - Optional metaDataPersistService = metaDataContexts.getMetaDataPersistService(); + Optional metaDataPersistService = metaDataContexts.getPersistService(); if (metaDataPersistService.isPresent() && null != metaDataPersistService.get().getGlobalRuleService()) { metaDataPersistService.get().getGlobalRuleService().persist(globalRuleConfigs, true); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java index 62132bb78a6d4..cd0f2cce1cb7b 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java @@ -83,7 +83,7 @@ private void updateToRepository(final TrafficRuleConfiguration toBeCreatedRuleCo } else { setUpCurrentRuleConfiguration(toBeCreatedRuleConfig, currentRuleConfig); } - Optional metaDataPersistService = metaDataContexts.getMetaDataPersistService(); + Optional metaDataPersistService = metaDataContexts.getPersistService(); metaDataPersistService.ifPresent(optional -> optional.getGlobalRuleService().persist(globalRuleConfigs, true)); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandler.java index 63ca636becaff..a33d92aad8da3 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandler.java @@ -72,7 +72,7 @@ private Collection getUnusedLoadBalancer(final TrafficRuleConfiguration private void updateToRepository(final TrafficRuleConfiguration config) { MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); - Optional metaDataPersistService = metaDataContexts.getMetaDataPersistService(); + Optional metaDataPersistService = metaDataContexts.getPersistService(); getUnusedLoadBalancer(config).forEach(each -> config.getLoadBalancers().remove(each)); metaDataPersistService.ifPresent(optional -> optional.getGlobalRuleService().persist(metaDataContexts.getGlobalRuleMetaData().getConfigurations(), true)); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandler.java index 2e332acf7d62b..cf1c8a12b8f34 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandler.java @@ -36,7 +36,7 @@ import org.apache.shardingsphere.infra.exception.ImportDatabaseNotExistedException; import org.apache.shardingsphere.infra.exception.DatabaseNotExistedException; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData; import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRuleConfiguration; import org.apache.shardingsphere.infra.yaml.engine.YamlEngine; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -111,20 +111,20 @@ private void alterRulesConfig(final String databaseName, final Collection toBeUpdatedRuleConfigs = new LinkedList<>(); MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); - ShardingSphereMetaData shardingSphereMetaData = metaDataContexts.getMetaData(databaseName); + ShardingSphereDatabaseMetaData databaseMetaData = metaDataContexts.getDatabaseMetaData(databaseName); for (YamlRuleConfiguration each : yamlRuleConfigs) { if (each instanceof YamlShardingRuleConfiguration) { ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfigurationYamlSwapper().swapToObject((YamlShardingRuleConfiguration) each); - shardingRuleConfigurationImportChecker.check(shardingSphereMetaData, shardingRuleConfig); + shardingRuleConfigurationImportChecker.check(databaseMetaData, shardingRuleConfig); toBeUpdatedRuleConfigs.add(shardingRuleConfig); } else if (each instanceof YamlReadwriteSplittingRuleConfiguration) { ReadwriteSplittingRuleConfiguration readwriteSplittingRuleConfig = new ReadwriteSplittingRuleConfigurationYamlSwapper() .swapToObject((YamlReadwriteSplittingRuleConfiguration) each); - readwriteSplittingRuleConfigurationImportChecker.check(shardingSphereMetaData, readwriteSplittingRuleConfig); + readwriteSplittingRuleConfigurationImportChecker.check(databaseMetaData, readwriteSplittingRuleConfig); toBeUpdatedRuleConfigs.add(readwriteSplittingRuleConfig); } else if (each instanceof YamlDatabaseDiscoveryRuleConfiguration) { DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = new DatabaseDiscoveryRuleConfigurationYamlSwapper().swapToObject((YamlDatabaseDiscoveryRuleConfiguration) each); - databaseDiscoveryRuleConfigurationImportChecker.check(shardingSphereMetaData, databaseDiscoveryRuleConfig); + databaseDiscoveryRuleConfigurationImportChecker.check(databaseMetaData, databaseDiscoveryRuleConfig); toBeUpdatedRuleConfigs.add(databaseDiscoveryRuleConfig); } else if (each instanceof YamlEncryptRuleConfiguration) { EncryptRuleConfiguration encryptRuleConfig = new EncryptRuleConfigurationYamlSwapper().swapToObject((YamlEncryptRuleConfiguration) each); @@ -136,10 +136,10 @@ private void alterRulesConfig(final String databaseName, final Collection metaDataPersistService = metaDataContexts.getMetaDataPersistService(); + Optional metaDataPersistService = metaDataContexts.getPersistService(); metaDataPersistService.ifPresent(optional -> optional.getDatabaseRulePersistService().persist(databaseName, toBeUpdatedRuleConfigs)); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java index 0935cafbea92a..99515e116195e 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java @@ -38,7 +38,7 @@ public final class LabelInstanceHandler extends UpdatableRALBackendHandler