From e469183ffff39fad654877a7d343a404064d9516 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Fri, 24 Nov 2023 21:56:31 +0800 Subject: [PATCH] Remove java stream api and build sql when execute addAssignment method --- .../EncryptInsertOnUpdateTokenGenerator.java | 2 +- .../pojo/EncryptFunctionAssignmentToken.java | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertOnUpdateTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertOnUpdateTokenGenerator.java index 23731d8c0fa5e..aea378440501d 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertOnUpdateTokenGenerator.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertOnUpdateTokenGenerator.java @@ -161,7 +161,7 @@ private EncryptAssignmentToken generateValuesSQLToken(final EncryptTable encrypt } else if (likeQueryColumn.isPresent() != valueLikeQueryColumn.isPresent()) { throw new UnsupportedEncryptSQLException(String.format("%s=VALUES(%s)", column, valueColumn)); } - if (result.getAssignment().isEmpty()) { + if (result.isAssignmentsEmpty()) { throw new UnsupportedEncryptSQLException(String.format("%s=VALUES(%s)", column, valueColumn)); } return result; diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/pojo/EncryptFunctionAssignmentToken.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/pojo/EncryptFunctionAssignmentToken.java index 92e8b9081123f..2073889776fdc 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/pojo/EncryptFunctionAssignmentToken.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/pojo/EncryptFunctionAssignmentToken.java @@ -21,13 +21,14 @@ import java.util.Collection; import java.util.LinkedList; -import java.util.stream.Collectors; /** * Function assignment token for encrypt. */ public final class EncryptFunctionAssignmentToken extends EncryptAssignmentToken { + private final StringBuilder builder = new StringBuilder(); + private final Collection assignments = new LinkedList<>(); public EncryptFunctionAssignmentToken(final int startIndex, final int stopIndex) { @@ -41,20 +42,23 @@ public EncryptFunctionAssignmentToken(final int startIndex, final int stopIndex) * @param value assignment value */ public void addAssignment(final String columnName, final Object value) { - assignments.add(new FunctionAssignment(columnName, value)); + FunctionAssignment functionAssignment = new FunctionAssignment(columnName, value); + assignments.add(functionAssignment); + builder.append(functionAssignment).append(", "); } /** - * Get assignments. - * @return FunctionAssignment collection + * Judge whether assignments is empty or not. + * + * @return whether assignments is empty or not */ - public Collection getAssignment() { - return assignments; + public boolean isAssignmentsEmpty() { + return assignments.isEmpty(); } @Override public String toString() { - return assignments.stream().map(FunctionAssignment::toString).collect(Collectors.joining(", ")); + return builder.substring(0, builder.length() - 2); } @RequiredArgsConstructor