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 2023/06/17 06:12:14 UTC
[shardingsphere] branch master updated: Refactor EncryptRule RDL statement updater (#26389)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 b06d72e8445 Refactor EncryptRule RDL statement updater (#26389)
b06d72e8445 is described below
commit b06d72e844565b9e131d11a00fb205e4a95955ce
Author: ChenJiaHao <Pa...@163.com>
AuthorDate: Sat Jun 17 14:12:08 2023 +0800
Refactor EncryptRule RDL statement updater (#26389)
---
.../DropCompatibleEncryptRuleStatementUpdater.java | 19 +++++++++++++++++++
.../update/DropEncryptRuleStatementUpdater.java | 16 ++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropCompatibleEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropCompatibleEncryptRuleStatementUpdater.java
index 743c2510fbb..4cbfe621518 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropCompatibleEncryptRuleStatementUpdater.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropCompatibleEncryptRuleStatementUpdater.java
@@ -19,9 +19,17 @@ package org.apache.shardingsphere.encrypt.distsql.handler.update;
import org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
import org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
/**
* Drop encrypt rule statement updater.
*
@@ -42,6 +50,17 @@ public final class DropCompatibleEncryptRuleStatementUpdater implements RuleDefi
return delegate.hasAnyOneToBeDropped(sqlStatement, currentRuleConfig.convertToEncryptRuleConfiguration());
}
+ @Override
+ public CompatibleEncryptRuleConfiguration buildToBeDroppedRuleConfiguration(final CompatibleEncryptRuleConfiguration currentRuleConfig, final DropEncryptRuleStatement sqlStatement) {
+ Collection<EncryptTableRuleConfiguration> toBeDroppedTables = new LinkedList<>();
+ Map<String, AlgorithmConfiguration> toBeDroppedEncryptors = new HashMap<>();
+ for (String each : sqlStatement.getTables()) {
+ toBeDroppedTables.add(new EncryptTableRuleConfiguration(each, Collections.emptyList()));
+ }
+ // TODO find unused encryptor
+ return new CompatibleEncryptRuleConfiguration(toBeDroppedTables, toBeDroppedEncryptors);
+ }
+
@Override
public boolean updateCurrentRuleConfiguration(final DropEncryptRuleStatement sqlStatement, final CompatibleEncryptRuleConfiguration currentRuleConfig) {
return delegate.updateCurrentRuleConfiguration(sqlStatement, currentRuleConfig.convertToEncryptRuleConfiguration());
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
index 40a3c737bbd..22243af992c 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdater.java
@@ -23,10 +23,15 @@ import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -56,6 +61,17 @@ public final class DropEncryptRuleStatementUpdater implements RuleDefinitionDrop
&& !getIdenticalData(currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toSet()), sqlStatement.getTables()).isEmpty();
}
+ @Override
+ public EncryptRuleConfiguration buildToBeDroppedRuleConfiguration(final EncryptRuleConfiguration currentRuleConfig, final DropEncryptRuleStatement sqlStatement) {
+ Collection<EncryptTableRuleConfiguration> toBeDroppedTables = new LinkedList<>();
+ Map<String, AlgorithmConfiguration> toBeDroppedEncryptors = new HashMap<>();
+ for (String each : sqlStatement.getTables()) {
+ toBeDroppedTables.add(new EncryptTableRuleConfiguration(each, Collections.emptyList()));
+ }
+ // TODO find unused encryptor
+ return new EncryptRuleConfiguration(toBeDroppedTables, toBeDroppedEncryptors);
+ }
+
@Override
public boolean updateCurrentRuleConfiguration(final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) {
sqlStatement.getTables().forEach(each -> dropRule(currentRuleConfig, each));