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 2022/08/27 08:28:46 UTC
[shardingsphere] branch master updated: Add SchemaNotFoundException (#20594)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 b337d55e13f Add SchemaNotFoundException (#20594)
b337d55e13f is described below
commit b337d55e13f3759d1301b62e36500d2cfb103eb8
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Aug 27 16:28:39 2022 +0800
Add SchemaNotFoundException (#20594)
---
.../content/user-manual/error-code/sql-error-code.cn.md | 3 ++-
.../content/user-manual/error-code/sql-error-code.en.md | 3 ++-
...CascadeTableException.java => SchemaNotFoundException.java} | 10 +++++-----
.../exception/UnsupportedDropCascadeTableException.java | 2 +-
.../validator/ddl/SingleTableDropSchemaMetadataValidator.java | 3 ++-
.../ddl/SingleTableDropSchemaMetadataValidatorTest.java | 3 ++-
6 files changed, 14 insertions(+), 10 deletions(-)
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 fe0a0b3952e..1b15e9e2316 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
@@ -36,7 +36,8 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 16000 | Can not find pipeline job \`%s\` |
| HY000 | 16001 | Failed to get DDL for table \`%s\` |
| 42S02 | 17000 | Single table \`%s\` does not exist |
-| 0A000 | 17001 | DROP TABLE ... CASCADE is not supported |
+| 42S02 | 17001 | Schema \`%s\` does not exist |
+| 0A000 | 17010 | DROP TABLE ... CASCADE is not supported |
| HY000 | 20000 | Sharding algorithm class \`%s\` should be implement \`%s\` |
| 44000 | 20001 | Can not get uniformed table structure for logic table \`%s\`, it has different meta data of actual tables are as follows: %s |
| 42S02 | 20002 | Can not get route result, please check your sharding rule configuration |
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 253d1446313..a58d153be10 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
@@ -36,7 +36,8 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| HY000 | 16000 | Can not find pipeline job \`%s\` |
| HY000 | 16001 | Failed to get DDL for table \`%s\` |
| 42S02 | 17000 | Single table \`%s\` does not exist |
-| 0A000 | 17001 | DROP TABLE ... CASCADE is not supported |
+| 42S02 | 17001 | Schema \`%s\` does not exist |
+| 0A000 | 17010 | DROP TABLE ... CASCADE is not supported |
| HY000 | 20000 | Sharding algorithm class \`%s\` should be implement \`%s\` |
| 44000 | 20001 | Can not get uniformed table structure for logic table \`%s\`, it has different meta data of actual tables are as follows: %s |
| 42S02 | 20002 | Can not get route result, please check your sharding rule configuration |
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/UnsupportedDropCascadeTableException.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/SchemaNotFoundException.java
similarity index 74%
copy from shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/UnsupportedDropCascadeTableException.java
copy to shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/SchemaNotFoundException.java
index 09bdcc6d7a7..e469463b4e7 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/UnsupportedDropCascadeTableException.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/SchemaNotFoundException.java
@@ -21,13 +21,13 @@ import org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLExcep
import org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
/**
- * Unsupported drop cascade table exception.
+ * Schema not found exception.
*/
-public final class UnsupportedDropCascadeTableException extends ShardingSphereSQLException {
+public final class SchemaNotFoundException extends ShardingSphereSQLException {
- private static final long serialVersionUID = -5995575055241171117L;
+ private static final long serialVersionUID = 2722045034640737328L;
- public UnsupportedDropCascadeTableException() {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 17001, "DROP TABLE ... CASCADE is not supported");
+ public SchemaNotFoundException(final String schemaName) {
+ super(XOpenSQLState.NOT_FOUND, 17001, "Schema `%s` does not exist", schemaName);
}
}
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/UnsupportedDropCascadeTableException.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/UnsupportedDropCascadeTableException.java
index 09bdcc6d7a7..bbdacd5fb5e 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/UnsupportedDropCascadeTableException.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/exception/UnsupportedDropCascadeTableException.java
@@ -28,6 +28,6 @@ public final class UnsupportedDropCascadeTableException extends ShardingSphereSQ
private static final long serialVersionUID = -5995575055241171117L;
public UnsupportedDropCascadeTableException() {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 17001, "DROP TABLE ... CASCADE is not supported");
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 17010, "DROP TABLE ... CASCADE is not supported");
}
}
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
index b8a2b271198..f8739cdcf9b 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidator.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.singletable.exception.SchemaNotFoundException;
import org.apache.shardingsphere.singletable.route.validator.SingleTableMetadataValidator;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropSchemaStatement;
@@ -39,7 +40,7 @@ public final class SingleTableDropSchemaMetadataValidator implements SingleTable
String schemaName = each.getValue();
ShardingSphereSchema schema = database.getSchema(schemaName);
if (null == schema) {
- throw new ShardingSphereException("Schema %s does not exist.", schemaName);
+ throw new SchemaNotFoundException(schemaName);
}
if (!containsCascade && !schema.getAllTableNames().isEmpty()) {
throw new ShardingSphereException("Can not drop schema %s because it contains tables.", schemaName);
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidatorTest.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidatorTest.java
index 1a2f163cd4c..b0ff502bd4b 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidatorTest.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/validator/ddl/SingleTableDropSchemaMetadataValidatorTest.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
+import org.apache.shardingsphere.singletable.exception.SchemaNotFoundException;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropSchemaStatement;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -42,7 +43,7 @@ public final class SingleTableDropSchemaMetadataValidatorTest {
new SingleTableDropSchemaMetadataValidator().validate(mock(SingleTableRule.class, RETURNS_DEEP_STUBS), createSQLStatementContext("foo_schema", false), mockDatabase());
}
- @Test(expected = ShardingSphereException.class)
+ @Test(expected = SchemaNotFoundException.class)
public void assertValidateWithNotExistedSchema() {
ShardingSphereDatabase database = mockDatabase();
when(database.getSchema("not_existed_schema")).thenReturn(null);