You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/11/05 16:23:25 UTC

(shardingsphere) branch master updated: Refactor ColumnShadowAlgorithmDeterminer (#33558)

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 5e8dbbc77eb Refactor ColumnShadowAlgorithmDeterminer (#33558)
5e8dbbc77eb is described below

commit 5e8dbbc77ebe6fed444566f5781fc819e5099939
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Nov 6 00:23:19 2024 +0800

    Refactor ColumnShadowAlgorithmDeterminer (#33558)
---
 .../shadow/spi/column/PreciseColumnShadowValue.java      |  4 ++--
 .../column/AbstractColumnMatchedShadowAlgorithm.java     |  4 ++--
 .../determiner/ColumnShadowAlgorithmDeterminer.java      | 16 +++++-----------
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/column/PreciseColumnShadowValue.java b/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/column/PreciseColumnShadowValue.java
index 26905cb6df1..261f5753ada 100644
--- a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/column/PreciseColumnShadowValue.java
+++ b/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/column/PreciseColumnShadowValue.java
@@ -31,9 +31,9 @@ import org.apache.shardingsphere.shadow.spi.ShadowValue;
 @Getter
 public final class PreciseColumnShadowValue<T extends Comparable<?>> implements ShadowValue {
     
-    private final String logicTableName;
+    private final String tableName;
     
-    private final ShadowOperationType shadowOperationType;
+    private final ShadowOperationType operationType;
     
     private final String columnName;
     
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java
index efec0e20fbd..eb0c6b3b20c 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java
@@ -64,10 +64,10 @@ public abstract class AbstractColumnMatchedShadowAlgorithm implements ColumnShad
     
     @Override
     public final boolean isShadow(final PreciseColumnShadowValue<Comparable<?>> shadowValue) {
-        String table = shadowValue.getLogicTableName();
+        String table = shadowValue.getTableName();
         String column = shadowValue.getColumnName();
         Comparable<?> value = shadowValue.getValue();
-        if (shadowOperationType == shadowValue.getShadowOperationType() && shadowColumn.equals(column)) {
+        if (shadowOperationType == shadowValue.getOperationType() && shadowColumn.equals(column)) {
             ColumnShadowValueValidator.validate(table, column, value);
             return matchesShadowValue(value);
         }
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminer.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminer.java
index da4e2a8d0fc..f528266f340 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminer.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminer.java
@@ -21,10 +21,8 @@ import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
 import org.apache.shardingsphere.shadow.condition.ShadowCondition;
-import org.apache.shardingsphere.shadow.spi.ShadowOperationType;
 import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm;
 import org.apache.shardingsphere.shadow.spi.column.PreciseColumnShadowValue;
-import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
 
 import java.util.Collection;
 import java.util.LinkedList;
@@ -44,22 +42,18 @@ public final class ColumnShadowAlgorithmDeterminer {
      * @return is shadow or not
      */
     public static boolean isShadow(final ColumnShadowAlgorithm<Comparable<?>> shadowAlgorithm, final ShadowCondition shadowCondition) {
-        ShadowColumnCondition shadowColumnCondition = shadowCondition.getColumnCondition();
-        String tableName = shadowCondition.getTableName();
-        ShadowOperationType operationType = shadowCondition.getOperationType();
-        for (PreciseColumnShadowValue<Comparable<?>> each : createColumnShadowValues(shadowColumnCondition.getColumn(), shadowColumnCondition.getValues(), tableName, operationType)) {
-            if (!tableName.equals(shadowColumnCondition.getOwner()) || !shadowAlgorithm.isShadow(each)) {
+        for (PreciseColumnShadowValue<Comparable<?>> each : createColumnShadowValues(shadowCondition)) {
+            if (!shadowCondition.getTableName().equals(shadowCondition.getColumnCondition().getOwner()) || !shadowAlgorithm.isShadow(each)) {
                 return false;
             }
         }
         return true;
     }
     
-    private static Collection<PreciseColumnShadowValue<Comparable<?>>> createColumnShadowValues(final String columnName, final Collection<Comparable<?>> columnValues, final String tableName,
-                                                                                                final ShadowOperationType operationType) {
+    private static Collection<PreciseColumnShadowValue<Comparable<?>>> createColumnShadowValues(final ShadowCondition shadowCondition) {
         Collection<PreciseColumnShadowValue<Comparable<?>>> result = new LinkedList<>();
-        for (Comparable<?> each : columnValues) {
-            result.add(new PreciseColumnShadowValue<>(tableName, operationType, columnName, each));
+        for (Comparable<?> each : shadowCondition.getColumnCondition().getValues()) {
+            result.add(new PreciseColumnShadowValue<>(shadowCondition.getTableName(), shadowCondition.getOperationType(), shadowCondition.getColumnCondition().getColumn(), each));
         }
         return result;
     }