From f8dcb5db6624053f433368d6c46c80599c04b825 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 1 Nov 2024 11:39:57 +0800 Subject: [PATCH] Refactor EncryptTableChangedProcessor and ReadwriteSplittingDataSourceChangedProcessor (#33490) --- .../rule/changed/EncryptTableChangedProcessor.java | 7 +------ .../ReadwriteSplittingDataSourceChangedProcessor.java | 9 ++++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java index e8570540e8279..57b652ab7ceb1 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/changed/EncryptTableChangedProcessor.java @@ -45,15 +45,10 @@ public EncryptTableRuleConfiguration swapRuleItemConfiguration(final AlterRuleIt @Override public EncryptRuleConfiguration findRuleConfiguration(final ShardingSphereDatabase database) { - return database.getRuleMetaData().findSingleRule(EncryptRule.class) - .map(optional -> getEncryptRuleConfiguration(optional.getConfiguration())) + return database.getRuleMetaData().findSingleRule(EncryptRule.class).map(EncryptRule::getConfiguration) .orElseGet(() -> new EncryptRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>())); } - private EncryptRuleConfiguration getEncryptRuleConfiguration(final EncryptRuleConfiguration config) { - return null == config.getTables() ? new EncryptRuleConfiguration(new LinkedList<>(), config.getEncryptors()) : config; - } - @Override public void changeRuleItemConfiguration(final AlterRuleItemEvent event, final EncryptRuleConfiguration currentRuleConfig, final EncryptTableRuleConfiguration toBeChangedItemConfig) { // TODO refactor DistSQL to only persist config diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java index a159c04261ef1..da07516749626 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java @@ -19,22 +19,21 @@ import com.google.common.base.Strings; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterNamedRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropNamedRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; -import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.mode.spi.RuleItemConfigurationChangedProcessor; import org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration; -import org.apache.shardingsphere.readwritesplitting.transaction.TransactionalReadQueryStrategy; import org.apache.shardingsphere.readwritesplitting.metadata.nodepath.ReadwriteSplittingRuleNodePathProvider; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule; +import org.apache.shardingsphere.readwritesplitting.transaction.TransactionalReadQueryStrategy; import org.apache.shardingsphere.readwritesplitting.yaml.config.rule.YamlReadwriteSplittingDataSourceGroupRuleConfiguration; import java.util.LinkedHashMap; import java.util.LinkedList; -import java.util.Optional; /** * Readwrite-splitting data source changed processor. @@ -58,8 +57,8 @@ private TransactionalReadQueryStrategy getTransactionalReadQueryStrategy(final Y @Override public ReadwriteSplittingRuleConfiguration findRuleConfiguration(final ShardingSphereDatabase database) { - Optional rule = database.getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class); - return rule.map(ReadwriteSplittingRule::getConfiguration).orElseGet(() -> new ReadwriteSplittingRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>())); + return database.getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class).map(ReadwriteSplittingRule::getConfiguration) + .orElseGet(() -> new ReadwriteSplittingRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>())); } @Override