You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/06/06 22:48:39 UTC

(shardingsphere) branch master updated: Merge SQLServerBeginDistributedTransactionStatement and XABeginStatement (#35617)

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

zhangliang 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 9a2473f7ca3 Merge SQLServerBeginDistributedTransactionStatement and XABeginStatement (#35617)
9a2473f7ca3 is described below

commit 9a2473f7ca3cea163f9aa65d446eb854e63e7dce
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Jun 7 06:48:32 2025 +0800

    Merge SQLServerBeginDistributedTransactionStatement and XABeginStatement (#35617)
    
    * Merge SQLServerBeginDistributedTransactionStatement and XABeginStatement
    
    * Merge SQLServerBeginDistributedTransactionStatement and XABeginStatement
    
    * Merge SQLServerBeginDistributedTransactionStatement and XABeginStatement
---
 .../main/antlr4/imports/sqlserver/TCLStatement.g4  |  8 +++----
 .../type/SQLServerTCLStatementVisitor.java         | 18 ++++++++++-----
 ...ServerBeginDistributedTransactionStatement.java | 27 ----------------------
 3 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4
index 3590e4db0e7..48207b32cb0 100644
--- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4
+++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4
@@ -39,10 +39,6 @@ beginTransaction
     : BEGIN (TRAN | TRANSACTION) ((transactionName | transactionVariableName) (WITH MARK (stringLiterals | NCHAR_TEXT)?)?)?
     ;
 
-beginDistributedTransaction
-    : BEGIN DISTRIBUTED (TRAN | TRANSACTION) (transactionName | transactionVariableName)?
-    ;
-
 commit
     : COMMIT ((TRAN | TRANSACTION) (transactionName | transactionVariableName)?)? (WITH LP_ DELAYED_DURABILITY EQ_ (OFF | ON) RP_)?
     ;
@@ -62,3 +58,7 @@ rollbackWork
 savepoint
     : SAVE (TRAN | TRANSACTION) (savepointName | savepointVariableName)
     ;
+
+beginDistributedTransaction
+    : BEGIN DISTRIBUTED (TRAN | TRANSACTION) (transactionName | transactionVariableName)?
+    ;
diff --git a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerTCLStatementVisitor.java b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerTCLStatementVisitor.java
index afe85b975d5..08a55ef244f 100644
--- a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerTCLStatementVisitor.java
+++ b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerTCLStatementVisitor.java
@@ -31,13 +31,13 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Set
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SetTransactionContext;
 import org.apache.shardingsphere.sql.parser.sqlserver.visitor.statement.SQLServerStatementVisitor;
 import org.apache.shardingsphere.sql.parser.statement.core.enums.TransactionIsolationLevel;
-import org.apache.shardingsphere.sql.parser.statement.sqlserver.tcl.SQLServerBeginDistributedTransactionStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.BeginTransactionStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.CommitStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.RollbackStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SavepointStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetAutoCommitStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetTransactionStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.xa.XABeginStatement;
 
 /**
  * TCL statement visitor for SQLServer.
@@ -75,11 +75,6 @@ public final class SQLServerTCLStatementVisitor extends SQLServerStatementVisito
         return new BeginTransactionStatement();
     }
     
-    @Override
-    public ASTNode visitBeginDistributedTransaction(final BeginDistributedTransactionContext ctx) {
-        return new SQLServerBeginDistributedTransactionStatement();
-    }
-    
     @Override
     public ASTNode visitCommit(final CommitContext ctx) {
         return new CommitStatement();
@@ -104,4 +99,15 @@ public final class SQLServerTCLStatementVisitor extends SQLServerStatementVisito
     public ASTNode visitSavepoint(final SavepointContext ctx) {
         return new SavepointStatement(null);
     }
+    
+    @Override
+    public ASTNode visitBeginDistributedTransaction(final BeginDistributedTransactionContext ctx) {
+        String xid = null;
+        if (null != ctx.transactionName()) {
+            xid = ctx.transactionName().getText();
+        } else if (null != ctx.transactionVariableName()) {
+            xid = ctx.transactionVariableName().getText();
+        }
+        return new XABeginStatement(xid);
+    }
 }
diff --git a/parser/sql/statement/type/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/statement/sqlserver/tcl/SQLServerBeginDistributedTransactionStatement.java b/parser/sql/statement/type/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/statement/sqlserver/tcl/SQLServerBeginDistributedTransactionStatement.java
deleted file mode 100644
index c04c3932f23..00000000000
--- a/parser/sql/statement/type/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/statement/sqlserver/tcl/SQLServerBeginDistributedTransactionStatement.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.sql.parser.statement.sqlserver.tcl;
-
-import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.TCLStatement;
-
-/**
- * SQLServer begin distributed transaction statement.
- */
-public final class SQLServerBeginDistributedTransactionStatement extends AbstractSQLStatement implements TCLStatement {
-}