From 30c1ec42db3a3e68ce91f99ea5e120849d279569 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 23 Jan 2024 20:34:12 +0800 Subject: [PATCH] Refactor CreateDatabaseRuleRDLExecuteEngine (#29820) * Remove useless generic type on RuleDefinitionBackendHandler * Refactor CreateDatabaseRuleRDLExecuteEngine * Refactor DropDatabaseRuleRDLExecuteEngine --- .../execute/type/CreateDatabaseRuleRDLExecuteEngine.java | 4 +--- .../execute/type/DropDatabaseRuleRDLExecuteEngine.java | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java index f7a3157cbc640..01a545505389a 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java @@ -49,9 +49,7 @@ public final class CreateDatabaseRuleRDLExecuteEngine implements DatabaseRuleRDL @SuppressWarnings("unchecked") public Collection execute(final RuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) { RuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(currentRuleConfig, sqlStatement); - if (null != currentRuleConfig) { - executor.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig); - } + executor.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig); ModeContextManager modeContextManager = ProxyContext.getInstance().getContextManager().getInstanceContext().getModeContextManager(); return modeContextManager.alterRuleConfiguration(database.getName(), getToBeCreatedRuleConfiguration(sqlStatement, database, currentRuleConfig, toBeCreatedRuleConfig)); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/DropDatabaseRuleRDLExecuteEngine.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/DropDatabaseRuleRDLExecuteEngine.java index c781f2daeae9e..ea33409d25931 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/DropDatabaseRuleRDLExecuteEngine.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/DropDatabaseRuleRDLExecuteEngine.java @@ -56,7 +56,7 @@ public Collection execute(final RuleDefinitionStatement sqlStat if (executor.updateCurrentRuleConfiguration(sqlStatement, currentRuleConfig) && ((DatabaseRuleConfiguration) currentRuleConfig).isEmpty()) { modeContextManager.removeRuleConfigurationItem(database.getName(), toBeDroppedRuleConfig); new NewYamlRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(Collections.singleton(currentRuleConfig)).values().stream().findFirst() - .ifPresent(swapper -> modeContextManager.removeRuleConfiguration(database.getName(), swapper.getRuleTagName().toLowerCase())); + .ifPresent(optional -> modeContextManager.removeRuleConfiguration(database.getName(), optional.getRuleTagName().toLowerCase())); return Collections.emptyList(); } if (executor instanceof DropReadwriteSplittingRuleExecutor) {