This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 3ece679b02e Minor refactor for EncryptSQLRewriteContextDecorator
(#34270)
3ece679b02e is described below
commit 3ece679b02ee5da45bb3bcda730d8803b41c0f37
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Jan 6 16:25:54 2025 +0800
Minor refactor for EncryptSQLRewriteContextDecorator (#34270)
---
.../encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java | 5 +++--
.../rewrite/context/EncryptSQLRewriteContextDecoratorTest.java | 2 --
2 files changed, 3 insertions(+), 4 deletions(-)
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 7f7fab2ad91..de39b0c0a0d 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
@@ -38,6 +38,7 @@ import
org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewri
import
org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.builder.SQLTokenGeneratorBuilder;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import java.util.Collection;
import java.util.Collections;
@@ -68,8 +69,8 @@ public final class EncryptSQLRewriteContextDecorator
implements SQLRewriteContex
if (!(sqlStatementContext instanceof TableAvailable)) {
return false;
}
- for (String each : ((TableAvailable)
sqlStatementContext).getTablesContext().getTableNames()) {
- if (rule.findEncryptTable(each).isPresent()) {
+ for (SimpleTableSegment each : ((TableAvailable)
sqlStatementContext).getTablesContext().getSimpleTables()) {
+ if
(rule.findEncryptTable(each.getTableName().getIdentifier().getValue()).isPresent())
{
return true;
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
index 173396ade44..1352fa10ea4 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
@@ -32,7 +32,6 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Collections;
-import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -67,7 +66,6 @@ class EncryptSQLRewriteContextDecoratorTest {
SelectStatementContext sqlStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl"));
when(sqlRewriteContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
- when(rule.findEncryptTable("foo_tbl")).thenReturn(Optional.empty());
decorator.decorate(rule, mock(ConfigurationProperties.class),
sqlRewriteContext, mock(RouteContext.class));
assertTrue(sqlRewriteContext.getSqlTokens().isEmpty());
}