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

zhangliang 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 a35676a69a2 Refactor ShadowTableRule (#33544)
a35676a69a2 is described below

commit a35676a69a22154a1b5683fb882d6e71282d83a4
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Nov 4 22:33:02 2024 +0800

    Refactor ShadowTableRule (#33544)
---
 .../AbstractShadowDMLStatementDataSourceMappingsFinder.java    |  2 +-
 .../java/org/apache/shardingsphere/shadow/rule/ShadowRule.java | 10 +++++-----
 .../org/apache/shardingsphere/shadow/rule/ShadowTableRule.java | 10 +++++-----
 .../org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java  |  4 ++--
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java
 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java
index 8c95b267415..88ce7f30ddc 100644
--- 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java
+++ 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/dml/AbstractShadowDMLStatementDataSourceMappingsFinder.java
@@ -129,7 +129,7 @@ public abstract class 
AbstractShadowDMLStatementDataSourceMappingsFinder impleme
     }
     
     private boolean isMatchAnyColumnShadowAlgorithms(final ShadowRule rule, 
final String shadowTable, final String shadowColumn) {
-        Collection<ColumnShadowAlgorithm<Comparable<?>>> 
columnShadowAlgorithms = rule.getShadowAlgorithms(operationType, shadowTable, 
shadowColumn);
+        Collection<ColumnShadowAlgorithm<Comparable<?>>> 
columnShadowAlgorithms = rule.getColumnShadowAlgorithms(operationType, 
shadowTable, shadowColumn);
         if (columnShadowAlgorithms.isEmpty()) {
             return false;
         }
diff --git 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index 0b093e6c58e..42af1f6ad49 100644
--- 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++ 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -145,7 +145,7 @@ public final class ShadowRule implements DatabaseRule {
     }
     
     /**
-     * Get hint shadow algorithms by table name.
+     * Get hint shadow algorithms.
      *
      * @param tableName table name
      * @return hint shadow algorithms
@@ -162,16 +162,16 @@ public final class ShadowRule implements DatabaseRule {
     }
     
     /**
-     * Get shadow algorithms.
+     * Get column shadow algorithms.
      *
      * @param shadowOperationType shadow operation type
      * @param tableName table name
      * @param shadowColumnName shadow column name
-     * @return shadow algorithms
+     * @return column shadow algorithms
      */
     @HighFrequencyInvocation
     @SuppressWarnings("unchecked")
-    public Collection<ColumnShadowAlgorithm<Comparable<?>>> 
getShadowAlgorithms(final ShadowOperationType shadowOperationType, final String 
tableName, final String shadowColumnName) {
+    public Collection<ColumnShadowAlgorithm<Comparable<?>>> 
getColumnShadowAlgorithms(final ShadowOperationType shadowOperationType, final 
String tableName, final String shadowColumnName) {
         Collection<ColumnShadowAlgorithm<Comparable<?>>> result = new 
LinkedList<>();
         for (ShadowAlgorithmNameRule each : 
tableRules.get(tableName).getColumnShadowAlgorithmNames().getOrDefault(shadowOperationType,
 Collections.emptyList())) {
             if (shadowColumnName.equals(each.getShadowColumnName())) {
@@ -206,7 +206,7 @@ public final class ShadowRule implements DatabaseRule {
     @HighFrequencyInvocation
     public Map<String, String> getShadowDataSourceMappings(final String 
tableName) {
         Map<String, String> result = new 
LinkedHashMap<>(dataSourceRules.size(), 1F);
-        for (String each : tableRules.get(tableName).getShadowDataSources()) {
+        for (String each : 
tableRules.get(tableName).getLogicDataSourceNames()) {
             ShadowDataSourceRule dataSourceRule = dataSourceRules.get(each);
             result.put(dataSourceRule.getProductionDataSource(), 
dataSourceRule.getShadowDataSource());
         }
diff --git 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowTableRule.java
 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowTableRule.java
index 56e1369d2e1..7520f2a6062 100644
--- 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowTableRule.java
+++ 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowTableRule.java
@@ -35,17 +35,17 @@ import java.util.stream.Collectors;
 @Getter
 public final class ShadowTableRule {
     
-    private final String tableName;
+    private final String name;
     
-    private final Collection<String> shadowDataSources;
+    private final Collection<String> logicDataSourceNames;
     
     private final Collection<String> hintShadowAlgorithmNames;
     
     private final Map<ShadowOperationType, 
Collection<ShadowAlgorithmNameRule>> columnShadowAlgorithmNames;
     
-    public ShadowTableRule(final String tableName, final Collection<String> 
shadowDataSources, final Collection<String> shadowAlgorithmNames, final 
Map<String, ShadowAlgorithm> shadowAlgorithms) {
-        this.tableName = tableName;
-        this.shadowDataSources = shadowDataSources;
+    public ShadowTableRule(final String tableName, final Collection<String> 
logicDataSourceNames, final Collection<String> shadowAlgorithmNames, final 
Map<String, ShadowAlgorithm> shadowAlgorithms) {
+        this.name = tableName;
+        this.logicDataSourceNames = logicDataSourceNames;
         hintShadowAlgorithmNames = 
getHintShadowAlgorithmNames(shadowAlgorithmNames, shadowAlgorithms);
         columnShadowAlgorithmNames = 
getColumnShadowAlgorithmRules(shadowAlgorithmNames, shadowAlgorithms);
     }
diff --git 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
index 0f382566b08..487e0692302 100644
--- 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
+++ 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
@@ -119,8 +119,8 @@ class ShadowRuleTest {
     }
     
     @Test
-    void assertGetShadowAlgorithms() {
-        assertThat(rule.getShadowAlgorithms(ShadowOperationType.INSERT, 
"foo_tbl", "foo_id").size(), is(1));
+    void assertGetColumnShadowAlgorithms() {
+        assertThat(rule.getColumnShadowAlgorithms(ShadowOperationType.INSERT, 
"foo_tbl", "foo_id").size(), is(1));
     }
     
     @Test

Reply via email to