tristaZero commented on a change in pull request #11995:
URL: https://github.com/apache/shardingsphere/pull/11995#discussion_r695554146



##########
File path: 
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/ShadowOperationType.java
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 lombok.NoArgsConstructor;
+
+import java.util.Optional;
+
+/**
+ * Operation types supported by shadow.
+ */
+@NoArgsConstructor
+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;
+    
+    /**
+     * Create shadow operation type.
+     *
+     * @param operationType operation type
+     * @return shadow operation type
+     */
+    public static Optional<ShadowOperationType> newInstance(final String 
operationType) {

Review comment:
       Could your refer to `MySQLAuthenticationMethod`?

##########
File path: 
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/note/SimpleSQLNoteShadowAlgorithm.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.HashMap;
+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 static final String NOTE_SPACE = ",";
+    
+    private static final String NOTE_ELEMENT_SPACE = "=";
+    
+    private static final String NOTE_PREFIX = "/*";
+    
+    private static final String NOTE_SUFFIX = "*/";
+    
+    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 = 
parseNote(noteShadowValue.getSqlNoteValue());
+        return noteOptional.filter(stringStringMap -> 
props.entrySet().stream().allMatch(entry -> Objects.equals(entry.getValue(), 
stringStringMap.get(String.valueOf(entry.getKey()))))).isPresent();
+    }
+    
+    private Optional<Map<String, String>> parseNote(final String sqlNoteValue) 
{

Review comment:
       It is suggested to extract this logic to a util class for other `note 
algorithms`.

##########
File path: 
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/ShadowAlgorithmType.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import java.util.Optional;
+
+/**
+ * Shadow algorithm type.
+ */
+public enum ShadowAlgorithmType {
+    
+    /**
+     * Shadow algorithm use column match with regular expression.
+     */
+    COLUMN_REGEX_MATCH,
+    
+    /**
+     * Shadow algorithm use simple sql note.
+     */
+    SIMPLE_NOTE;
+    
+    /**
+     * Create shadow algorithm type.
+     *
+     * @param shadowAlgorithmType shadow algorithm type
+     * @return shadow operation type
+     */
+    public static Optional<ShadowAlgorithmType> newInstance(final String 
shadowAlgorithmType) {

Review comment:
       Do you think `instanceof` is suitable to replace this class?

##########
File path: 
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/note/PreciseNoteShadowValue.java
##########
@@ -15,24 +15,19 @@
  * 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 lombok.ToString;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
 
-/**
- * Simple note shadow algorithm.
- */
+@RequiredArgsConstructor
 @Getter
-@Setter
-public final class SimpleSQLNoteShadowAlgorithm implements ShadowAlgorithm {
+@ToString
+public class PreciseNoteShadowValue<T extends Comparable<?>> implements 
ShadowValue {

Review comment:
       Is it supposed to be a final class?

##########
File path: 
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/shadow/column/PreciseColumnShadowValue.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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 lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import org.apache.shardingsphere.shadow.api.shadow.ShadowValue;
+
+/**
+ * Shadow value for precise column.
+ */
+@RequiredArgsConstructor
+@Getter
+@ToString
+public class PreciseColumnShadowValue<T extends Comparable<?>> implements 
ShadowValue {

Review comment:
       Is it supposed to be a final class?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to