You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/07/24 12:30:10 UTC
(shardingsphere) branch master updated: Refactor EncryptSQLRewriteContextDecorator (#32249)
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 90b3ea89140 Refactor EncryptSQLRewriteContextDecorator (#32249)
90b3ea89140 is described below
commit 90b3ea89140f36b8e1e6954262cf4b90b5aed87b
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Jul 24 20:30:04 2024 +0800
Refactor EncryptSQLRewriteContextDecorator (#32249)
---
.../rewrite/condition/EncryptConditionEngine.java | 2 ++
.../context/EncryptSQLRewriteContextDecorator.java | 22 +++++++++++-----------
.../shardingsphere/encrypt/rule/EncryptRule.java | 3 +++
.../parameter/rewriter/ParameterRewriter.java | 2 +-
4 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
index 5e26f2ecd88..548244898bb 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptBinaryCon
import org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptInCondition;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
+import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -54,6 +55,7 @@ import java.util.TreeSet;
/**
* Encrypt condition engine.
*/
+@HighFrequencyInvocation
@RequiredArgsConstructor
public final class EncryptConditionEngine {
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
index e71e0096990..38ee7e74010 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
@@ -62,17 +62,6 @@ public final class EncryptSQLRewriteContextDecorator implements SQLRewriteContex
sqlRewriteContext.addSQLTokenGenerators(sqlTokenGenerators);
}
- private Collection<EncryptCondition> createEncryptConditions(final EncryptRule encryptRule, final SQLRewriteContext sqlRewriteContext) {
- SQLStatementContext sqlStatementContext = sqlRewriteContext.getSqlStatementContext();
- if (!(sqlStatementContext instanceof WhereAvailable)) {
- return Collections.emptyList();
- }
- Collection<WhereSegment> whereSegments = ((WhereAvailable) sqlStatementContext).getWhereSegments();
- Collection<ColumnSegment> columnSegments = ((WhereAvailable) sqlStatementContext).getColumnSegments();
- return new EncryptConditionEngine(encryptRule, sqlRewriteContext.getDatabase().getSchemas()).createEncryptConditions(whereSegments, columnSegments, sqlStatementContext,
- sqlRewriteContext.getDatabase().getName());
- }
-
private boolean containsEncryptTable(final EncryptRule encryptRule, final SQLStatementContext sqlStatementContext) {
if (!(sqlStatementContext instanceof TableAvailable)) {
return false;
@@ -85,6 +74,17 @@ public final class EncryptSQLRewriteContextDecorator implements SQLRewriteContex
return false;
}
+ private Collection<EncryptCondition> createEncryptConditions(final EncryptRule encryptRule, final SQLRewriteContext sqlRewriteContext) {
+ SQLStatementContext sqlStatementContext = sqlRewriteContext.getSqlStatementContext();
+ if (!(sqlStatementContext instanceof WhereAvailable)) {
+ return Collections.emptyList();
+ }
+ Collection<WhereSegment> whereSegments = ((WhereAvailable) sqlStatementContext).getWhereSegments();
+ Collection<ColumnSegment> columnSegments = ((WhereAvailable) sqlStatementContext).getColumnSegments();
+ return new EncryptConditionEngine(encryptRule, sqlRewriteContext.getDatabase().getSchemas())
+ .createEncryptConditions(whereSegments, columnSegments, sqlStatementContext, sqlRewriteContext.getDatabase().getName());
+ }
+
private void rewriteParameters(final SQLRewriteContext sqlRewriteContext, final Collection<ParameterRewriter> parameterRewriters) {
for (ParameterRewriter each : parameterRewriters) {
each.rewrite(sqlRewriteContext.getParameterBuilder(), sqlRewriteContext.getSqlStatementContext(), sqlRewriteContext.getParameters());
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
index f71d3ba2cc9..f6f2b9765b7 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
@@ -29,6 +29,7 @@ import org.apache.shardingsphere.encrypt.rule.attribute.EncryptTableMapperRuleAt
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.rule.PartialRuleUpdateSupported;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
@@ -106,6 +107,7 @@ public final class EncryptRule implements DatabaseRule, PartialRuleUpdateSupport
* @param tableName table name
* @return encrypt table
*/
+ @HighFrequencyInvocation
public Optional<EncryptTable> findEncryptTable(final String tableName) {
return Optional.ofNullable(tables.get(tableName));
}
@@ -116,6 +118,7 @@ public final class EncryptRule implements DatabaseRule, PartialRuleUpdateSupport
* @param tableName table name
* @return encrypt table
*/
+ @HighFrequencyInvocation
public EncryptTable getEncryptTable(final String tableName) {
return findEncryptTable(tableName).orElseThrow(() -> new EncryptTableNotFoundException(tableName));
}
diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/ParameterRewriter.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/ParameterRewriter.java
index eda544b88dd..09aaabf687b 100644
--- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/ParameterRewriter.java
+++ b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/parameter/rewriter/ParameterRewriter.java
@@ -28,7 +28,7 @@ import java.util.List;
public interface ParameterRewriter {
/**
- * Judge whether need rewrite.
+ * Judge whether to need rewrite.
*
* @param sqlStatementContext SQL statement context
* @return is need rewrite or not