From f992ddeead536143fc18bba8250d812180cef7e2 Mon Sep 17 00:00:00 2001 From: daleyzou Date: Tue, 19 Sep 2023 17:47:54 +0800 Subject: [PATCH] * Made some optimizations for the isColumnNameNotConflicts method --- .../update/AlterEncryptRuleStatementUpdater.java | 12 ++---------- .../update/CreateEncryptRuleStatementUpdater.java | 12 ++---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java index 4f1f84b110e9c..c27191cb497d0 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleStatementUpdater.java @@ -26,7 +26,6 @@ import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration; import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration; import org.apache.shardingsphere.encrypt.distsql.handler.converter.EncryptRuleStatementConverter; -import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment; import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment; import org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement; import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm; @@ -78,15 +77,8 @@ private void checkColumnNames(final AlterEncryptRuleStatement sqlStatement) { } private boolean isColumnNameNotConflicts(final EncryptRuleSegment rule) { - for (EncryptColumnSegment each : rule.getColumns()) { - if (null != each.getLikeQuery() && each.getName().equals(each.getLikeQuery().getName())) { - return false; - } - if (null != each.getAssistedQuery() && each.getName().equals(each.getAssistedQuery().getName())) { - return false; - } - } - return true; + return rule.getColumns().stream().noneMatch(each -> null != each.getLikeQuery() && each.getName().equals(each.getLikeQuery().getName()) + || null != each.getAssistedQuery() && each.getName().equals(each.getAssistedQuery().getName())); } private void checkToBeAlteredEncryptors(final AlterEncryptRuleStatement sqlStatement) { diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java index 88d0fbb8d7041..fd89993ba7801 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleStatementUpdater.java @@ -30,7 +30,6 @@ import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm; import org.apache.shardingsphere.encrypt.distsql.handler.converter.EncryptRuleStatementConverter; import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnItemSegment; -import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment; import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment; import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement; import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm; @@ -96,15 +95,8 @@ private void checkColumnNames(final CreateEncryptRuleStatement sqlStatement) { } private boolean isColumnNameNotConflicts(final EncryptRuleSegment rule) { - for (EncryptColumnSegment each : rule.getColumns()) { - if (null != each.getLikeQuery() && each.getName().equals(each.getLikeQuery().getName())) { - return false; - } - if (null != each.getAssistedQuery() && each.getName().equals(each.getAssistedQuery().getName())) { - return false; - } - } - return true; + return rule.getColumns().stream().noneMatch(each -> null != each.getLikeQuery() && each.getName().equals(each.getLikeQuery().getName()) + || null != each.getAssistedQuery() && each.getName().equals(each.getAssistedQuery().getName())); } private void checkToBeCreatedEncryptors(final CreateEncryptRuleStatement sqlStatement) {