This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng 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 567faccc79d Refactor CompatibleEncryptRuleConfiguration convert to 
EncryptRuleConfiguration logic (#25601)
567faccc79d is described below

commit 567faccc79df39a378b4faccf2518d25d9f0c41d
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Fri May 12 13:43:10 2023 +0800

    Refactor CompatibleEncryptRuleConfiguration convert to 
EncryptRuleConfiguration logic (#25601)
---
 .../encrypt/api/config/CompatibleEncryptRuleConfiguration.java   | 9 +++++++++
 .../checker/CompatibleEncryptRuleConfigurationChecker.java       | 3 +--
 .../encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java   | 6 +++++-
 .../update/AlterCompatibleEncryptRuleStatementUpdater.java       | 5 ++---
 .../update/CreateCompatibleEncryptRuleStatementUpdater.java      | 7 +++----
 .../update/DropCompatibleEncryptRuleStatementUpdater.java        | 7 +++----
 .../distsql/ral/queryable/ConvertYamlConfigurationExecutor.java  | 3 +++
 .../distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java       | 7 +++++--
 .../apache/shardingsphere/proxy/backend/util/ExportUtils.java    | 3 +++
 .../backend/util/YamlDatabaseConfigurationImportExecutor.java    | 2 ++
 10 files changed, 36 insertions(+), 16 deletions(-)

diff --git 
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/CompatibleEncryptRuleConfiguration.java
 
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/CompatibleEncryptRuleConfiguration.java
index b5f3eac0261..54c3612b194 100644
--- 
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/CompatibleEncryptRuleConfiguration.java
+++ 
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/api/config/CompatibleEncryptRuleConfiguration.java
@@ -40,4 +40,13 @@ public final class CompatibleEncryptRuleConfiguration 
implements DatabaseRuleCon
     private final Collection<EncryptTableRuleConfiguration> tables;
     
     private final Map<String, AlgorithmConfiguration> encryptors;
+    
+    /**
+     * Convert to encrypt rule configuration.
+     * 
+     * @return encrypt rule configuration
+     */
+    public EncryptRuleConfiguration convertToEncryptRuleConfiguration() {
+        return new EncryptRuleConfiguration(tables, encryptors);
+    }
 }
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/CompatibleEncryptRuleConfigurationChecker.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/CompatibleEncryptRuleConfigurationChecker.java
index fab7d6d4eb7..ae31292024d 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/CompatibleEncryptRuleConfigurationChecker.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/CompatibleEncryptRuleConfigurationChecker.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.encrypt.checker;
 
 import 
org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
 import 
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -39,7 +38,7 @@ public final class CompatibleEncryptRuleConfigurationChecker 
implements RuleConf
     
     @Override
     public void check(final String databaseName, final 
CompatibleEncryptRuleConfiguration config, final Map<String, DataSource> 
dataSourceMap, final Collection<ShardingSphereRule> rules) {
-        delegate.check(databaseName, new 
EncryptRuleConfiguration(config.getTables(), config.getEncryptors()), 
dataSourceMap, rules);
+        delegate.check(databaseName, 
config.convertToEncryptRuleConfiguration(), dataSourceMap, rules);
     }
     
     @Override
diff --git 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
index 1f74f43ab98..b5c9ba6f240 100644
--- 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
+++ 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.encrypt.distsql.handler.query;
 
 import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
+import 
org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration;
 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.EncryptColumnRuleConfiguration;
@@ -47,7 +48,10 @@ public final class ShowEncryptRuleExecutor implements 
RQLExecutor<ShowEncryptRul
         Optional<EncryptRule> rule = 
database.getRuleMetaData().findSingleRule(EncryptRule.class);
         Collection<LocalDataQueryResultRow> result = new LinkedList<>();
         if (rule.isPresent()) {
-            result = buildData((EncryptRuleConfiguration) 
rule.get().getConfiguration(), sqlStatement);
+            EncryptRuleConfiguration ruleConfig = 
rule.get().getConfiguration() instanceof CompatibleEncryptRuleConfiguration
+                    ? ((CompatibleEncryptRuleConfiguration) 
rule.get().getConfiguration()).convertToEncryptRuleConfiguration()
+                    : (EncryptRuleConfiguration) rule.get().getConfiguration();
+            result = buildData(ruleConfig, sqlStatement);
         }
         return result;
     }
diff --git 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterCompatibleEncryptRuleStatementUpdater.java
 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterCompatibleEncryptRuleStatementUpdater.java
