strongduanmu commented on a change in pull request #11895:
URL: https://github.com/apache/shardingsphere/pull/11895#discussion_r691903083
##########
File path:
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilder.java
##########
@@ -20,54 +20,35 @@
import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.datanode.DataNodes;
import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
import
org.apache.shardingsphere.infra.metadata.schema.builder.loader.TableMetaDataLoader;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.spi.DialectTableMetaDataLoader;
import
org.apache.shardingsphere.infra.metadata.schema.builder.spi.RuleBasedTableMetaDataBuilder;
import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import javax.sql.DataSource;
import java.sql.SQLException;
-
-import java.util.Collections;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Optional;
-import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
/**
* Table meta data builder for encrypt.
*/
public final class EncryptTableMetaDataBuilder implements
RuleBasedTableMetaDataBuilder<EncryptRule> {
- // TODO remove this method
- @Override
- public Optional<TableMetaData> load(final String tableName, final
DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final
DataNodes dataNodes,
- final EncryptRule encryptRule, final
ConfigurationProperties props) throws SQLException {
- String dataSourceName =
dataNodes.getDataNodes(tableName).stream().map(DataNode::getDataSourceName).findFirst().orElseGet(()
-> dataSourceMap.keySet().iterator().next());
- return encryptRule.findEncryptTable(tableName).isPresent()
- ? TableMetaDataLoader.load(dataSourceMap.get(dataSourceName),
tableName, databaseType) : Optional.empty();
- }
-
@Override
- public Map<String, TableMetaData> load(final Collection<String>
tableNames, final EncryptRule rule, final SchemaBuilderMaterials materials,
- final ExecutorService
executorService) throws SQLException {
- Optional<DialectTableMetaDataLoader> loader =
TableMetaDataLoader.findDialectTableMetaDataLoader(materials.getDatabaseType());
+ public Map<String, TableMetaData> load(final Collection<String>
tableNames, final EncryptRule rule, final SchemaBuilderMaterials materials)
throws SQLException {
Collection<String> loadTableNames = tableNames.stream().filter(each ->
rule.findEncryptTable(each).isPresent()).collect(Collectors.toList());
if (loadTableNames.isEmpty()) {
return Collections.emptyMap();
}
- Map<String, Collection<String>> dataSourceTables =
getTableGroup(loadTableNames, materials);
- return loader.isPresent() ? TableMetaDataLoader.load(loader.get(),
dataSourceTables, materials.getDataSourceMap(), executorService)
- : TableMetaDataLoader.load(dataSourceTables,
materials.getDatabaseType(), materials.getDataSourceMap());
+ return TableMetaDataLoader.load(getTableGroup(loadTableNames,
materials), materials.getDatabaseType(), materials.getDataSourceMap());
Review comment:
@tuichenchuxin Can the getTableGroup methods in sharding, encrypt, and
single be extracted as public methods?
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilder.java
##########
@@ -55,73 +55,52 @@
* @throws SQLException SQL exception
*/
public static Optional<TableMetaData> build(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- Optional<TableMetaData> tableMetaData = load(tableName, materials);
- return tableMetaData.map(optional -> decorate(tableName, optional,
materials.getRules()));
+ return Optional.ofNullable(load(Collections.singleton(tableName),
materials).getOrDefault(tableName, null)).map(tableMetaData ->
decorate(tableName, tableMetaData, materials.getRules()));
}
/**
- * Load physical table metadata.
- *
- * @param tableName table name
- * @param materials schema builder materials
- * @return table meta data
- * @throws SQLException SQL exception
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static Optional<TableMetaData> load(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- DataNodes dataNodes = new DataNodes(materials.getRules());
- for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
- if (entry.getKey() instanceof TableContainedRule) {
- TableContainedRule rule = (TableContainedRule) entry.getKey();
- RuleBasedTableMetaDataBuilder loader = entry.getValue();
- Optional<TableMetaData> result = loader.load(tableName,
materials.getDatabaseType(), materials.getDataSourceMap(), dataNodes, rule,
materials.getProps());
- if (result.isPresent()) {
- TableMetaData tableMetaData = new TableMetaData(tableName,
result.get().getColumns().values(), result.get().getIndexes().values());
- return Optional.of(tableMetaData);
- }
- }
- }
- return Optional.empty();
- }
-
- /**
- * Load logic table metadata.
+ * Load all table metadata.
Review comment:
@tuichenchuxin `Load table metadata` is better.
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingTableMetaDataBuilder.java
##########
@@ -65,37 +63,14 @@
private static final int FUTURE_GET_TIME_OUT_SECOND = 5;
- // TODO remove this method
- @Override
- public Optional<TableMetaData> 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();
- }
- boolean isCheckingMetaData =
props.getValue(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED);
- int maxConnectionsSizePerQuery =
props.getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
- TableRule tableRule = rule.getTableRule(tableName);
- if (!isCheckingMetaData) {
- DataNode dataNode =
dataNodes.getDataNodes(tableName).iterator().next();
- return
TableMetaDataLoader.load(dataSourceMap.get(dataNode.getDataSourceName()),
dataNode.getTableName(), databaseType);
- }
- Map<String, TableMetaData> actualTableMetaDataMap =
parallelLoadTables(databaseType, dataSourceMap, dataNodes, tableName,
maxConnectionsSizePerQuery);
- if (actualTableMetaDataMap.isEmpty()) {
- return Optional.empty();
- }
- checkUniformed(tableRule.getLogicTable(), actualTableMetaDataMap,
rule);
- return Optional.of(actualTableMetaDataMap.values().iterator().next());
- }
-
@Override
- public Map<String, TableMetaData> load(final Collection<String>
tableNames, final ShardingRule rule, final SchemaBuilderMaterials materials,
- final ExecutorService
executorService) throws SQLException {
+ public Map<String, TableMetaData> load(final Collection<String>
tableNames, final ShardingRule rule, final SchemaBuilderMaterials materials)
throws SQLException {
Collection<String> loadTableNames = tableNames.stream().filter(each ->
rule.findTableRule(each).isPresent()).collect(Collectors.toList());
if (loadTableNames.isEmpty()) {
return Collections.emptyMap();
}
boolean isCheckingMetaData =
materials.getProps().getValue(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED);
- return isCheckingMetaData ? loadWithCheck(loadTableNames, rule,
materials) : loadWithOutCheck(loadTableNames, rule, materials, executorService);
+ return isCheckingMetaData ? loadWithCheck(loadTableNames, rule,
materials) : loadWithOutCheck(loadTableNames, rule, materials);
Review comment:
@tuichenchuxin `loadWithoutCheck` may be better.
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilder.java
##########
@@ -55,73 +55,52 @@
* @throws SQLException SQL exception
*/
public static Optional<TableMetaData> build(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- Optional<TableMetaData> tableMetaData = load(tableName, materials);
- return tableMetaData.map(optional -> decorate(tableName, optional,
materials.getRules()));
+ return Optional.ofNullable(load(Collections.singleton(tableName),
materials).getOrDefault(tableName, null)).map(tableMetaData ->
decorate(tableName, tableMetaData, materials.getRules()));
Review comment:
@tuichenchuxin Please extract a variable to improve code readability.
BTW, `getOrDefault` is better replaced by `get`.
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilder.java
##########
@@ -55,73 +55,52 @@
* @throws SQLException SQL exception
*/
public static Optional<TableMetaData> build(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- Optional<TableMetaData> tableMetaData = load(tableName, materials);
- return tableMetaData.map(optional -> decorate(tableName, optional,
materials.getRules()));
+ return Optional.ofNullable(load(Collections.singleton(tableName),
materials).getOrDefault(tableName, null)).map(tableMetaData ->
decorate(tableName, tableMetaData, materials.getRules()));
}
/**
- * Load physical table metadata.
- *
- * @param tableName table name
- * @param materials schema builder materials
- * @return table meta data
- * @throws SQLException SQL exception
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static Optional<TableMetaData> load(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- DataNodes dataNodes = new DataNodes(materials.getRules());
- for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
- if (entry.getKey() instanceof TableContainedRule) {
- TableContainedRule rule = (TableContainedRule) entry.getKey();
- RuleBasedTableMetaDataBuilder loader = entry.getValue();
- Optional<TableMetaData> result = loader.load(tableName,
materials.getDatabaseType(), materials.getDataSourceMap(), dataNodes, rule,
materials.getProps());
- if (result.isPresent()) {
- TableMetaData tableMetaData = new TableMetaData(tableName,
result.get().getColumns().values(), result.get().getIndexes().values());
- return Optional.of(tableMetaData);
- }
- }
- }
- return Optional.empty();
- }
-
- /**
- * Load logic table metadata.
+ * Load all table metadata.
*
+ * @param tableNames table name collection
* @param materials schema builder materials
- * @param executorService executorService
- * @return table meta data collection
+ * @return table meta data map
* @throws SQLException SQL exception
*/
@SuppressWarnings("rawtypes")
- public static Collection<TableMetaData> loadLogicTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService) throws
SQLException {
- Collection<TableMetaData> result = new LinkedList<>();
+ public static Map<String, TableMetaData> load(final Collection<String>
tableNames, final SchemaBuilderMaterials materials) throws SQLException {
+ Map<String, TableMetaData> result = new LinkedHashMap<>();
for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
if (entry.getKey() instanceof TableContainedRule) {
- loadTableContainedRuleTables(materials, executorService,
result, entry);
+ loadTableContainedRuleTables(tableNames, materials, result,
entry);
}
}
return result;
}
@SuppressWarnings({"unchecked", "rawtypes"})
- private static void loadTableContainedRuleTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService, final
Collection<TableMetaData> result,
+ private static void loadTableContainedRuleTables(final Collection<String>
tableNames, final SchemaBuilderMaterials materials, final Map<String,
TableMetaData> result,
final
Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> ruleBuilderEntry)
throws SQLException {
TableContainedRule rule = (TableContainedRule)
ruleBuilderEntry.getKey();
RuleBasedTableMetaDataBuilder loader = ruleBuilderEntry.getValue();
- Collection<String> loadedTables =
result.stream().map(TableMetaData::getName).collect(Collectors.toSet());
- Collection<String> needLoadTables =
rule.getTables().stream().filter(each ->
!loadedTables.contains(each)).collect(Collectors.toList());
+ Collection<String> needLoadTables = tableNames.stream().filter(each ->
rule.getTables().contains(each)).filter(each ->
!result.containsKey(each)).collect(Collectors.toList());
if (!needLoadTables.isEmpty()) {
- Map<String, TableMetaData> tableMetaDataMap =
loader.load(needLoadTables, rule, materials, executorService);
- result.addAll(tableMetaDataMap.entrySet().stream()
- .map(entry -> new TableMetaData(entry.getKey(),
entry.getValue().getColumns().values(),
entry.getValue().getIndexes().values())).collect(Collectors.toList()));
+ Map<String, TableMetaData> tableMetaDataMap =
loader.load(needLoadTables, rule, materials);
+ Map<String, TableMetaData> metaDataMap =
changeTableNameIfLogic(tableMetaDataMap);
+ result.putAll(metaDataMap);
}
}
+ private static Map<String, TableMetaData> changeTableNameIfLogic(final
Map<String, TableMetaData> tableMetaDataMap) {
Review comment:
@tuichenchuxin `decorateTableMetaData` may be better.
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilder.java
##########
@@ -55,73 +55,52 @@
* @throws SQLException SQL exception
*/
public static Optional<TableMetaData> build(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- Optional<TableMetaData> tableMetaData = load(tableName, materials);
- return tableMetaData.map(optional -> decorate(tableName, optional,
materials.getRules()));
+ return Optional.ofNullable(load(Collections.singleton(tableName),
materials).getOrDefault(tableName, null)).map(tableMetaData ->
decorate(tableName, tableMetaData, materials.getRules()));
}
/**
- * Load physical table metadata.
- *
- * @param tableName table name
- * @param materials schema builder materials
- * @return table meta data
- * @throws SQLException SQL exception
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static Optional<TableMetaData> load(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- DataNodes dataNodes = new DataNodes(materials.getRules());
- for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
- if (entry.getKey() instanceof TableContainedRule) {
- TableContainedRule rule = (TableContainedRule) entry.getKey();
- RuleBasedTableMetaDataBuilder loader = entry.getValue();
- Optional<TableMetaData> result = loader.load(tableName,
materials.getDatabaseType(), materials.getDataSourceMap(), dataNodes, rule,
materials.getProps());
- if (result.isPresent()) {
- TableMetaData tableMetaData = new TableMetaData(tableName,
result.get().getColumns().values(), result.get().getIndexes().values());
- return Optional.of(tableMetaData);
- }
- }
- }
- return Optional.empty();
- }
-
- /**
- * Load logic table metadata.
+ * Load all table metadata.
*
+ * @param tableNames table name collection
* @param materials schema builder materials
- * @param executorService executorService
- * @return table meta data collection
+ * @return table meta data map
* @throws SQLException SQL exception
*/
@SuppressWarnings("rawtypes")
- public static Collection<TableMetaData> loadLogicTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService) throws
SQLException {
- Collection<TableMetaData> result = new LinkedList<>();
+ public static Map<String, TableMetaData> load(final Collection<String>
tableNames, final SchemaBuilderMaterials materials) throws SQLException {
+ Map<String, TableMetaData> result = new LinkedHashMap<>();
for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
if (entry.getKey() instanceof TableContainedRule) {
- loadTableContainedRuleTables(materials, executorService,
result, entry);
+ loadTableContainedRuleTables(tableNames, materials, result,
entry);
Review comment:
@tuichenchuxin The method is called loadTableContainedRuleTables, and it
is better to have a return value instead of returning void.
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoader.java
##########
@@ -110,21 +97,38 @@
}
/**
- * Load table meta data by executor service.
+ * Load table meta data.
*
- * @param loader dialect table meta data loader
- * @param dataSourceTables data source table names map
+ * @param dataSourceTable data source table name map
+ * @param databaseType database type
* @param dataSourceMap data source map
- * @param executorService executor service
* @return table meta data map
* @throws SQLException SQL exception
*/
- public static Map<String, TableMetaData> load(final
DialectTableMetaDataLoader loader, final Map<String, Collection<String>>
dataSourceTables,
- final Map<String,
DataSource> dataSourceMap, final ExecutorService executorService) throws
SQLException {
+ public static Map<String, TableMetaData> load(final Map<String,
Collection<String>> dataSourceTable, final DatabaseType databaseType,
+ final Map<String,
DataSource> dataSourceMap) throws SQLException {
+ Optional<DialectTableMetaDataLoader> dialectTableMetaDataLoader =
findDialectTableMetaDataLoader(databaseType);
Review comment:
@tuichenchuxin We may need a TableMetaDataLoaderEngine to handle this
logic.
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilder.java
##########
@@ -55,73 +55,52 @@
* @throws SQLException SQL exception
*/
public static Optional<TableMetaData> build(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- Optional<TableMetaData> tableMetaData = load(tableName, materials);
- return tableMetaData.map(optional -> decorate(tableName, optional,
materials.getRules()));
+ return Optional.ofNullable(load(Collections.singleton(tableName),
materials).getOrDefault(tableName, null)).map(tableMetaData ->
decorate(tableName, tableMetaData, materials.getRules()));
}
/**
- * Load physical table metadata.
- *
- * @param tableName table name
- * @param materials schema builder materials
- * @return table meta data
- * @throws SQLException SQL exception
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static Optional<TableMetaData> load(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- DataNodes dataNodes = new DataNodes(materials.getRules());
- for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
- if (entry.getKey() instanceof TableContainedRule) {
- TableContainedRule rule = (TableContainedRule) entry.getKey();
- RuleBasedTableMetaDataBuilder loader = entry.getValue();
- Optional<TableMetaData> result = loader.load(tableName,
materials.getDatabaseType(), materials.getDataSourceMap(), dataNodes, rule,
materials.getProps());
- if (result.isPresent()) {
- TableMetaData tableMetaData = new TableMetaData(tableName,
result.get().getColumns().values(), result.get().getIndexes().values());
- return Optional.of(tableMetaData);
- }
- }
- }
- return Optional.empty();
- }
-
- /**
- * Load logic table metadata.
+ * Load all table metadata.
*
+ * @param tableNames table name collection
* @param materials schema builder materials
- * @param executorService executorService
- * @return table meta data collection
+ * @return table meta data map
* @throws SQLException SQL exception
*/
@SuppressWarnings("rawtypes")
- public static Collection<TableMetaData> loadLogicTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService) throws
SQLException {
- Collection<TableMetaData> result = new LinkedList<>();
+ public static Map<String, TableMetaData> load(final Collection<String>
tableNames, final SchemaBuilderMaterials materials) throws SQLException {
+ Map<String, TableMetaData> result = new LinkedHashMap<>();
for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
if (entry.getKey() instanceof TableContainedRule) {
- loadTableContainedRuleTables(materials, executorService,
result, entry);
+ loadTableContainedRuleTables(tableNames, materials, result,
entry);
}
}
return result;
}
@SuppressWarnings({"unchecked", "rawtypes"})
- private static void loadTableContainedRuleTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService, final
Collection<TableMetaData> result,
+ private static void loadTableContainedRuleTables(final Collection<String>
tableNames, final SchemaBuilderMaterials materials, final Map<String,
TableMetaData> result,
final
Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> ruleBuilderEntry)
throws SQLException {
TableContainedRule rule = (TableContainedRule)
ruleBuilderEntry.getKey();
Review comment:
@tuichenchuxin Can type conversion be performed at the method call?
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilder.java
##########
@@ -55,73 +55,52 @@
* @throws SQLException SQL exception
*/
public static Optional<TableMetaData> build(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- Optional<TableMetaData> tableMetaData = load(tableName, materials);
- return tableMetaData.map(optional -> decorate(tableName, optional,
materials.getRules()));
+ return Optional.ofNullable(load(Collections.singleton(tableName),
materials).getOrDefault(tableName, null)).map(tableMetaData ->
decorate(tableName, tableMetaData, materials.getRules()));
}
/**
- * Load physical table metadata.
- *
- * @param tableName table name
- * @param materials schema builder materials
- * @return table meta data
- * @throws SQLException SQL exception
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static Optional<TableMetaData> load(final String tableName, final
SchemaBuilderMaterials materials) throws SQLException {
- DataNodes dataNodes = new DataNodes(materials.getRules());
- for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
- if (entry.getKey() instanceof TableContainedRule) {
- TableContainedRule rule = (TableContainedRule) entry.getKey();
- RuleBasedTableMetaDataBuilder loader = entry.getValue();
- Optional<TableMetaData> result = loader.load(tableName,
materials.getDatabaseType(), materials.getDataSourceMap(), dataNodes, rule,
materials.getProps());
- if (result.isPresent()) {
- TableMetaData tableMetaData = new TableMetaData(tableName,
result.get().getColumns().values(), result.get().getIndexes().values());
- return Optional.of(tableMetaData);
- }
- }
- }
- return Optional.empty();
- }
-
- /**
- * Load logic table metadata.
+ * Load all table metadata.
*
+ * @param tableNames table name collection
* @param materials schema builder materials
- * @param executorService executorService
- * @return table meta data collection
+ * @return table meta data map
* @throws SQLException SQL exception
*/
@SuppressWarnings("rawtypes")
- public static Collection<TableMetaData> loadLogicTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService) throws
SQLException {
- Collection<TableMetaData> result = new LinkedList<>();
+ public static Map<String, TableMetaData> load(final Collection<String>
tableNames, final SchemaBuilderMaterials materials) throws SQLException {
+ Map<String, TableMetaData> result = new LinkedHashMap<>();
for (Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> entry :
OrderedSPIRegistry.getRegisteredServices(RuleBasedTableMetaDataBuilder.class,
materials.getRules()).entrySet()) {
if (entry.getKey() instanceof TableContainedRule) {
- loadTableContainedRuleTables(materials, executorService,
result, entry);
+ loadTableContainedRuleTables(tableNames, materials, result,
entry);
}
}
return result;
}
@SuppressWarnings({"unchecked", "rawtypes"})
- private static void loadTableContainedRuleTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService, final
Collection<TableMetaData> result,
+ private static void loadTableContainedRuleTables(final Collection<String>
tableNames, final SchemaBuilderMaterials materials, final Map<String,
TableMetaData> result,
final
Entry<ShardingSphereRule, RuleBasedTableMetaDataBuilder> ruleBuilderEntry)
throws SQLException {
TableContainedRule rule = (TableContainedRule)
ruleBuilderEntry.getKey();
RuleBasedTableMetaDataBuilder loader = ruleBuilderEntry.getValue();
- Collection<String> loadedTables =
result.stream().map(TableMetaData::getName).collect(Collectors.toSet());
- Collection<String> needLoadTables =
rule.getTables().stream().filter(each ->
!loadedTables.contains(each)).collect(Collectors.toList());
+ Collection<String> needLoadTables = tableNames.stream().filter(each ->
rule.getTables().contains(each)).filter(each ->
!result.containsKey(each)).collect(Collectors.toList());
Review comment:
@tuichenchuxin This filtering logic can be handled outside the method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]