You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/10/17 05:57:39 UTC
[shardingsphere] branch master updated: Add TableAddressingMetaData
for prepare refactor metadata (#7818)
This is an automated email from the ASF dual-hosted git repository.
zhangyonglun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 4117653 Add TableAddressingMetaData for prepare refactor metadata (#7818)
4117653 is described below
commit 41176536a49bb112118213c1e1f57135cd56a0a6
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Oct 17 13:57:19 2020 +0800
Add TableAddressingMetaData for prepare refactor metadata (#7818)
* Add TableAddressingMetaData
* Add TableAddressingMetaDataDecorator
* Add TableAddressingMetaDataLoader
* Update TableAddressingMetaDataLoader
* Add ShardingTableAddressingMetaDataDecorator
* Add PrimaryReplicaReplicationTableAddressingMetaDataDecorator
* Fix test case
---
.../EncryptSQLRewriterParameterizedTest.java | 13 ++--
...eplicationTableAddressingMetaDataDecorator.java | 58 ++++++++++++++++
.../rule/PrimaryReplicaReplicationRule.java | 15 +++-
...del.addressing.TableAddressingMetaDataDecorator | 18 +++++
.../ShardingTableAddressingMetaDataDecorator.java | 56 +++++++++++++++
...del.addressing.TableAddressingMetaDataDecorator | 18 +++++
.../MixSQLRewriterParameterizedTest.java | 17 ++---
.../ShardingSQLRewriterParameterizedTest.java | 17 ++---
.../engine/type/standard/AbstractSQLRouteTest.java | 15 ++--
.../context/schema/GovernanceSchemaContexts.java | 3 +-
.../metadata/model/ShardingSphereMetaData.java | 3 +
.../TableAddressingMetaData.java} | 21 +++---
.../TableAddressingMetaDataDecorator.java} | 29 ++++----
.../addressing/TableAddressingMetaDataLoader.java | 80 ++++++++++++++++++++++
.../model/logic/LogicSchemaMetaDataLoader.java | 2 +-
.../model/schema/PhysicalSchemaMetaDataLoader.java | 6 +-
.../model/schema/SchemaMetaDataLoaderTest.java | 2 +-
.../AbstractMetaDataRefreshStrategyTest.java | 4 +-
.../context/schema/SchemaContextsBuilder.java | 5 +-
.../sql/context/ExecutionContextBuilderTest.java | 16 +++--
.../hint/ShardingCTLHintBackendHandlerTest.java | 9 +--
21 files changed, 328 insertions(+), 79 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
index a709092..11a6c75 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameterized/EncryptSQLRewriterParameterizedTest.java
@@ -18,12 +18,16 @@
package org.apache.shardingsphere.encrypt.rewrite.parameterized;
import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.infra.binder.LogicSQL;
+import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
-import org.apache.shardingsphere.infra.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
import org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry;
import org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult;
import org.apache.shardingsphere.infra.rewrite.engine.result.RouteSQLRewriteResult;
@@ -36,13 +40,10 @@ import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.engine.SQLRouteEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRulesBuilder;
-import org.apache.shardingsphere.infra.binder.LogicSQL;
+import org.apache.shardingsphere.infra.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngineFactory;
import org.apache.shardingsphere.sql.parser.engine.StandardSQLParserEngine;
import org.junit.runners.Parameterized.Parameters;
@@ -102,6 +103,6 @@ public final class EncryptSQLRewriterParameterizedTest extends AbstractSQLRewrit
LogicSchemaMetaData logicSchemaMetaData = mock(LogicSchemaMetaData.class);
when(logicSchemaMetaData.getConfiguredSchemaMetaData()).thenReturn(schemaMetaData);
when(logicSchemaMetaData.getSchemaMetaData()).thenReturn(schemaMetaData);
- return new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(CachedDatabaseMetaData.class));
+ return new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
}
}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/replication/primaryreplica/metadata/PrimaryReplicaReplicationTableAddressingMetaDataDecorator.java b/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/replication/primaryreplica/metadata/PrimaryReplicaReplicationTabl [...]
new file mode 100644
index 0000000..5dc1ca3
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/replication/primaryreplica/metadata/PrimaryReplicaReplicationTableAddressingMetaDataDecorator.java
@@ -0,0 +1,58 @@
+/*
+ * 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.replication.primaryreplica.metadata;
+
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataDecorator;
+import org.apache.shardingsphere.replication.primaryreplica.constant.PrimaryReplicaReplicationOrder;
+import org.apache.shardingsphere.replication.primaryreplica.rule.PrimaryReplicaReplicationDataSourceRule;
+import org.apache.shardingsphere.replication.primaryreplica.rule.PrimaryReplicaReplicationRule;
+
+import java.util.Collection;
+import java.util.Map.Entry;
+
+/**
+ * Table addressing meta data decorator of primary replica replication.
+ */
+public final class PrimaryReplicaReplicationTableAddressingMetaDataDecorator implements TableAddressingMetaDataDecorator<PrimaryReplicaReplicationRule> {
+
+ @Override
+ public void decorate(final PrimaryReplicaReplicationRule rule, final TableAddressingMetaData metaData) {
+ for (String each : rule.getAllLogicDataSourceNames()) {
+ rule.findDataSourceRule(each).ifPresent(dataSourceRule -> decorate(dataSourceRule, metaData));
+ }
+ }
+
+ private void decorate(final PrimaryReplicaReplicationDataSourceRule dataSourceRule, final TableAddressingMetaData metaData) {
+ for (Entry<String, Collection<String>> entry : metaData.getTableDataSourceNamesMapper().entrySet()) {
+ entry.getValue().remove(dataSourceRule.getPrimaryDataSourceName());
+ entry.getValue().removeAll(dataSourceRule.getReplicaDataSourceNames());
+ entry.getValue().add(dataSourceRule.getName());
+ }
+ }
+
+ @Override
+ public int getOrder() {
+ return PrimaryReplicaReplicationOrder.ORDER;
+ }
+
+ @Override
+ public Class<PrimaryReplicaReplicationRule> getTypeClass() {
+ return PrimaryReplicaReplicationRule.class;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/replication/primaryreplica/rule/PrimaryReplicaReplicationRule.java b/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/replication/primaryreplica/rule/PrimaryReplicaReplicationRule.java
index 8ef5a52..e0dd215 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/replication/primaryreplica/rule/PrimaryReplicaReplicationRule.java
+++ b/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/replication/primaryreplica/rule/PrimaryReplicaReplicationRule.java
@@ -26,10 +26,10 @@ import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
+import org.apache.shardingsphere.replication.primaryreplica.algorithm.config.AlgorithmProvidedPrimaryReplicaReplicationRuleConfiguration;
import org.apache.shardingsphere.replication.primaryreplica.api.config.PrimaryReplicaReplicationRuleConfiguration;
import org.apache.shardingsphere.replication.primaryreplica.api.config.rule.PrimaryReplicaReplicationDataSourceRuleConfiguration;
import org.apache.shardingsphere.replication.primaryreplica.spi.ReplicaLoadBalanceAlgorithm;
-import org.apache.shardingsphere.replication.primaryreplica.algorithm.config.AlgorithmProvidedPrimaryReplicaReplicationRuleConfiguration;
import java.util.Collection;
import java.util.HashMap;
@@ -76,9 +76,18 @@ public final class PrimaryReplicaReplicationRule implements DataSourceRoutedRule
}
/**
+ * Get all logic data source names.
+ *
+ * @return all logic data source names
+ */
+ public Collection<String> getAllLogicDataSourceNames() {
+ return dataSourceRules.keySet();
+ }
+
+ /**
* Get single data source rule.
*
- * @return Primary-replica replication data source rule
+ * @return primary-replica replication data source rule
*/
public PrimaryReplicaReplicationDataSourceRule getSingleDataSourceRule() {
return dataSourceRules.values().iterator().next();
@@ -88,7 +97,7 @@ public final class PrimaryReplicaReplicationRule implements DataSourceRoutedRule
* Find data source rule.
*
* @param dataSourceName data source name
- * @return Primary-replica replication data source rule
+ * @return primary-replica replication data source rule
*/
public Optional<PrimaryReplicaReplicationDataSourceRule> findDataSourceRule(final String dataSourceName) {
return Optional.ofNullable(dataSourceRules.get(dataSourceName));
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataDecorator b/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDa [...]
new file mode 100644
index 0000000..ad3e2cf
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataDecorator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.replication.primaryreplica.metadata.PrimaryReplicaReplicationTableAddressingMetaDataDecorator
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingTableAddressingMetaDataDecorator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingTableAddressingMetaDataDecorator.java
new file mode 100644
index 0000000..aa80389
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingTableAddressingMetaDataDecorator.java
@@ -0,0 +1,56 @@
+/*
+ * 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.sharding.metadata;
+
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataDecorator;
+import org.apache.shardingsphere.sharding.constant.ShardingOrder;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+
+import java.util.LinkedList;
+import java.util.stream.Collectors;
+
+/**
+ * Table addressing meta data decorator of sharding.
+ */
+public final class ShardingTableAddressingMetaDataDecorator implements TableAddressingMetaDataDecorator<ShardingRule> {
+
+ @Override
+ public void decorate(final ShardingRule rule, final TableAddressingMetaData metaData) {
+ rule.getTableRules().forEach(each -> decorate(each, metaData));
+ }
+
+ private void decorate(final TableRule tableRule, final TableAddressingMetaData metaData) {
+ for (String each : tableRule.getActualDataNodes().stream().map(DataNode::getTableName).collect(Collectors.toSet())) {
+ metaData.getTableDataSourceNamesMapper().remove(each);
+ }
+ metaData.getTableDataSourceNamesMapper().put(tableRule.getLogicTable(), new LinkedList<>(tableRule.getActualDatasourceNames()));
+ }
+
+ @Override
+ public int getOrder() {
+ return ShardingOrder.ORDER;
+ }
+
+ @Override
+ public Class<ShardingRule> getTypeClass() {
+ return ShardingRule.class;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataDecorator b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataDecorator
new file mode 100644
index 0000000..984236d
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataDecorator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.sharding.metadata.ShardingTableAddressingMetaDataDecorator
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
index b52b8e7..e46b315 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/MixSQLRewriterParameterizedTest.java
@@ -18,11 +18,19 @@
package org.apache.shardingsphere.sharding.rewrite.parameterized;
import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.infra.binder.LogicSQL;
+import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.index.PhysicalIndexMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
import org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry;
import org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult;
import org.apache.shardingsphere.infra.rewrite.engine.result.RouteSQLRewriteResult;
@@ -36,16 +44,9 @@ import org.apache.shardingsphere.infra.route.engine.SQLRouteEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRulesBuilder;
import org.apache.shardingsphere.infra.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.index.PhysicalIndexMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngineFactory;
import org.apache.shardingsphere.sql.parser.engine.StandardSQLParserEngine;
import org.junit.runners.Parameterized.Parameters;
@@ -122,7 +123,7 @@ public final class MixSQLRewriterParameterizedTest extends AbstractSQLRewriterPa
LogicSchemaMetaData logicSchemaMetaData = mock(LogicSchemaMetaData.class);
when(logicSchemaMetaData.getConfiguredSchemaMetaData()).thenReturn(schemaMetaData);
when(logicSchemaMetaData.getSchemaMetaData()).thenReturn(schemaMetaData);
- return new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(CachedDatabaseMetaData.class));
+ return new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
}
private Map<String, PhysicalColumnMetaData> createColumnMetaDataMap() {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java
index 9c9cde1..155e29d 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/ShardingSQLRewriterParameterizedTest.java
@@ -18,11 +18,19 @@
package org.apache.shardingsphere.sharding.rewrite.parameterized;
import com.google.common.base.Preconditions;
+import org.apache.shardingsphere.infra.binder.LogicSQL;
+import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.index.PhysicalIndexMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
import org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry;
import org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult;
import org.apache.shardingsphere.infra.rewrite.engine.result.RouteSQLRewriteResult;
@@ -36,16 +44,9 @@ import org.apache.shardingsphere.infra.route.engine.SQLRouteEngine;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRulesBuilder;
import org.apache.shardingsphere.infra.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.index.PhysicalIndexMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngineFactory;
import org.apache.shardingsphere.sql.parser.engine.StandardSQLParserEngine;
import org.junit.runners.Parameterized.Parameters;
@@ -117,7 +118,7 @@ public final class ShardingSQLRewriterParameterizedTest extends AbstractSQLRewri
LogicSchemaMetaData logicSchemaMetaData = mock(LogicSchemaMetaData.class);
when(logicSchemaMetaData.getConfiguredSchemaMetaData()).thenReturn(schemaMetaData);
when(logicSchemaMetaData.getSchemaMetaData()).thenReturn(schemaMetaData);
- return new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(CachedDatabaseMetaData.class));
+ return new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
}
private Map<String, PhysicalColumnMetaData> createColumnMetaDataMap() {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
index b22409d..a949cc1 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
@@ -17,24 +17,25 @@
package org.apache.shardingsphere.sharding.route.engine.type.standard;
+import org.apache.shardingsphere.infra.binder.LogicSQL;
+import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.DatabaseAccessConfiguration;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.engine.SQLRouteEngine;
import org.apache.shardingsphere.infra.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.sharding.route.engine.fixture.AbstractRoutingEngineTest;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.engine.SQLParserEngineFactory;
import org.apache.shardingsphere.sql.parser.engine.StandardSQLParserEngine;
@@ -55,7 +56,7 @@ public abstract class AbstractSQLRouteTest extends AbstractRoutingEngineTest {
protected final RouteContext assertRoute(final String sql, final List<Object> parameters) {
ShardingRule shardingRule = createAllShardingRule();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(buildDataSourceMetas(), buildLogicSchemaMetaData(), mock(CachedDatabaseMetaData.class));
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(buildDataSourceMetas(), buildLogicSchemaMetaData(), mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
ConfigurationProperties props = new ConfigurationProperties(new Properties());
StandardSQLParserEngine standardSqlParserEngine = SQLParserEngineFactory.getSQLParserEngine("MySQL");
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/schema/GovernanceSchemaContexts.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/schema/GovernanceSchemaContexts.java
index 54b9634..81c21d2 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/schema/GovernanceSchemaContexts.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/schema/GovernanceSchemaContexts.java
@@ -308,8 +308,9 @@ public final class GovernanceSchemaContexts implements SchemaContexts {
}
private ShardingSphereSchema getChangedShardingSphereSchema(final ShardingSphereSchema oldSchema, final LogicSchemaMetaData newLogicSchemaMetaData, final String schemaName) {
+ // TODO refresh tableAddressingMetaData
ShardingSphereMetaData metaData = new ShardingSphereMetaData(
- oldSchema.getMetaData().getDataSourcesMetaData(), newLogicSchemaMetaData, oldSchema.getMetaData().getCachedDatabaseMetaData());
+ oldSchema.getMetaData().getDataSourcesMetaData(), newLogicSchemaMetaData, oldSchema.getMetaData().getTableAddressingMetaData(), oldSchema.getMetaData().getCachedDatabaseMetaData());
return new ShardingSphereSchema(schemaName, oldSchema.getConfigurations(), oldSchema.getRules(), oldSchema.getDataSources(), metaData);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java
index 32b95f1..82c6bad 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.metadata.model;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
@@ -34,5 +35,7 @@ public final class ShardingSphereMetaData {
private final LogicSchemaMetaData schemaMetaData;
+ private final TableAddressingMetaData tableAddressingMetaData;
+
private final CachedDatabaseMetaData cachedDatabaseMetaData;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaData.java
similarity index 57%
copy from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaData.java
index 32b95f1..ffc3af6 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaData.java
@@ -15,24 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.metadata.model;
+package org.apache.shardingsphere.infra.metadata.model.addressing;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
-import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
-import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
/**
- * ShardingSphere meta data.
+ * Table addressing meta data.
*/
-@RequiredArgsConstructor
@Getter
-public final class ShardingSphereMetaData {
-
- private final DataSourcesMetaData dataSourcesMetaData;
-
- private final LogicSchemaMetaData schemaMetaData;
+public final class TableAddressingMetaData {
- private final CachedDatabaseMetaData cachedDatabaseMetaData;
+ private final Map<String, Collection<String>> tableDataSourceNamesMapper = new HashMap<>();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaDataDecorator.java
similarity index 55%
copy from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaDataDecorator.java
index 32b95f1..7f40999 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/ShardingSphereMetaData.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaDataDecorator.java
@@ -15,24 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.metadata.model;
+package org.apache.shardingsphere.infra.metadata.model.addressing;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
-import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
-import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.ordered.OrderedSPI;
/**
- * ShardingSphere meta data.
+ * Table addressing meta data decorator.
+ *
+ * @param <T> type of ShardingSphere rule
*/
-@RequiredArgsConstructor
-@Getter
-public final class ShardingSphereMetaData {
+public interface TableAddressingMetaDataDecorator<T extends ShardingSphereRule> extends OrderedSPI<T> {
- private final DataSourcesMetaData dataSourcesMetaData;
-
- private final LogicSchemaMetaData schemaMetaData;
-
- private final CachedDatabaseMetaData cachedDatabaseMetaData;
+ /**
+ * Build ShardingSphere rule.
+ *
+ * @param rule ShardingSphere rule
+ * @param metaData table addressing meta data
+ */
+ void decorate(T rule, TableAddressingMetaData metaData);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaDataLoader.java
new file mode 100644
index 0000000..5903797
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/addressing/TableAddressingMetaDataLoader.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.model.addressing;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Table addressing meta data loader.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TableAddressingMetaDataLoader {
+
+ static {
+ ShardingSphereServiceLoader.register(TableAddressingMetaDataDecorator.class);
+ }
+
+ /**
+ * Load table addressing meta data.
+ *
+ * @param databaseType database type
+ * @param dataSourceMap data source map
+ * @param rules ShardingSphere rules
+ * @return table addressing meta data
+ * @throws SQLException SQL exception
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static TableAddressingMetaData load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules) throws SQLException {
+ TableAddressingMetaData result = initializeMetaData(databaseType, dataSourceMap);
+ for (Entry<ShardingSphereRule, TableAddressingMetaDataDecorator> entry : OrderedSPIRegistry.getRegisteredServices(rules, TableAddressingMetaDataDecorator.class).entrySet()) {
+ entry.getValue().decorate(entry.getKey(), result);
+ }
+ return result;
+ }
+
+ private static TableAddressingMetaData initializeMetaData(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap) throws SQLException {
+ TableAddressingMetaData result = new TableAddressingMetaData();
+ for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
+ appendMetaData(result, databaseType, entry.getKey(), entry.getValue());
+ }
+ return result;
+ }
+
+ private static void appendMetaData(final TableAddressingMetaData metaData, final DatabaseType databaseType, final String dataSourceName, final DataSource dataSource) throws SQLException {
+ for (String each : PhysicalSchemaMetaDataLoader.loadTableNames(dataSource, databaseType, Collections.emptyList())) {
+ if (!metaData.getTableDataSourceNamesMapper().containsKey(each)) {
+ metaData.getTableDataSourceNamesMapper().put(each, new LinkedHashSet<>());
+ }
+ metaData.getTableDataSourceNamesMapper().get(each).add(dataSourceName);
+ }
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/logic/LogicSchemaMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/logic/LogicSchemaMetaDataLoader.java
index e2e2117..1600e15 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/logic/LogicSchemaMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/logic/LogicSchemaMetaDataLoader.java
@@ -140,7 +140,7 @@ public final class LogicSchemaMetaDataLoader {
final Collection<String> excludedTableNames) throws SQLException {
Map<String, Collection<String>> result = new HashMap<>(dataSourceMap.size(), 1);
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
- Collection<String> tableNames = PhysicalSchemaMetaDataLoader.loadUnconfiguredTableNames(entry.getValue(), databaseType, excludedTableNames);
+ Collection<String> tableNames = PhysicalSchemaMetaDataLoader.loadTableNames(entry.getValue(), databaseType, excludedTableNames);
if (!tableNames.isEmpty()) {
result.put(entry.getKey(), tableNames);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/PhysicalSchemaMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/PhysicalSchemaMetaDataLoader.java
index a009e9e..df186dd 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/PhysicalSchemaMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/PhysicalSchemaMetaDataLoader.java
@@ -47,15 +47,15 @@ public final class PhysicalSchemaMetaDataLoader {
private static final String TABLE_NAME = "TABLE_NAME";
/**
- * Load unconfigured table name.
+ * Load all table names.
*
* @param dataSource data source
* @param databaseType database type
* @param excludedTableNames excluded table names
- * @return unconfigured table names
+ * @return all table names
* @throws SQLException SQL exception
*/
- public static Collection<String> loadUnconfiguredTableNames(final DataSource dataSource, final DatabaseType databaseType, final Collection<String> excludedTableNames) throws SQLException {
+ public static Collection<String> loadTableNames(final DataSource dataSource, final DatabaseType databaseType, final Collection<String> excludedTableNames) throws SQLException {
List<String> result;
try (MetaDataConnectionAdapter connectionAdapter = new MetaDataConnectionAdapter(databaseType, dataSource.getConnection())) {
result = loadAllTableNames(connectionAdapter);
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/SchemaMetaDataLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/SchemaMetaDataLoaderTest.java
index d0fdc41..2276c37 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/SchemaMetaDataLoaderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/model/physical/model/schema/SchemaMetaDataLoaderTest.java
@@ -70,7 +70,7 @@ public final class SchemaMetaDataLoaderTest {
@Test
public void assertLoadUnconfiguredTableNamesForOracle() throws SQLException {
- Collection<String> tableNames = PhysicalSchemaMetaDataLoader.loadUnconfiguredTableNames(dataSource, databaseType, Collections.emptyList());
+ Collection<String> tableNames = PhysicalSchemaMetaDataLoader.loadTableNames(dataSource, databaseType, Collections.emptyList());
assertThat(tableNames.size(), is(0));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/AbstractMetaDataRefreshStrategyTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/AbstractMetaDataRefreshStrategyTest.java
index e340039..0c9a215 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/AbstractMetaDataRefreshStrategyTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/refresh/AbstractMetaDataRefreshStrategyTest.java
@@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import lombok.Getter;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
@@ -46,7 +47,8 @@ public abstract class AbstractMetaDataRefreshStrategyTest {
private ShardingSphereMetaData buildMetaData() {
PhysicalSchemaMetaData schemaMetaData = new PhysicalSchemaMetaData(ImmutableMap.of("t_order", new PhysicalTableMetaData(
Collections.singletonList(new PhysicalColumnMetaData("order_id", 1, "String", false, false, false)), Collections.singletonList(new PhysicalIndexMetaData("index")))));
- return new ShardingSphereMetaData(null, new LogicSchemaMetaData(schemaMetaData, ImmutableMap.of("t_order_item", Lists.newArrayList("t_order_item"))), mock(CachedDatabaseMetaData.class));
+ return new ShardingSphereMetaData(null,
+ new LogicSchemaMetaData(schemaMetaData, ImmutableMap.of("t_order_item", Lists.newArrayList("t_order_item"))), mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/schema/SchemaContextsBuilder.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/schema/SchemaContextsBuilder.java
index 90ceb0c..663b600 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/schema/SchemaContextsBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/schema/SchemaContextsBuilder.java
@@ -28,6 +28,8 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaDataLoader;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
@@ -110,8 +112,9 @@ public final class SchemaContextsBuilder {
long start = System.currentTimeMillis();
DataSourcesMetaData dataSourceMetas = new DataSourcesMetaData(databaseType, getDatabaseAccessConfigurationMap(dataSourceMap));
LogicSchemaMetaData logicSchemaMetaData = new LogicSchemaMetaDataLoader(rules).load(databaseType, dataSourceMap, props);
+ TableAddressingMetaData tableAddressingMetaData = TableAddressingMetaDataLoader.load(databaseType, dataSourceMap, rules);
CachedDatabaseMetaData cachedDatabaseMetaData = createCachedDatabaseMetaData(dataSources.get(schemaName)).orElse(null);
- ShardingSphereMetaData result = new ShardingSphereMetaData(dataSourceMetas, logicSchemaMetaData, cachedDatabaseMetaData);
+ ShardingSphereMetaData result = new ShardingSphereMetaData(dataSourceMetas, logicSchemaMetaData, tableAddressingMetaData, cachedDatabaseMetaData);
log.info("Load meta data for schema {} finished, cost {} milliseconds.", schemaName, System.currentTimeMillis() - start);
return result;
}
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 6ae0522..6c2f08a 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
@@ -17,19 +17,20 @@
package org.apache.shardingsphere.infra.executor.sql.context;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
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.SQLRewriteUnit;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.column.PhysicalColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
-import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.junit.Test;
import java.sql.Types;
@@ -56,7 +57,7 @@ public final class ExecutionContextBuilderTest {
DataSourcesMetaData dataSourcesMetaData = mock(DataSourcesMetaData.class);
String firstDataSourceName = "firstDataSourceName";
when(dataSourcesMetaData.getAllInstanceDataSourceNames()).thenReturn(Arrays.asList(firstDataSourceName, "lastDataSourceName"));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(dataSourcesMetaData, buildLogicSchemaMetaData(), mock(CachedDatabaseMetaData.class));
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(dataSourcesMetaData, buildLogicSchemaMetaData(), mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
Collection<ExecutionUnit> actual = ExecutionContextBuilder.build(metaData, genericSQLRewriteResult, mock(SQLStatementContext.class));
Collection<ExecutionUnit> expected = Collections.singletonList(new ExecutionUnit(firstDataSourceName, new SQLUnit(sql, parameters)));
assertThat(actual, is(expected));
@@ -71,7 +72,8 @@ public final class ExecutionContextBuilderTest {
Map<RouteUnit, SQLRewriteUnit> sqlRewriteUnits = new HashMap<>(2, 1);
sqlRewriteUnits.put(routeUnit1, sqlRewriteUnit1);
sqlRewriteUnits.put(routeUnit2, sqlRewriteUnit2);
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DataSourcesMetaData.class), buildLogicSchemaMetaData(), mock(CachedDatabaseMetaData.class));
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(
+ mock(DataSourcesMetaData.class), buildLogicSchemaMetaData(), mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
Collection<ExecutionUnit> actual = ExecutionContextBuilder.build(metaData, 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")));
@@ -89,7 +91,7 @@ public final class ExecutionContextBuilderTest {
Map<RouteUnit, SQLRewriteUnit> sqlRewriteUnits = new HashMap<>(2, 1);
sqlRewriteUnits.put(routeUnit2, sqlRewriteUnit2);
LogicSchemaMetaData logicSchemaMetaData = buildLogicSchemaMetaDataWithoutPrimaryKey();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(CachedDatabaseMetaData.class));
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DataSourcesMetaData.class), logicSchemaMetaData, mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class));
Collection<ExecutionUnit> actual = ExecutionContextBuilder.build(metaData, new RouteSQLRewriteResult(sqlRewriteUnits), mock(SQLStatementContext.class));
ExecutionUnit expectedUnit2 = new ExecutionUnit("actualName2", new SQLUnit("sql2", Collections.singletonList("parameter2")));
Collection<ExecutionUnit> expected = new LinkedHashSet<>(1, 1);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
index 2c58e7b..c27e82d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
@@ -27,9 +27,12 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.apache.shardingsphere.infra.metadata.model.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.model.addressing.TableAddressingMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.model.datasource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.model.logic.LogicSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
+import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
import org.apache.shardingsphere.infra.schema.ShardingSphereSchema;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -41,8 +44,6 @@ import org.apache.shardingsphere.proxy.backend.text.sctl.exception.InvalidShardi
import org.apache.shardingsphere.proxy.backend.text.sctl.exception.UnsupportedShardingCTLTypeException;
import org.apache.shardingsphere.proxy.backend.text.sctl.hint.internal.HintManagerHolder;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.schema.PhysicalSchemaMetaData;
-import org.apache.shardingsphere.infra.metadata.model.physical.model.table.PhysicalTableMetaData;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
@@ -207,8 +208,8 @@ public final class ShardingCTLHintBackendHandlerTest {
private Map<String, ShardingSphereSchema> getSchemas() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
- when(schema.getMetaData()).thenReturn(new ShardingSphereMetaData(mock(DataSourcesMetaData.class),
- new LogicSchemaMetaData(new PhysicalSchemaMetaData(ImmutableMap.of("user", mock(PhysicalTableMetaData.class))), Collections.emptyMap()), mock(CachedDatabaseMetaData.class)));
+ when(schema.getMetaData()).thenReturn(new ShardingSphereMetaData(mock(DataSourcesMetaData.class), new LogicSchemaMetaData(new PhysicalSchemaMetaData(
+ ImmutableMap.of("user", mock(PhysicalTableMetaData.class))), Collections.emptyMap()), mock(TableAddressingMetaData.class), mock(CachedDatabaseMetaData.class)));
when(schema.isComplete()).thenReturn(true);
return Collections.singletonMap("schema", schema);
}