index 92a9262ac24..958924088d6 100644
--- 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterCompatibleEncryptRuleStatementUpdater.java
+++ 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterCompatibleEncryptRuleStatementUpdater.java
@@ -35,7 +35,7 @@ public final class AlterCompatibleEncryptRuleStatementUpdater 
implements RuleDef
     
     @Override
     public void checkSQLStatement(final ShardingSphereDatabase database, final 
AlterEncryptRuleStatement sqlStatement, final 
CompatibleEncryptRuleConfiguration currentRuleConfig) {
-        delegate.checkSQLStatement(database, sqlStatement, new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()));
+        delegate.checkSQLStatement(database, sqlStatement, 
currentRuleConfig.convertToEncryptRuleConfiguration());
     }
     
     @Override
@@ -46,8 +46,7 @@ public final class AlterCompatibleEncryptRuleStatementUpdater 
implements RuleDef
     
     @Override
     public void updateCurrentRuleConfiguration(final 
CompatibleEncryptRuleConfiguration currentRuleConfig, final 
CompatibleEncryptRuleConfiguration toBeAlteredRuleConfig) {
-        delegate.updateCurrentRuleConfiguration(new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()),
-                new 
EncryptRuleConfiguration(toBeAlteredRuleConfig.getTables(), 
toBeAlteredRuleConfig.getEncryptors()));
+        
delegate.updateCurrentRuleConfiguration(currentRuleConfig.convertToEncryptRuleConfiguration(),
 toBeAlteredRuleConfig.convertToEncryptRuleConfiguration());
     }
     
     @Override
diff --git 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateCompatibleEncryptRuleStatementUpdater.java
 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateCompatibleEncryptRuleStatementUpdater.java
index d80d34878be..267aa586ad4 100644
--- 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateCompatibleEncryptRuleStatementUpdater.java
+++ 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateCompatibleEncryptRuleStatementUpdater.java
@@ -35,19 +35,18 @@ public final class 
CreateCompatibleEncryptRuleStatementUpdater implements RuleDe
     
     @Override
     public void checkSQLStatement(final ShardingSphereDatabase database, final 
CreateEncryptRuleStatement sqlStatement, final 
CompatibleEncryptRuleConfiguration currentRuleConfig) {
-        delegate.checkSQLStatement(database, sqlStatement, new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()));
+        delegate.checkSQLStatement(database, sqlStatement, 
currentRuleConfig.convertToEncryptRuleConfiguration());
     }
     
     @Override
     public CompatibleEncryptRuleConfiguration 
buildToBeCreatedRuleConfiguration(final CompatibleEncryptRuleConfiguration 
currentRuleConfig, final CreateEncryptRuleStatement sqlStatement) {
-        EncryptRuleConfiguration ruleConfig = 
delegate.buildToBeCreatedRuleConfiguration(new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()), sqlStatement);
+        EncryptRuleConfiguration ruleConfig = 
delegate.buildToBeCreatedRuleConfiguration(currentRuleConfig.convertToEncryptRuleConfiguration(),
 sqlStatement);
         return new CompatibleEncryptRuleConfiguration(ruleConfig.getTables(), 
ruleConfig.getEncryptors());
     }
     
     @Override
     public void updateCurrentRuleConfiguration(final 
CompatibleEncryptRuleConfiguration currentRuleConfig, final 
CompatibleEncryptRuleConfiguration toBeCreatedRuleConfig) {
-        delegate.updateCurrentRuleConfiguration(new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()),
-                new 
EncryptRuleConfiguration(toBeCreatedRuleConfig.getTables(), 
toBeCreatedRuleConfig.getEncryptors()));
+        
delegate.updateCurrentRuleConfiguration(currentRuleConfig.convertToEncryptRuleConfiguration(),
 toBeCreatedRuleConfig.convertToEncryptRuleConfiguration());
     }
     
     @Override
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 0707dfe5356..743c2510fbb 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,7 +19,6 @@ 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.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 
@@ -35,17 +34,17 @@ public final class 
DropCompatibleEncryptRuleStatementUpdater implements RuleDefi
     
     @Override
     public void checkSQLStatement(final ShardingSphereDatabase database, final 
DropEncryptRuleStatement sqlStatement, final CompatibleEncryptRuleConfiguration 
currentRuleConfig) {
-        delegate.checkSQLStatement(database, sqlStatement, new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()));
+        delegate.checkSQLStatement(database, sqlStatement, 
currentRuleConfig.convertToEncryptRuleConfiguration());
     }
     
     @Override
     public boolean hasAnyOneToBeDropped(final DropEncryptRuleStatement 
sqlStatement, final CompatibleEncryptRuleConfiguration currentRuleConfig) {
-        return delegate.hasAnyOneToBeDropped(sqlStatement, new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()));
+        return delegate.hasAnyOneToBeDropped(sqlStatement, 
currentRuleConfig.convertToEncryptRuleConfiguration());
     }
     
     @Override
     public boolean updateCurrentRuleConfiguration(final 
DropEncryptRuleStatement sqlStatement, final CompatibleEncryptRuleConfiguration 
currentRuleConfig) {
-        return delegate.updateCurrentRuleConfiguration(sqlStatement, new 
EncryptRuleConfiguration(currentRuleConfig.getTables(), 
currentRuleConfig.getEncryptors()));
+        return delegate.updateCurrentRuleConfiguration(sqlStatement, 
currentRuleConfig.convertToEncryptRuleConfiguration());
     }
     
     @Override
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
index 2937a10e091..e997a73523f 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
@@ -22,6 +22,7 @@ import com.google.common.base.Strings;
 import com.zaxxer.hikari.HikariDataSource;
 import 
