This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 f6b5a018567 Reuse SwitchTypeInTransactionException (#20853)
f6b5a018567 is described below
commit f6b5a018567fbddf0373edf2c95811fc765dd3fb
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 7 14:06:00 2022 +0800
Reuse SwitchTypeInTransactionException (#20853)
---
.../proxy/backend/handler/transaction/TransactionSetHandler.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java
index eca53efc1c0..81280144176 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionSetHandler.java
@@ -18,14 +18,16 @@
package org.apache.shardingsphere.proxy.backend.handler.transaction;
import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
import org.apache.shardingsphere.proxy.backend.util.TransactionUtil;
import
org.apache.shardingsphere.sql.parser.sql.common.constant.TransactionAccessType;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.SetTransactionStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
+import
org.apache.shardingsphere.transaction.exception.SwitchTypeInTransactionException;
import java.sql.Connection;
import java.sql.SQLException;
@@ -42,9 +44,7 @@ public final class TransactionSetHandler implements
ProxyBackendHandler {
@Override
public ResponseHeader execute() throws SQLException {
- if (null == sqlStatement.getScope() &&
connectionSession.getTransactionStatus().isInTransaction()) {
- throw new SQLException("when in transaction, not support set
transaction");
- }
+ ShardingSpherePreconditions.checkState(null != sqlStatement.getScope()
|| !connectionSession.getTransactionStatus().isInTransaction(), new
SwitchTypeInTransactionException());
if (TransactionAccessType.READ_ONLY == sqlStatement.getAccessMode()) {
connectionSession.setReadOnly(true);
} else if (TransactionAccessType.READ_WRITE ==
sqlStatement.getAccessMode()) {