strongduanmu commented on a change in pull request #11767:
URL: https://github.com/apache/shardingsphere/pull/11767#discussion_r689086804
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/TableMetaDataBuilder.java
##########
@@ -79,7 +83,36 @@
}
return Optional.empty();
}
-
+
+ /**
+ * Load logic table metadata.
+ *
+ * @param materials schema builder materials
+ * @param executorService executorService
+ * @return table meta data collection
+ * @throws SQLException SQL exception
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static Optional<Collection<TableMetaData>> loadLogicTables(final
SchemaBuilderMaterials materials, final ExecutorService executorService) throws
SQLException {
Review comment:
@tuichenchuxin Why add Optional for Collection result?
##########
File path:
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilder.java
##########
@@ -49,6 +58,71 @@
? TableMetaDataLoader.load(dataSourceMap.get(dataSourceName),
tableName, databaseType) : Optional.empty();
}
+ @Override
+ public Optional<Map<String, TableMetaData>> load(final Collection<String>
tableNames, final DatabaseType databaseType, final Map<String, DataSource>
dataSourceMap, final DataNodes dataNodes,
+ final EncryptRule rule,
final ConfigurationProperties props, final ExecutorService executorService)
throws SQLException {
+ Optional<DialectTableMetaDataLoader> loader =
findDialectTableMetaDataLoader(databaseType);
+ return loader.isPresent() ? loadByDialect(loader.get(), tableNames,
dataSourceMap, dataNodes, rule, executorService)
Review comment:
@tuichenchuxin Can we remove the method of default?
##########
File path:
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilder.java
##########
@@ -49,6 +58,71 @@
? TableMetaDataLoader.load(dataSourceMap.get(dataSourceName),
tableName, databaseType) : Optional.empty();
}
+ @Override
+ public Optional<Map<String, TableMetaData>> load(final Collection<String>
tableNames, final DatabaseType databaseType, final Map<String, DataSource>
dataSourceMap, final DataNodes dataNodes,
+ final EncryptRule rule,
final ConfigurationProperties props, final ExecutorService executorService)
throws SQLException {
+ Optional<DialectTableMetaDataLoader> loader =
findDialectTableMetaDataLoader(databaseType);
+ return loader.isPresent() ? loadByDialect(loader.get(), tableNames,
dataSourceMap, dataNodes, rule, executorService)
+ : loadByDefault(tableNames, dataSourceMap, dataNodes, rule,
databaseType);
+ }
+
+ private Optional<Map<String, TableMetaData>> loadByDialect(final
DialectTableMetaDataLoader dialectTableMetaDataLoader, final Collection<String>
tableNames,
+ final
Map<String, DataSource> dataSourceMap, final DataNodes dataNodes, final
EncryptRule rule,
+ final
ExecutorService executorService) throws SQLException {
+ if (!tableNames.stream().allMatch(tableName ->
rule.findEncryptTable(tableName).isPresent())) {
Review comment:
@tuichenchuxin Is it better to load the table where the encryption rule
exists?
##########
File path:
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilder.java
##########
@@ -49,6 +58,71 @@
? TableMetaDataLoader.load(dataSourceMap.get(dataSourceName),
tableName, databaseType) : Optional.empty();
}
+ @Override
+ public Optional<Map<String, TableMetaData>> load(final Collection<String>
tableNames, final DatabaseType databaseType, final Map<String, DataSource>
dataSourceMap, final DataNodes dataNodes,
+ final EncryptRule rule,
final ConfigurationProperties props, final ExecutorService executorService)
throws SQLException {
+ Optional<DialectTableMetaDataLoader> loader =
findDialectTableMetaDataLoader(databaseType);
+ return loader.isPresent() ? loadByDialect(loader.get(), tableNames,
dataSourceMap, dataNodes, rule, executorService)
+ : loadByDefault(tableNames, dataSourceMap, dataNodes, rule,
databaseType);
+ }
+
+ private Optional<Map<String, TableMetaData>> loadByDialect(final
DialectTableMetaDataLoader dialectTableMetaDataLoader, final Collection<String>
tableNames,
+ final
Map<String, DataSource> dataSourceMap, final DataNodes dataNodes, final
EncryptRule rule,
+ final
ExecutorService executorService) throws SQLException {
+ if (!tableNames.stream().allMatch(tableName ->
rule.findEncryptTable(tableName).isPresent())) {
+ return Optional.empty();
+ }
+ Map<String, TableMetaData> result = new LinkedHashMap<>();
+ Map<String, List<String>> dataSourceTablesMap = new LinkedHashMap<>();
+ for (String tableName : tableNames) {
Review comment:
@tuichenchuxin It may be better to extract as a 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]