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 83101c77df4 Rename ShadowCondition (#33534)
83101c77df4 is described below
commit 83101c77df40cedbca14d650fd59b2e218570439
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Nov 4 16:27:04 2024 +0800
Rename ShadowCondition (#33534)
* Rename ShadowCondition
* Rename ShadowCondition
* Rename ShadowCondition
---
...gSphere_standardize_and_format_code_We_use_Spotless.en.md | 6 +++---
docs/blog/content/material/spotless.cn.md | 6 +++---
.../{ShadowDetermineCondition.java => ShadowCondition.java} | 12 ++++++------
.../route/determiner/ColumnShadowAlgorithmDeterminer.java | 8 ++++----
.../route/determiner/HintShadowAlgorithmDeterminer.java | 10 +++++-----
.../AbstractShadowDMLStatementDataSourceMappingsFinder.java | 12 ++++++------
.../other/ShadowNonDMLStatementDataSourceMappingsFinder.java | 6 +++---
.../determiner/ColumnShadowAlgorithmDeterminerTest.java | 9 ++++-----
.../route/determiner/HintShadowAlgorithmDeterminerTest.java | 8 ++++----
9 files changed, 38 insertions(+), 39 deletions(-)
diff --git
a/docs/blog/content/material/2022_06_08_How_does_Apache_ShardingSphere_standardize_and_format_code_We_use_Spotless.en.md
b/docs/blog/content/material/2022_06_08_How_does_Apache_ShardingSphere_standardize_and_format_code_We_use_Spotless.en.md
index 1871401d765..91ce3f3b055 100644
---
a/docs/blog/content/material/2022_06_08_How_does_Apache_ShardingSphere_standardize_and_format_code_We_use_Spotless.en.md
+++
b/docs/blog/content/material/2022_06_08_How_does_Apache_ShardingSphere_standardize_and_format_code_We_use_Spotless.en.md
@@ -193,12 +193,12 @@ In extreme circumstances, Spotless formatted code cannot
pass Checkstyle checkin
The underlying cause is a conflict between the checking mechanism and
formatting configurations set by both. For example, Spotless formats a newline
with a 16-space indent, while Checkstyle checks for a 12-space newline.
```java
-private static Collection<PreciseHintShadowValue<Comparable<?>>>
createNoteShadowValues(final ShadowDetermineCondition shadowDetermineCondition)
{
+private static Collection<PreciseHintShadowValue<Comparable<?>>>
createNoteShadowValues(final ShadowDetermineCondition shadowCondition) {
// format that can pass Checkstyle
- return
shadowDetermineCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
+ return
shadowCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
each -> new PreciseHintShadowValue<>(tableName, shadowOperationType,
each)).collect(Collectors.toList());
// After being formatted by Spotless
- return
shadowDetermineCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
+ return
shadowCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
each -> new PreciseHintShadowValue<>(tableName,
shadowOperationType, each)).collect(Collectors.toList());
}
```
diff --git a/docs/blog/content/material/spotless.cn.md
b/docs/blog/content/material/spotless.cn.md
index 941e2fb32c5..4e5a43f08b3 100644
--- a/docs/blog/content/material/spotless.cn.md
+++ b/docs/blog/content/material/spotless.cn.md
@@ -221,12 +221,12 @@ user@machine repo % mvn spotless:check
根本原因在于两者设定的检查配置和格式化配置冲突。举个例子,Spotless 格式化后换行缩进了 16 个空格,而 Checkstyle 的换行检查是 12
个空格。
```java
-private static Collection<PreciseHintShadowValue<Comparable<?>>>
createNoteShadowValues(final ShadowDetermineCondition shadowDetermineCondition)
{
+private static Collection<PreciseHintShadowValue<Comparable<?>>>
createNoteShadowValues(final ShadowDetermineCondition shadowCondition) {
// Checkstyle 可以通过的格式
- return
shadowDetermineCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
+ return
shadowCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
each -> new PreciseHintShadowValue<>(tableName, shadowOperationType,
each)).collect(Collectors.toList());
// Spotless 格式化后
- return
shadowDetermineCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
+ return
shadowCondition.getSqlComments().stream().<PreciseHintShadowValue<Comparable<?>>>map(
each -> new PreciseHintShadowValue<>(tableName,
shadowOperationType, each)).collect(Collectors.toList());
}
```
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/ShadowCondition.java
similarity index 75%
rename from
features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowDetermineCondition.java
rename to
features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/condition/ShadowCondition.java
index 7619691b60c..2806b92dfaa 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/ShadowCondition.java
@@ -22,19 +22,19 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.shadow.spi.ShadowOperationType;
/**
- * Shadow determine condition.
+ * Shadow condition.
*/
@RequiredArgsConstructor
@Getter
-public final class ShadowDetermineCondition {
+public final class ShadowCondition {
private final String tableName;
- private final ShadowOperationType shadowOperationType;
+ private final ShadowOperationType operationType;
- private final ShadowColumnCondition shadowColumnCondition;
+ private final ShadowColumnCondition columnCondition;
- public ShadowDetermineCondition(final String tableName, final
ShadowOperationType shadowOperationType) {
- this(tableName, shadowOperationType, null);
+ public ShadowCondition(final String tableName, final ShadowOperationType
operationType) {
+ this(tableName, operationType, null);
}
}
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 f1ffac30c7c..a1a3dfc162d 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
@@ -19,11 +19,11 @@ package org.apache.shardingsphere.shadow.route.determiner;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+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 org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
import java.util.Collection;
import java.util.LinkedList;
@@ -41,10 +41,10 @@ public final class ColumnShadowAlgorithmDeterminer {
* @param shadowCondition shadow determine condition
* @return is shadow or not
*/
- public static boolean isShadow(final ColumnShadowAlgorithm<Comparable<?>>
shadowAlgorithm, final ShadowDetermineCondition shadowCondition) {
- ShadowColumnCondition shadowColumnCondition =
shadowCondition.getShadowColumnCondition();
+ public static boolean isShadow(final ColumnShadowAlgorithm<Comparable<?>>
shadowAlgorithm, final ShadowCondition shadowCondition) {
+ ShadowColumnCondition shadowColumnCondition =
shadowCondition.getColumnCondition();
String tableName = shadowCondition.getTableName();
- ShadowOperationType operationType =
shadowCondition.getShadowOperationType();
+ ShadowOperationType operationType = shadowCondition.getOperationType();
for (PreciseColumnShadowValue<Comparable<?>> each :
createColumnShadowValues(shadowColumnCondition.getColumn(),
shadowColumnCondition.getValues(), tableName, operationType)) {
if (!tableName.equals(shadowColumnCondition.getOwner()) ||
!shadowAlgorithm.isShadow(each)) {
return false;
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminer.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminer.java
index 037bea3c3d2..49ee2209203 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminer.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminer.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shadow.route.determiner;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowCondition;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowOperationType;
import org.apache.shardingsphere.shadow.spi.hint.HintShadowAlgorithm;
@@ -40,14 +40,14 @@ public final class HintShadowAlgorithmDeterminer {
* @param useShadow use shadow or not
* @return is shadow or not
*/
- public static boolean isShadow(final HintShadowAlgorithm<Comparable<?>>
shadowAlgorithm, final ShadowDetermineCondition shadowCondition, final
ShadowRule shadowRule, final boolean useShadow) {
+ public static boolean isShadow(final HintShadowAlgorithm<Comparable<?>>
shadowAlgorithm, final ShadowCondition shadowCondition, final ShadowRule
shadowRule, final boolean useShadow) {
PreciseHintShadowValue<Comparable<?>> shadowValue =
createHintShadowValues(shadowCondition, useShadow);
return shadowAlgorithm.isShadow(shadowRule.getAllShadowTableNames(),
shadowValue);
}
- private static PreciseHintShadowValue<Comparable<?>>
createHintShadowValues(final ShadowDetermineCondition shadowDetermineCondition,
final boolean useShadow) {
- ShadowOperationType shadowOperationType =
shadowDetermineCondition.getShadowOperationType();
- String tableName = shadowDetermineCondition.getTableName();
+ private static PreciseHintShadowValue<Comparable<?>>
createHintShadowValues(final ShadowCondition shadowCondition, final boolean
useShadow) {
+ ShadowOperationType shadowOperationType =
shadowCondition.getOperationType();
+ String tableName = shadowCondition.getTableName();
return new PreciseHintShadowValue<>(tableName, shadowOperationType,
useShadow);
}
}
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 adeed4b4fdf..8c95b267415 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
@@ -23,7 +23,7 @@ import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementCont
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowCondition;
import
org.apache.shardingsphere.shadow.route.determiner.ColumnShadowAlgorithmDeterminer;
import
org.apache.shardingsphere.shadow.route.determiner.HintShadowAlgorithmDeterminer;
import
org.apache.shardingsphere.shadow.route.finder.ShadowDataSourceMappingsFinder;
@@ -83,8 +83,8 @@ public abstract class
AbstractShadowDMLStatementDataSourceMappingsFinder impleme
private boolean isMatchDefaultAlgorithm(final ShadowRule rule) {
Optional<ShadowAlgorithm> defaultAlgorithm =
rule.getDefaultShadowAlgorithm();
if (defaultAlgorithm.isPresent() && defaultAlgorithm.get() instanceof
HintShadowAlgorithm<?>) {
- ShadowDetermineCondition determineCondition = new
ShadowDetermineCondition("", ShadowOperationType.HINT_MATCH);
- return
HintShadowAlgorithmDeterminer.isShadow((HintShadowAlgorithm<Comparable<?>>)
defaultAlgorithm.get(), determineCondition, rule, isShadow);
+ ShadowCondition shadowCondition = new ShadowCondition("",
ShadowOperationType.HINT_MATCH);
+ return
HintShadowAlgorithmDeterminer.isShadow((HintShadowAlgorithm<Comparable<?>>)
defaultAlgorithm.get(), shadowCondition, rule, isShadow);
}
return false;
}
@@ -92,7 +92,7 @@ public abstract class
AbstractShadowDMLStatementDataSourceMappingsFinder impleme
private Map<String, String> findBySQLHints(final ShadowRule rule, final
Collection<String> relatedShadowTables) {
Map<String, String> result = new LinkedHashMap<>();
for (String each : relatedShadowTables) {
- if (isContainsShadowInSQLHints(rule, each, new
ShadowDetermineCondition(each, operationType))) {
+ if (isContainsShadowInSQLHints(rule, each, new
ShadowCondition(each, operationType))) {
result.putAll(rule.getShadowDataSourceMappings(each));
return result;
}
@@ -100,7 +100,7 @@ public abstract class
AbstractShadowDMLStatementDataSourceMappingsFinder impleme
return result;
}
- private boolean isContainsShadowInSQLHints(final ShadowRule rule, final
String tableName, final ShadowDetermineCondition shadowCondition) {
+ private boolean isContainsShadowInSQLHints(final ShadowRule rule, final
String tableName, final ShadowCondition shadowCondition) {
for (HintShadowAlgorithm<Comparable<?>> each :
rule.getHintShadowAlgorithms(tableName)) {
if (HintShadowAlgorithmDeterminer.isShadow(each, shadowCondition,
rule, isShadow)) {
return true;
@@ -143,7 +143,7 @@ public abstract class
AbstractShadowDMLStatementDataSourceMappingsFinder impleme
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, condition))) {
+ if (ColumnShadowAlgorithmDeterminer.isShadow(each, new
ShadowCondition(shadowTable, operationType, condition))) {
return true;
}
}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java
index f055cc1dbf1..401cdbb0859 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/finder/other/ShadowNonDMLStatementDataSourceMappingsFinder.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shadow.route.finder.other;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.hint.HintValueContext;
-import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowCondition;
import
org.apache.shardingsphere.shadow.route.determiner.HintShadowAlgorithmDeterminer;
import
org.apache.shardingsphere.shadow.route.finder.ShadowDataSourceMappingsFinder;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
@@ -41,13 +41,13 @@ public final class
ShadowNonDMLStatementDataSourceMappingsFinder implements Shad
if (!hintValueContext.isShadow()) {
return Collections.emptyMap();
}
- if (isMatchAnyHintShadowAlgorithms(rule, new
ShadowDetermineCondition("", ShadowOperationType.HINT_MATCH))) {
+ if (isMatchAnyHintShadowAlgorithms(rule, new ShadowCondition("",
ShadowOperationType.HINT_MATCH))) {
return rule.getAllShadowDataSourceMappings();
}
return Collections.emptyMap();
}
- private boolean isMatchAnyHintShadowAlgorithms(final ShadowRule rule,
final ShadowDetermineCondition shadowCondition) {
+ private boolean isMatchAnyHintShadowAlgorithms(final ShadowRule rule,
final ShadowCondition shadowCondition) {
return rule.getAllHintShadowAlgorithms().stream().anyMatch(each ->
HintShadowAlgorithmDeterminer.isShadow(each, shadowCondition, rule,
hintValueContext.isShadow()));
}
}
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 4e3ab6c08a8..4933415f703 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
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shadow.route.determiner;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
-import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowCondition;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import org.apache.shardingsphere.shadow.spi.ShadowOperationType;
import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm;
@@ -38,11 +38,10 @@ class ColumnShadowAlgorithmDeterminerTest {
@Test
void assertIsShadow() {
Properties props = PropertiesBuilder.build(new Property("column",
"user_id"), new Property("operation", "insert"), new Property("regex", "[1]"));
- assertTrue(ColumnShadowAlgorithmDeterminer.isShadow(
- (ColumnShadowAlgorithm)
TypedSPILoader.getService(ShadowAlgorithm.class, "REGEX_MATCH", props),
createShadowDetermineCondition()));
+
assertTrue(ColumnShadowAlgorithmDeterminer.isShadow((ColumnShadowAlgorithm)
TypedSPILoader.getService(ShadowAlgorithm.class, "REGEX_MATCH", props),
createShadowCondition()));
}
- private ShadowDetermineCondition createShadowDetermineCondition() {
- return new ShadowDetermineCondition("t_order",
ShadowOperationType.INSERT, new ShadowColumnCondition("t_order", "user_id",
Collections.singleton(1)));
+ private ShadowCondition createShadowCondition() {
+ return new ShadowCondition("t_order", ShadowOperationType.INSERT, new
ShadowColumnCondition("t_order", "user_id", Collections.singleton(1)));
}
}
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminerTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminerTest.java
index b51d023c455..51f58c3799c 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminerTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/determiner/HintShadowAlgorithmDeterminerTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.shadow.route.determiner;
import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.condition.ShadowCondition;
import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
@@ -44,7 +44,7 @@ class HintShadowAlgorithmDeterminerTest {
void assertIsShadow() {
HintShadowAlgorithm hintShadowAlgorithm = (HintShadowAlgorithm)
TypedSPILoader.getService(ShadowAlgorithm.class, "SQL_HINT", new Properties());
HintValueContext hintValueContext = createHintValueContext();
- assertTrue(HintShadowAlgorithmDeterminer.isShadow(hintShadowAlgorithm,
createShadowDetermineCondition(), new
ShadowRule(createShadowRuleConfiguration()), hintValueContext.isShadow()));
+ assertTrue(HintShadowAlgorithmDeterminer.isShadow(hintShadowAlgorithm,
createShadowCondition(), new ShadowRule(createShadowRuleConfiguration()),
hintValueContext.isShadow()));
}
private HintValueContext createHintValueContext() {
@@ -68,7 +68,7 @@ class HintShadowAlgorithmDeterminerTest {
return result;
}
- private ShadowDetermineCondition createShadowDetermineCondition() {
- return new ShadowDetermineCondition("t_order",
ShadowOperationType.INSERT);
+ private ShadowCondition createShadowCondition() {
+ return new ShadowCondition("t_order", ShadowOperationType.INSERT);
}
}