From 5e8dbbc77ebe6fed444566f5781fc819e5099939 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Wed, 6 Nov 2024 00:23:19 +0800 Subject: [PATCH] Refactor ColumnShadowAlgorithmDeterminer (#33558) --- .../spi/column/PreciseColumnShadowValue.java | 4 ++-- .../AbstractColumnMatchedShadowAlgorithm.java | 4 ++-- .../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 26905cb6df15a..261f5753ada39 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 @@ @Getter public final class PreciseColumnShadowValue> 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 efec0e20fbd1e..eb0c6b3b20caa 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 @@ private ShadowOperationType getShadowOperationType(final Properties props) { @Override public final boolean isShadow(final PreciseColumnShadowValue> 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 da4e2a8d0fcdf..f528266f340cc 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.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> shadowAlgorithm, final ShadowCondition shadowCondition) { - ShadowColumnCondition shadowColumnCondition = shadowCondition.getColumnCondition(); - String tableName = shadowCondition.getTableName(); - ShadowOperationType operationType = shadowCondition.getOperationType(); - for (PreciseColumnShadowValue> each : createColumnShadowValues(shadowColumnCondition.getColumn(), shadowColumnCondition.getValues(), tableName, operationType)) { - if (!tableName.equals(shadowColumnCondition.getOwner()) || !shadowAlgorithm.isShadow(each)) { + for (PreciseColumnShadowValue> each : createColumnShadowValues(shadowCondition)) { + if (!shadowCondition.getTableName().equals(shadowCondition.getColumnCondition().getOwner()) || !shadowAlgorithm.isShadow(each)) { return false; } } return true; } - private static Collection>> createColumnShadowValues(final String columnName, final Collection> columnValues, final String tableName, - final ShadowOperationType operationType) { + private static Collection>> createColumnShadowValues(final ShadowCondition shadowCondition) { Collection>> 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; }