Skip to content

Commit

Permalink
Refactor ShadowDetermineCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Nov 4, 2024
1 parent abc97fb commit e070d64
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,23 @@
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 {

private final String tableName;

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private boolean isMatchAnyColumnShadowAlgorithms(final ShadowRule rule, final St

private boolean isMatchColumnShadowAlgorithm(final String shadowTable, final Collection<ColumnShadowAlgorithm<Comparable<?>>> algorithms, final ShadowColumnCondition condition) {
for (ColumnShadowAlgorithm<Comparable<?>> each : algorithms) {
if (ColumnShadowAlgorithmDeterminer.isShadow(each, new ShadowDetermineCondition(shadowTable, operationType).initShadowColumnCondition(condition))) {
if (ColumnShadowAlgorithmDeterminer.isShadow(each, new ShadowDetermineCondition(shadowTable, operationType, condition))) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

0 comments on commit e070d64

Please sign in to comment.