You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/06/18 09:39:32 UTC
[shardingsphere] branch master updated: Optimize DropShardingTableRuleStatementUpdater (#26412)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 03b10d58859 Optimize DropShardingTableRuleStatementUpdater (#26412)
03b10d58859 is described below
commit 03b10d58859e1cbb413954a44b2d4a2b37f91377
Author: Raigor <ra...@gmail.com>
AuthorDate: Sun Jun 18 17:39:25 2023 +0800
Optimize DropShardingTableRuleStatementUpdater (#26412)
---
...va => DropDefaultShardingStrategyStatementUpdater.java} | 4 ++--
.../update/DropShardingTableRuleStatementUpdater.java | 14 +++++---------
...dingsphere.distsql.handler.update.RuleDefinitionUpdater | 2 +-
.../DropDefaultShardingStrategyStatementUpdaterTest.java | 4 ++--
.../handler/exception/rule/RuleInUsedException.java | 4 ++++
5 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultStrategyStatementUpdater.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyStatementUpdater.java
similarity index 96%
rename from features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultStrategyStatementUpdater.java
rename to features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyStatementUpdater.java
index 64ad50b59c4..2e1c919d37a 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultStrategyStatementUpdater.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyStatementUpdater.java
@@ -29,9 +29,9 @@ import org.apache.shardingsphere.sharding.distsql.parser.statement.DropDefaultSh
import java.util.Optional;
/**
- * Drop sharding table rule statement updater.
+ * Drop default sharding strategy statement updater.
*/
-public final class DropDefaultStrategyStatementUpdater implements RuleDefinitionDropUpdater<DropDefaultShardingStrategyStatement, ShardingRuleConfiguration> {
+public final class DropDefaultShardingStrategyStatementUpdater implements RuleDefinitionDropUpdater<DropDefaultShardingStrategyStatement, ShardingRuleConfiguration> {
@Override
public void checkSQLStatement(final ShardingSphereDatabase database, final DropDefaultShardingStrategyStatement sqlStatement,
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java
index d12a66b39fe..7faa990b44b 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleStatementUpdater.java
@@ -84,7 +84,7 @@ public final class DropShardingTableRuleStatementUpdater implements RuleDefiniti
Collection<String> bindingTables = getBindingTables(currentRuleConfig);
Collection<String> usedTableNames = getToBeDroppedShardingTableNames(sqlStatement).stream().filter(each -> containsIgnoreCase(bindingTables, each)).collect(Collectors.toList());
if (!usedTableNames.isEmpty()) {
- throw new RuleInUsedException("Sharding", databaseName, usedTableNames);
+ throw new RuleInUsedException("Sharding", databaseName, usedTableNames, "sharding table reference");
}
}
@@ -135,10 +135,8 @@ public final class DropShardingTableRuleStatementUpdater implements RuleDefiniti
private void dropUnusedKeyGenerator(final ShardingRuleConfiguration currentRuleConfig) {
Collection<String> inUsedKeyGenerators = currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getKeyGenerateStrategy).filter(Objects::nonNull)
.map(KeyGenerateStrategyConfiguration::getKeyGeneratorName).collect(Collectors.toSet());
- inUsedKeyGenerators.addAll(currentRuleConfig.getTables().stream().filter(each -> null != each.getKeyGenerateStrategy())
- .map(each -> each.getKeyGenerateStrategy().getKeyGeneratorName()).collect(Collectors.toSet()));
- inUsedKeyGenerators.addAll(currentRuleConfig.getAutoTables().stream().filter(each -> null != each.getKeyGenerateStrategy())
- .map(each -> each.getKeyGenerateStrategy().getKeyGeneratorName()).collect(Collectors.toSet()));
+ inUsedKeyGenerators.addAll(currentRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getKeyGenerateStrategy).filter(Objects::nonNull)
+ .map(KeyGenerateStrategyConfiguration::getKeyGeneratorName).collect(Collectors.toSet()));
if (null != currentRuleConfig.getDefaultKeyGenerateStrategy()) {
inUsedKeyGenerators.add(currentRuleConfig.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
}
@@ -149,10 +147,8 @@ public final class DropShardingTableRuleStatementUpdater implements RuleDefiniti
private void dropUnusedAuditor(final ShardingRuleConfiguration currentRuleConfig) {
Collection<String> inUsedAuditors = currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getAuditStrategy).filter(Objects::nonNull)
.flatMap(each -> each.getAuditorNames().stream()).collect(Collectors.toSet());
- inUsedAuditors.addAll(currentRuleConfig.getTables().stream().filter(each -> null != each.getAuditStrategy())
- .flatMap(each -> each.getAuditStrategy().getAuditorNames().stream()).collect(Collectors.toSet()));
- inUsedAuditors.addAll(currentRuleConfig.getAutoTables().stream().filter(each -> null != each.getAuditStrategy())
- .flatMap(each -> each.getAuditStrategy().getAuditorNames().stream()).collect(Collectors.toSet()));
+ inUsedAuditors.addAll(currentRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getAuditStrategy).filter(Objects::nonNull)
+ .flatMap(each -> each.getAuditorNames().stream()).collect(Collectors.toSet()));
if (null != currentRuleConfig.getDefaultAuditStrategy()) {
inUsedAuditors.addAll(currentRuleConfig.getDefaultAuditStrategy().getAuditorNames());
}
diff --git a/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater
index b1e5c614736..c8d2b84f333 100644
--- a/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater
+++ b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.update.RuleDefinitionUpdater
@@ -26,4 +26,4 @@ org.apache.shardingsphere.sharding.distsql.handler.update.CreateDefaultShardingS
org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingKeyGeneratorStatementUpdater
org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingAuditorStatementUpdater
org.apache.shardingsphere.sharding.distsql.handler.update.AlterDefaultShardingStrategyStatementUpdater
-org.apache.shardingsphere.sharding.distsql.handler.update.DropDefaultStrategyStatementUpdater
+org.apache.shardingsphere.sharding.distsql.handler.update.DropDefaultShardingStrategyStatementUpdater
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java
index 184ed1d545f..29048f516d4 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyStatementUpdaterTest.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
-import org.apache.shardingsphere.sharding.distsql.handler.update.DropDefaultStrategyStatementUpdater;
+import org.apache.shardingsphere.sharding.distsql.handler.update.DropDefaultShardingStrategyStatementUpdater;
import org.apache.shardingsphere.sharding.distsql.parser.statement.DropDefaultShardingStrategyStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -44,7 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(MockitoExtension.class)
class DropDefaultShardingStrategyStatementUpdaterTest {
- private final DropDefaultStrategyStatementUpdater updater = new DropDefaultStrategyStatementUpdater();
+ private final DropDefaultShardingStrategyStatementUpdater updater = new DropDefaultShardingStrategyStatementUpdater();
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/rule/RuleInUsedException.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/rule/RuleInUsedException.java
index 4b669198987..56b4f86bc41 100644
--- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/rule/RuleInUsedException.java
+++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/exception/rule/RuleInUsedException.java
@@ -31,4 +31,8 @@ public final class RuleInUsedException extends RuleDefinitionViolationException
public RuleInUsedException(final String ruleType, final String databaseName, final Collection<String> ruleNames) {
super(XOpenSQLState.CHECK_OPTION_VIOLATION, 102, "%s rules `%s` in database `%s` are still in used.", ruleType, ruleNames, databaseName);
}
+
+ public RuleInUsedException(final String ruleType, final String databaseName, final Collection<String> ruleNames, final String usingType) {
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 102, "%s rules `%s` in database `%s` are still in used by %s.", ruleType, ruleNames, databaseName, usingType);
+ }
}