This is an automated email from the ASF dual-hosted git repository.
panjuan 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 2bccb77 Refactor shadow algorithm. (#11995)
2bccb77 is described below
commit 2bccb77541ca4a9277dcbcd6a4fc8607fe71e64b
Author: gin <[email protected]>
AuthorDate: Wed Aug 25 21:04:24 2021 +0800
Refactor shadow algorithm. (#11995)
* Refactor shadow algorithm.
* Optimize code structure.
* Optimization method name.
* Remove unused imports.
* Remove unused annotation.
---
.../shadow/ShadowValue.java} | 8 +-
.../api/shadow/column/ColumnShadowAlgorithm.java} | 26 +++----
.../shadow/column/PreciseColumnShadowValue.java} | 25 +++---
.../api/shadow/column/ShadowOperationType.java | 68 ++++++++++++++++
.../api/shadow/note/NoteShadowAlgorithm.java} | 26 +++----
.../api/shadow/note/PreciseNoteShadowValue.java} | 21 ++---
.../shardingsphere/shadow/spi/ShadowAlgorithm.java | 3 +-
.../ShadowAlgorithmException.java} | 21 ++---
.../column/ColumnRegexMatchShadowAlgorithm.java | 91 ++++++++++++++++++++++
.../shadow/note/NoteShadowAlgorithmUtil.java | 87 +++++++++++++++++++++
.../shadow/note/SimpleSQLNoteShadowAlgorithm.java | 63 +++++++++++++++
...pache.shardingsphere.shadow.spi.ShadowAlgorithm | 4 +-
.../ColumnRegexMatchShadowAlgorithmTest.java | 79 +++++++++++++++++++
.../note/SimpleSQLNoteShadowAlgorithmTest.java | 77 ++++++++++++++++++
...orithmProviderConfigurationYamlSwapperTest.java | 4 +-
.../PropertiesShadowSpringBootStarterTest.java | 6 +-
.../boot/YmlShadowSpringBootStarterTest.java | 6 +-
.../application-shadow-properties.properties | 4 +-
.../src/test/resources/application-shadow-yml.yml | 8 +-
.../main/resources/META-INF/namespace/shadow.xsd | 4 +-
.../ShadowAlgorithmSpringNamespaceTest.java | 6 +-
.../shadow-algorithm-application-context.xml | 4 +-
22 files changed, 543 insertions(+), 98 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/ShadowValue.java
similarity index 79%
copy from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
copy to
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/ShadowValue.java
index 3f86ca8..0dd0956 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/ShadowValue.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.spi;
-
-import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
+package org.apache.shardingsphere.shadow.api.shadow;
/**
- * Shadow algorithm.
+ * Shadow value.
*/
-public interface ShadowAlgorithm extends ShardingSphereAlgorithm {
+public interface ShadowValue {
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ColumnShadowAlgorithm.java
similarity index 63%
copy from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
copy to
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ColumnShadowAlgorithm.java
index 91ec03f..00e299d 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ColumnShadowAlgorithm.java
@@ -15,25 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.algorithm;
+package org.apache.shardingsphere.shadow.api.shadow.column;
-import lombok.Getter;
-import lombok.Setter;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-import java.util.Properties;
+import java.util.Collection;
/**
- * Column match shadow algorithm.
+ * Column shadow algorithm.
*/
-@Getter
-@Setter
-public final class ColumnRegularMatchShadowAlgorithm implements
ShadowAlgorithm {
+public interface ColumnShadowAlgorithm<T extends Comparable<?>> extends
ShadowAlgorithm {
- private Properties props = new Properties();
-
- @Override
- public String getType() {
- return "COLUMN-REGULAR-MATCH";
- }
+ /**
+ * Is need shadow.
+ *
+ * @param relatedShadowTables related shadow tables
+ * @param columnShadowValue column shadow value
+ * @return is need shadow or not
+ */
+ boolean isShadow(Collection<String> relatedShadowTables,
PreciseColumnShadowValue<T> columnShadowValue);
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
similarity index 63%
copy from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
copy to
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
index 91ec03f..89a0fd3 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
@@ -15,25 +15,24 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.algorithm;
+package org.apache.shardingsphere.shadow.api.shadow.column;
import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-
-import java.util.Properties;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
/**
- * Column match shadow algorithm.
+ * Shadow value for precise column.
*/
+@RequiredArgsConstructor
@Getter
-@Setter
-public final class ColumnRegularMatchShadowAlgorithm implements
ShadowAlgorithm {
+public final class PreciseColumnShadowValue<T extends Comparable<?>>
implements ShadowValue {
+
+ private final String logicTableName;
+
+ private final ShadowOperationType shadowOperationType;
- private Properties props = new Properties();
+ private final String columnName;
- @Override
- public String getType() {
- return "COLUMN-REGULAR-MATCH";
- }
+ private final T value;
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
new file mode 100644
index 0000000..c511732
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.api.shadow.column;
+
+import java.util.Optional;
+
+/**
+ * Operation types supported by shadow.
+ */
+public enum ShadowOperationType {
+
+ /**
+ * The shadow operation is insert.
+ */
+ INSERT,
+
+ /**
+ * The shadow operation is delete.
+ */
+ DELETE,
+
+ /**
+ * The shadow operation is update.
+ */
+ UPDATE,
+
+ /**
+ * The shadow operation is select.
+ */
+ SELECT;
+
+ /**
+ * Contains operation type.
+ *
+ * @param operationType operation type
+ * @return shadow operation type
+ */
+ public static Optional<ShadowOperationType> contains(final String
operationType) {
+ if (ShadowOperationType.INSERT.name().equalsIgnoreCase(operationType))
{
+ return Optional.of(ShadowOperationType.INSERT);
+ }
+ if (ShadowOperationType.DELETE.name().equalsIgnoreCase(operationType))
{
+ return Optional.of(ShadowOperationType.DELETE);
+ }
+ if (ShadowOperationType.UPDATE.name().equalsIgnoreCase(operationType))
{
+ return Optional.of(ShadowOperationType.UPDATE);
+ }
+ if (ShadowOperationType.SELECT.name().equalsIgnoreCase(operationType))
{
+ return Optional.of(ShadowOperationType.SELECT);
+ }
+ return Optional.empty();
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/NoteShadowAlgorithm.java
similarity index 64%
copy from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
copy to
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/NoteShadowAlgorithm.java
index 91ec03f..2d4ef54 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/NoteShadowAlgorithm.java
@@ -15,25 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.algorithm;
+package org.apache.shardingsphere.shadow.api.shadow.note;
-import lombok.Getter;
-import lombok.Setter;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-import java.util.Properties;
+import java.util.Collection;
/**
- * Column match shadow algorithm.
+ * Note shadow algorithm.
*/
-@Getter
-@Setter
-public final class ColumnRegularMatchShadowAlgorithm implements
ShadowAlgorithm {
+public interface NoteShadowAlgorithm<T extends Comparable<?>> extends
ShadowAlgorithm {
- private Properties props = new Properties();
-
- @Override
- public String getType() {
- return "COLUMN-REGULAR-MATCH";
- }
+ /**
+ * Is need shadow.
+ *
+ * @param relatedShadowTables related shadow tables
+ * @param noteShadowValue note shadow value
+ * @return is need shadow or not
+ */
+ boolean isShadow(Collection<String> relatedShadowTables,
PreciseNoteShadowValue<T> noteShadowValue);
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/SimpleSQLNoteShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
similarity index 66%
rename from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/SimpleSQLNoteShadowAlgorithm.java
rename to
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
index 7f15cbf..2e297bc 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/SimpleSQLNoteShadowAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
@@ -15,24 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.algorithm;
+package org.apache.shardingsphere.shadow.api.shadow.note;
import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-import java.util.Properties;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
-/**
- * Simple note shadow algorithm.
- */
+@RequiredArgsConstructor
@Getter
-@Setter
-public final class SimpleSQLNoteShadowAlgorithm implements ShadowAlgorithm {
+public final class PreciseNoteShadowValue<T extends Comparable<?>> implements
ShadowValue {
- private Properties props = new Properties();
+ private final String logicTableName;
- @Override
- public String getType() {
- return "SIMPLE-NOTE";
- }
+ private final T sqlNoteValue;
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
index 3f86ca8..2701c49 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
@@ -18,9 +18,10 @@
package org.apache.shardingsphere.shadow.spi;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
+import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmPostProcessor;
/**
* Shadow algorithm.
*/
-public interface ShadowAlgorithm extends ShardingSphereAlgorithm {
+public interface ShadowAlgorithm extends ShardingSphereAlgorithm,
ShardingSphereAlgorithmPostProcessor {
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/ShadowAlgorithmException.java
similarity index 64%
rename from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
rename to
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/ShadowAlgorithmException.java
index 91ec03f..20f4962 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/ColumnRegularMatchShadowAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/ShadowAlgorithmException.java
@@ -15,25 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.algorithm;
+package org.apache.shardingsphere.shadow.algorithm.shadow;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
-
-import java.util.Properties;
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
/**
- * Column match shadow algorithm.
+ * Shadow algorithm exception.
*/
-@Getter
-@Setter
-public final class ColumnRegularMatchShadowAlgorithm implements
ShadowAlgorithm {
+public final class ShadowAlgorithmException extends ShardingSphereException {
- private Properties props = new Properties();
+ private static final long serialVersionUID = 8144277065388645946L;
- @Override
- public String getType() {
- return "COLUMN-REGULAR-MATCH";
+ public ShadowAlgorithmException(final String errorMessage, final Object...
args) {
+ super(errorMessage, args);
}
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithm.java
new file mode 100644
index 0000000..e8efcfa
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithm.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.algorithm.shadow.column;
+
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
+import
org.apache.shardingsphere.shadow.api.shadow.column.PreciseColumnShadowValue;
+import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * Column regex match shadow algorithm.
+ */
+@Getter
+@Setter
+public final class ColumnRegexMatchShadowAlgorithm implements
ColumnShadowAlgorithm<String> {
+
+ private static final String COLUMN = "column";
+
+ private static final String OPERATION = "operation";
+
+ private static final String REGEX = "regex";
+
+ private Properties props = new Properties();
+
+ private ShadowOperationType shadowOperationType;
+
+ @Override
+ public String getType() {
+ return "COLUMN_REGEX_MATCH";
+ }
+
+ @Override
+ public void init() {
+ checkProps();
+ }
+
+ private void checkProps() {
+ checkOperation();
+ checkColumn();
+ checkRegex();
+ }
+
+ private void checkRegex() {
+ String expression = props.getProperty(REGEX);
+ Preconditions.checkNotNull(expression, "Column regex match shadow
algorithm regex cannot be null.");
+ }
+
+ private void checkColumn() {
+ String expression = props.getProperty(COLUMN);
+ Preconditions.checkNotNull(expression, "Column regex match shadow
algorithm column cannot be null.");
+ }
+
+ private void checkOperation() {
+ String operationType = props.getProperty(OPERATION);
+ Preconditions.checkNotNull(operationType, "Column regex match shadow
algorithm operation cannot be null.");
+ Optional<ShadowOperationType> shadowOperationType =
ShadowOperationType.contains(operationType);
+ Preconditions.checkState(shadowOperationType.isPresent(), "Column
regex match shadow algorithm operation must be one of select insert update
delete.");
+ shadowOperationType.ifPresent(type -> this.shadowOperationType = type);
+ }
+
+ @Override
+ public boolean isShadow(final Collection<String> shadowTableNames, final
PreciseColumnShadowValue<String> shadowValue) {
+ boolean containTable =
shadowTableNames.contains(shadowValue.getLogicTableName());
+ boolean isSameOperation = shadowOperationType ==
shadowValue.getShadowOperationType();
+ boolean isSameColumnName = Objects.equals(props.get(COLUMN),
shadowValue.getColumnName());
+ boolean isRegexMatch =
shadowValue.getValue().matches(props.get(REGEX).toString());
+ return containTable && isSameOperation && isSameColumnName &&
isRegexMatch;
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/NoteShadowAlgorithmUtil.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/NoteShadowAlgorithmUtil.java
new file mode 100644
index 0000000..1b52dde
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/NoteShadowAlgorithmUtil.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.algorithm.shadow.note;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Note shadow algorithm util.
+ */
+public final class NoteShadowAlgorithmUtil {
+
+ private static final String SIMPLE_SQL_NOTE_SPACE = ",";
+
+ private static final String SIMPLE_SQL_NOTE_ELEMENT_SPACE = "=";
+
+ private static final String SIMPLE_SQL_NOTE_PREFIX = "/*";
+
+ private static final String SIMPLE_SQL_NOTE_SUFFIX = "*/";
+
+ /**
+ * Parse simple SQL note.
+ *
+ * @param sqlNoteValue SQL note value
+ * @return note map
+ */
+ public static Optional<Map<String, String>> parseSimpleSQLNote(final
String sqlNoteValue) {
+ String noteValue = sqlNoteValue.trim();
+ if (noteValue.startsWith(SIMPLE_SQL_NOTE_PREFIX)) {
+ noteValue = removePrefix(noteValue);
+ }
+ if (noteValue.endsWith(SIMPLE_SQL_NOTE_SUFFIX)) {
+ noteValue = removeSuffix(noteValue);
+ }
+ if (isBlank(noteValue)) {
+ return Optional.empty();
+ } else {
+ noteValue = noteValue.trim();
+ String[] noteElements = noteValue.split(SIMPLE_SQL_NOTE_SPACE);
+ Map<String, String> result = new HashMap<>(noteElements.length);
+ for (String each : noteElements) {
+ String temp = each;
+ temp = temp.trim();
+ String[] split = temp.split(SIMPLE_SQL_NOTE_ELEMENT_SPACE);
+ result.put(split[0].trim(), split[1].trim());
+ }
+ return Optional.of(result);
+ }
+ }
+
+ private static String removePrefix(final String input) {
+ return input.substring(SIMPLE_SQL_NOTE_PREFIX.length());
+ }
+
+ private static String removeSuffix(final String input) {
+ return input.substring(0, input.length() -
SIMPLE_SQL_NOTE_SUFFIX.length());
+ }
+
+ private static boolean isBlank(final String noteValue) {
+ final int strLen = noteValue == null ? 0 : noteValue.length();
+ if (strLen == 0) {
+ return true;
+ }
+ for (int i = 0; i < strLen; i++) {
+ if (!Character.isWhitespace(noteValue.charAt(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
new file mode 100644
index 0000000..8429929
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.algorithm.shadow.note;
+
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * Simple note shadow algorithm.
+ */
+@Getter
+@Setter
+public final class SimpleSQLNoteShadowAlgorithm implements
NoteShadowAlgorithm<String> {
+
+ private Properties props = new Properties();
+
+ @Override
+ public String getType() {
+ return "SIMPLE_NOTE";
+ }
+
+ @Override
+ public void init() {
+ checkPropsSize();
+ }
+
+ private void checkPropsSize() {
+ Preconditions.checkState(!props.isEmpty(), "Simple note shadow
algorithm props cannot be empty.");
+ }
+
+ @Override
+ public boolean isShadow(final Collection<String> shadowTableNames, final
PreciseNoteShadowValue<String> noteShadowValue) {
+ if (!shadowTableNames.contains(noteShadowValue.getLogicTableName())) {
+ return false;
+ }
+ Optional<Map<String, String>> noteOptional =
NoteShadowAlgorithmUtil.parseSimpleSQLNote(noteShadowValue.getSqlNoteValue());
+ return noteOptional.filter(stringStringMap ->
props.entrySet().stream().allMatch(entry -> Objects.equals(entry.getValue(),
stringStringMap.get(String.valueOf(entry.getKey()))))).isPresent();
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/resources/META-INF/services/org.apache.shardingsphere.shadow.spi.ShadowAlgorithm
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/resources/META-INF/services/org.apache.shardingsphere.shadow.spi.ShadowAlgorithm
index 0ccb32c..a428d4b 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/resources/META-INF/services/org.apache.shardingsphere.shadow.spi.ShadowAlgorithm
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/resources/META-INF/services/org.apache.shardingsphere.shadow.spi.ShadowAlgorithm
@@ -15,5 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.shadow.algorithm.ColumnRegularMatchShadowAlgorithm
-org.apache.shardingsphere.shadow.algorithm.SimpleSQLNoteShadowAlgorithm
+org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm
+org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
new file mode 100644
index 0000000..38bba92
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.algorithm.shadow.column;
+
+import
org.apache.shardingsphere.shadow.api.shadow.column.PreciseColumnShadowValue;
+import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class ColumnRegexMatchShadowAlgorithmTest {
+
+ private ColumnRegexMatchShadowAlgorithm shadowAlgorithm;
+
+ @Before
+ public void init() {
+ shadowAlgorithm = new ColumnRegexMatchShadowAlgorithm();
+ shadowAlgorithm.setProps(createProperties());
+ shadowAlgorithm.init();
+ }
+
+ private Properties createProperties() {
+ Properties properties = new Properties();
+ properties.setProperty("column", "shadow");
+ properties.setProperty("operation", "insert");
+ properties.setProperty("regex", "[1]");
+ return properties;
+ }
+
+ @Test
+ public void assertIsShadow() {
+ assertTrueCase();
+ assertFalseCase();
+ }
+
+ private void assertFalseCase() {
+ assertThat(shadowAlgorithm.isShadow(createTableNames(),
createPreciseColumnShadowValue("auto", ShadowOperationType.INSERT, "shadow",
"1")), is(false));
+ assertThat(shadowAlgorithm.isShadow(createTableNames(),
createPreciseColumnShadowValue("t_user", ShadowOperationType.UPDATE, "shadow",
"1")), is(false));
+ assertThat(shadowAlgorithm.isShadow(createTableNames(),
createPreciseColumnShadowValue("t_user", ShadowOperationType.UPDATE, "auto",
"1")), is(false));
+ assertThat(shadowAlgorithm.isShadow(createTableNames(),
createPreciseColumnShadowValue("t_user", ShadowOperationType.UPDATE, "shadow",
"2")), is(false));
+ }
+
+ private void assertTrueCase() {
+ assertThat(shadowAlgorithm.isShadow(createTableNames(),
createPreciseColumnShadowValue("t_user", ShadowOperationType.INSERT, "shadow",
"1")), is(true));
+ assertThat(shadowAlgorithm.isShadow(createTableNames(),
createPreciseColumnShadowValue("t_order", ShadowOperationType.INSERT, "shadow",
"1")), is(true));
+ }
+
+ private PreciseColumnShadowValue<String>
createPreciseColumnShadowValue(final String logicTableName, final
ShadowOperationType shadowOperationType, final String columnName, final String
value) {
+ return new PreciseColumnShadowValue<>(logicTableName,
shadowOperationType, columnName, value);
+ }
+
+ private Collection<String> createTableNames() {
+ Collection<String> shadowTableNames = new LinkedList<>();
+ shadowTableNames.add("t_user");
+ shadowTableNames.add("t_order");
+ return shadowTableNames;
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithmTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithmTest.java
new file mode 100644
index 0000000..4391a1f
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithmTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.algorithm.shadow.note;
+
+import org.apache.shardingsphere.shadow.api.shadow.note.PreciseNoteShadowValue;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class SimpleSQLNoteShadowAlgorithmTest {
+
+ private SimpleSQLNoteShadowAlgorithm shadowAlgorithm;
+
+ @Before
+ public void init() {
+ shadowAlgorithm = new SimpleSQLNoteShadowAlgorithm();
+ shadowAlgorithm.setProps(createProperties());
+ }
+
+ private Properties createProperties() {
+ Properties properties = new Properties();
+ properties.setProperty("shadow", "true");
+ return properties;
+ }
+
+ @Test
+ public void assertIsShadow() {
+ assertTrueCase();
+ assertFalseCase();
+ }
+
+ private void assertFalseCase() {
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue("/**/")), is(false));
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue("/*")), is(false));
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue("aaa = bbb")), is(false));
+ }
+
+ private void assertTrueCase() {
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue("/* shadow = true */")), is(true));
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue(" shadow = true */")), is(true));
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue("/* shadow = true ")), is(true));
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue(" shadow = true ")), is(true));
+ assertThat(shadowAlgorithm.isShadow(createShadowTableNames(),
createNoteShadowValue(" shadow = true, aaa = bbb ")), is(true));
+ }
+
+ private PreciseNoteShadowValue<String> createNoteShadowValue(final String
sqlNote) {
+ return new PreciseNoteShadowValue<>("t_user", sqlNote);
+ }
+
+ private Collection<String> createShadowTableNames() {
+ Collection<String> shadowTableNames = new LinkedList<>();
+ shadowTableNames.add("t_user");
+ shadowTableNames.add("t_order");
+ return shadowTableNames;
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java
index 4834439..c9cd614 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/swapper/ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.shadow.swapper;
import
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlShardingSphereAlgorithmConfiguration;
-import
org.apache.shardingsphere.shadow.algorithm.ColumnRegularMatchShadowAlgorithm;
+import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
@@ -74,7 +74,7 @@ public final class
ShadowRuleAlgorithmProviderConfigurationYamlSwapperTest {
result.setEnable(true);
result.getDataSources().put("shadow-data-source", new
ShadowDataSourceConfiguration("ds", "ds-shadow"));
result.getTables().put("t_order", new
ShadowTableConfiguration(Arrays.asList("user-id-match-algorithm",
"note-algorithm")));
- result.getShadowAlgorithms().put("user-id-match-algorithm", new
ColumnRegularMatchShadowAlgorithm());
+ result.getShadowAlgorithms().put("user-id-match-algorithm", new
ColumnRegexMatchShadowAlgorithm());
return result;
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java
index 4dfa1ba..33590a3 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/PropertiesShadowSpringBootStarterTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.shadow.spring.boot;
-import
org.apache.shardingsphere.shadow.algorithm.ColumnRegularMatchShadowAlgorithm;
-import org.apache.shardingsphere.shadow.algorithm.SimpleSQLNoteShadowAlgorithm;
import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
+import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
+import
org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
@@ -57,7 +57,7 @@ public class PropertiesShadowSpringBootStarterTest {
}
private void assertShadowAlgorithms(final Map<String, ShadowAlgorithm>
shadowAlgorithms) {
- assertThat(shadowAlgorithms.get("t-order-user-id-algorithm")
instanceof ColumnRegularMatchShadowAlgorithm, is(true));
+ assertThat(shadowAlgorithms.get("t-order-user-id-algorithm")
instanceof ColumnRegexMatchShadowAlgorithm, is(true));
assertThat(shadowAlgorithms.get("t-order-note-algorithm") instanceof
SimpleSQLNoteShadowAlgorithm, is(true));
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java
index aa07bed..90707d7 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/YmlShadowSpringBootStarterTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.shadow.spring.boot;
-import
org.apache.shardingsphere.shadow.algorithm.ColumnRegularMatchShadowAlgorithm;
-import org.apache.shardingsphere.shadow.algorithm.SimpleSQLNoteShadowAlgorithm;
import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
+import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
+import
org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
@@ -57,7 +57,7 @@ public class YmlShadowSpringBootStarterTest {
}
private void assertShadowAlgorithms(final Map<String, ShadowAlgorithm>
shadowAlgorithms) {
- assertThat(shadowAlgorithms.get("t-order-user-id-algorithm")
instanceof ColumnRegularMatchShadowAlgorithm, is(true));
+ assertThat(shadowAlgorithms.get("t-order-user-id-algorithm")
instanceof ColumnRegexMatchShadowAlgorithm, is(true));
assertThat(shadowAlgorithms.get("t-order-note-algorithm") instanceof
SimpleSQLNoteShadowAlgorithm, is(true));
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties
index c5d9dd9..b44dca1 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-properties.properties
@@ -29,10 +29,10 @@
spring.shardingsphere.rules.shadow.tables.t_order.shadow-algorithm-names[2]=t-or
spring.shardingsphere.rules.shadow.tables.t_user.shadow-algorithm-names[0]=t-order-user-id-algorithm
spring.shardingsphere.rules.shadow.tables.t_user.shadow-algorithm-names[1]=t-order-note-algorithm
-spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-user-id-algorithm.type=COLUMN-REGULAR-MATCH
+spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-user-id-algorithm.type=COLUMN_REGEX_MATCH
spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-user-id-algorithm.props.column=user_id
spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-user-id-algorithm.props.operation=INSERT
spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-user-id-algorithm.props.regex=[a]
-spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-note-algorithm.type=SIMPLE-NOTE
+spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-note-algorithm.type=SIMPLE_NOTE
spring.shardingsphere.rules.shadow.shadow-algorithms.t-order-note-algorithm.props.shadow=true
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml
index 411cb30..84dd3e8 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow-yml.yml
@@ -39,12 +39,12 @@ spring:
- t-order-note-algorithm
shadow-algorithms:
t-order-user-id-algorithm:
- type: COLUMN-REGULAR-MATCH
+ type: COLUMN_REGEX_MATCH
props:
- column: user_id
- regex: [a]
operation: INSERT
+ column: user_id
+ regex: aa
t-order-note-algorithm:
- type: SIMPLE-NOTE
+ type: SIMPLE_NOTE
props:
shadow: true
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd
index 14c07a3..320251b 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/main/resources/META-INF/namespace/shadow.xsd
@@ -81,8 +81,8 @@
<xsd:simpleType name="algorithmType">
<xsd:restriction base="xsd:string">
- <xsd:enumeration value="COLUMN-REGULAR-MATCH" />
- <xsd:enumeration value="SIMPLE-NOTE" />
+ <xsd:enumeration value="COLUMN_REGEX_MATCH" />
+ <xsd:enumeration value="SIMPLE_NOTE" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java
index 440bc29..6f42032 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/java/org/apache/shardingsphere/shadow/spring/namespace/ShadowAlgorithmSpringNamespaceTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.shadow.spring.namespace;
-import
org.apache.shardingsphere.shadow.algorithm.ColumnRegularMatchShadowAlgorithm;
-import org.apache.shardingsphere.shadow.algorithm.SimpleSQLNoteShadowAlgorithm;
import
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
+import
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
+import
org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
@@ -51,7 +51,7 @@ public final class ShadowAlgorithmSpringNamespaceTest extends
AbstractJUnit4Spri
}
private void assertShadowAlgorithms(final Map<String, ShadowAlgorithm>
shadowAlgorithms) {
- assertThat(shadowAlgorithms.get("columnRegularMatchShadowAlgorithm")
instanceof ColumnRegularMatchShadowAlgorithm, is(true));
+ assertThat(shadowAlgorithms.get("columnRegularMatchShadowAlgorithm")
instanceof ColumnRegexMatchShadowAlgorithm, is(true));
assertThat(shadowAlgorithms.get("noteShadowAlgorithm") instanceof
SimpleSQLNoteShadowAlgorithm, is(true));
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml
index 5c9ec8a..6bb6b83 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-namespace/src/test/resources/META-INF/spring/shadow-algorithm-application-context.xml
@@ -25,14 +25,14 @@
http://shardingsphere.apache.org/schema/shardingsphere/shadow/shadow.xsd
">
- <shadow:shadow-algorithm id="columnRegularMatchShadowAlgorithm"
type="COLUMN-REGULAR-MATCH">
+ <shadow:shadow-algorithm id="columnRegularMatchShadowAlgorithm"
type="COLUMN_REGEX_MATCH">
<props>
<prop key="column">user_id</prop>
<prop key="regex">[a]</prop>
<prop key="operation">UPDATE</prop>
</props>
</shadow:shadow-algorithm>
- <shadow:shadow-algorithm id="noteShadowAlgorithm" type="SIMPLE-NOTE">
+ <shadow:shadow-algorithm id="noteShadowAlgorithm" type="SIMPLE_NOTE">
<props>
<prop key="shadow">true</prop>
</props>