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 cde18e704da Merge EncryptCondition.getValues() into
EncryptConditionValues (#33623)
cde18e704da is described below
commit cde18e704da6fc8418960330d2c48d0dcf0cbe5f
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Nov 12 13:27:45 2024 +0800
Merge EncryptCondition.getValues() into EncryptConditionValues (#33623)
---
.../encrypt/rewrite/condition/EncryptCondition.java | 9 ---------
.../encrypt/rewrite/condition/EncryptConditionValues.java | 9 +++------
.../rewrite/condition/impl/EncryptBinaryCondition.java | 7 -------
.../encrypt/rewrite/condition/impl/EncryptInCondition.java | 6 ------
.../rewriter/EncryptPredicateParameterRewriter.java | 3 ++-
.../predicate/EncryptPredicateRightValueTokenGenerator.java | 3 ++-
.../rewrite/condition/EncryptConditionValuesTest.java | 7 ++++++-
.../rewrite/condition/impl/EncryptBinaryConditionTest.java | 10 ++++------
.../rewrite/condition/impl/EncryptInConditionTest.java | 13 +++++++------
9 files changed, 24 insertions(+), 43 deletions(-)
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java
index 773db389e5a..af320e1ff41 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.encrypt.rewrite.condition;
-import java.util.List;
import java.util.Map;
/**
@@ -66,12 +65,4 @@ public interface EncryptCondition {
* @return position value map
*/
Map<Integer, Object> getPositionValueMap();
-
- /**
- * Get values.
- *
- * @param params SQL parameters
- * @return values
- */
- List<Object> getValues(List<Object> params);
}
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
index ba3e437b72d..f231f9078f0 100644
---
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
@@ -21,7 +21,6 @@ import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
/**
@@ -30,9 +29,7 @@ import java.util.Map.Entry;
@RequiredArgsConstructor
public final class EncryptConditionValues {
- private final Map<Integer, Integer> positionIndexMap;
-
- private final Map<Integer, Object> positionValueMap;
+ private final EncryptCondition condition;
/**
* Get values.
@@ -41,8 +38,8 @@ public final class EncryptConditionValues {
* @return values
*/
public List<Object> getValues(final List<Object> params) {
- List<Object> result = new ArrayList<>(positionValueMap.values());
- for (Entry<Integer, Integer> entry : positionIndexMap.entrySet()) {
+ List<Object> result = new
ArrayList<>(condition.getPositionValueMap().values());
+ for (Entry<Integer, Integer> entry :
condition.getPositionIndexMap().entrySet()) {
Object param = params.get(entry.getValue());
if (entry.getKey() < result.size()) {
result.add(entry.getKey(), param);
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 098b18930ee..a345ef0d7c6 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,14 +21,12 @@ 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.LinkedHashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -77,9 +75,4 @@ public final class EncryptBinaryCondition implements
EncryptCondition {
}
}
}
-
- @Override
- public List<Object> getValues(final List<Object> params) {
- 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 94cc83b6cb6..7f6801f6d2a 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,7 +21,6 @@ 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;
@@ -69,9 +68,4 @@ public final class EncryptInCondition implements
EncryptCondition {
positionValueMap.put(position, ((LiteralExpressionSegment)
expressionSegment).getLiterals());
}
}
-
- @Override
- public List<Object> getValues(final List<Object> params) {
- return new EncryptConditionValues(positionIndexMap,
positionValueMap).getValues(params);
- }
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java
index b936dcc457e..a0c6f75d03f 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.encrypt.rewrite.parameter.rewriter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition;
+import
org.apache.shardingsphere.encrypt.rewrite.condition.EncryptConditionValues;
import
org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptBinaryCondition;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
@@ -58,7 +59,7 @@ public final class EncryptPredicateParameterRewriter
implements ParameterRewrite
String schemaName = ((TableAvailable)
sqlStatementContext).getTablesContext().getSchemaName()
.orElseGet(() -> new
DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(databaseName));
for (EncryptCondition each : encryptConditions) {
- encryptParameters(paramBuilder, each.getPositionIndexMap(),
getEncryptedValues(schemaName, each, each.getValues(params)));
+ encryptParameters(paramBuilder, each.getPositionIndexMap(),
getEncryptedValues(schemaName, each, new
EncryptConditionValues(each).getValues(params)));
}
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java
index bf45039948e..09cf4eb1803 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.encrypt.exception.metadata.MissingMatchedEncryp
import org.apache.shardingsphere.encrypt.rewrite.aware.DatabaseNameAware;
import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptConditionsAware;
import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition;
+import
org.apache.shardingsphere.encrypt.rewrite.condition.EncryptConditionValues;
import
org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptBinaryCondition;
import
org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptInCondition;
import
org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptPredicateEqualRightValueToken;
@@ -84,7 +85,7 @@ public final class EncryptPredicateRightValueTokenGenerator
implements Collectio
int startIndex = encryptCondition.getStartIndex();
int stopIndex = encryptCondition.getStopIndex();
Map<Integer, Object> indexValues = getPositionValues(
- encryptCondition.getPositionValueMap().keySet(),
getEncryptedValues(schemaName, encryptTable, encryptCondition,
encryptCondition.getValues(parameters)));
+ encryptCondition.getPositionValueMap().keySet(),
getEncryptedValues(schemaName, encryptTable, encryptCondition, new
EncryptConditionValues(encryptCondition).getValues(parameters)));
Collection<Integer> parameterMarkerIndexes =
encryptCondition.getPositionIndexMap().keySet();
if (encryptCondition instanceof EncryptBinaryCondition &&
((EncryptBinaryCondition) encryptCondition).getExpressionSegment() instanceof
FunctionSegment) {
FunctionSegment functionSegment = (FunctionSegment)
((EncryptBinaryCondition) encryptCondition).getExpressionSegment();
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
index b6c8ae8be5f..fbc7cec9b4a 100644
---
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
@@ -27,6 +27,8 @@ import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
class EncryptConditionValuesTest {
@@ -36,7 +38,10 @@ class EncryptConditionValuesTest {
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"));
+ EncryptCondition condition = mock(EncryptCondition.class);
+ when(condition.getPositionIndexMap()).thenReturn(positionIndexMap);
+ when(condition.getPositionValueMap()).thenReturn(positionValueMap);
+ List<Object> actual = new
EncryptConditionValues(condition).getValues(Arrays.asList("foo", "bar"));
assertThat(actual.size(), is(3));
assertThat(actual.get(0), is("foo"));
assertThat(actual.get(1), is(1));
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java
index 7376cda1975..151340ab499 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java
@@ -21,7 +21,6 @@ import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simp
import org.junit.jupiter.api.Test;
import java.util.Collections;
-import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -29,10 +28,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
class EncryptBinaryConditionTest {
@Test
- void assertGetConditionValues() {
- List<Object> actual = new EncryptBinaryCondition("col", null, null,
- 0, 0, new LiteralExpressionSegment(0, 0,
1)).getValues(Collections.emptyList());
- assertThat(actual.size(), is(1));
- assertThat(actual.get(0), is(1));
+ void assertNewInstance() {
+ EncryptBinaryCondition actual = new EncryptBinaryCondition("col",
null, null, 0, 0, new LiteralExpressionSegment(0, 0, 1));
+ assertThat(actual.getPositionIndexMap(), is(Collections.emptyMap()));
+ assertThat(actual.getPositionValueMap().size(), is(1));
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java
index 7c366788b02..314c5f701d6 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java
@@ -32,13 +32,14 @@ import static org.mockito.Mockito.mock;
class EncryptInConditionTest {
@Test
- void assertGetValues() {
+ void assertNewInstance() {
List<ExpressionSegment> expressions = Arrays.asList(new
ParameterMarkerExpressionSegment(0, 0, 0), new LiteralExpressionSegment(0, 0,
1),
new ParameterMarkerExpressionSegment(0, 0, 1),
mock(ExpressionSegment.class));
- List<Object> actual = new EncryptInCondition("foo_col", null, 0, 0,
expressions).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"));
+ EncryptInCondition actual = new EncryptInCondition("foo_col", null, 0,
0, expressions);
+ assertThat(actual.getPositionIndexMap().size(), is(2));
+ assertThat(actual.getPositionIndexMap().get(0), is(0));
+ assertThat(actual.getPositionIndexMap().get(2), is(1));
+ assertThat(actual.getPositionValueMap().size(), is(1));
+ assertThat(actual.getPositionValueMap().get(1), is(1));
}
}