You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2020/11/07 08:17:50 UTC
[shardingsphere] branch master updated: Split SchemaMetaDataLoader
to SchemaMetaDataLoader and TableMetaDataLoader (#8066)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 7546181 Split SchemaMetaDataLoader to SchemaMetaDataLoader and TableMetaDataLoader (#8066)
7546181 is described below
commit 7546181304fe25ce22ae6f865809565236d43b3c
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Nov 7 16:17:34 2020 +0800
Split SchemaMetaDataLoader to SchemaMetaDataLoader and TableMetaDataLoader (#8066)
* Remove useless SchemaMetaDataLoader.load with single data source
* Split SchemaMetaDataLoader to SchemaMetaDataLoader and TableMetaDataLoader
* Refactor ShardingSphereMetaDataLoader
---
.../encrypt/metadata/EncryptMetaDataLoader.java | 4 +-
.../metadata/EncryptMetaDataLoaderTest.java | 5 +-
.../sharding/metadata/ShardingMetaDataLoader.java | 6 +-
.../schema/loader/SchemaMetaDataLoader.java | 69 +-----------------
.../schema/loader/TableMetaDataLoader.java | 82 ++++++++++++++++++++++
.../loader/spi/ShardingSphereMetaDataLoader.java | 6 +-
.../loader/CommonFixtureLogicMetaDataLoader.java | 4 +-
.../DataNodeRoutedFixtureLogicMetaDataLoader.java | 4 +-
.../schema/loader/SchemaMetaDataLoaderTest.java | 23 ++----
...oaderTest.java => TableMetaDataLoaderTest.java} | 32 ++-------
.../driver/executor/AbstractStatementExecutor.java | 8 +--
.../jdbc/JDBCDatabaseCommunicationEngine.java | 8 +--
12 files changed, 116 insertions(+), 135 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java
index 4639c3d..6d82e09 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java
@@ -54,8 +54,8 @@ public final class EncryptMetaDataLoader implements ShardingSphereMetaDataLoader
}
@Override
- public Optional<PhysicalTableMetaData> load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final DataNodes dataNodes,
- final String tableName, final EncryptRule encryptRule, final ConfigurationProperties props) throws SQLException {
+ public Optional<PhysicalTableMetaData> load(final String tableName, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final DataNodes dataNodes,
+ final EncryptRule encryptRule, final ConfigurationProperties props) throws SQLException {
return encryptRule.findEncryptTable(tableName).isPresent() ? PhysicalTableMetaDataLoader.load(dataSourceMap.values().iterator().next(), tableName, databaseType) : Optional.empty();
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoaderTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoaderTest.java
index 1ee8728..99e31d3 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoaderTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoaderTest.java
@@ -107,8 +107,7 @@ public final class EncryptMetaDataLoaderTest {
public void assertLoadByExistedTable() throws SQLException {
EncryptRule rule = createEncryptRule();
EncryptMetaDataLoader loader = (EncryptMetaDataLoader) OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(rule), ShardingSphereMetaDataLoader.class).get(rule);
- Optional<PhysicalTableMetaData> actual = loader.load(
- databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), TABLE_NAME, rule, props);
+ Optional<PhysicalTableMetaData> actual = loader.load(TABLE_NAME, databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), rule, props);
assertTrue(actual.isPresent());
assertThat(actual.get().getColumnMetaData(0).getName(), is("id"));
assertThat(actual.get().getColumnMetaData(1).getName(), is("pwd_cipher"));
@@ -120,7 +119,7 @@ public final class EncryptMetaDataLoaderTest {
EncryptRule rule = createEncryptRule();
EncryptMetaDataLoader loader = new EncryptMetaDataLoader();
Optional<PhysicalTableMetaData> actual = loader.load(
- databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), "not_existed_table", rule, props);
+ "not_existed_table", databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), rule, props);
assertFalse(actual.isPresent());
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataLoader.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataLoader.java
index cf4f91b..952f097 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataLoader.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataLoader.java
@@ -64,15 +64,15 @@ public final class ShardingMetaDataLoader implements ShardingSphereMetaDataLoade
PhysicalSchemaMetaData result = new PhysicalSchemaMetaData(new HashMap<>(rule.getTableRules().size(), 1));
for (TableRule each : rule.getTableRules()) {
if (!excludedTableNames.contains(each.getLogicTable())) {
- load(databaseType, dataSourceMap, dataNodes, each.getLogicTable(), rule, props).ifPresent(tableMetaData -> result.put(each.getLogicTable(), tableMetaData));
+ load(each.getLogicTable(), databaseType, dataSourceMap, dataNodes, rule, props).ifPresent(tableMetaData -> result.put(each.getLogicTable(), tableMetaData));
}
}
return result;
}
@Override
- public Optional<PhysicalTableMetaData> load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final DataNodes dataNodes,
- final String tableName, final ShardingRule rule, final ConfigurationProperties props) throws SQLException {
+ public Optional<PhysicalTableMetaData> load(final String tableName, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final DataNodes dataNodes,
+ final ShardingRule rule, final ConfigurationProperties props) throws SQLException {
if (!rule.findTableRule(tableName).isPresent()) {
return Optional.empty();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoader.java
index 87275b7..9294836 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoader.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.metadata.schema.loader;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNodes;
import org.apache.shardingsphere.infra.metadata.schema.loader.spi.ShardingSphereMetaDataDecorator;
@@ -35,11 +34,9 @@ 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.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Optional;
import java.util.TreeSet;
/**
@@ -65,7 +62,7 @@ public final class SchemaMetaDataLoader {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static PhysicalSchemaMetaData load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
- final Collection<ShardingSphereRule> rules, final ConfigurationProperties props) throws SQLException {
+ final Collection<ShardingSphereRule> rules, final ConfigurationProperties props) throws SQLException {
Collection<String> excludedTableNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
PhysicalSchemaMetaData result = new PhysicalSchemaMetaData();
for (Entry<ShardingSphereRule, ShardingSphereMetaDataLoader> entry : OrderedSPIRegistry.getRegisteredServices(rules, ShardingSphereMetaDataLoader.class).entrySet()) {
@@ -80,60 +77,6 @@ public final class SchemaMetaDataLoader {
return result;
}
- /**
- * Load schema meta data.
- *
- * @param databaseType database type
- * @param dataSource data source
- * @param rules ShardingSphere rules
- * @param props configuration properties
- * @return schema meta data
- * @throws SQLException SQL exception
- */
- public static PhysicalSchemaMetaData load(final DatabaseType databaseType, final DataSource dataSource,
- final Collection<ShardingSphereRule> rules, final ConfigurationProperties props) throws SQLException {
- return load(databaseType, Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSource), rules, props);
- }
-
- /**
- * Load schema meta data.
- *
- * @param databaseType database type
- * @param dataSourceMap data source map
- * @param rules ShardingSphere rules
- * @param tableName table name
- * @param props configuration properties
- * @return schema meta data
- * @throws SQLException SQL exception
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static Optional<PhysicalTableMetaData> load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
- final Collection<ShardingSphereRule> rules, final String tableName, final ConfigurationProperties props) throws SQLException {
- for (Entry<ShardingSphereRule, ShardingSphereMetaDataLoader> entry : OrderedSPIRegistry.getRegisteredServices(rules, ShardingSphereMetaDataLoader.class).entrySet()) {
- Optional<PhysicalTableMetaData> result = entry.getValue().load(databaseType, dataSourceMap, new DataNodes(rules), tableName, entry.getKey(), props);
- if (result.isPresent()) {
- return Optional.of(decorate(rules, tableName, result.get()));
- }
- }
- return Optional.empty();
- }
-
- /**
- * Load schema meta data.
- *
- * @param databaseType database type
- * @param dataSource data source
- * @param rules ShardingSphere rules
- * @param tableName table name
- * @param props configuration properties
- * @return schema meta data
- * @throws SQLException SQL exception
- */
- public static Optional<PhysicalTableMetaData> load(final DatabaseType databaseType, final DataSource dataSource,
- final Collection<ShardingSphereRule> rules, final String tableName, final ConfigurationProperties props) throws SQLException {
- return load(databaseType, Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSource), rules, tableName, props);
- }
-
@SuppressWarnings({"unchecked", "rawtypes"})
private static void decorate(final Collection<ShardingSphereRule> rules, final PhysicalSchemaMetaData schemaMetaData) {
Map<String, PhysicalTableMetaData> tableMetaDataMap = new HashMap<>(schemaMetaData.getAllTableNames().size(), 1);
@@ -145,14 +88,4 @@ public final class SchemaMetaDataLoader {
}
schemaMetaData.merge(new PhysicalSchemaMetaData(tableMetaDataMap));
}
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private static PhysicalTableMetaData decorate(final Collection<ShardingSphereRule> rules, final String tableName, final PhysicalTableMetaData tableMetaData) {
- Map<ShardingSphereRule, ShardingSphereMetaDataDecorator> decorators = OrderedSPIRegistry.getRegisteredServices(rules, ShardingSphereMetaDataDecorator.class);
- PhysicalTableMetaData result = null;
- for (Entry<ShardingSphereRule, ShardingSphereMetaDataDecorator> entry : decorators.entrySet()) {
- result = entry.getValue().decorate(tableName, null == result ? tableMetaData : result, entry.getKey());
- }
- return Optional.ofNullable(result).orElse(tableMetaData);
- }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/TableMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/TableMetaDataLoader.java
new file mode 100644
index 0000000..8026c15
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/TableMetaDataLoader.java
@@ -0,0 +1,82 @@
+/*
+ * 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.schema.loader;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNodes;
+import org.apache.shardingsphere.infra.metadata.schema.loader.spi.ShardingSphereMetaDataDecorator;
+import org.apache.shardingsphere.infra.metadata.schema.loader.spi.ShardingSphereMetaDataLoader;
+import org.apache.shardingsphere.infra.metadata.schema.model.physical.PhysicalTableMetaData;
+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.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+/**
+ * Table meta data loader.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TableMetaDataLoader {
+
+ static {
+ ShardingSphereServiceLoader.register(ShardingSphereMetaDataLoader.class);
+ ShardingSphereServiceLoader.register(ShardingSphereMetaDataDecorator.class);
+ }
+
+ /**
+ * Load table meta data.
+ *
+ * @param tableName table name
+ * @param databaseType database type
+ * @param dataSourceMap data source map
+ * @param rules ShardingSphere rules
+ * @param props configuration properties
+ * @return table meta data
+ * @throws SQLException SQL exception
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static Optional<PhysicalTableMetaData> load(final String tableName, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
+ final Collection<ShardingSphereRule> rules, final ConfigurationProperties props) throws SQLException {
+ for (Entry<ShardingSphereRule, ShardingSphereMetaDataLoader> entry : OrderedSPIRegistry.getRegisteredServices(rules, ShardingSphereMetaDataLoader.class).entrySet()) {
+ Optional<PhysicalTableMetaData> result = entry.getValue().load(tableName, databaseType, dataSourceMap, new DataNodes(rules), entry.getKey(), props);
+ if (result.isPresent()) {
+ return Optional.of(decorate(tableName, result.get(), rules));
+ }
+ }
+ return Optional.empty();
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private static PhysicalTableMetaData decorate(final String tableName, final PhysicalTableMetaData tableMetaData, final Collection<ShardingSphereRule> rules) {
+ Map<ShardingSphereRule, ShardingSphereMetaDataDecorator> decorators = OrderedSPIRegistry.getRegisteredServices(rules, ShardingSphereMetaDataDecorator.class);
+ PhysicalTableMetaData result = null;
+ for (Entry<ShardingSphereRule, ShardingSphereMetaDataDecorator> entry : decorators.entrySet()) {
+ result = entry.getValue().decorate(tableName, null == result ? tableMetaData : result, entry.getKey());
+ }
+ return Optional.ofNullable(result).orElse(tableMetaData);
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/ShardingSphereMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/ShardingSphereMetaDataLoader.java
index 27f1611..91f1a0f 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/ShardingSphereMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/ShardingSphereMetaDataLoader.java
@@ -56,15 +56,15 @@ public interface ShardingSphereMetaDataLoader<T extends ShardingSphereRule> exte
/**
* Load table meta data.
*
+ * @param tableName table name
* @param databaseType database type
* @param dataSourceMap data source map
* @param dataNodes data nodes
- * @param tableName table name
* @param rule rule
* @param props configuration properties
* @return meta data
* @throws SQLException SQL exception
*/
- Optional<PhysicalTableMetaData> load(DatabaseType databaseType, Map<String, DataSource> dataSourceMap,
- DataNodes dataNodes, String tableName, T rule, ConfigurationProperties props) throws SQLException;
+ Optional<PhysicalTableMetaData> load(String tableName, DatabaseType databaseType, Map<String, DataSource> dataSourceMap,
+ DataNodes dataNodes, T rule, ConfigurationProperties props) throws SQLException;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/CommonFixtureLogicMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/CommonFixtureLogicMetaDataLoader.java
index d37dfea..b66243b 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/CommonFixtureLogicMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/CommonFixtureLogicMetaDataLoader.java
@@ -44,8 +44,8 @@ public final class CommonFixtureLogicMetaDataLoader implements ShardingSphereMet
}
@Override
- public Optional<PhysicalTableMetaData> load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
- final DataNodes dataNodes, final String tableName, final CommonFixtureRule rule, final ConfigurationProperties props) {
+ public Optional<PhysicalTableMetaData> load(final String tableName, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
+ final DataNodes dataNodes, final CommonFixtureRule rule, final ConfigurationProperties props) {
return Optional.empty();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/DataNodeRoutedFixtureLogicMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/DataNodeRoutedFixtureLogicMetaDataLoader.java
index cb46e9e..33106ed 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/DataNodeRoutedFixtureLogicMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/fixture/loader/DataNodeRoutedFixtureLogicMetaDataLoader.java
@@ -44,8 +44,8 @@ public final class DataNodeRoutedFixtureLogicMetaDataLoader implements ShardingS
}
@Override
- public Optional<PhysicalTableMetaData> load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
- final DataNodes dataNodes, final String tableName, final DataNodeRoutedFixtureRule rule, final ConfigurationProperties props) {
+ public Optional<PhysicalTableMetaData> load(final String tableName, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
+ final DataNodes dataNodes, final DataNodeRoutedFixtureRule rule, final ConfigurationProperties props) {
return ("data_node_routed_table_0".equals(tableName) || "data_node_routed_table_1".equals(tableName))
? Optional.of(new PhysicalTableMetaData(Collections.emptyList(), Collections.emptyList())) : Optional.empty();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoaderTest.java
index 74a1652..ec99ff4 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoaderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoaderTest.java
@@ -31,9 +31,9 @@ import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Arrays;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -50,13 +50,10 @@ public final class SchemaMetaDataLoaderTest {
private ConfigurationProperties props;
@Test
- public void assertSyncLoadFullDatabases() throws SQLException {
- assertPhysicalSchemaMetaData(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), props));
- }
-
- @Test
- public void assertAsyncLoadFullDatabases() throws SQLException {
- assertPhysicalSchemaMetaData(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), props));
+ public void assertLoadFullDatabases() throws SQLException {
+ PhysicalSchemaMetaData actual = SchemaMetaDataLoader.load(
+ databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), props);
+ assertPhysicalSchemaMetaData(actual);
}
private void assertPhysicalSchemaMetaData(final PhysicalSchemaMetaData actual) {
@@ -68,14 +65,4 @@ public final class SchemaMetaDataLoaderTest {
assertTrue(actual.containsTable("data_node_routed_table_1"));
assertTrue(actual.get("data_node_routed_table_1").getColumns().containsKey("id"));
}
-
- @Test
- public void assertLoadWithExistedTableName() throws SQLException {
- assertTrue(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), "data_node_routed_table_0", props).isPresent());
- }
-
- @Test
- public void assertLoadWithNotExistedTableName() throws SQLException {
- assertFalse(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), "invalid_table", props).isPresent());
- }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/TableMetaDataLoaderTest.java
similarity index 53%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoaderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/TableMetaDataLoaderTest.java
index 74a1652..6a589ff 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/SchemaMetaDataLoaderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/TableMetaDataLoaderTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.schema.fixture.rule.CommonFixtureRule;
import org.apache.shardingsphere.infra.metadata.schema.fixture.rule.DataNodeRoutedFixtureRule;
-import org.apache.shardingsphere.infra.metadata.schema.model.physical.PhysicalSchemaMetaData;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -31,14 +30,13 @@ import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Arrays;
+import java.util.Collections;
-import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(MockitoJUnitRunner.class)
-public final class SchemaMetaDataLoaderTest {
+public final class TableMetaDataLoaderTest {
@Mock
private DatabaseType databaseType;
@@ -50,32 +48,14 @@ public final class SchemaMetaDataLoaderTest {
private ConfigurationProperties props;
@Test
- public void assertSyncLoadFullDatabases() throws SQLException {
- assertPhysicalSchemaMetaData(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), props));
- }
-
- @Test
- public void assertAsyncLoadFullDatabases() throws SQLException {
- assertPhysicalSchemaMetaData(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), props));
- }
-
- private void assertPhysicalSchemaMetaData(final PhysicalSchemaMetaData actual) {
- assertThat(actual.getAllTableNames().size(), is(4));
- assertTrue(actual.containsTable("common_table_0"));
- assertTrue(actual.containsTable("common_table_1"));
- assertTrue(actual.containsTable("data_node_routed_table_0"));
- assertTrue(actual.get("data_node_routed_table_0").getColumns().containsKey("id"));
- assertTrue(actual.containsTable("data_node_routed_table_1"));
- assertTrue(actual.get("data_node_routed_table_1").getColumns().containsKey("id"));
- }
-
- @Test
public void assertLoadWithExistedTableName() throws SQLException {
- assertTrue(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), "data_node_routed_table_0", props).isPresent());
+ assertTrue(TableMetaDataLoader.load("data_node_routed_table_0",
+ databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), props).isPresent());
}
@Test
public void assertLoadWithNotExistedTableName() throws SQLException {
- assertFalse(SchemaMetaDataLoader.load(databaseType, dataSource, Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), "invalid_table", props).isPresent());
+ assertFalse(TableMetaDataLoader.load("invalid_table",
+ databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeRoutedFixtureRule()), props).isPresent());
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java
index a0c0118..67a6b56 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java
@@ -27,16 +27,16 @@ import org.apache.shardingsphere.infra.executor.sql.QueryResult;
import org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.StatementExecuteUnit;
import org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.executor.SQLExecutor;
import org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.executor.SQLExecutorCallback;
-import org.apache.shardingsphere.infra.metadata.schema.loader.SchemaMetaDataLoader;
-import org.apache.shardingsphere.infra.metadata.schema.refresh.spi.SchemaMetaDataNotifier;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.schema.loader.TableMetaDataLoader;
import org.apache.shardingsphere.infra.metadata.schema.model.physical.PhysicalSchemaMetaData;
import org.apache.shardingsphere.infra.metadata.schema.refresh.MetaDataRefreshStrategy;
import org.apache.shardingsphere.infra.metadata.schema.refresh.MetaDataRefreshStrategyFactory;
+import org.apache.shardingsphere.infra.metadata.schema.refresh.spi.SchemaMetaDataNotifier;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.infra.rule.DataNodeRoutedRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -84,7 +84,7 @@ public abstract class AbstractStatementExecutor {
if (refreshStrategy.isPresent()) {
Collection<String> routeDataSourceNames = routeUnits.stream().map(RouteUnit::getDataSourceMapper).map(RouteMapper::getLogicName).collect(Collectors.toList());
refreshStrategy.get().refreshMetaData(metaData.getSchema(), schemaContexts.getDatabaseType(), routeDataSourceNames,
- sqlStatement, tableName -> SchemaMetaDataLoader.load(schemaContexts.getDatabaseType(), dataSourceMap, metaData.getRuleMetaData().getRules(), tableName, schemaContexts.getProps()));
+ sqlStatement, tableName -> TableMetaDataLoader.load(tableName, schemaContexts.getDatabaseType(), dataSourceMap, metaData.getRuleMetaData().getRules(), schemaContexts.getProps()));
notifyPersistLogicMetaData(DefaultSchema.LOGIC_NAME, metaData.getSchema().getSchemaMetaData());
}
}
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 c2c3271..cd43231 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
@@ -30,14 +30,14 @@ import org.apache.shardingsphere.infra.executor.sql.log.SQLLogger;
import org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader;
import org.apache.shardingsphere.infra.merge.MergeEngine;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
-import org.apache.shardingsphere.infra.metadata.schema.loader.SchemaMetaDataLoader;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.schema.loader.TableMetaDataLoader;
import org.apache.shardingsphere.infra.metadata.schema.model.physical.PhysicalTableMetaData;
import org.apache.shardingsphere.infra.metadata.schema.refresh.MetaDataRefreshStrategy;
import org.apache.shardingsphere.infra.metadata.schema.refresh.MetaDataRefreshStrategyFactory;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.infra.rule.DataNodeRoutedRule;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.SQLExecuteEngine;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -111,8 +111,8 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
}
private Optional<PhysicalTableMetaData> loadTableMetaData(final String tableName) throws SQLException {
- return SchemaMetaDataLoader.load(ProxyContext.getInstance().getSchemaContexts().getDatabaseType(),
- metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), tableName, ProxyContext.getInstance().getSchemaContexts().getProps());
+ return TableMetaDataLoader.load(tableName, ProxyContext.getInstance().getSchemaContexts().getDatabaseType(),
+ metaData.getResource().getDataSources(), metaData.getRuleMetaData().getRules(), ProxyContext.getInstance().getSchemaContexts().getProps());
}
private BackendResponse merge(final SQLStatementContext<?> sqlStatementContext) throws SQLException {