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 dde19eebfa1 Add SwitchTypeInTransactionException (#20470)
dde19eebfa1 is described below
commit dde19eebfa1549c9147af35d9dacb7b409b35a65
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Aug 23 20:28:34 2022 +0800
Add SwitchTypeInTransactionException (#20470)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../util/exception/sql/sqlstate/XOpenSQLState.java | 2 ++
.../SwitchTypeInTransactionException.java | 33 ++++++++++++++++++++++
.../session/transaction/TransactionStatus.java | 4 +--
.../backend/session/ConnectionSessionTest.java | 4 +--
6 files changed, 41 insertions(+), 4 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 ea987845f48..3780149c4ef 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
@@ -21,6 +21,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 11004 | File access failed, reason is: %s |
| 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 |
| 42000 | 12000 | Unsupported command: %s |
| 44000 | 13000 | SQL check failed, error message: %s |
| HY000 | 14000 | The table \`%s\` of schema \`%s\` is locked |
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 21059e12c99..7d4e462ddb9 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
@@ -21,6 +21,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY000 | 11004 | File access failed, reason is: %s |
| 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 |
| 42000 | 12000 | Unsupported command: %s |
| 44000 | 13000 | SQL check failed, error message: %s |
| HY000 | 14000 | The table \`%s\` of schema \`%s\` is locked |
diff --git
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
index 600554bcc60..49b46fd5b37 100644
---
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
+++
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
@@ -41,6 +41,8 @@ public enum XOpenSQLState implements SQLState {
MISMATCH_INSERT_VALUES_AND_COLUMNS("21S01"),
+ INVALID_TRANSACTION_STATE("25000"),
+
INVALID_AUTHORIZATION_SPECIFICATION("28000"),
INVALID_CATALOG_NAME("3D000"),
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/exception/SwitchTypeInTransactionException.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/exception/SwitchTypeInTransactionException.java
new file mode 100644
index 00000000000..2ae02dfbc36
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/exception/SwitchTypeInTransactionException.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.transaction.exception;
+
+import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Switch type in transaction exception.
+ */
+public final class SwitchTypeInTransactionException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = 5333976223578960845L;
+
+ public SwitchTypeInTransactionException() {
+ super(XOpenSQLState.INVALID_TRANSACTION_STATE, 11320, "Switch
transaction type failed, please terminate the current transaction");
+ }
+}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/transaction/TransactionStatus.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/transaction/TransactionStatus.java
index a3665016b5f..3e3a13e4450 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/transaction/TransactionStatus.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/transaction/TransactionStatus.java
@@ -19,8 +19,8 @@ package
org.apache.shardingsphere.proxy.backend.session.transaction;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.transaction.core.TransactionType;
+import
org.apache.shardingsphere.transaction.exception.SwitchTypeInTransactionException;
/**
* Transaction status.
@@ -47,7 +47,7 @@ public final class TransactionStatus {
*/
public void setTransactionType(final TransactionType transactionType) {
if (inTransaction) {
- throw new ShardingSphereException("Failed to switch transaction
type, please terminate current transaction.");
+ throw new SwitchTypeInTransactionException();
}
this.transactionType = transactionType;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
index aad22cd46b1..cdec98ee901 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.proxy.backend.session;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
@@ -27,6 +26,7 @@ import
org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.JD
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
import org.apache.shardingsphere.transaction.core.TransactionType;
+import
org.apache.shardingsphere.transaction.exception.SwitchTypeInTransactionException;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
import org.junit.Before;
import org.junit.Test;
@@ -73,7 +73,7 @@ public final class ConnectionSessionTest extends
ProxyContextRestorer {
assertThat(connectionSession.getDatabaseName(), is("currentDatabase"));
}
- @Test(expected = ShardingSphereException.class)
+ @Test(expected = SwitchTypeInTransactionException.class)
public void assertFailedSwitchTransactionTypeWhileBegin() throws
SQLException {
connectionSession.setCurrentDatabase("db");
JDBCBackendTransactionManager transactionManager = new
JDBCBackendTransactionManager(backendConnection);