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

duanzhengqiang 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 2282cdbf2a4 Refactor Part ShadowRuleConfigurationChecker code to 
swapper (#30673)
2282cdbf2a4 is described below

commit 2282cdbf2a4b27630048430fb8837e2a129f6967
Author: LotusMoon <[email protected]>
AuthorDate: Wed Mar 27 20:06:24 2024 +0800

    Refactor Part ShadowRuleConfigurationChecker code to swapper (#30673)
    
    * Support encrypt rewriter with custom databaseName config
    
    * move setDefaultShadowAlgorithm setDefaultShadowDataSource to yaml swapper
---
 .../checker/ShadowRuleConfigurationChecker.java    | 23 ------------------
 .../YamlShadowRuleConfigurationSwapper.java        | 27 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 23 deletions(-)

diff --git 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
index 27fb7f80107..1dd3c4a89d8 100644
--- 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
+++ 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
@@ -49,11 +49,7 @@ public final class ShadowRuleConfigurationChecker implements 
RuleConfigurationCh
         checkShadowAlgorithms(ruleConfig.getShadowAlgorithms());
         
checkDefaultShadowAlgorithmConfiguration(ruleConfig.getDefaultShadowAlgorithmName(),
 ruleConfig.getShadowAlgorithms());
         checkDataSources(ruleConfig.getDataSources(), dataSourceMap, 
databaseName);
-        // TODO move setDefaultShadowDataSource to yaml swapper
-        setDefaultShadowDataSource(ruleConfig.getTables(), 
ruleConfig.getDataSources());
         checkShadowTableDataSourcesReferences(ruleConfig.getTables(), 
ruleConfig.getDataSources());
-        // TODO move setDefaultShadowAlgorithm to yaml swapper
-        setDefaultShadowAlgorithm(ruleConfig.getTables(), 
ruleConfig.getDefaultShadowAlgorithmName());
         checkShadowTableAlgorithmsReferences(ruleConfig.getTables(), 
ruleConfig.getShadowAlgorithms(), databaseName);
     }
     
@@ -70,16 +66,6 @@ public final class ShadowRuleConfigurationChecker implements 
RuleConfigurationCh
         }
     }
     
