From 152da00c6c175b5954b78028135af588880ea6b3 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sun, 31 Mar 2024 22:30:57 +0800 Subject: [PATCH] Refactor RuleDefinitionException (#30718) * Refactor DuplicateRuleException * Refactor MissingRequiredRuleException * Refactor InUsedRuleException * Refactor EmptyRuleException * Refactor MissingRequiredSingleTableException * Refactor DuplicateStorageUnitException * Refactor DuplicateStorageUnitException --- .../user-manual/error-code/sql-error-code.cn.md | 13 +++++++------ .../user-manual/error-code/sql-error-code.en.md | 13 ++++++++----- .../update/DropReadwriteSplittingRuleExecutor.java | 4 ++-- .../DropReadwriteSplittingRuleExecutorTest.java | 4 ++-- .../update/DropShardingTableRuleExecutor.java | 4 ++-- .../update/DropShardingTableRuleExecutorTest.java | 4 ++-- .../exception/rule/DuplicateRuleException.java | 6 +++--- ...xistedException.java => EmptyRuleException.java} | 8 ++++---- ...nUsedException.java => InUsedRuleException.java} | 12 ++++++------ .../rule/MissingRequiredRuleException.java | 10 +++++----- .../AlterStorageUnitConnectionInfoException.java | 2 +- ...tion.java => DuplicateStorageUnitException.java} | 4 ++-- .../storageunit/StorageUnitsConnectException.java | 2 +- .../rdl/resource/AlterStorageUnitExecutor.java | 4 ++-- .../rdl/resource/RegisterStorageUnitExecutor.java | 6 +++--- .../rdl/resource/AlterStorageUnitExecutorTest.java | 4 ++-- .../resource/RegisterStorageUnitExecutorTest.java | 8 ++++---- .../MissingRequiredSingleTableException.java | 6 +++--- .../proxy/backend/connector/DatabaseConnector.java | 4 ++-- .../handler/distsql/rul/PreviewExecutor.java | 4 ++-- 20 files changed, 63 insertions(+), 59 deletions(-) rename infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/{RuleNotExistedException.java => EmptyRuleException.java} (80%) rename infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/{RuleInUsedException.java => InUsedRuleException.java} (81%) rename infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/{DuplicateStorageUnitExceptionDefinition.java => DuplicateStorageUnitException.java} (87%) diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md b/docs/document/content/user-manual/error-code/sql-error-code.cn.md index 0177ef65c8627..7feac46bb702e 100644 --- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md +++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md @@ -20,6 +20,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供, | HY000 | 10005 | Column '%s' in %s is ambiguous. | | 42S02 | 10006 | Unknown column '%s' in '%s'. | | 42S02 | 10007 | Table or view \`%s\` does not exist. | +| 42S02 | 10008 | Missing required table '%s' in storage unit '%s'. | | 42000 | 10010 | Rule does not exist. | | 42S02 | 10020 | Schema \`%s\` does not exist. | | 42S02 | 10021 | Single table \`%s\` does not exist. | @@ -31,14 +32,14 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供, | 44000 | 10102 | Storage units '%s' do not exist in database '%s'. | | 44000 | 10103 | Storage unit '%s' still used by '%s'. | | 42S01 | 10104 | Duplicate storage unit names '%s'. | -| 08000 | 10105 | Storage units can not connect, error messages are: %s. | -| 0A000 | 10106 | Can not alter connection info in storage units: '%s'. | +| 08000 | 10110 | Storage units can not connect, error messages are: %s. | +| 0A000 | 10111 | Can not alter connection info in storage units: '%s'. | | 44000 | 10120 | Invalid storage unit status, error message is: %s. | | 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s | -| 44000 | 10201 | %s rules '%s' do not exist in database '%s'. | -| 44000 | 10202 | %s rules '%s' in database '%s' are still in used. | -| 44000 | 10205 | Duplicate %s rule names '%s' in database '%s'. | -| 44000 | 10210 | There is no rule in database '%s'. | +| 42S02 | 10201 | There is no rule in database '%s'. | +| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'. | +| 44000 | 10203 | %s rules '%s' in database '%s' are still in used. | +| 42S01 | 10204 | Duplicate %s rule names '%s' in database '%s'. | | 44000 | 10300 | Algorithm '%s.'%s' initialization failed, reason is: %s. | | 44000 | 10301 | '%s' algorithm on %s is required. | | 42S02 | 10302 | '%s' algorithm '%s' on %s is unregistered. | diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md b/docs/document/content/user-manual/error-code/sql-error-code.en.md index 1e59d9be03f38..ca22a4e991c36 100644 --- a/docs/document/content/user-manual/error-code/sql-error-code.en.md +++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md @@ -20,6 +20,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi | HY000 | 10005 | Column '%s' in %s is ambiguous. | | 42S02 | 10006 | Unknown column '%s' in '%s'. | | 42S02 | 10007 | Table or view \`%s\` does not exist. | +| 42S02 | 10008 | Missing required table '%s' in storage unit '%s'. | | 42000 | 10010 | Rule does not exist. | | 42S02 | 10020 | Schema \`%s\` does not exist. | | 42S02 | 10021 | Single table \`%s\` does not exist. | @@ -31,13 +32,15 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi | 44000 | 10102 | Storage units '%s' do not exist in database '%s'. | | 44000 | 10103 | Storage unit '%s' still used by '%s'. | | 42S01 | 10104 | Duplicate storage unit names '%s'. | -| 08000 | 10105 | Storage units can not connect, error messages are: %s. | -| 0A000 | 10106 | Can not alter connection info in storage units: '%s'. | +| 08000 | 10110 | Storage units can not connect, error messages are: %s. | +| 0A000 | 10111 | Can not alter connection info in storage units: '%s'. | | 44000 | 10120 | Invalid storage unit status, error message is: %s. | | 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s | -| 44000 | 10201 | %s rules '%s' do not exist in database '%s'. | -| 44000 | 10202 | %s rules '%s' in database '%s' are still in used. | -| 44000 | 10205 | Duplicate %s rule names '%s' in database '%s'. | +| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s | +| 42S02 | 10201 | There is no rule in database '%s'. | +| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'. | +| 44000 | 10203 | %s rules '%s' in database '%s' are still in used. | +| 42S01 | 10204 | Duplicate %s rule names '%s' in database '%s'. | | 44000 | 10210 | There is no rule in database '%s'. | | 44000 | 10300 | Algorithm '%s.'%s' initialization failed, reason is: %s. | | 44000 | 10301 | '%s' algorithm on %s is required. | 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 53b59165dfc8b..fc5c2887a4017 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 @@ -20,7 +20,7 @@ import lombok.Setter; import org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleDropExecutor; import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException; -import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException; +import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException; import org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.datanode.DataNode; @@ -72,7 +72,7 @@ private void checkToBeDroppedRuleNames(final DropReadwriteSplittingRuleStatement private void checkToBeDroppedInUsed(final DropReadwriteSplittingRuleStatement sqlStatement) { Collection resourceBeUsed = getInUsedResources(); Collection ruleInUsed = sqlStatement.getNames().stream().filter(resourceBeUsed::contains).collect(Collectors.toSet()); - ShardingSpherePreconditions.checkState(ruleInUsed.isEmpty(), () -> new RuleInUsedException("Readwrite-splitting", database.getName(), ruleInUsed)); + ShardingSpherePreconditions.checkState(ruleInUsed.isEmpty(), () -> new InUsedRuleException("Readwrite-splitting", database.getName(), ruleInUsed)); } private Collection getInUsedResources() { 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 05d8b93e1a9d1..996288d664379 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 @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException; import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException; -import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException; +import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; @@ -88,7 +88,7 @@ void assertCheckSQLStatementWithInUsed() throws RuleDefinitionException { executor.setDatabase(database); when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); - assertThrows(RuleInUsedException.class, () -> executor.checkBeforeUpdate(createSQLStatement())); + assertThrows(InUsedRuleException.class, () -> executor.checkBeforeUpdate(createSQLStatement())); } @Test 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 d880c6012fb20..28126d82a584b 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 @@ -22,7 +22,7 @@ import lombok.Setter; import org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleDropExecutor; import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException; -import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException; +import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException; import org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; @@ -79,7 +79,7 @@ private void checkBindingTables(final DropShardingTableRuleStatement sqlStatemen Collection bindingTables = getBindingTables(); Collection usedTableNames = getToBeDroppedShardingTableNames(sqlStatement).stream().filter(bindingTables::contains).collect(Collectors.toList()); if (!usedTableNames.isEmpty()) { - throw new RuleInUsedException("Sharding", database.getName(), usedTableNames, "sharding table reference"); + throw new InUsedRuleException("Sharding", database.getName(), usedTableNames, "sharding table reference"); } } diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java index 15d757af95cd7..41a0a7edba671 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java @@ -20,7 +20,7 @@ import com.google.common.base.Splitter; import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException; import org.apache.shardingsphere.infra.exception.rule.MissingRequiredRuleException; -import org.apache.shardingsphere.infra.exception.rule.RuleInUsedException; +import org.apache.shardingsphere.infra.exception.rule.InUsedRuleException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; @@ -83,7 +83,7 @@ void assertCheckSQLStatementWithBindingTableRule() throws RuleDefinitionExceptio ShardingRule rule = mock(ShardingRule.class); when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); - assertThrows(RuleInUsedException.class, () -> executor.checkBeforeUpdate(createSQLStatement("t_order_item"))); + assertThrows(InUsedRuleException.class, () -> executor.checkBeforeUpdate(createSQLStatement("t_order_item"))); } @Test diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java index dc89551c2a8aa..eb2211441e06d 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/DuplicateRuleException.java @@ -30,14 +30,14 @@ public final class DuplicateRuleException extends RuleDefinitionException { private static final long serialVersionUID = -1738699538105858939L; public DuplicateRuleException(final String ruleType, final String databaseName, final Collection ruleNames) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, String.format("Duplicate %s rule names '%s' in database '%s'.", ruleType, ruleNames, databaseName)); + super(XOpenSQLState.DUPLICATE, 4, String.format("Duplicate %s rule names '%s' in database '%s'.", ruleType, ruleNames, databaseName)); } public DuplicateRuleException(final String ruleType, final Collection ruleNames) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, String.format("Duplicate %s rule names '%s'.", ruleType, ruleNames)); + super(XOpenSQLState.DUPLICATE, 4, String.format("Duplicate %s rule names '%s'.", ruleType, ruleNames)); } public DuplicateRuleException(final String type, final String databaseName) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 5, String.format("Duplicate '%s' in database '%s'.", type, databaseName)); + super(XOpenSQLState.DUPLICATE, 4, String.format("Duplicate '%s' in database '%s'.", type, databaseName)); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleNotExistedException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/EmptyRuleException.java similarity index 80% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleNotExistedException.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/EmptyRuleException.java index 8d5d6a5543c14..1b4a9b54c7d21 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleNotExistedException.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/EmptyRuleException.java @@ -21,13 +21,13 @@ import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException; /** - * Rule does not exist exception. + * Empty rule unit exception. */ -public final class RuleNotExistedException extends RuleDefinitionException { +public final class EmptyRuleException extends RuleDefinitionException { private static final long serialVersionUID = -4150905802300104824L; - public RuleNotExistedException(final String databaseName) { - super(XOpenSQLState.SYNTAX_ERROR, 10, "There is no rule in database '%s'.", databaseName); + public EmptyRuleException(final String databaseName) { + super(XOpenSQLState.NOT_FOUND, 1, "There is no rule in database '%s'.", databaseName); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleInUsedException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InUsedRuleException.java similarity index 81% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleInUsedException.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InUsedRuleException.java index 804942f60ed00..8862e2a10ca06 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/RuleInUsedException.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/InUsedRuleException.java @@ -23,17 +23,17 @@ import java.util.Collection; /** - * Rule in used exception. + * In used rule exception. */ -public final class RuleInUsedException extends RuleDefinitionException { +public final class InUsedRuleException extends RuleDefinitionException { private static final long serialVersionUID = 3308787279125477660L; - public RuleInUsedException(final String ruleType, final String databaseName, final Collection ruleNames) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "%s rules '%s' in database '%s' are still in used.", ruleType, ruleNames, databaseName); + public InUsedRuleException(final String ruleType, final String databaseName, final Collection ruleNames) { + super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "%s rules '%s' in database '%s' are still in used.", ruleType, ruleNames, databaseName); } - public RuleInUsedException(final String ruleType, final String databaseName, final Collection ruleNames, final String usingType) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "%s rules '%s' in database '%s' are still in used by %s.", ruleType, ruleNames, databaseName, usingType); + public InUsedRuleException(final String ruleType, final String databaseName, final Collection ruleNames, final String usingType) { + super(XOpenSQLState.CHECK_OPTION_VIOLATION, 3, "%s rules '%s' in database '%s' are still in used by %s.", ruleType, ruleNames, databaseName, usingType); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java index b1ac637ffa775..bda267b509417 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/rule/MissingRequiredRuleException.java @@ -30,22 +30,22 @@ public final class MissingRequiredRuleException extends RuleDefinitionException private static final long serialVersionUID = -8464574460917965546L; public MissingRequiredRuleException(final String ruleType) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rule does not exist.", ruleType); + super(XOpenSQLState.NOT_FOUND, 2, "%s rule does not exist.", ruleType); } public MissingRequiredRuleException(final String ruleType, final String databaseName) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rule does not exist in database '%s'.", ruleType, databaseName); + super(XOpenSQLState.NOT_FOUND, 2, "%s rule does not exist in database '%s'.", ruleType, databaseName); } public MissingRequiredRuleException(final String ruleType, final Collection ruleNames) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rules '%s' do not exist.", ruleType, ruleNames); + super(XOpenSQLState.NOT_FOUND, 2, "%s rules '%s' do not exist.", ruleType, ruleNames); } public MissingRequiredRuleException(final String ruleType, final String databaseName, final String ruleName) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rule '%s' do not exist in database '%s'.", ruleType, ruleName, databaseName); + super(XOpenSQLState.NOT_FOUND, 2, "%s rule '%s' do not exist in database '%s'.", ruleType, ruleName, databaseName); } public MissingRequiredRuleException(final String ruleType, final String databaseName, final Collection ruleNames) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "%s rules '%s' do not exist in database '%s'.", ruleType, ruleNames, databaseName); + super(XOpenSQLState.NOT_FOUND, 1, "%s rules '%s' do not exist in database '%s'.", ruleType, ruleNames, databaseName); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java index a436a472512e6..4414abe82690a 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/AlterStorageUnitConnectionInfoException.java @@ -30,6 +30,6 @@ public final class AlterStorageUnitConnectionInfoException extends ResourceDefin private static final long serialVersionUID = 525999625052706626L; public AlterStorageUnitConnectionInfoException(final Collection storageUnitNames) { - super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 6, "Can not alter connection info in storage units: '%s'.", String.join(", ", storageUnitNames)); + super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 11, "Can not alter connection info in storage units: '%s'.", String.join(", ", storageUnitNames)); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitException.java similarity index 87% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitException.java index 39ba29e8342dd..66e10013bf7aa 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitExceptionDefinition.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/DuplicateStorageUnitException.java @@ -25,11 +25,11 @@ /** * Duplicate storage unit exception. */ -public final class DuplicateStorageUnitExceptionDefinition extends ResourceDefinitionException { +public final class DuplicateStorageUnitException extends ResourceDefinitionException { private static final long serialVersionUID = 2103793827572264148L; - public DuplicateStorageUnitExceptionDefinition(final Collection storageUnitNames) { + public DuplicateStorageUnitException(final Collection storageUnitNames) { super(XOpenSQLState.DUPLICATE, 4, "Duplicate storage unit names '%s'.", String.join(", ", storageUnitNames)); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java index b7507c1473bc6..72e851f551f02 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/storageunit/StorageUnitsConnectException.java @@ -31,7 +31,7 @@ public final class StorageUnitsConnectException extends ResourceDefinitionExcept private static final long serialVersionUID = 1824912697040264268L; public StorageUnitsConnectException(final Map causes) { - super(XOpenSQLState.CONNECTION_EXCEPTION, 5, "Storage units can not connect, error messages are: %s.", causes.entrySet().stream().map(entry -> String.format( + super(XOpenSQLState.CONNECTION_EXCEPTION, 10, "Storage units can not connect, error messages are: %s.", causes.entrySet().stream().map(entry -> String.format( "Storage unit name: '%s', error message is: %s", entry.getKey(), entry.getValue().getMessage())).collect(Collectors.joining(System.lineSeparator()))); } } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java index 8f881c0b91bf6..ec7d7650b25da 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java @@ -34,7 +34,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException; import org.apache.shardingsphere.infra.exception.storageunit.AlterStorageUnitConnectionInfoException; -import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition; +import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitException; import org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException; import org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; @@ -80,7 +80,7 @@ private void checkBefore(final AlterStorageUnitStatement sqlStatement) { private void checkDuplicatedStorageUnitNames(final Collection storageUnitNames) { Collection duplicatedStorageUnitNames = storageUnitNames.stream().filter(each -> storageUnitNames.stream().filter(each::equals).count() > 1).collect(Collectors.toList()); - ShardingSpherePreconditions.checkState(duplicatedStorageUnitNames.isEmpty(), () -> new DuplicateStorageUnitExceptionDefinition(duplicatedStorageUnitNames)); + ShardingSpherePreconditions.checkState(duplicatedStorageUnitNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedStorageUnitNames)); } private void checkStorageUnitNameExisted(final Collection storageUnitNames) { diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java index cf8e568fdcca1..09b8d65beceea 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException; -import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition; +import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitException; import org.apache.shardingsphere.infra.exception.storageunit.StorageUnitsOperateException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; @@ -89,7 +89,7 @@ private void checkDuplicatedDataSourceNames(final ContextManager contextManager, } dataSourceNames.add(each.getName()); } - ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitExceptionDefinition(duplicatedDataSourceNames)); + ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedDataSourceNames)); } private void checkDuplicatedLogicalDataSourceNames(final Collection requiredDataSourceNames) { @@ -98,7 +98,7 @@ private void checkDuplicatedLogicalDataSourceNames(final Collection requ return; } Collection duplicatedDataSourceNames = requiredDataSourceNames.stream().filter(logicalDataSourceNames::contains).collect(Collectors.toSet()); - ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitExceptionDefinition(duplicatedDataSourceNames)); + ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedDataSourceNames)); } private Collection getCurrentStorageUnitNames(final ContextManager contextManager) { diff --git a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java index 9064965753d49..7bc32bc10c7d4 100644 --- a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java +++ b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutorTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.AlterStorageUnitStatement; import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; import org.apache.shardingsphere.infra.exception.storageunit.AlterStorageUnitConnectionInfoException; -import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition; +import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitException; import org.apache.shardingsphere.infra.exception.storageunit.MissingRequiredStorageUnitsException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; @@ -75,7 +75,7 @@ void assertExecuteUpdateSuccess() { @Test void assertExecuteUpdateWithDuplicateStorageUnitNames() { - assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createAlterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class))); + assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createAlterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class))); } @Test diff --git a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java index 666f8e2f92a4a..e0900a347b419 100644 --- a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java +++ b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.distsql.segment.HostnameAndPortBasedDataSourceSegment; import org.apache.shardingsphere.distsql.segment.URLBasedDataSourceSegment; import org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.RegisterStorageUnitStatement; -import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitExceptionDefinition; +import org.apache.shardingsphere.infra.exception.storageunit.DuplicateStorageUnitException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; @@ -70,14 +70,14 @@ void assertExecuteUpdateSuccess() { @Test void assertExecuteUpdateWithDuplicateStorageUnitNamesInStatement() { - assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createRegisterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class))); + assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createRegisterStorageUnitStatementWithDuplicateStorageUnitNames(), mock(ContextManager.class))); } @Test void assertExecuteUpdateWithDuplicateStorageUnitNamesWithResourceMetaData() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getStorageUnits("foo_db").keySet()).thenReturn(Collections.singleton("ds_0")); - assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager)); + assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager)); } @Test @@ -87,7 +87,7 @@ void assertExecuteUpdateWithDuplicateStorageUnitNamesWithDataSourceContainedRule DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class); when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("ds_0", Collections.emptyList())); when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); - assertThrows(DuplicateStorageUnitExceptionDefinition.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager)); + assertThrows(DuplicateStorageUnitException.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager)); } private RegisterStorageUnitStatement createRegisterStorageUnitStatement() { diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java index 97d167e40ce10..425e8bd6686f6 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/exception/MissingRequiredSingleTableException.java @@ -18,16 +18,16 @@ package org.apache.shardingsphere.single.distsql.handler.exception; import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; -import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.RuleDefinitionException; +import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException; /** * Missing required single table exception. */ -public final class MissingRequiredSingleTableException extends RuleDefinitionException { +public final class MissingRequiredSingleTableException extends MetaDataSQLException { private static final long serialVersionUID = 3155006580453893122L; public MissingRequiredSingleTableException(final String storageUnitName, final String tableName) { - super(XOpenSQLState.CHECK_OPTION_VIOLATION, 6, "Missing required table '%s' in storage unit '%s'.", tableName, storageUnitName); + super(XOpenSQLState.NOT_FOUND, 8, "Missing required table '%s' in storage unit '%s'.", tableName, storageUnitName); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java index d1b6c6405ff2d..59f752acb42af 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java @@ -32,7 +32,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.dialect.SQLExceptionTransformEngine; -import org.apache.shardingsphere.infra.exception.rule.RuleNotExistedException; +import org.apache.shardingsphere.infra.exception.rule.EmptyRuleException; import org.apache.shardingsphere.infra.exception.storageunit.EmptyStorageUnitException; import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; import org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorExceptionHandler; @@ -132,7 +132,7 @@ private void failedIfBackendNotReady(final ConnectionSession connectionSession, boolean isSystemSchema = SystemSchemaUtils.containsSystemSchema(sqlStatementContext.getDatabaseType(), sqlStatementContext.getTablesContext().getSchemaNames(), database); ShardingSpherePreconditions.checkState(isSystemSchema || database.containsDataSource(), () -> new EmptyStorageUnitException(connectionSession.getDatabaseName())); if (!isSystemSchema && !database.isComplete()) { - throw new RuleNotExistedException(connectionSession.getDatabaseName()); + throw new EmptyRuleException(connectionSession.getDatabaseName()); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java index 2acbcff77b150..c723b682e2c99 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware; import org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor; -import org.apache.shardingsphere.infra.exception.rule.RuleNotExistedException; +import org.apache.shardingsphere.infra.exception.rule.EmptyRuleException; import org.apache.shardingsphere.distsql.statement.rul.sql.PreviewStatement; import org.apache.shardingsphere.infra.binder.context.aware.CursorDefinitionAware; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; @@ -97,7 +97,7 @@ public Collection getRows(final PreviewStatement sqlSta if (toBePreviewedStatementContext instanceof CursorAvailable && toBePreviewedStatementContext instanceof CursorDefinitionAware) { setUpCursorDefinition(toBePreviewedStatementContext); } - ShardingSpherePreconditions.checkState(database.isComplete(), () -> new RuleNotExistedException(database.getName())); + ShardingSpherePreconditions.checkState(database.isComplete(), () -> new EmptyRuleException(database.getName())); String schemaName = queryContext.getSqlStatementContext().getTablesContext().getSchemaName() .orElseGet(() -> new DatabaseTypeRegistry(database.getProtocolType()).getDefaultSchemaName(database.getName())); Collection executionUnits = getExecutionUnits(contextManager, schemaName, metaData, queryContext);