You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/17 02:22:51 UTC

[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #12483: Refactor TableMetaDataBuilder And SchemaBuilder

strongduanmu commented on a change in pull request #12483:
URL: https://github.com/apache/shardingsphere/pull/12483#discussion_r710671973



##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
##########
@@ -39,42 +36,30 @@
 public final class SchemaBuilder {
     
     /**
-     * Build sharding sphere schema.
+     * Build schema for kernel.
      *
-     * @param materials schema builder materials
+     * @param tableMetaDatas table meta datas
+     * @param rules sharding sphere rule
      * @return sharding sphere schema
-     * @throws SQLException SQL exception
      */
-    public static ShardingSphereSchema build(final SchemaBuilderMaterials materials) throws SQLException {
-        Collection<String> allTableNames = materials.getRules().stream().filter(each -> each instanceof TableContainedRule)
-                .flatMap(shardingSphereRule -> ((TableContainedRule) shardingSphereRule).getTables().stream()).collect(Collectors.toSet());
-        return new ShardingSphereSchema(TableMetaDataBuilder.load(allTableNames, materials));
+    public static ShardingSphereSchema buildForKernel(final Collection<TableMetaData> tableMetaDatas, final Collection<ShardingSphereRule> rules) {

Review comment:
       @tuichenchuxin Do you think `buildKernelSchema` and `buildFederateSchema` is better?

##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
##########
@@ -39,42 +36,30 @@
 public final class SchemaBuilder {
     
     /**
-     * Build sharding sphere schema.
+     * Build schema for kernel.
      *
-     * @param materials schema builder materials
+     * @param tableMetaDatas table meta datas
+     * @param rules sharding sphere rule
      * @return sharding sphere schema
-     * @throws SQLException SQL exception
      */
-    public static ShardingSphereSchema build(final SchemaBuilderMaterials materials) throws SQLException {
-        Collection<String> allTableNames = materials.getRules().stream().filter(each -> each instanceof TableContainedRule)
-                .flatMap(shardingSphereRule -> ((TableContainedRule) shardingSphereRule).getTables().stream()).collect(Collectors.toSet());
-        return new ShardingSphereSchema(TableMetaDataBuilder.load(allTableNames, materials));
+    public static ShardingSphereSchema buildForKernel(final Collection<TableMetaData> tableMetaDatas, final Collection<ShardingSphereRule> rules) {
+        return buildSchema(tableMetaDatas, each -> TableMetaDataBuilder.decorateForKernel(each, rules));
     }
     
     /**
-     * Decorate sharding sphere schema.
+     * Build schema for Federate.
      *
-     * @param schema sharding sphere schema
-     * @param materials schema builder materials
+     * @param tableMetaDatas table meta datas
+     * @param rules sharding sphere rule
      * @return sharding sphere schema
      */
-    public static ShardingSphereSchema decorate(final ShardingSphereSchema schema, final SchemaBuilderMaterials materials) {
-        Map<String, TableMetaData> tableMetaDataMap = schema.getTables().values().stream().collect(Collectors
-            .toMap(TableMetaData::getName, Function.identity(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
-        for (ShardingSphereRule each : materials.getRules()) {
-            if (each instanceof TableContainedRule) {
-                decorateByRule(tableMetaDataMap, each);
-            }
-        }
-        return new ShardingSphereSchema(tableMetaDataMap);
+    public static ShardingSphereSchema buildForFederate(final Collection<TableMetaData> tableMetaDatas, final Collection<ShardingSphereRule> rules) {
+        return buildSchema(tableMetaDatas, each -> TableMetaDataBuilder.decorateForFederate(each, rules));

Review comment:
       @tuichenchuxin Same suggestions with the previous one.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org