org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
+import 
org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration;
 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.EncryptColumnRuleConfiguration;
@@ -118,6 +119,8 @@ public final class ConvertYamlConfigurationExecutor 
implements QueryableRALExecu
                 
appendReadWriteSplittingDistSQL((ReadwriteSplittingRuleConfiguration) each, 
result);
             } else if (each instanceof EncryptRuleConfiguration) {
                 appendEncryptDistSQL((EncryptRuleConfiguration) each, result);
+            } else if (each instanceof CompatibleEncryptRuleConfiguration) {
+                appendEncryptDistSQL(((CompatibleEncryptRuleConfiguration) 
each).convertToEncryptRuleConfiguration(), result);
             } else if (each instanceof ShadowRuleConfiguration) {
                 appendShadowDistSQL((ShadowRuleConfiguration) each, result);
             } else if (each instanceof MaskRuleConfiguration) {
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java
index 8f3f2318a15..da27fe07e7c 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/rule/ShowRulesUsedStorageUnitExecutor.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.rule;
 
 import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
 import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesUsedStorageUnitStatement;
+import 
org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.rule.EncryptRule;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
@@ -110,8 +111,10 @@ public final class ShowRulesUsedStorageUnitExecutor 
implements RQLExecutor<ShowR
         if (!rule.isPresent()) {
             return Collections.emptyList();
         }
-        EncryptRuleConfiguration config = (EncryptRuleConfiguration) 
rule.get().getConfiguration();
-        return config.getTables().stream().map(each -> buildRow(ENCRYPT, 
each.getName())).collect(Collectors.toList());
+        EncryptRuleConfiguration ruleConfig =
+                rule.get().getConfiguration() instanceof 
CompatibleEncryptRuleConfiguration ? ((CompatibleEncryptRuleConfiguration) 
rule.get().getConfiguration()).convertToEncryptRuleConfiguration()
+                        : (EncryptRuleConfiguration) 
rule.get().getConfiguration();
+        return ruleConfig.getTables().stream().map(each -> buildRow(ENCRYPT, 
each.getName())).collect(Collectors.toList());
     }
     
     private Collection<LocalDataQueryResultRow> getShadowData(final 
ShardingSphereDatabase database, final String resourceName) {
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
index 654d8ba8c1e..d55e1cb9d98 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.backend.util;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
 import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
@@ -129,6 +130,8 @@ public final class ExportUtils {
             return ((ReadwriteSplittingRuleConfiguration) 
ruleConfig).getDataSources().isEmpty();
         } else if (ruleConfig instanceof EncryptRuleConfiguration) {
             return ((EncryptRuleConfiguration) 
ruleConfig).getTables().isEmpty();
+        } else if (ruleConfig instanceof CompatibleEncryptRuleConfiguration) {
+            return ((CompatibleEncryptRuleConfiguration) 
ruleConfig).getTables().isEmpty();
         } else if (ruleConfig instanceof ShadowRuleConfiguration) {
             return ((ShadowRuleConfiguration) 
ruleConfig).getTables().isEmpty();
         } else if (ruleConfig instanceof MaskRuleConfiguration) {
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index 64797ac90b9..d3cd88f069b 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -212,6 +212,8 @@ public final class YamlDatabaseConfigurationImportExecutor {
             ruleConfigs.forEach(each -> 
addReadwriteSplittingRuleConfiguration((ReadwriteSplittingRuleConfiguration) 
each, allRuleConfigs, database));
         } else if (ruleConfig instanceof EncryptRuleConfiguration) {
             ruleConfigs.forEach(each -> 
addEncryptRuleConfiguration((EncryptRuleConfiguration) each, allRuleConfigs, 
database));
+        } else if (ruleConfig instanceof CompatibleEncryptRuleConfiguration) {
+            ruleConfigs.forEach(each -> 
addEncryptRuleConfiguration(((CompatibleEncryptRuleConfiguration) 
each).convertToEncryptRuleConfiguration(), allRuleConfigs, database));
         } else if (ruleConfig instanceof ShadowRuleConfiguration) {
             ruleConfigs.forEach(each -> 
addShadowRuleConfiguration((ShadowRuleConfiguration) each, allRuleConfigs, 
database));
         } else if (ruleConfig instanceof MaskRuleConfiguration) {

Reply via email to