You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/01/29 10:33:57 UTC

[shardingsphere] branch master updated: Remove useless SchemaRulesBuilder.buildRules() (#15182)

This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 a133597  Remove useless SchemaRulesBuilder.buildRules() (#15182)
a133597 is described below

commit a13359760ad66798e4f152c1be71d5f31d825105
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Jan 29 18:32:59 2022 +0800

    Remove useless SchemaRulesBuilder.buildRules() (#15182)
    
    * Remove useless SchemaRulesBuilder.buildRules()
    
    * Fix test case
---
 .../rule/builder/schema/SchemaRulesBuilder.java    | 26 ----------------------
 .../mode/manager/ContextManager.java               |  8 +++----
 .../mode/manager/ContextManagerTest.java           |  1 -
 3 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java
index 8096402..48e25be 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilder.java
@@ -22,24 +22,17 @@ import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.function.DistributedRuleConfiguration;
 import org.apache.shardingsphere.infra.config.function.EnhancedRuleConfiguration;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.config.schema.SchemaConfiguration;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeRecognizer;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
 
-import javax.sql.DataSource;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Properties;
 import java.util.stream.Collectors;
 
 /**
@@ -55,25 +48,6 @@ public final class SchemaRulesBuilder {
     
     /**
      * Build rules.
-     * 
-     * @param schemaConfigs schema configuration map
-     * @param props properties
-     * @return ShardingSphere rules
-     */
-    public static Map<String, Collection<ShardingSphereRule>> buildRules(final Map<String, ? extends SchemaConfiguration> schemaConfigs, final Properties props) {
-        Map<String, Collection<ShardingSphereRule>> result = new HashMap<>(schemaConfigs.size(), 1);
-        for (Entry<String, ? extends SchemaConfiguration> entry : schemaConfigs.entrySet()) {
-            Map<String, DataSource> dataSourceMap = entry.getValue().getDataSources();
-            Collection<RuleConfiguration> ruleConfigs = entry.getValue().getRuleConfigurations();
-            DatabaseType databaseType = DatabaseTypeRecognizer.getDatabaseType(dataSourceMap.values());
-            result.put(entry.getKey(), 
-                    buildRules(new SchemaRulesBuilderMaterials(entry.getKey(), ruleConfigs, databaseType, dataSourceMap, new ConfigurationProperties(null == props ? new Properties() : props))));
-        }
-        return result;
-    }
-    
-    /**
-     * Build rules.
      *
      * @param materials rules builder materials
      * @return built rules
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
index eee4add..470b928 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
@@ -41,7 +41,6 @@ import org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader;
 import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder;
-import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
 import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine;
@@ -344,10 +343,9 @@ public final class ContextManager implements AutoCloseable {
     }
     
     private ShardingSphereSchema loadActualSchema(final String schemaName) throws SQLException {
-        Map<String, SchemaConfiguration> schemaRuleConfigs = Collections.singletonMap(schemaName, new DataSourceProvidedSchemaConfiguration(
-                metaDataContexts.getMetaData(schemaName).getResource().getDataSources(), metaDataContexts.getMetaData(schemaName).getRuleMetaData().getConfigurations()));
-        Map<String, Collection<ShardingSphereRule>> rules = SchemaRulesBuilder.buildRules(schemaRuleConfigs, metaDataContexts.getProps().getProps());
-        return SchemaLoader.load(schemaRuleConfigs.get(schemaName).getDataSources(), rules.get(schemaName), metaDataContexts.getProps().getProps());
+        Map<String, DataSource> dataSourceMap = metaDataContexts.getMetaData(schemaName).getResource().getDataSources();
+        Collection<ShardingSphereRule> rules = metaDataContexts.getMetaDataMap().get(schemaName).getRuleMetaData().getRules();
+        return SchemaLoader.load(dataSourceMap, rules, metaDataContexts.getProps().getProps());
     }
     
     private Collection<DataSource> getPendingClosedDataSources(final String schemaName, final Map<String, DataSourceProperties> dataSourcePropsMap) {
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
index 818ae3b..acdaac1 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
@@ -416,7 +416,6 @@ public final class ContextManagerTest {
         ShardingSphereResource originalResource = mock(ShardingSphereResource.class);
         when(originalResource.getDataSources()).thenReturn(dataSources);
         ShardingSphereRuleMetaData originalRuleMetaData = mock(ShardingSphereRuleMetaData.class);
-        when(originalRuleMetaData.getConfigurations()).thenReturn(new LinkedList<>());
         ShardingSphereMetaData originalMetaData = mock(ShardingSphereMetaData.class);
         when(originalMetaData.getResource()).thenReturn(originalResource);
         when(originalMetaData.getRuleMetaData()).thenReturn(originalRuleMetaData);