You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/06/12 06:06:42 UTC
[shardingsphere] branch master updated: Refactor EncryptAssignmentTokenGenerator (#26268)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 dfc854d7ec7 Refactor EncryptAssignmentTokenGenerator (#26268)
dfc854d7ec7 is described below
commit dfc854d7ec7d5caaef11087df719090f6be6042f
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Jun 12 14:06:33 2023 +0800
Refactor EncryptAssignmentTokenGenerator (#26268)
* Refactor EncryptAssignmentTokenGenerator
* Fix test cases
---
.../generator/EncryptAlterTableTokenGenerator.java | 63 +++++++++++-----------
.../generator/EncryptAssignmentTokenGenerator.java | 60 ++++++++++-----------
.../shardingsphere/encrypt/rule/EncryptTable.java | 2 +
.../EncryptBinaryOperationConditionTest.java | 2 +-
.../EncryptInConditionTest.java | 2 +-
.../EncryptSQLRewriteContextDecoratorTest.java | 3 +-
.../EncryptAlterTableTokenGeneratorTest.java | 4 +-
.../EncryptAssignmentTokenGeneratorTest.java | 2 +
.../EncryptCreateTableTokenGeneratorTest.java | 3 +-
.../EncryptOrderByItemTokenGeneratorTest.java | 3 +-
.../EncryptProjectionTokenGeneratorTest.java | 3 +-
11 files changed, 71 insertions(+), 76 deletions(-)
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
index da5b1ec3f44..7d6f7686e77 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGenerator.java
@@ -67,10 +67,10 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
if (!encryptTable.isPresent()) {
return Collections.emptyList();
}
- Collection<SQLToken> result = new LinkedList<>(getAddColumnTokens(tableName, encryptTable.get(), alterTableStatementContext.getSqlStatement().getAddColumnDefinitions()));
- result.addAll(getModifyColumnTokens(tableName, encryptTable.get(), alterTableStatementContext.getSqlStatement().getModifyColumnDefinitions()));
- result.addAll(getChangeColumnTokens(tableName, encryptTable.get(), alterTableStatementContext.getSqlStatement().getChangeColumnDefinitions()));
- List<SQLToken> dropColumnTokens = getDropColumnTokens(tableName, encryptTable.get(), alterTableStatementContext.getSqlStatement().getDropColumnDefinitions());
+ Collection<SQLToken> result = new LinkedList<>(getAddColumnTokens(encryptTable.get(), alterTableStatementContext.getSqlStatement().getAddColumnDefinitions()));
+ result.addAll(getModifyColumnTokens(encryptTable.get(), alterTableStatementContext.getSqlStatement().getModifyColumnDefinitions()));
+ result.addAll(getChangeColumnTokens(encryptTable.get(), alterTableStatementContext.getSqlStatement().getChangeColumnDefinitions()));
+ List<SQLToken> dropColumnTokens = getDropColumnTokens(encryptTable.get(), alterTableStatementContext.getSqlStatement().getDropColumnDefinitions());
String databaseName = alterTableStatementContext.getDatabaseType().getType();
if ("SQLServer".equals(databaseName)) {
result.addAll(mergeDropColumnStatement(dropColumnTokens, "", ""));
@@ -82,25 +82,25 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
return result;
}
- private Collection<SQLToken> getAddColumnTokens(final String tableName, final EncryptTable encryptTable, final Collection<AddColumnDefinitionSegment> columnDefinitionSegments) {
+ private Collection<SQLToken> getAddColumnTokens(final EncryptTable encryptTable, final Collection<AddColumnDefinitionSegment> columnDefinitionSegments) {
Collection<SQLToken> result = new LinkedList<>();
for (AddColumnDefinitionSegment each : columnDefinitionSegments) {
- result.addAll(getAddColumnTokens(tableName, encryptTable, each));
+ result.addAll(getAddColumnTokens(encryptTable, each));
}
return result;
}
@SuppressWarnings("rawtypes")
- private Collection<SQLToken> getAddColumnTokens(final String tableName, final EncryptTable encryptTable, final AddColumnDefinitionSegment addColumnDefinitionSegment) {
+ private Collection<SQLToken> getAddColumnTokens(final EncryptTable encryptTable, final AddColumnDefinitionSegment addColumnDefinitionSegment) {
Collection<SQLToken> result = new LinkedList<>();
for (ColumnDefinitionSegment each : addColumnDefinitionSegment.getColumnDefinitions()) {
String columnName = each.getColumnName().getIdentifier().getValue();
- Optional<StandardEncryptAlgorithm> encryptor = encryptRule.findStandardEncryptor(tableName, columnName);
+ Optional<StandardEncryptAlgorithm> encryptor = encryptRule.findStandardEncryptor(encryptTable.getTable(), columnName);
if (encryptor.isPresent()) {
result.addAll(getAddColumnTokens(encryptTable, columnName, addColumnDefinitionSegment, each));
}
}
- getAddColumnPositionToken(tableName, encryptTable, addColumnDefinitionSegment).ifPresent(result::add);
+ getAddColumnPositionToken(encryptTable, addColumnDefinitionSegment).ifPresent(result::add);
return result;
}
@@ -118,22 +118,22 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
}
@SuppressWarnings("rawtypes")
- private Optional<SQLToken> getAddColumnPositionToken(final String tableName, final EncryptTable encryptTable, final AddColumnDefinitionSegment addColumnDefinitionSegment) {
+ private Optional<SQLToken> getAddColumnPositionToken(final EncryptTable encryptTable, final AddColumnDefinitionSegment addColumnDefinitionSegment) {
Optional<StandardEncryptAlgorithm> encryptor = addColumnDefinitionSegment.getColumnPosition().filter(optional -> null != optional.getColumnName())
- .flatMap(optional -> encryptRule.findStandardEncryptor(tableName, optional.getColumnName().getIdentifier().getValue()));
+ .flatMap(optional -> encryptRule.findStandardEncryptor(encryptTable.getTable(), optional.getColumnName().getIdentifier().getValue()));
return encryptor.isPresent() ? Optional.of(getPositionColumnToken(encryptTable, addColumnDefinitionSegment.getColumnPosition().get())) : Optional.empty();
}
@SuppressWarnings("rawtypes")
- private Collection<SQLToken> getModifyColumnTokens(final String tableName, final EncryptTable encryptTable, final Collection<ModifyColumnDefinitionSegment> columnDefinitionSegments) {
+ private Collection<SQLToken> getModifyColumnTokens(final EncryptTable encryptTable, final Collection<ModifyColumnDefinitionSegment> columnDefinitionSegments) {
Collection<SQLToken> result = new LinkedList<>();
for (ModifyColumnDefinitionSegment each : columnDefinitionSegments) {
String columnName = each.getColumnDefinition().getColumnName().getIdentifier().getValue();
- Optional<StandardEncryptAlgorithm> encryptor = encryptRule.findStandardEncryptor(tableName, columnName);
+ Optional<StandardEncryptAlgorithm> encryptor = encryptRule.findStandardEncryptor(encryptTable.getTable(), columnName);
if (encryptor.isPresent()) {
result.addAll(getModifyColumnTokens(encryptTable, columnName, each));
}
- each.getColumnPosition().flatMap(optional -> getColumnPositionToken(tableName, encryptTable, optional)).ifPresent(result::add);
+ each.getColumnPosition().flatMap(optional -> getColumnPositionToken(encryptTable, optional)).ifPresent(result::add);
}
return result;
}
@@ -157,25 +157,25 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
}
@SuppressWarnings("rawtypes")
- private Optional<SQLToken> getColumnPositionToken(final String tableName, final EncryptTable encryptTable, final ColumnPositionSegment columnPositionSegment) {
+ private Optional<SQLToken> getColumnPositionToken(final EncryptTable encryptTable, final ColumnPositionSegment columnPositionSegment) {
Optional<StandardEncryptAlgorithm> encryptor = Optional.of(columnPositionSegment).filter(optional -> null != optional.getColumnName())
- .flatMap(optional -> encryptRule.findStandardEncryptor(tableName, optional.getColumnName().getIdentifier().getValue()));
+ .flatMap(optional -> encryptRule.findStandardEncryptor(encryptTable.getTable(), optional.getColumnName().getIdentifier().getValue()));
return encryptor.isPresent() ? Optional.of(getPositionColumnToken(encryptTable, columnPositionSegment)) : Optional.empty();
}
- private Collection<SQLToken> getChangeColumnTokens(final String tableName, final EncryptTable encryptTable, final Collection<ChangeColumnDefinitionSegment> changeColumnDefinitions) {
+ private Collection<SQLToken> getChangeColumnTokens(final EncryptTable encryptTable, final Collection<ChangeColumnDefinitionSegment> changeColumnDefinitions) {
Collection<SQLToken> result = new LinkedList<>();
for (ChangeColumnDefinitionSegment each : changeColumnDefinitions) {
- result.addAll(getChangeColumnTokens(tableName, encryptTable, each));
- each.getColumnPosition().flatMap(optional -> getColumnPositionToken(tableName, encryptTable, optional)).ifPresent(result::add);
+ result.addAll(getChangeColumnTokens(encryptTable, each));
+ each.getColumnPosition().flatMap(optional -> getColumnPositionToken(encryptTable, optional)).ifPresent(result::add);
}
return result;
}
- private Collection<? extends SQLToken> getChangeColumnTokens(final String tableName, final EncryptTable encryptTable, final ChangeColumnDefinitionSegment segment) {
- isSameEncryptColumn(tableName, encryptTable, segment);
- if (!encryptRule.findStandardEncryptor(tableName, segment.getPreviousColumn().getIdentifier().getValue()).isPresent()
- || !encryptRule.findStandardEncryptor(tableName, segment.getColumnDefinition().getColumnName().getIdentifier().getValue()).isPresent()) {
+ private Collection<? extends SQLToken> getChangeColumnTokens(final EncryptTable encryptTable, final ChangeColumnDefinitionSegment segment) {
+ isSameEncryptColumn(encryptTable, segment);
+ if (!encryptRule.findStandardEncryptor(encryptTable.getTable(), segment.getPreviousColumn().getIdentifier().getValue()).isPresent()
+ || !encryptRule.findStandardEncryptor(encryptTable.getTable(), segment.getColumnDefinition().getColumnName().getIdentifier().getValue()).isPresent()) {
return Collections.emptyList();
}
Collection<SQLToken> result = new LinkedList<>();
@@ -185,9 +185,9 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
}
@SuppressWarnings("rawtypes")
- private void isSameEncryptColumn(final String tableName, final EncryptTable encryptTable, final ChangeColumnDefinitionSegment segment) {
- Optional<StandardEncryptAlgorithm> previousAlgorithm = encryptRule.findStandardEncryptor(tableName, segment.getPreviousColumn().getIdentifier().getValue());
- Optional<StandardEncryptAlgorithm> currentAlgorithm = encryptRule.findStandardEncryptor(tableName, segment.getColumnDefinition().getColumnName().getIdentifier().getValue());
+ private void isSameEncryptColumn(final EncryptTable encryptTable, final ChangeColumnDefinitionSegment segment) {
+ Optional<StandardEncryptAlgorithm> previousAlgorithm = encryptRule.findStandardEncryptor(encryptTable.getTable(), segment.getPreviousColumn().getIdentifier().getValue());
+ Optional<StandardEncryptAlgorithm> currentAlgorithm = encryptRule.findStandardEncryptor(encryptTable.getTable(), segment.getColumnDefinition().getColumnName().getIdentifier().getValue());
if (!previousAlgorithm.isPresent() && !currentAlgorithm.isPresent()) {
return;
}
@@ -195,7 +195,8 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
&& currentAlgorithm.isPresent() && previousAlgorithm.get().equals(currentAlgorithm.get()) && checkPreviousAndAfterHasSameColumnNumber(encryptTable, segment)) {
return;
}
- throw new EncryptColumnAlterException(tableName, segment.getColumnDefinition().getColumnName().getIdentifier().getValue(), segment.getPreviousColumn().getIdentifier().getValue());
+ throw new EncryptColumnAlterException(
+ encryptTable.getTable(), segment.getColumnDefinition().getColumnName().getIdentifier().getValue(), segment.getPreviousColumn().getIdentifier().getValue());
}
private boolean checkPreviousAndAfterHasSameColumnNumber(final EncryptTable encryptTable, final ChangeColumnDefinitionSegment changeColumnDefinitionSegment) {
@@ -236,20 +237,20 @@ public final class EncryptAlterTableTokenGenerator implements CollectionSQLToken
return result;
}
- private List<SQLToken> getDropColumnTokens(final String tableName, final EncryptTable encryptTable, final Collection<DropColumnDefinitionSegment> columnDefinitionSegments) {
+ private List<SQLToken> getDropColumnTokens(final EncryptTable encryptTable, final Collection<DropColumnDefinitionSegment> columnDefinitionSegments) {
List<SQLToken> result = new ArrayList<>();
for (DropColumnDefinitionSegment each : columnDefinitionSegments) {
- result.addAll(getDropColumnTokens(tableName, encryptTable, each));
+ result.addAll(getDropColumnTokens(encryptTable, each));
}
return result;
}
@SuppressWarnings("rawtypes")
- private Collection<SQLToken> getDropColumnTokens(final String tableName, final EncryptTable encryptTable, final DropColumnDefinitionSegment dropColumnDefinitionSegment) {
+ private Collection<SQLToken> getDropColumnTokens(final EncryptTable encryptTable, final DropColumnDefinitionSegment dropColumnDefinitionSegment) {
Collection<SQLToken> result = new LinkedList<>();
for (ColumnSegment each : dropColumnDefinitionSegment.getColumns()) {
String columnName = each.getQualifiedName();
- Optional<StandardEncryptAlgorithm> encryptor = encryptRule.findStandardEncryptor(tableName, columnName);
+ Optional<StandardEncryptAlgorithm> encryptor = encryptRule.findStandardEncryptor(encryptTable.getTable(), columnName);
if (encryptor.isPresent()) {
result.addAll(getDropColumnTokens(encryptTable, columnName, each, dropColumnDefinitionSegment));
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGenerator.java
index b6a87185ccf..9ea9c6cee09 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGenerator.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptAssignmentTok
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptLiteralAssignmentToken;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptParameterAssignmentToken;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
@@ -66,10 +67,14 @@ public final class EncryptAssignmentTokenGenerator implements CollectionSQLToken
public Collection<SQLToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
Collection<SQLToken> result = new LinkedList<>();
String tableName = ((TableAvailable) sqlStatementContext).getAllTables().iterator().next().getTableName().getIdentifier().getValue();
+ Optional<EncryptTable> encryptTable = encryptRule.findEncryptTable(tableName);
+ if (!encryptTable.isPresent()) {
+ return Collections.emptyList();
+ }
String schemaName = sqlStatementContext.getTablesContext().getSchemaName().orElseGet(() -> DatabaseTypeEngine.getDefaultSchemaName(sqlStatementContext.getDatabaseType(), databaseName));
for (AssignmentSegment each : getSetAssignmentSegment(sqlStatementContext.getSqlStatement()).getAssignments()) {
if (encryptRule.findStandardEncryptor(tableName, each.getColumns().get(0).getIdentifier().getValue()).isPresent()) {
- generateSQLToken(schemaName, tableName, each).ifPresent(result::add);
+ generateSQLToken(schemaName, encryptTable.get(), each).ifPresent(result::add);
}
}
return result;
@@ -84,68 +89,57 @@ public final class EncryptAssignmentTokenGenerator implements CollectionSQLToken
return ((UpdateStatement) sqlStatement).getSetAssignment();
}
- private Optional<EncryptAssignmentToken> generateSQLToken(final String schemaName, final String tableName, final AssignmentSegment assignmentSegment) {
+ private Optional<EncryptAssignmentToken> generateSQLToken(final String schemaName, final EncryptTable encryptTable, final AssignmentSegment assignmentSegment) {
if (assignmentSegment.getValue() instanceof ParameterMarkerExpressionSegment) {
- return Optional.of(generateParameterSQLToken(tableName, assignmentSegment));
+ return Optional.of(generateParameterSQLToken(encryptTable, assignmentSegment));
}
if (assignmentSegment.getValue() instanceof LiteralExpressionSegment) {
- return Optional.of(generateLiteralSQLToken(schemaName, tableName, assignmentSegment));
+ return Optional.of(generateLiteralSQLToken(schemaName, encryptTable, assignmentSegment));
}
return Optional.empty();
}
- private EncryptAssignmentToken generateParameterSQLToken(final String tableName, final AssignmentSegment assignmentSegment) {
+ private EncryptAssignmentToken generateParameterSQLToken(final EncryptTable encryptTable, final AssignmentSegment assignmentSegment) {
EncryptParameterAssignmentToken result = new EncryptParameterAssignmentToken(assignmentSegment.getColumns().get(0).getStartIndex(), assignmentSegment.getStopIndex());
String columnName = assignmentSegment.getColumns().get(0).getIdentifier().getValue();
- addCipherColumn(tableName, columnName, result);
- addAssistedQueryColumn(tableName, columnName, result);
- addLikeQueryColumn(tableName, columnName, result);
+ result.addColumnName(encryptTable.getCipherColumn(columnName));
+ encryptTable.findAssistedQueryColumn(columnName).ifPresent(result::addColumnName);
+ encryptTable.findLikeQueryColumn(columnName).ifPresent(result::addColumnName);
return result;
}
- private void addCipherColumn(final String tableName, final String columnName, final EncryptParameterAssignmentToken token) {
- token.addColumnName(encryptRule.getCipherColumn(tableName, columnName));
- }
-
- private void addAssistedQueryColumn(final String tableName, final String columnName, final EncryptParameterAssignmentToken token) {
- encryptRule.findAssistedQueryColumn(tableName, columnName).ifPresent(token::addColumnName);
- }
-
- private void addLikeQueryColumn(final String tableName, final String columnName, final EncryptParameterAssignmentToken token) {
- encryptRule.findLikeQueryColumn(tableName, columnName).ifPresent(token::addColumnName);
- }
-
- private EncryptAssignmentToken generateLiteralSQLToken(final String schemaName, final String tableName, final AssignmentSegment assignmentSegment) {
+ private EncryptAssignmentToken generateLiteralSQLToken(final String schemaName, final EncryptTable encryptTable, final AssignmentSegment assignmentSegment) {
EncryptLiteralAssignmentToken result = new EncryptLiteralAssignmentToken(assignmentSegment.getColumns().get(0).getStartIndex(), assignmentSegment.getStopIndex());
- addCipherAssignment(schemaName, tableName, assignmentSegment, result);
- addAssistedQueryAssignment(schemaName, tableName, assignmentSegment, result);
- addLikeAssignment(schemaName, tableName, assignmentSegment, result);
+ addCipherAssignment(schemaName, encryptTable, assignmentSegment, result);
+ addAssistedQueryAssignment(schemaName, encryptTable, assignmentSegment, result);
+ addLikeAssignment(schemaName, encryptTable, assignmentSegment, result);
return result;
}
- private void addCipherAssignment(final String schemaName, final String tableName, final AssignmentSegment assignmentSegment, final EncryptLiteralAssignmentToken token) {
+ private void addCipherAssignment(final String schemaName, final EncryptTable encryptTable, final AssignmentSegment assignmentSegment, final EncryptLiteralAssignmentToken token) {
Object originalValue = ((LiteralExpressionSegment) assignmentSegment.getValue()).getLiterals();
- Object cipherValue = encryptRule.encrypt(databaseName, schemaName, tableName, assignmentSegment.getColumns().get(0).getIdentifier().getValue(),
+ Object cipherValue = encryptRule.encrypt(databaseName, schemaName, encryptTable.getTable(), assignmentSegment.getColumns().get(0).getIdentifier().getValue(),
Collections.singletonList(originalValue)).iterator().next();
- token.addAssignment(encryptRule.getCipherColumn(tableName, assignmentSegment.getColumns().get(0).getIdentifier().getValue()), cipherValue);
+ token.addAssignment(encryptTable.getCipherColumn(assignmentSegment.getColumns().get(0).getIdentifier().getValue()), cipherValue);
}
- private void addAssistedQueryAssignment(final String schemaName, final String tableName, final AssignmentSegment assignmentSegment, final EncryptLiteralAssignmentToken token) {
+ private void addAssistedQueryAssignment(final String schemaName, final EncryptTable encryptTable,
+ final AssignmentSegment assignmentSegment, final EncryptLiteralAssignmentToken token) {
Object originalValue = ((LiteralExpressionSegment) assignmentSegment.getValue()).getLiterals();
- Optional<String> assistedQueryColumn = encryptRule.findAssistedQueryColumn(tableName, assignmentSegment.getColumns().get(0).getIdentifier().getValue());
+ Optional<String> assistedQueryColumn = encryptTable.findAssistedQueryColumn(assignmentSegment.getColumns().get(0).getIdentifier().getValue());
if (assistedQueryColumn.isPresent()) {
Object assistedQueryValue = encryptRule.getEncryptAssistedQueryValues(databaseName, schemaName,
- tableName, assignmentSegment.getColumns().get(0).getIdentifier().getValue(), Collections.singletonList(originalValue)).iterator().next();
+ encryptTable.getTable(), assignmentSegment.getColumns().get(0).getIdentifier().getValue(), Collections.singletonList(originalValue)).iterator().next();
token.addAssignment(assistedQueryColumn.get(), assistedQueryValue);
}
}
- private void addLikeAssignment(final String schemaName, final String tableName, final AssignmentSegment assignmentSegment, final EncryptLiteralAssignmentToken token) {
+ private void addLikeAssignment(final String schemaName, final EncryptTable encryptTable, final AssignmentSegment assignmentSegment, final EncryptLiteralAssignmentToken token) {
Object originalValue = ((LiteralExpressionSegment) assignmentSegment.getValue()).getLiterals();
- Optional<String> assistedQueryColumn = encryptRule.findLikeQueryColumn(tableName, assignmentSegment.getColumns().get(0).getIdentifier().getValue());
+ Optional<String> assistedQueryColumn = encryptTable.findLikeQueryColumn(assignmentSegment.getColumns().get(0).getIdentifier().getValue());
if (assistedQueryColumn.isPresent()) {
Object assistedQueryValue = encryptRule.getEncryptLikeQueryValues(databaseName, schemaName,
- tableName, assignmentSegment.getColumns().get(0).getIdentifier().getValue(), Collections.singletonList(originalValue)).iterator().next();
+ encryptTable.getTable(), assignmentSegment.getColumns().get(0).getIdentifier().getValue(), Collections.singletonList(originalValue)).iterator().next();
token.addAssignment(assistedQueryColumn.get(), assistedQueryValue);
}
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
index 9f6fc0098a0..36f5a6c80de 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTable.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.encrypt.rule;
+import lombok.Getter;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.exception.metadata.EncryptColumnNotFoundException;
@@ -34,6 +35,7 @@ import java.util.TreeMap;
*/
public final class EncryptTable {
+ @Getter
private final String table;
private final Map<String, EncryptColumn> columns;
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptBinaryOperationConditionTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptBinaryOperationConditionTest.java
similarity index 96%
rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptBinaryOperationConditionTest.java
rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptBinaryOperationConditionTest.java
index 1a15e7bbf95..9881abf295e 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptBinaryOperationConditionTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptBinaryOperationConditionTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.rewrite.impl;
+package org.apache.shardingsphere.encrypt.rewrite.condition;
import org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptBinaryCondition;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptInConditionTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptInConditionTest.java
similarity index 96%
rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptInConditionTest.java
rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptInConditionTest.java
index 79dc682be70..330d5bab98f 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptInConditionTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptInConditionTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.rewrite.impl;
+package org.apache.shardingsphere.encrypt.rewrite.condition;
import org.apache.shardingsphere.encrypt.rewrite.condition.impl.EncryptInCondition;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptSQLRewriteContextDecoratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
similarity index 93%
rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptSQLRewriteContextDecoratorTest.java
rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
index 238a36a5655..ea9f12de23b 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptSQLRewriteContextDecoratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
@@ -15,9 +15,8 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.rewrite.impl;
+package org.apache.shardingsphere.encrypt.rewrite.context;
-import org.apache.shardingsphere.encrypt.rewrite.context.EncryptSQLRewriteContextDecorator;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGeneratorTest.java
similarity index 98%
rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGeneratorTest.java
index 256f09c3981..29069322d22 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAlterTableTokenGeneratorTest.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.rewrite.impl;
+package org.apache.shardingsphere.encrypt.rewrite.token.generator;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptAlterTableTokenGenerator;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptAlterTableToken;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
import org.apache.shardingsphere.encrypt.rule.EncryptColumnItem;
@@ -70,6 +69,7 @@ class EncryptAlterTableTokenGeneratorTest {
private EncryptTable mockEncryptTable() {
EncryptTable result = mock(EncryptTable.class);
+ when(result.getTable()).thenReturn("t_encrypt");
when(result.getCipherColumn("certificate_number")).thenReturn("cipher_certificate_number");
when(result.findAssistedQueryColumn("certificate_number")).thenReturn(Optional.of("assisted_certificate_number"));
when(result.findLikeQueryColumn("certificate_number")).thenReturn(Optional.of("like_certificate_number"));
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGeneratorTest.java
index 95be0645b10..1ffbfea6bf0 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptAssignmentTokenGeneratorTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.encrypt.rewrite.token.generator;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
@@ -78,6 +79,7 @@ class EncryptAssignmentTokenGeneratorTest {
private EncryptRule mockEncryptRule() {
EncryptRule result = mock(EncryptRule.class, RETURNS_DEEP_STUBS);
+ when(result.findEncryptTable("table")).thenReturn(Optional.of(mock(EncryptTable.class)));
when(result.findStandardEncryptor("table", "columns")).thenReturn(Optional.of(mock(StandardEncryptAlgorithm.class)));
return result;
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateTableTokenGeneratorTest.java
similarity index 97%
rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateTableTokenGeneratorTest.java
index cb462cb8a0d..005bc7d535c 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateTableTokenGeneratorTest.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.rewrite.impl;
+package org.apache.shardingsphere.encrypt.rewrite.token.generator;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptCreateTableTokenGenerator;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
import org.apache.shardingsphere.encrypt.rule.EncryptColumnItem;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
similarity index 97%
rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
index 51f54d58d8c..30c7e06e98c 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.rewrite.impl;
+package org.apache.shardingsphere.encrypt.rewrite.token.generator;
import org.apache.shardingsphere.encrypt.api.encrypt.standard.StandardEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptOrderByItemTokenGenerator;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGeneratorTest.java
similarity index 98%
rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGeneratorTest.java
index 1989dbc902d..c7f05eb366b 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGeneratorTest.java
@@ -15,9 +15,8 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.rewrite.impl;
+package org.apache.shardingsphere.encrypt.rewrite.token.generator;
-import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptProjectionTokenGenerator;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
import org.apache.shardingsphere.encrypt.rule.EncryptColumnItem;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;