You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/12/13 11:31:24 UTC

[shardingsphere] branch master updated: Add SQL Hint data source not exists exception(#22849) (#22853)

This is an automated email from the ASF dual-hosted git repository.

tuichenchuxin 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 a1bb702b572 Add SQL Hint data source not exists exception(#22849) (#22853)
a1bb702b572 is described below

commit a1bb702b572764f391c6fda46864eec6cb786d28
Author: ZhangCheng <fl...@outlook.com>
AuthorDate: Tue Dec 13 19:31:16 2022 +0800

    Add SQL Hint data source not exists exception(#22849) (#22853)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../hint/SQLHintDataSourceNotExistsException.java  | 35 ++++++++++++++++++++++
 .../route/engine/impl/PartialSQLRouteExecutor.java |  4 +--
 4 files changed, 39 insertions(+), 2 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 fec376ae06f..e70bc98b847 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
@@ -79,6 +79,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | SQL State | Vendor Code | 错误信息 |
 | --------- | ----------- | ------ |
 | 44000     | 16000       | SQL check failed, error message: %s |
+| 44000     | 16001       | Hint datasource: %s is not exist. |
 
 ### 集群
 
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 0c65a07ae9d..234bd5f1e63 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
@@ -79,6 +79,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | SQL State | Vendor Code | Reason |
 | --------- | ----------- | ------ |
 | 44000     | 16000       | SQL check failed, error message: %s |
+| 44000     | 16001       | Hint datasource: %s is not exist. |
 
 ### Cluster
 
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintDataSourceNotExistsException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintDataSourceNotExistsException.java
new file mode 100644
index 00000000000..e463d6aa3ea
--- /dev/null
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintDataSourceNotExistsException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.hint;
+
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import org.apache.shardingsphere.infra.util.exception.external.sql.type.kernel.KernelSQLException;
+
+/**
+ * SQL Hint data source not exists exception.
+ */
+public final class SQLHintDataSourceNotExistsException extends KernelSQLException {
+    
+    private static final long serialVersionUID = -8222967059220727514L;
+    
+    private static final int KERNEL_CODE = 6;
+    
+    public SQLHintDataSourceNotExistsException(final String errorMessage) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, KERNEL_CODE, 1, "Hint datasource: %s is not exist.", errorMessage);
+    }
+}
diff --git a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
index 53191285a13..f84b1dbf2c0 100644
--- a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
+++ b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.context.ConnectionContext;
 import org.apache.shardingsphere.infra.hint.HintManager;
+import org.apache.shardingsphere.infra.hint.SQLHintDataSourceNotExistsException;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.SQLRouter;
 import org.apache.shardingsphere.infra.route.SQLRouterFactory;
@@ -85,8 +86,7 @@ public final class PartialSQLRouteExecutor implements SQLRouteExecutor {
             result = ((CommonSQLStatementContext<?>) sqlStatementContext).findHintDataSourceName();
         }
         if (result.isPresent() && !dataSources.containsKey(result.get())) {
-            // TODO use correct ShardingSphere exception
-            throw new RuntimeException(String.format("Hint datasource: %s is not exist!", result.get()));
+            throw new SQLHintDataSourceNotExistsException(result.get());
         }
         return result;
     }