diff --git a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java index 83e6bcef24788..d6f3c0d4091f5 100644 --- a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java +++ b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java @@ -60,13 +60,13 @@ private boolean containsIgnoreCase(final Collection currentRules, final } @Override - public boolean hasAnyOneToBeDropped(final DropBroadcastTableRuleStatement sqlStatement, final BroadcastRuleConfiguration currentRuleConfig) { - return isExistRuleConfig(currentRuleConfig) && !getIdenticalData(currentRuleConfig.getTables(), sqlStatement.getTables()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropBroadcastTableRuleStatement sqlStatement) { + return isExistRuleConfig(rule.getConfiguration()) && !getIdenticalData(rule.getConfiguration().getTables(), sqlStatement.getTables()).isEmpty(); } @Override - public BroadcastRuleConfiguration buildToBeAlteredRuleConfiguration(final DropBroadcastTableRuleStatement sqlStatement, final BroadcastRuleConfiguration currentRuleConfig) { - BroadcastRuleConfiguration result = new BroadcastRuleConfiguration(new HashSet<>(currentRuleConfig.getTables())); + public BroadcastRuleConfiguration buildToBeAlteredRuleConfiguration(final DropBroadcastTableRuleStatement sqlStatement) { + BroadcastRuleConfiguration result = new BroadcastRuleConfiguration(new HashSet<>(rule.getConfiguration().getTables())); result.getTables().removeIf(each -> containsIgnoreCase(sqlStatement.getTables(), each)); return result; } diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java index b0aedec34194e..f51f2450ebe55 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java @@ -63,33 +63,35 @@ private void checkToBeDroppedEncryptTableNames(final DropEncryptRuleStatement sq } @Override - public boolean hasAnyOneToBeDropped(final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig - && !getIdenticalData(currentRuleConfig.getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toSet()), sqlStatement.getTables()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropEncryptRuleStatement sqlStatement) { + return null != rule && !getIdenticalData(((EncryptRuleConfiguration) rule.getConfiguration()) + .getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toSet()), sqlStatement.getTables()).isEmpty(); } @Override - public EncryptRuleConfiguration buildToBeDroppedRuleConfiguration(final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) { + public EncryptRuleConfiguration buildToBeDroppedRuleConfiguration(final DropEncryptRuleStatement sqlStatement) { Collection toBeDroppedTables = new LinkedList<>(); Map toBeDroppedEncryptors = new HashMap<>(); for (String each : sqlStatement.getTables()) { toBeDroppedTables.add(new EncryptTableRuleConfiguration(each, Collections.emptyList())); - dropRule(currentRuleConfig, each); + dropRule(each); } - UnusedAlgorithmFinder.findUnusedEncryptor(currentRuleConfig).forEach(each -> toBeDroppedEncryptors.put(each, currentRuleConfig.getEncryptors().get(each))); + UnusedAlgorithmFinder.findUnusedEncryptor((EncryptRuleConfiguration) rule.getConfiguration()) + .forEach(each -> toBeDroppedEncryptors.put(each, ((EncryptRuleConfiguration) rule.getConfiguration()).getEncryptors().get(each))); return new EncryptRuleConfiguration(toBeDroppedTables, toBeDroppedEncryptors); } @Override public boolean updateCurrentRuleConfiguration(final DropEncryptRuleStatement sqlStatement, final EncryptRuleConfiguration currentRuleConfig) { - sqlStatement.getTables().forEach(each -> dropRule(currentRuleConfig, each)); + sqlStatement.getTables().forEach(this::dropRule); dropUnusedEncryptor(currentRuleConfig); return currentRuleConfig.isEmpty(); } - private void dropRule(final EncryptRuleConfiguration currentRuleConfig, final String ruleName) { - Optional encryptTableRuleConfig = currentRuleConfig.getTables().stream().filter(each -> each.getName().equals(ruleName)).findAny(); - encryptTableRuleConfig.ifPresent(optional -> currentRuleConfig.getTables().remove(encryptTableRuleConfig.get())); + private void dropRule(final String ruleName) { + Optional encryptTableRuleConfig = ((EncryptRuleConfiguration) rule.getConfiguration()).getTables().stream() + .filter(each -> each.getName().equals(ruleName)).findAny(); + encryptTableRuleConfig.ifPresent(optional -> ((EncryptRuleConfiguration) rule.getConfiguration()).getTables().remove(encryptTableRuleConfig.get())); } private void dropUnusedEncryptor(final EncryptRuleConfiguration currentRuleConfig) { diff --git a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java index 26571a74d2686..7f46a79b1ebd3 100644 --- a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java +++ b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java @@ -66,6 +66,9 @@ void assertCheckSQLStatementWithoutToBeDroppedRule() { @Test void assertUpdateCurrentRuleConfiguration() { EncryptRuleConfiguration ruleConfig = createCurrentRuleConfiguration(); + EncryptRule rule = mock(EncryptRule.class); + when(rule.getConfiguration()).thenReturn(ruleConfig); + executor.setRule(rule); assertTrue(executor.updateCurrentRuleConfiguration(createSQLStatement("t_encrypt"), ruleConfig)); assertTrue(ruleConfig.getEncryptors().isEmpty()); } @@ -73,6 +76,9 @@ void assertUpdateCurrentRuleConfiguration() { @Test void assertUpdateCurrentRuleConfigurationWithInUsedEncryptor() { EncryptRuleConfiguration ruleConfig = createCurrentRuleConfigurationWithMultipleTableRules(); + EncryptRule rule = mock(EncryptRule.class); + when(rule.getConfiguration()).thenReturn(ruleConfig); + executor.setRule(rule); assertFalse(executor.updateCurrentRuleConfiguration(createSQLStatement("t_encrypt"), ruleConfig)); assertThat(ruleConfig.getEncryptors().size(), is(1)); } diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java index e08f6f3a97b72..8a884c459f3b6 100644 --- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java +++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java @@ -63,33 +63,33 @@ private void checkToBeDroppedMaskTableNames(final DropMaskRuleStatement sqlState } @Override - public boolean hasAnyOneToBeDropped(final DropMaskRuleStatement sqlStatement, final MaskRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig - && !getIdenticalData(currentRuleConfig.getTables().stream().map(MaskTableRuleConfiguration::getName).collect(Collectors.toSet()), sqlStatement.getTables()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropMaskRuleStatement sqlStatement) { + return null != rule + && !getIdenticalData(rule.getConfiguration().getTables().stream().map(MaskTableRuleConfiguration::getName).collect(Collectors.toSet()), sqlStatement.getTables()).isEmpty(); } @Override - public MaskRuleConfiguration buildToBeDroppedRuleConfiguration(final DropMaskRuleStatement sqlStatement, final MaskRuleConfiguration currentRuleConfig) { + public MaskRuleConfiguration buildToBeDroppedRuleConfiguration(final DropMaskRuleStatement sqlStatement) { Collection toBeDroppedTables = new LinkedList<>(); Map toBeDroppedAlgorithms = new LinkedHashMap<>(); for (String each : sqlStatement.getTables()) { toBeDroppedTables.add(new MaskTableRuleConfiguration(each, Collections.emptyList())); - dropRule(currentRuleConfig, each); + dropRule(each); } - findUnusedAlgorithms(currentRuleConfig).forEach(each -> toBeDroppedAlgorithms.put(each, currentRuleConfig.getMaskAlgorithms().get(each))); + findUnusedAlgorithms(rule.getConfiguration()).forEach(each -> toBeDroppedAlgorithms.put(each, rule.getConfiguration().getMaskAlgorithms().get(each))); return new MaskRuleConfiguration(toBeDroppedTables, toBeDroppedAlgorithms); } @Override public boolean updateCurrentRuleConfiguration(final DropMaskRuleStatement sqlStatement, final MaskRuleConfiguration currentRuleConfig) { - sqlStatement.getTables().forEach(each -> dropRule(currentRuleConfig, each)); + sqlStatement.getTables().forEach(this::dropRule); dropUnusedAlgorithm(currentRuleConfig); return currentRuleConfig.isEmpty(); } - private void dropRule(final MaskRuleConfiguration currentRuleConfig, final String ruleName) { - Optional maskTableRuleConfig = currentRuleConfig.getTables().stream().filter(each -> each.getName().equals(ruleName)).findAny(); - maskTableRuleConfig.ifPresent(optional -> currentRuleConfig.getTables().remove(maskTableRuleConfig.get())); + private void dropRule(final String ruleName) { + Optional maskTableRuleConfig = rule.getConfiguration().getTables().stream().filter(each -> each.getName().equals(ruleName)).findAny(); + maskTableRuleConfig.ifPresent(optional -> rule.getConfiguration().getTables().remove(maskTableRuleConfig.get())); } private void dropUnusedAlgorithm(final MaskRuleConfiguration currentRuleConfig) { diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java index a81a40a74d134..93080888b7441 100644 --- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java +++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java @@ -60,6 +60,9 @@ void assertCheckSQLStatementWithoutToBeDroppedRule() { @Test void assertUpdateCurrentRuleConfiguration() { MaskRuleConfiguration ruleConfig = createCurrentRuleConfiguration(); + MaskRule rule = mock(MaskRule.class); + when(rule.getConfiguration()).thenReturn(ruleConfig); + executor.setRule(rule); assertTrue(executor.updateCurrentRuleConfiguration(createSQLStatement(false, "t_mask"), ruleConfig)); assertTrue(ruleConfig.getMaskAlgorithms().isEmpty()); assertTrue(ruleConfig.getTables().isEmpty()); diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java index 4087c2a6416e4..0bd8e1e2bffcb 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java @@ -96,44 +96,44 @@ private Collection getInUsedResources() { } @Override - public ReadwriteSplittingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) { + public ReadwriteSplittingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropReadwriteSplittingRuleStatement sqlStatement) { Collection toBeDroppedDataSources = new LinkedList<>(); Map toBeDroppedLoadBalancers = new HashMap<>(); for (String each : sqlStatement.getNames()) { toBeDroppedDataSources.add(new ReadwriteSplittingDataSourceRuleConfiguration(each, null, null, null)); - dropRule(currentRuleConfig, each); + dropRule(each); } - findUnusedLoadBalancers(currentRuleConfig).forEach(each -> toBeDroppedLoadBalancers.put(each, currentRuleConfig.getLoadBalancers().get(each))); + findUnusedLoadBalancers().forEach(each -> toBeDroppedLoadBalancers.put(each, rule.getConfiguration().getLoadBalancers().get(each))); return new ReadwriteSplittingRuleConfiguration(toBeDroppedDataSources, toBeDroppedLoadBalancers); } @Override public boolean updateCurrentRuleConfiguration(final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) { for (String each : sqlStatement.getNames()) { - dropRule(currentRuleConfig, each); + dropRule(each); } dropUnusedLoadBalancer(currentRuleConfig); return currentRuleConfig.isEmpty(); } - private void dropRule(final ReadwriteSplittingRuleConfiguration currentRuleConfig, final String ruleName) { - Optional dataSourceRuleConfig = currentRuleConfig.getDataSources().stream().filter(each -> ruleName.equals(each.getName())).findAny(); - dataSourceRuleConfig.ifPresent(optional -> currentRuleConfig.getDataSources().remove(optional)); + private void dropRule(final String ruleName) { + Optional dataSourceRuleConfig = rule.getConfiguration().getDataSources().stream().filter(each -> ruleName.equals(each.getName())).findAny(); + dataSourceRuleConfig.ifPresent(optional -> rule.getConfiguration().getDataSources().remove(optional)); } private void dropUnusedLoadBalancer(final ReadwriteSplittingRuleConfiguration currentRuleConfig) { - findUnusedLoadBalancers(currentRuleConfig).forEach(each -> currentRuleConfig.getLoadBalancers().remove(each)); + findUnusedLoadBalancers().forEach(each -> currentRuleConfig.getLoadBalancers().remove(each)); } - private Collection findUnusedLoadBalancers(final ReadwriteSplittingRuleConfiguration currentRuleConfig) { - Collection inUsedAlgorithms = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getLoadBalancerName).collect(Collectors.toSet()); - return currentRuleConfig.getLoadBalancers().keySet().stream().filter(each -> !inUsedAlgorithms.contains(each)).collect(Collectors.toSet()); + private Collection findUnusedLoadBalancers() { + Collection inUsedAlgorithms = rule.getConfiguration().getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getLoadBalancerName).collect(Collectors.toSet()); + return rule.getConfiguration().getLoadBalancers().keySet().stream().filter(each -> !inUsedAlgorithms.contains(each)).collect(Collectors.toSet()); } @Override - public boolean hasAnyOneToBeDropped(final DropReadwriteSplittingRuleStatement sqlStatement, final ReadwriteSplittingRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig && !getIdenticalData(currentRuleConfig.getDataSources().stream() - .map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toSet()), sqlStatement.getNames()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropReadwriteSplittingRuleStatement sqlStatement) { + return null != rule && !getIdenticalData( + rule.getConfiguration().getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getName).collect(Collectors.toSet()), sqlStatement.getNames()).isEmpty(); } @Override diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java index 7d432a8a9005b..76c4b4a279a75 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java @@ -95,6 +95,9 @@ void assertCheckSQLStatementWithInUsed() throws RuleDefinitionViolationException @Test void assertUpdateCurrentRuleConfiguration() { ReadwriteSplittingRuleConfiguration ruleConfig = createCurrentRuleConfiguration(); + ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class); + when(rule.getConfiguration()).thenReturn(ruleConfig); + executor.setRule(rule); assertTrue(executor.updateCurrentRuleConfiguration(createSQLStatement(), ruleConfig)); assertThat(ruleConfig.getLoadBalancers().size(), is(0)); } @@ -102,6 +105,9 @@ void assertUpdateCurrentRuleConfiguration() { @Test void assertUpdateCurrentRuleConfigurationWithInUsedLoadBalancer() { ReadwriteSplittingRuleConfiguration ruleConfig = createMultipleCurrentRuleConfigurations(); + ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class); + when(rule.getConfiguration()).thenReturn(ruleConfig); + executor.setRule(rule); assertFalse(executor.updateCurrentRuleConfiguration(createSQLStatement(), ruleConfig)); assertThat(ruleConfig.getLoadBalancers().size(), is(1)); } @@ -109,6 +115,9 @@ void assertUpdateCurrentRuleConfigurationWithInUsedLoadBalancer() { @Test void assertUpdateCurrentRuleConfigurationWithoutLoadBalancerName() { ReadwriteSplittingRuleConfiguration ruleConfig = createCurrentRuleConfigurationWithoutLoadBalancerName(); + ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class); + when(rule.getConfiguration()).thenReturn(ruleConfig); + executor.setRule(rule); assertTrue(executor.updateCurrentRuleConfiguration(createSQLStatement(), ruleConfig)); assertThat(ruleConfig.getLoadBalancers().size(), is(0)); } diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java index 67c2c5eafcc4a..f992330fb994e 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java @@ -53,16 +53,16 @@ private void checkAlgorithm() { } @Override - public boolean hasAnyOneToBeDropped(final DropDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig && null != currentRuleConfig.getDefaultShadowAlgorithmName(); + public boolean hasAnyOneToBeDropped(final DropDefaultShadowAlgorithmStatement sqlStatement) { + return null != rule && null != rule.getConfiguration().getDefaultShadowAlgorithmName(); } @Override - public ShadowRuleConfiguration buildToBeDroppedRuleConfiguration(final DropDefaultShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { + public ShadowRuleConfiguration buildToBeDroppedRuleConfiguration(final DropDefaultShadowAlgorithmStatement sqlStatement) { ShadowRuleConfiguration result = new ShadowRuleConfiguration(); - result.setShadowAlgorithms(Collections.singletonMap(currentRuleConfig.getDefaultShadowAlgorithmName(), - currentRuleConfig.getShadowAlgorithms().get(currentRuleConfig.getDefaultShadowAlgorithmName()))); - result.setDefaultShadowAlgorithmName(currentRuleConfig.getDefaultShadowAlgorithmName()); + result.setShadowAlgorithms(Collections.singletonMap(rule.getConfiguration().getDefaultShadowAlgorithmName(), + rule.getConfiguration().getShadowAlgorithms().get(rule.getConfiguration().getDefaultShadowAlgorithmName()))); + result.setDefaultShadowAlgorithmName(rule.getConfiguration().getDefaultShadowAlgorithmName()); return result; } diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java index a018326ad3c83..00a2f623cbecc 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java @@ -80,16 +80,16 @@ private Collection getAlgorithmInUse() { } @Override - public boolean hasAnyOneToBeDropped(final DropShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig - && !getIdenticalData(ShadowRuleStatementSupporter.getAlgorithmNames(currentRuleConfig), sqlStatement.getNames()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropShadowAlgorithmStatement sqlStatement) { + return null != rule + && !getIdenticalData(ShadowRuleStatementSupporter.getAlgorithmNames(rule.getConfiguration()), sqlStatement.getNames()).isEmpty(); } @Override - public ShadowRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { + public ShadowRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShadowAlgorithmStatement sqlStatement) { ShadowRuleConfiguration result = new ShadowRuleConfiguration(); for (String each : sqlStatement.getNames()) { - result.getShadowAlgorithms().put(each, currentRuleConfig.getShadowAlgorithms().get(each)); + result.getShadowAlgorithms().put(each, rule.getConfiguration().getShadowAlgorithms().get(each)); } return result; } diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java index 3384b6d0f99ab..db390211f53d7 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java @@ -66,33 +66,33 @@ private Collection getDataSourceNames() { } @Override - public boolean hasAnyOneToBeDropped(final DropShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { - return isExistRuleConfig(currentRuleConfig) && !getIdenticalData(sqlStatement.getNames(), getDataSourceNames()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropShadowRuleStatement sqlStatement) { + return isExistRuleConfig(rule.getConfiguration()) && !getIdenticalData(sqlStatement.getNames(), getDataSourceNames()).isEmpty(); } @Override - public ShadowRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { + public ShadowRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShadowRuleStatement sqlStatement) { ShadowRuleConfiguration result = new ShadowRuleConfiguration(); for (String each : sqlStatement.getNames()) { result.getDataSources().add(new ShadowDataSourceConfiguration(each, null, null)); - dropRule(currentRuleConfig, each); + dropRule(each); } - currentRuleConfig.getTables().forEach((key, value) -> value.getDataSourceNames().removeIf(sqlStatement.getNames()::contains)); - for (Entry each : currentRuleConfig.getTables().entrySet()) { + rule.getConfiguration().getTables().forEach((key, value) -> value.getDataSourceNames().removeIf(sqlStatement.getNames()::contains)); + for (Entry each : rule.getConfiguration().getTables().entrySet()) { if (each.getValue().getDataSourceNames().isEmpty()) { result.getTables().put(each.getKey(), each.getValue()); } } - currentRuleConfig.getTables().entrySet().removeIf(each -> each.getValue().getDataSourceNames().isEmpty()); - UnusedAlgorithmFinder.findUnusedShadowAlgorithm(currentRuleConfig).forEach(each -> result.getShadowAlgorithms().put(each, currentRuleConfig.getShadowAlgorithms().get(each))); + rule.getConfiguration().getTables().entrySet().removeIf(each -> each.getValue().getDataSourceNames().isEmpty()); + UnusedAlgorithmFinder.findUnusedShadowAlgorithm(rule.getConfiguration()).forEach(each -> result.getShadowAlgorithms().put(each, rule.getConfiguration().getShadowAlgorithms().get(each))); return result; } @Override - public ShadowRuleConfiguration buildToBeAlteredRuleConfiguration(final DropShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { + public ShadowRuleConfiguration buildToBeAlteredRuleConfiguration(final DropShadowRuleStatement sqlStatement) { Map tables = new LinkedHashMap<>(); Collection toBeDroppedDataSourceNames = sqlStatement.getNames(); - for (Entry each : currentRuleConfig.getTables().entrySet()) { + for (Entry each : rule.getConfiguration().getTables().entrySet()) { if (!toBeDroppedDataSourceNames.containsAll(each.getValue().getDataSourceNames())) { List currentDataSources = new LinkedList<>(each.getValue().getDataSourceNames()); currentDataSources.removeAll(toBeDroppedDataSourceNames); @@ -107,7 +107,7 @@ public ShadowRuleConfiguration buildToBeAlteredRuleConfiguration(final DropShado @Override public boolean updateCurrentRuleConfiguration(final DropShadowRuleStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) { for (String each : sqlStatement.getNames()) { - dropRule(currentRuleConfig, each); + dropRule(each); } currentRuleConfig.getTables().forEach((key, value) -> value.getDataSourceNames().removeIf(sqlStatement.getNames()::contains)); currentRuleConfig.getTables().entrySet().removeIf(entry -> entry.getValue().getDataSourceNames().isEmpty()); @@ -115,9 +115,9 @@ public boolean updateCurrentRuleConfiguration(final DropShadowRuleStatement sqlS return currentRuleConfig.isEmpty(); } - private void dropRule(final ShadowRuleConfiguration currentRuleConfig, final String ruleName) { - Optional dataSourceRuleConfig = currentRuleConfig.getDataSources().stream().filter(each -> ruleName.equals(each.getName())).findAny(); - dataSourceRuleConfig.ifPresent(optional -> currentRuleConfig.getDataSources().remove(optional)); + private void dropRule(final String ruleName) { + Optional dataSourceRuleConfig = rule.getConfiguration().getDataSources().stream().filter(each -> ruleName.equals(each.getName())).findAny(); + dataSourceRuleConfig.ifPresent(optional -> rule.getConfiguration().getDataSources().remove(optional)); } private void dropUnusedAlgorithm(final ShadowRuleConfiguration currentRuleConfig) { diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java index 873080cced61b..ae6fb62f0816c 100644 --- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java +++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java @@ -68,9 +68,12 @@ void assertUpdate() { ShadowRuleConfiguration ruleConfig = new ShadowRuleConfiguration(); ruleConfig.setDefaultShadowAlgorithmName("default"); ruleConfig.getShadowAlgorithms().put(ruleConfig.getDefaultShadowAlgorithmName(), mock(AlgorithmConfiguration.class)); + ShadowRule rule = mock(ShadowRule.class); + when(rule.getConfiguration()).thenReturn(ruleConfig); + executor.setRule(rule); executor.checkBeforeUpdate(new DropDefaultShadowAlgorithmStatement(true)); DropDefaultShadowAlgorithmStatement sqlStatement = new DropDefaultShadowAlgorithmStatement(false); - assertTrue(executor.hasAnyOneToBeDropped(sqlStatement, ruleConfig)); + assertTrue(executor.hasAnyOneToBeDropped(sqlStatement)); executor.updateCurrentRuleConfiguration(sqlStatement, ruleConfig); assertNull(ruleConfig.getDefaultShadowAlgorithmName()); assertTrue(ruleConfig.getShadowAlgorithms().isEmpty()); diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java index 57f4dfa2fa964..bfca5df509fa3 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java @@ -63,24 +63,24 @@ private Optional getStrategyConfiguration(final S } @Override - public boolean hasAnyOneToBeDropped(final DropDefaultShardingStrategyStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + public boolean hasAnyOneToBeDropped(final DropDefaultShardingStrategyStatement sqlStatement) { if (sqlStatement.getDefaultType().equalsIgnoreCase(ShardingStrategyLevelType.TABLE.name())) { - return null != currentRuleConfig && null != currentRuleConfig.getDefaultTableShardingStrategy(); + return null != rule && null != rule.getConfiguration().getDefaultTableShardingStrategy(); } - return null != currentRuleConfig && null != currentRuleConfig.getDefaultDatabaseShardingStrategy(); + return null != rule && null != rule.getConfiguration().getDefaultDatabaseShardingStrategy(); } @Override - public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropDefaultShardingStrategyStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropDefaultShardingStrategyStatement sqlStatement) { ShardingRuleConfiguration result = new ShardingRuleConfiguration(); if (sqlStatement.getDefaultType().equalsIgnoreCase(ShardingStrategyLevelType.TABLE.name())) { - result.setDefaultTableShardingStrategy(currentRuleConfig.getDefaultTableShardingStrategy()); - currentRuleConfig.setDefaultTableShardingStrategy(null); + result.setDefaultTableShardingStrategy(rule.getConfiguration().getDefaultTableShardingStrategy()); + rule.getConfiguration().setDefaultTableShardingStrategy(null); } else { - result.setDefaultDatabaseShardingStrategy(currentRuleConfig.getDefaultDatabaseShardingStrategy()); - currentRuleConfig.setDefaultDatabaseShardingStrategy(null); + result.setDefaultDatabaseShardingStrategy(rule.getConfiguration().getDefaultDatabaseShardingStrategy()); + rule.getConfiguration().setDefaultDatabaseShardingStrategy(null); } - UnusedAlgorithmFinder.findUnusedShardingAlgorithm(currentRuleConfig).forEach(each -> result.getShardingAlgorithms().put(each, currentRuleConfig.getShardingAlgorithms().get(each))); + UnusedAlgorithmFinder.findUnusedShardingAlgorithm(rule.getConfiguration()).forEach(each -> result.getShardingAlgorithms().put(each, rule.getConfiguration().getShardingAlgorithms().get(each))); return result; } diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java index 1fbca2f9236f1..5eb547c63ed88 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java @@ -93,10 +93,10 @@ private Collection getCurrentShardingAlgorithms() { } @Override - public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingAlgorithmStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingAlgorithmStatement sqlStatement) { ShardingRuleConfiguration result = new ShardingRuleConfiguration(); for (String each : sqlStatement.getNames()) { - result.getShardingAlgorithms().put(each, currentRuleConfig.getShardingAlgorithms().get(each)); + result.getShardingAlgorithms().put(each, rule.getConfiguration().getShardingAlgorithms().get(each)); } return result; } @@ -110,8 +110,8 @@ public boolean updateCurrentRuleConfiguration(final DropShardingAlgorithmStateme } @Override - public boolean hasAnyOneToBeDropped(final DropShardingAlgorithmStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig && !getIdenticalData(getCurrentShardingAlgorithms(), sqlStatement.getNames()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropShardingAlgorithmStatement sqlStatement) { + return null != rule && !getIdenticalData(getCurrentShardingAlgorithms(), sqlStatement.getNames()).isEmpty(); } private void dropShardingAlgorithm(final String algorithmName) { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java index 6b0a337fee4c5..6a8148021a0fa 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java @@ -75,10 +75,10 @@ private Collection getUsedAuditors() { } @Override - public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingAuditorStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingAuditorStatement sqlStatement) { ShardingRuleConfiguration result = new ShardingRuleConfiguration(); for (String each : sqlStatement.getNames()) { - result.getAuditors().put(each, currentRuleConfig.getAuditors().get(each)); + result.getAuditors().put(each, rule.getConfiguration().getAuditors().get(each)); } return result; } @@ -90,8 +90,8 @@ public boolean updateCurrentRuleConfiguration(final DropShardingAuditorStatement } @Override - public boolean hasAnyOneToBeDropped(final DropShardingAuditorStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig && !getIdenticalData(currentRuleConfig.getAuditors().keySet(), sqlStatement.getNames()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropShardingAuditorStatement sqlStatement) { + return null != rule && !getIdenticalData(rule.getConfiguration().getAuditors().keySet(), sqlStatement.getNames()).isEmpty(); } @Override diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java index eefc6e7b1bec6..466309d4f1e83 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java @@ -76,10 +76,10 @@ private Collection getUsedKeyGenerators() { } @Override - public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingKeyGeneratorStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingKeyGeneratorStatement sqlStatement) { ShardingRuleConfiguration result = new ShardingRuleConfiguration(); for (String each : sqlStatement.getNames()) { - result.getKeyGenerators().put(each, currentRuleConfig.getKeyGenerators().get(each)); + result.getKeyGenerators().put(each, rule.getConfiguration().getKeyGenerators().get(each)); } return result; } @@ -91,8 +91,8 @@ public boolean updateCurrentRuleConfiguration(final DropShardingKeyGeneratorStat } @Override - public boolean hasAnyOneToBeDropped(final DropShardingKeyGeneratorStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { - return null != currentRuleConfig && !getIdenticalData(currentRuleConfig.getKeyGenerators().keySet(), sqlStatement.getNames()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropShardingKeyGeneratorStatement sqlStatement) { + return null != rule && !getIdenticalData(rule.getConfiguration().getKeyGenerators().keySet(), sqlStatement.getNames()).isEmpty(); } @Override diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java index 6bcf79ad861d3..6468e70569131 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java @@ -69,7 +69,7 @@ private boolean containsIgnoreCase(final Collection ruleNames, final Str } @Override - public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingTableReferenceRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingTableReferenceRuleStatement sqlStatement) { ShardingRuleConfiguration result = new ShardingRuleConfiguration(); for (String each : sqlStatement.getNames()) { result.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration(each, "")); @@ -84,8 +84,8 @@ public boolean updateCurrentRuleConfiguration(final DropShardingTableReferenceRu } @Override - public boolean hasAnyOneToBeDropped(final DropShardingTableReferenceRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { - return isExistRuleConfig(currentRuleConfig) && !getIdenticalData(getCurrentShardingTableReferenceRuleNames(), sqlStatement.getNames()).isEmpty(); + public boolean hasAnyOneToBeDropped(final DropShardingTableReferenceRuleStatement sqlStatement) { + return isExistRuleConfig(rule.getConfiguration()) && !getIdenticalData(getCurrentShardingTableReferenceRuleNames(), sqlStatement.getNames()).isEmpty(); } @Override diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java index c864438ced9a8..1fa4915cfc789 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java @@ -92,28 +92,29 @@ private Collection getBindingTables() { } @Override - public boolean hasAnyOneToBeDropped(final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { - if (null == currentRuleConfig) { + public boolean hasAnyOneToBeDropped(final DropShardingTableRuleStatement sqlStatement) { + if (null == rule) { return false; } Collection currentTableNames = new LinkedList<>(); - currentTableNames.addAll(currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet())); - currentTableNames.addAll(currentRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet())); + currentTableNames.addAll(rule.getConfiguration().getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toSet())); + currentTableNames.addAll(rule.getConfiguration().getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getLogicTable).collect(Collectors.toSet())); return !getIdenticalData(currentTableNames, sqlStatement.getTableNames().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toSet())).isEmpty(); } @Override - public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingTableRuleStatement sqlStatement, final ShardingRuleConfiguration currentRuleConfig) { + public ShardingRuleConfiguration buildToBeDroppedRuleConfiguration(final DropShardingTableRuleStatement sqlStatement) { ShardingRuleConfiguration result = new ShardingRuleConfiguration(); Collection toBeDroppedShardingTableNames = getToBeDroppedShardingTableNames(sqlStatement); for (String each : toBeDroppedShardingTableNames) { - result.getTables().addAll(currentRuleConfig.getTables().stream().filter(table -> each.equalsIgnoreCase(table.getLogicTable())).collect(Collectors.toList())); - result.getAutoTables().addAll(currentRuleConfig.getAutoTables().stream().filter(table -> each.equalsIgnoreCase(table.getLogicTable())).collect(Collectors.toList())); - dropShardingTable(currentRuleConfig, each); + result.getTables().addAll(rule.getConfiguration().getTables().stream().filter(table -> each.equalsIgnoreCase(table.getLogicTable())).collect(Collectors.toList())); + result.getAutoTables().addAll(rule.getConfiguration().getAutoTables().stream().filter(table -> each.equalsIgnoreCase(table.getLogicTable())).collect(Collectors.toList())); + dropShardingTable(rule.getConfiguration(), each); } - UnusedAlgorithmFinder.findUnusedShardingAlgorithm(currentRuleConfig).forEach(each -> result.getShardingAlgorithms().put(each, currentRuleConfig.getShardingAlgorithms().get(each))); - UnusedAlgorithmFinder.findUnusedKeyGenerator(currentRuleConfig).forEach(each -> result.getKeyGenerators().put(each, currentRuleConfig.getKeyGenerators().get(each))); - UnusedAlgorithmFinder.findUnusedAuditor(currentRuleConfig).forEach(each -> result.getAuditors().put(each, currentRuleConfig.getAuditors().get(each))); + UnusedAlgorithmFinder.findUnusedShardingAlgorithm( + rule.getConfiguration()).forEach(each -> result.getShardingAlgorithms().put(each, rule.getConfiguration().getShardingAlgorithms().get(each))); + UnusedAlgorithmFinder.findUnusedKeyGenerator(rule.getConfiguration()).forEach(each -> result.getKeyGenerators().put(each, rule.getConfiguration().getKeyGenerators().get(each))); + UnusedAlgorithmFinder.findUnusedAuditor(rule.getConfiguration()).forEach(each -> result.getAuditors().put(each, rule.getConfiguration().getAuditors().get(each))); return result; } diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableReferenceExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableReferenceExecutorTest.java index 88ff376b611bf..9cbd5a7434655 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableReferenceExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableReferenceExecutorTest.java @@ -77,7 +77,7 @@ void assertHasAnyOneToBeDropped() { ShardingRule rule = mock(ShardingRule.class); when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); - assertTrue(executor.hasAnyOneToBeDropped(sqlStatement, currentRuleConfig)); + assertTrue(executor.hasAnyOneToBeDropped(sqlStatement)); } private ShardingRuleConfiguration createCurrentRuleConfiguration() { @@ -95,7 +95,7 @@ void assertHasNotAnyOneToBeDropped() { ShardingRule rule = mock(ShardingRule.class); when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); - assertFalse(executor.hasAnyOneToBeDropped(sqlStatement, currentRuleConfig)); + assertFalse(executor.hasAnyOneToBeDropped(sqlStatement)); } @Test diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java index 8577da3e0653d..55cdec10a9f02 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java @@ -57,7 +57,7 @@ public void executeUpdate() { executor.setRule(rule.orElse(null)); checkBeforeUpdate(rule.orElse(null)); RuleConfiguration currentRuleConfig = rule.map(ShardingSphereRule::getConfiguration).orElse(null); - if (getRefreshStatus(currentRuleConfig)) { + if (getRefreshStatus()) { contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService() .switchActiveVersion(DatabaseRuleOperatorFactory.newInstance(contextManager, executor).operate(sqlStatement, database, currentRuleConfig)); } @@ -77,7 +77,7 @@ private void checkCurrentRule(final ShardingSphereRule rule, final DistSQLExecut } @SuppressWarnings({"rawtypes", "unchecked"}) - private boolean getRefreshStatus(final RuleConfiguration currentRuleConfig) { - return !(executor instanceof DatabaseRuleDropExecutor) || ((DatabaseRuleDropExecutor) executor).hasAnyOneToBeDropped(sqlStatement, currentRuleConfig); + private boolean getRefreshStatus() { + return !(executor instanceof DatabaseRuleDropExecutor) || ((DatabaseRuleDropExecutor) executor).hasAnyOneToBeDropped(sqlStatement); } } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java index b773b23c0f4ac..c46229005b0bf 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java @@ -48,18 +48,18 @@ public final class DropDatabaseRuleOperator implements DatabaseRuleOperator { @Override @SuppressWarnings("unchecked") public Collection operate(final RuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) { - if (!executor.hasAnyOneToBeDropped(sqlStatement, currentRuleConfig)) { + if (!executor.hasAnyOneToBeDropped(sqlStatement)) { return Collections.emptyList(); } ModeContextManager modeContextManager = contextManager.getInstanceContext().getModeContextManager(); - RuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(sqlStatement, currentRuleConfig); + RuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(sqlStatement); if (sqlStatement instanceof StaticDataSourceContainedRuleAwareStatement) { database.getRuleMetaData().findSingleRule(StaticDataSourceContainedRule.class) .ifPresent(optional -> ((StaticDataSourceContainedRuleAwareStatement) sqlStatement).getNames().forEach(optional::cleanStorageNodeDataSource)); // TODO refactor to new metadata refresh way } modeContextManager.removeRuleConfigurationItem(database.getName(), toBeDroppedRuleConfig); - RuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement, currentRuleConfig); + RuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); if (null != toBeAlteredRuleConfig && ((DatabaseRuleConfiguration) toBeAlteredRuleConfig).isEmpty()) { new NewYamlRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(Collections.singleton(currentRuleConfig)).values().stream().findFirst() .ifPresent(optional -> modeContextManager.removeRuleConfiguration(database.getName(), optional.getRuleTagName().toLowerCase())); diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/database/DatabaseRuleDropExecutor.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/database/DatabaseRuleDropExecutor.java index 7d9e577d2b939..0115adb7a984e 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/database/DatabaseRuleDropExecutor.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/database/DatabaseRuleDropExecutor.java @@ -39,10 +39,9 @@ public interface DatabaseRuleDropExecutor executor) { - return !(executor instanceof DatabaseRuleDropExecutor) || ((DatabaseRuleDropExecutor) executor).hasAnyOneToBeDropped(sqlStatement, currentRuleConfig); + private boolean getRefreshStatus(final SQLStatement sqlStatement, final DatabaseRuleDefinitionExecutor executor) { + return !(executor instanceof DatabaseRuleDropExecutor) || ((DatabaseRuleDropExecutor) executor).hasAnyOneToBeDropped(sqlStatement); } @SuppressWarnings("rawtypes") @@ -134,7 +134,7 @@ private RuleConfiguration processAlter(final RuleDefinitionStatement sqlStatemen @SuppressWarnings({"rawtypes", "unchecked"}) private void processDrop(final ShardingSphereDatabase database, final Collection configs, final RuleDefinitionStatement sqlStatement, final DatabaseRuleDropExecutor executor, final RuleConfiguration currentRuleConfig) { - if (!executor.hasAnyOneToBeDropped(sqlStatement, currentRuleConfig)) { + if (!executor.hasAnyOneToBeDropped(sqlStatement)) { return; } if (executor.updateCurrentRuleConfiguration(sqlStatement, currentRuleConfig)) {