Skip to content

Commit

Permalink
Refactor EncryptTableChangedProcessor and ReadwriteSplittingDataSourc…
Browse files Browse the repository at this point in the history
…eChangedProcessor (#33490)
  • Loading branch information
terrymanu authored Nov 1, 2024
1 parent 0893abe commit f8dcb5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -58,8 +57,8 @@ private TransactionalReadQueryStrategy getTransactionalReadQueryStrategy(final Y

@Override
public ReadwriteSplittingRuleConfiguration findRuleConfiguration(final ShardingSphereDatabase database) {
Optional<ReadwriteSplittingRule> 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
Expand Down

0 comments on commit f8dcb5d

Please sign in to comment.