This is an automated email from the ASF dual-hosted git repository.

yx9o 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 7c0b372fb7f Add EncryptConditionValues (#33622)
7c0b372fb7f is described below

commit 7c0b372fb7f46e9c098e904278b8b9fc30bef5ed
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Nov 12 12:58:44 2024 +0800

    Add EncryptConditionValues (#33622)
    
    * Add EncryptConditionValues
    
    * Add EncryptConditionValues
---
 .../rewrite/condition/EncryptConditionValues.java  | 55 ++++++++++++++++++++++
 .../condition/impl/EncryptBinaryCondition.java     | 14 +-----
 .../rewrite/condition/impl/EncryptInCondition.java | 14 +-----
 .../condition/EncryptConditionValuesTest.java      | 45 ++++++++++++++++++
 4 files changed, 104 insertions(+), 24 deletions(-)

diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionValues.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionValues.java
new file mode 100644
index 00000000000..ba3e437b72d
--- /dev/null
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionValues.java
@@ -0,0 +1,55 @@
+/*
+ * 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.encrypt.rewrite.condition;
+
+import lombok.RequiredArgsConstructor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Encrypt condition values.
+ */
+@RequiredArgsConstructor
+public final class EncryptConditionValues {
+    
+    private final Map<Integer, Integer> positionIndexMap;
+    
+    private final Map<Integer, Object> positionValueMap;
+    
+    /**
+     * Get values.
+     *
+     * @param params parameters
+     * @return values
+     */
+    public List<Object> getValues(final List<Object> params) {
+        List<Object> result = new ArrayList<>(positionValueMap.values());
+        for (Entry<Integer, Integer> entry : positionIndexMap.entrySet()) {
+            Object param = params.get(entry.getValue());
+            if (entry.getKey() < result.size()) {
+                result.add(entry.getKey(), param);
+            } else {
+                result.add(param);
+            }
+        }
+        return result;
+    }
+}
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java
index c1eb2a3ab18..098b18930ee 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java
@@ -21,16 +21,15 @@ import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.ToString;
 import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition;
+import 
org.apache.shardingsphere.encrypt.rewrite.condition.EncryptConditionValues;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 /**
  * Encrypt condition for equal.
@@ -81,15 +80,6 @@ public final class EncryptBinaryCondition implements 
EncryptCondition {
     
     @Override
     public List<Object> getValues(final List<Object> params) {
-        List<Object> result = new ArrayList<>(positionValueMap.values());
-        for (Entry<Integer, Integer> entry : positionIndexMap.entrySet()) {
-            Object param = params.get(entry.getValue());
-            if (entry.getKey() < result.size()) {
-                result.add(entry.getKey(), param);
-            } else {
-                result.add(param);
-            }
-        }
-        return result;
+        return new EncryptConditionValues(positionIndexMap, 
positionValueMap).getValues(params);
     }
 }
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java
index 9a12b9c1a07..94cc83b6cb6 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java
@@ -21,15 +21,14 @@ import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.ToString;
 import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition;
+import 
org.apache.shardingsphere.encrypt.rewrite.condition.EncryptConditionValues;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 /**
  * Encrypt condition.
@@ -73,15 +72,6 @@ public final class EncryptInCondition implements 
EncryptCondition {
     
     @Override
     public List<Object> getValues(final List<Object> params) {
-        List<Object> result = new ArrayList<>(positionValueMap.values());
-        for (Entry<Integer, Integer> entry : positionIndexMap.entrySet()) {
-            Object param = params.get(entry.getValue());
-            if (entry.getKey() < result.size()) {
-                result.add(entry.getKey(), param);
-            } else {
-                result.add(param);
-            }
-        }
-        return result;
+        return new EncryptConditionValues(positionIndexMap, 
positionValueMap).getValues(params);
     }
 }
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionValuesTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionValuesTest.java
new file mode 100644
index 00000000000..b6c8ae8be5f
--- /dev/null
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionValuesTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.encrypt.rewrite.condition;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class EncryptConditionValuesTest {
+    
+    @Test
+    void assertGetValues() {
+        Map<Integer, Integer> positionIndexMap = new HashMap<>(2, 1F);
+        positionIndexMap.put(0, 0);
+        positionIndexMap.put(2, 1);
+        Map<Integer, Object> positionValueMap = Collections.singletonMap(1, 1);
+        List<Object> actual = new EncryptConditionValues(positionIndexMap, 
positionValueMap).getValues(Arrays.asList("foo", "bar"));
+        assertThat(actual.size(), is(3));
+        assertThat(actual.get(0), is("foo"));
+        assertThat(actual.get(1), is(1));
+        assertThat(actual.get(2), is("bar"));
+    }
+}

Reply via email to