diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java index f032e2709c56a..7619691b60ce0 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java @@ -18,11 +18,13 @@ package org.apache.shardingsphere.shadow.condition; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; /** * Shadow determine condition. */ +@RequiredArgsConstructor @Getter public final class ShadowDetermineCondition { @@ -30,21 +32,9 @@ public final class ShadowDetermineCondition { private final ShadowOperationType shadowOperationType; - private ShadowColumnCondition shadowColumnCondition; + private final ShadowColumnCondition shadowColumnCondition; public ShadowDetermineCondition(final String tableName, final ShadowOperationType shadowOperationType) { - this.tableName = tableName; - this.shadowOperationType = shadowOperationType; - } - - /** - * Initialize shadow column condition. - * - * @param shadowColumnCondition shadow column condition - * @return shadow determine condition - */ - public ShadowDetermineCondition initShadowColumnCondition(final ShadowColumnCondition shadowColumnCondition) { - this.shadowColumnCondition = shadowColumnCondition; - return this; + this(tableName, shadowOperationType, null); } } 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 35df01ab9b8d3..adeed4b4fdf45 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 @@ -143,7 +143,7 @@ private boolean isMatchAnyColumnShadowAlgorithms(final ShadowRule rule, final St private boolean isMatchColumnShadowAlgorithm(final String shadowTable, final Collection>> algorithms, final ShadowColumnCondition condition) { for (ColumnShadowAlgorithm> each : algorithms) { - if (ColumnShadowAlgorithmDeterminer.isShadow(each, new ShadowDetermineCondition(shadowTable, operationType).initShadowColumnCondition(condition))) { + if (ColumnShadowAlgorithmDeterminer.isShadow(each, new ShadowDetermineCondition(shadowTable, operationType, condition))) { return true; } } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminerTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminerTest.java index ae733e38c7f3c..4e3ab6c08a8e4 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminerTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/ColumnShadowAlgorithmDeterminerTest.java @@ -43,8 +43,6 @@ void assertIsShadow() { } private ShadowDetermineCondition createShadowDetermineCondition() { - ShadowDetermineCondition result = new ShadowDetermineCondition("t_order", ShadowOperationType.INSERT); - result.initShadowColumnCondition(new ShadowColumnCondition("t_order", "user_id", Collections.singleton(1))); - return result; + return new ShadowDetermineCondition("t_order", ShadowOperationType.INSERT, new ShadowColumnCondition("t_order", "user_id", Collections.singleton(1))); } }