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

panjuan 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 f20cc5248f4 Refactor ContextManager.createMetaDataContexts (#18855)
f20cc5248f4 is described below

commit f20cc5248f476adaed97397216c2d7a42c0d7682
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jul 5 13:54:00 2022 +0800

    Refactor ContextManager.createMetaDataContexts (#18855)
    
    * For code format
    
    * Refactor ContextManager.createMetaDataContexts
---
 .../ShardingRuleConfigurationYamlSwapperTest.java  |  2 +-
 .../mode/manager/ContextManager.java               | 22 ++--------------------
 2 files changed, 3 insertions(+), 21 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
index 0f17ed1a6e1..67ff0e399e0 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
@@ -65,7 +65,7 @@ public final class ShardingRuleConfigurationYamlSwapperTest {
     
     @Mock
     private KeyGenerateStrategyConfigurationYamlSwapper 
keyGenerateStrategyConfigurationYamlSwapper;
-
+    
     @Mock
     private ShardingAuditStrategyConfigurationYamlSwapper 
shardingAuditStrategyConfigurationYamlSwapper;
     
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 2fd3705e12c..42b1b99a4a2 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
@@ -247,7 +247,7 @@ public final class ContextManager implements AutoCloseable {
     public void alterRuleConfiguration(final String databaseName, final 
Collection<RuleConfiguration> ruleConfigs) {
         try {
             Collection<ResourceHeldRule> staleResourceHeldRules = 
getStaleResourceHeldRules(databaseName);
-            metaDataContexts = createMetaDataContexts(databaseName, 
ruleConfigs);
+            metaDataContexts = createMetaDataContexts(databaseName, null, 
ruleConfigs);
             persistMetaData(metaDataContexts);
             
staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResources);
         } catch (final SQLException ex) {
@@ -266,7 +266,7 @@ public final class ContextManager implements AutoCloseable {
         try {
             Collection<ResourceHeldRule> staleResourceHeldRules = 
getStaleResourceHeldRules(databaseName);
             SwitchingResource switchingResource = new 
ResourceSwitchManager().create(metaDataContexts.getMetaData().getDatabases().get(databaseName).getResource(),
 dataSourcePropsMap);
-            metaDataContexts = createMetaDataContexts(databaseName, 
switchingResource);
+            metaDataContexts = createMetaDataContexts(databaseName, 
switchingResource, null);
             persistMetaData(metaDataContexts);
             
staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResources);
             switchingResource.closeStaleDataSources();
@@ -304,24 +304,6 @@ public final class ContextManager implements AutoCloseable 
{
         return result;
     }
     
-    private MetaDataContexts createMetaDataContexts(final String databaseName, 
final Collection<RuleConfiguration> ruleConfigs) throws SQLException {
-        Map<String, ShardingSphereDatabase> changedDatabases = 
createChangedDatabases(databaseName, null, ruleConfigs);
-        ShardingSphereRuleMetaData changedGlobalMetaData = new 
ShardingSphereRuleMetaData(
-                
GlobalRulesBuilder.buildRules(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations(),
 changedDatabases, instanceContext));
-        return new 
MetaDataContexts(metaDataContexts.getPersistService().orElse(null),
-                new ShardingSphereMetaData(changedDatabases, 
changedGlobalMetaData, metaDataContexts.getMetaData().getProps()),
-                OptimizerContextFactory.create(changedDatabases, 
changedGlobalMetaData));
-    }
-    
-    private MetaDataContexts createMetaDataContexts(final String databaseName, 
final SwitchingResource switchingResource) throws SQLException {
-        Map<String, ShardingSphereDatabase> changedDatabases = 
createChangedDatabases(databaseName, switchingResource, null);
-        ShardingSphereRuleMetaData changedGlobalMetaData = new 
ShardingSphereRuleMetaData(
-                
GlobalRulesBuilder.buildRules(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations(),
 changedDatabases, instanceContext));
-        return new 
MetaDataContexts(metaDataContexts.getPersistService().orElse(null),
-                new ShardingSphereMetaData(changedDatabases, 
changedGlobalMetaData, metaDataContexts.getMetaData().getProps()),
-                OptimizerContextFactory.create(changedDatabases, 
changedGlobalMetaData));
-    }
-    
     private MetaDataContexts createMetaDataContexts(final String databaseName, 
final SwitchingResource switchingResource, final Collection<RuleConfiguration> 
ruleConfigs) throws SQLException {
         Map<String, ShardingSphereDatabase> changedDatabases = 
createChangedDatabases(databaseName, switchingResource, ruleConfigs);
         ShardingSphereRuleMetaData changedGlobalMetaData = new 
ShardingSphereRuleMetaData(

Reply via email to