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 9697149  Simplfy AuthorityRuleConfiguration (#9937)
9697149 is described below

commit 969714916777266493f11859dce773aadfa26ee8
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Apr 5 15:18:27 2021 +0800

    Simplfy AuthorityRuleConfiguration (#9937)
---
 .../api/config/AuthorityRuleConfiguration.java         |  4 +---
 .../shardingsphere/authority/rule/AuthorityRule.java   |  4 +---
 .../yaml/config/YamlAuthorityRuleConfiguration.java    |  5 +----
 .../swapper/AuthorityRuleConfigurationYamlSwapper.java | 18 ++----------------
 4 files changed, 5 insertions(+), 26 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
index ae1ac00..5a53460 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
@@ -22,8 +22,6 @@ import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 
-import java.util.Map;
-
 /**
  * Authority rule configuration.
  */
@@ -31,5 +29,5 @@ import java.util.Map;
 @Getter
 public final class AuthorityRuleConfiguration implements RuleConfiguration {
     
-    private final Map<String, ShardingSphereAlgorithmConfiguration> 
privilegeLoaders;
+    private final ShardingSphereAlgorithmConfiguration privilegeLoader;
 }
diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
index b047b74..6c1cd3d 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.authority.rule;
 
-import com.google.common.base.Preconditions;
 import 
org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration;
 import org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm;
 import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
@@ -43,8 +42,7 @@ public final class AuthorityRule implements 
ShardingSphereRule {
     
     public AuthorityRule(final AuthorityRuleConfiguration config, final String 
schemaName, final DatabaseType databaseType, 
                          final Collection<DataSource> dataSources, final 
Collection<ShardingSphereUser> users, final Collection<ShardingSphereRule> 
builtRules) {
-        Preconditions.checkState(1 == config.getPrivilegeLoaders().size(), 
"Only support one privilege loader.");
-        PrivilegeLoadAlgorithm privilegeLoader = 
ShardingSphereAlgorithmFactory.createAlgorithm(config.getPrivilegeLoaders().values().iterator().next(),
 PrivilegeLoadAlgorithm.class);
+        PrivilegeLoadAlgorithm privilegeLoader = 
ShardingSphereAlgorithmFactory.createAlgorithm(config.getPrivilegeLoader(), 
PrivilegeLoadAlgorithm.class);
         Authentication authentication = null == 
AuthenticationContext.getInstance().getAuthentication() ? new 
DefaultAuthentication() : 
AuthenticationContext.getInstance().getAuthentication();
         authentication.init(privilegeLoader.load(schemaName, databaseType, 
dataSources, builtRules, users));
         AuthenticationContext.getInstance().init(authentication);
diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
index 9d3ca34..97113e2 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
@@ -23,9 +23,6 @@ import 
org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration
 import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
 import 
org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
-
 /**
  * Authority rule configuration for YAML.
  */
@@ -33,7 +30,7 @@ import java.util.Map;
 @Setter
 public final class YamlAuthorityRuleConfiguration implements 
YamlRuleConfiguration {
     
-    private Map<String, YamlShardingSphereAlgorithmConfiguration> 
privilegeLoaders = new LinkedHashMap<>();
+    private YamlShardingSphereAlgorithmConfiguration privilegeLoader;
     
     @Override
     public Class<AuthorityRuleConfiguration> getRuleConfigurationType() {
diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
index 7e1ff37..eef268e 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
@@ -20,15 +20,9 @@ package org.apache.shardingsphere.authority.yaml.swapper;
 import 
org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration;
 import org.apache.shardingsphere.authority.constant.AuthorityOrder;
 import 
org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
-import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import 
org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
 import 
org.apache.shardingsphere.infra.yaml.swapper.algorithm.ShardingSphereAlgorithmConfigurationYamlSwapper;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
 /**
  * Authority rule configuration YAML swapper.
  */
@@ -39,21 +33,13 @@ public final class AuthorityRuleConfigurationYamlSwapper 
implements YamlRuleConf
     @Override
     public YamlAuthorityRuleConfiguration swapToYamlConfiguration(final 
AuthorityRuleConfiguration data) {
         YamlAuthorityRuleConfiguration result = new 
YamlAuthorityRuleConfiguration();
-        data.getPrivilegeLoaders().forEach((key, value) -> 
result.getPrivilegeLoaders().put(key, 
algorithmSwapper.swapToYamlConfiguration(value)));
+        
result.setPrivilegeLoader(algorithmSwapper.swapToYamlConfiguration(data.getPrivilegeLoader()));
         return result;
     }
     
     @Override
     public AuthorityRuleConfiguration swapToObject(final 
YamlAuthorityRuleConfiguration yamlConfig) {
-        return new 
AuthorityRuleConfiguration(swapAuthorityAlgorithm(yamlConfig));
-    }
-    
-    private Map<String, ShardingSphereAlgorithmConfiguration> 
swapAuthorityAlgorithm(final YamlAuthorityRuleConfiguration yamlConfig) {
-        Map<String, ShardingSphereAlgorithmConfiguration> result = new 
LinkedHashMap<>(yamlConfig.getPrivilegeLoaders().size(), 1);
-        for (Entry<String, YamlShardingSphereAlgorithmConfiguration> entry : 
yamlConfig.getPrivilegeLoaders().entrySet()) {
-            result.put(entry.getKey(), 
algorithmSwapper.swapToObject(entry.getValue()));
-        }
-        return result;
+        return new 
AuthorityRuleConfiguration(algorithmSwapper.swapToObject(yamlConfig.getPrivilegeLoader()));
     }
     
     @Override

Reply via email to