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

panjuan 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 cef51ad18dc Add JDBCTransactionAcrossDatabasesException (#20504)
cef51ad18dc is described below

commit cef51ad18dcda2a9f94287092d9e67d57ba34c14
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 25 12:34:21 2022 +0800

    Add JDBCTransactionAcrossDatabasesException (#20504)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../core/statement/ShardingSphereStatement.java    |  4 +--
 .../JDBCTransactionAcrossDatabasesException.java   | 33 ++++++++++++++++++++++
 4 files changed, 37 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 7a6e666a42a..c7477a9b4ce 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
@@ -22,6 +22,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42000     | 11200       | Can not support database \`%s\` in SQL translation 
|
 | 42000     | 11201       | Translation error, SQL is: %s |
 | 25000     | 11320       | Switch transaction type failed, please terminate 
the current transaction |
+| 25000     | 11321       | JDBC does not support operations across multiple 
logical databases in transaction |
 | 42S02     | 11400       | Can not get traffic execution unit |
 | 42000     | 12000       | Unsupported command: %s |
 | 44000     | 13000       | SQL check failed, error message: %s |
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 7745c46de33..f76ef256c8b 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
@@ -22,6 +22,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42000     | 11200       | Can not support database \`%s\` in SQL translation 
|
 | 42000     | 11201       | Translation error, SQL is: %s |
 | 25000     | 11320       | Switch transaction type failed, please terminate 
the current transaction |
+| 25000     | 11321       | JDBC does not support operations across multiple 
logical databases in transaction |
 | 42S02     | 11400       | Can not get traffic execution unit |
 | 42000     | 12000       | Unsupported command: %s |
 | 44000     | 13000       | SQL check failed, error message: %s |
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index 9995efe500f..022c89c4b2f 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -28,6 +28,7 @@ import 
org.apache.shardingsphere.driver.jdbc.adapter.AbstractStatementAdapter;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import 
org.apache.shardingsphere.driver.jdbc.core.resultset.GeneratedKeysResultSet;
 import 
org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet;
+import 
org.apache.shardingsphere.driver.jdbc.exception.JDBCTransactionAcrossDatabasesException;
 import org.apache.shardingsphere.driver.jdbc.exception.SQLExceptionErrorCode;
 import org.apache.shardingsphere.infra.binder.QueryContext;
 import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
@@ -42,7 +43,6 @@ import 
org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
 import org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.apache.shardingsphere.infra.executor.check.SQLCheckEngine;
 import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
 import 
org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
@@ -472,7 +472,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         if (sqlStatementContext instanceof TableAvailable) {
             ((TableAvailable) 
sqlStatementContext).getTablesContext().getDatabaseName().ifPresent(databaseName
 -> {
                 if (!databaseName.equals(connectionDatabaseName)) {
-                    throw new ShardingSphereException("JDBC does not support 
operations across multiple logical databases in transaction.");
+                    throw new JDBCTransactionAcrossDatabasesException();
                 }
             });
         }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/JDBCTransactionAcrossDatabasesException.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/JDBCTransactionAcrossDatabasesException.java
new file mode 100644
index 00000000000..7da39a17c0a
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/JDBCTransactionAcrossDatabasesException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.driver.jdbc.exception;
+
+import 
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * JDBC transaction across databases exception.
+ */
+public final class JDBCTransactionAcrossDatabasesException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = 3294968323117604702L;
+    
+    public JDBCTransactionAcrossDatabasesException() {
+        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 11321, "JDBC does not 
support operations across multiple logical databases in transaction");
+    }
+}

Reply via email to