-    private void setDefaultShadowDataSource(final Map<String, 
ShadowTableConfiguration> shadowTables, final 
Collection<ShadowDataSourceConfiguration> shadowDataSources) {
-        if (1 == shadowDataSources.size()) {
-            for (ShadowTableConfiguration each : shadowTables.values()) {
-                if (each.getDataSourceNames().isEmpty()) {
-                    
each.getDataSourceNames().add(shadowDataSources.iterator().next().getName());
-                }
-            }
-        }
-    }
-    
     private void checkShadowTableDataSourcesReferences(final Map<String, 
ShadowTableConfiguration> shadowTables, final 
Collection<ShadowDataSourceConfiguration> shadowDataSources) {
         Collection<String> dataSourceNames = 
shadowDataSources.stream().map(ShadowDataSourceConfiguration::getName).collect(Collectors.toSet());
         shadowTables.forEach((key, value) -> {
@@ -96,15 +82,6 @@ public final class ShadowRuleConfigurationChecker implements 
RuleConfigurationCh
         }
     }
     
-    private void setDefaultShadowAlgorithm(final Map<String, 
ShadowTableConfiguration> shadowTables, final String 
defaultShadowAlgorithmName) {
-        for (ShadowTableConfiguration each : shadowTables.values()) {
-            Collection<String> shadowAlgorithmNames = 
each.getShadowAlgorithmNames();
-            if (null != defaultShadowAlgorithmName && 
shadowAlgorithmNames.isEmpty()) {
-                shadowAlgorithmNames.add(defaultShadowAlgorithmName);
-            }
-        }
-    }
-    
     private void checkShadowTableAlgorithmsReferences(final Map<String, 
ShadowTableConfiguration> shadowTables, final Map<String, 
AlgorithmConfiguration> shadowAlgorithms, final String databaseName) {
         for (ShadowTableConfiguration each : shadowTables.values()) {
             
ShardingSpherePreconditions.checkState(!each.getShadowAlgorithmNames().isEmpty(),
 () -> new EmptyAlgorithmException("Shadow", new 
SQLExceptionIdentifier(databaseName)));
diff --git 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java
 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java
index becc22d10ac..db10ea396c4 100644
--- 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java
+++ 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java
@@ -21,11 +21,15 @@ import 
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigur
 import 
org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
 import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
 import 
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
 import org.apache.shardingsphere.shadow.constant.ShadowOrder;
 import 
org.apache.shardingsphere.shadow.yaml.config.YamlShadowRuleConfiguration;
 import 
org.apache.shardingsphere.shadow.yaml.config.datasource.YamlShadowDataSourceConfiguration;
 import 
org.apache.shardingsphere.shadow.yaml.swapper.table.YamlShadowTableConfigurationSwapper;
 
+import java.util.Collection;
+import java.util.Map;
+
 /**
  * YAML shadow rule configuration swapper.
  */
@@ -39,6 +43,8 @@ public final class YamlShadowRuleConfigurationSwapper 
implements YamlRuleConfigu
     public YamlShadowRuleConfiguration swapToYamlConfiguration(final 
ShadowRuleConfiguration data) {
         YamlShadowRuleConfiguration result = new YamlShadowRuleConfiguration();
         
result.setDefaultShadowAlgorithmName(data.getDefaultShadowAlgorithmName());
+        setTableDefaultShadowDataSource(data.getTables(), 
data.getDataSources());
+        setTableDefaultShadowAlgorithm(data.getTables(), 
data.getDefaultShadowAlgorithmName());
         parseDataSources(data, result);
         parseShadowTables(data, result);
         parseShadowAlgorithms(data, result);
@@ -71,6 +77,8 @@ public final class YamlShadowRuleConfigurationSwapper 
implements YamlRuleConfigu
         parseYamlDataSources(yamlConfig, result);
         parseYamlShadowTables(yamlConfig, result);
         parseYamlShadowAlgorithms(yamlConfig, result);
+        setTableDefaultShadowDataSource(result.getTables(), 
result.getDataSources());
+        setTableDefaultShadowAlgorithm(result.getTables(), 
result.getDefaultShadowAlgorithmName());
         return result;
     }
     
@@ -90,6 +98,25 @@ public final class YamlShadowRuleConfigurationSwapper 
implements YamlRuleConfigu
         return new ShadowDataSourceConfiguration(name, 
yamlConfig.getProductionDataSourceName(), yamlConfig.getShadowDataSourceName());
     }
     
+    private void setTableDefaultShadowDataSource(final Map<String, 
ShadowTableConfiguration> shadowTables, final 
Collection<ShadowDataSourceConfiguration> shadowDataSources) {
+        if (1 == shadowDataSources.size()) {
+            for (ShadowTableConfiguration each : shadowTables.values()) {
+                if (each.getDataSourceNames().isEmpty()) {
+                    
each.getDataSourceNames().add(shadowDataSources.iterator().next().getName());
+                }
+            }
+        }
+    }
+    
+    private void setTableDefaultShadowAlgorithm(final Map<String, 
ShadowTableConfiguration> shadowTables, final String 
defaultShadowAlgorithmName) {
+        for (ShadowTableConfiguration each : shadowTables.values()) {
+            Collection<String> shadowAlgorithmNames = 
each.getShadowAlgorithmNames();
+            if (null != defaultShadowAlgorithmName && 
shadowAlgorithmNames.isEmpty()) {
+                shadowAlgorithmNames.add(defaultShadowAlgorithmName);
+            }
+        }
+    }
+    
     @Override
     public Class<ShadowRuleConfiguration> getTypeClass() {
         return ShadowRuleConfiguration.class;

Reply via email to