Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactor for EncryptSQLRewriteContextDecorator #34270

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
Expand Down Expand Up @@ -68,8 +69,8 @@ private boolean containsEncryptTable(final EncryptRule rule, final SQLStatementC
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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;
Expand Down Expand Up @@ -67,7 +66,6 @@ void assertDecorateWithoutEncryptTable() {
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());
}
Expand Down
Loading