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

yx9o 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 7571ef83685 Refactor TransactionXAHandler (#20863)
7571ef83685 is described below

commit 7571ef836855cf9fc228734ba7148de314a1e1d1
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 7 22:52:29 2022 +0800

    Refactor TransactionXAHandler (#20863)
---
 .../proxy/backend/handler/transaction/TransactionXAHandler.java   | 8 ++++----
 .../sql/parser/sql/common/statement/tcl/XAStatement.java          | 2 +-
 .../parser/sql/dialect/statement/mysql/tcl/MySQLXAStatement.java  | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
index cfefb146e7f..97e12472264 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
@@ -20,6 +20,7 @@ package 
org.apache.shardingsphere.proxy.backend.handler.transaction;
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.binder.QueryContext;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine;
 import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
@@ -31,6 +32,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.XAStatement
 import 
org.apache.shardingsphere.transaction.exception.StartNestedXATransactionException;
 
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 import java.util.Collections;
 
 /**
@@ -72,9 +74,7 @@ public final class TransactionXAHandler implements 
ProxyBackendHandler {
                  * we have to let session occupy the thread when doing xa 
transaction.
                  * according to 
https://dev.mysql.com/doc/refman/5.7/en/xa-states.html XA and local 
transactions are mutually exclusive
                  */
-                if 
(connectionSession.getTransactionStatus().isInTransaction()) {
-                    throw new StartNestedXATransactionException();
-                }
+                
ShardingSpherePreconditions.checkState(!connectionSession.getTransactionStatus().isInTransaction(),
 new StartNestedXATransactionException());
                 ResponseHeader header = backendHandler.execute();
                 
connectionSession.getConnectionContext().getTransactionConnectionContext().setInTransaction(true);
                 return header;
@@ -91,7 +91,7 @@ public final class TransactionXAHandler implements 
ProxyBackendHandler {
                     
connectionSession.getConnectionContext().clearCursorConnectionContext();
                 }
             default:
-                throw new SQLException("unrecognized XA statement " + 
tclStatement.getOp());
+                throw new 
SQLFeatureNotSupportedException(String.format("unrecognized XA statement `%s`", 
tclStatement.getOp()));
         }
     }
 }
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/tcl/XAStatement.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/tcl/XAStatement.java
index b3666507ece..31b25666865 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/tcl/XAStatement.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/tcl/XAStatement.java
@@ -23,7 +23,7 @@ import lombok.ToString;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
 
 /**
- * Set xa statement.
+ * XA statement.
  */
 @Getter
 @Setter
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/tcl/MySQLXAStatement.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/tcl/MySQLXAStatement.java
index 51be98e91c8..83fbedd281c 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/tcl/MySQLXAStatement.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/tcl/MySQLXAStatement.java
@@ -22,7 +22,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.XAStatement
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
 
 /**
- * MySQL savepoint statement.
+ * MySQL XA statement.
  */
 @ToString(callSuper = true)
 public final class MySQLXAStatement extends XAStatement implements 
MySQLStatement {

Reply via email to