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 23:38:08 UTC

(shardingsphere) branch master updated: Merge StartTransactionStatement and BeginTransactionStatement (#35619)

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 6c54d92bb84 Merge StartTransactionStatement and BeginTransactionStatement (#35619)
6c54d92bb84 is described below

commit 6c54d92bb847bfd0bb864cddff6a818962b9556e
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Jun 7 07:38:02 2025 +0800

    Merge StartTransactionStatement and BeginTransactionStatement (#35619)
    
    * Refactor PostgreSQLCheckpointStatement to DALStatement
    
    * Refactor PostgreSQLCheckpointStatement to DALStatement
    
    * Refactor PostgreSQLCheckpointStatement to DALStatement
    
    * Refactor PostgreSQLCheckpointStatement to DALStatement
    
    * Merge StartTransactionStatement and BeginTransactionStatement
---
 .../type/OpenGaussTCLStatementVisitor.java         |  3 +--
 .../type/PostgreSQLTCLStatementVisitor.java        |  3 +--
 .../statement/tcl/StartTransactionStatement.java   | 26 ----------------------
 .../handler/tcl/TCLBackendHandlerFactory.java      |  3 +--
 .../command/query/PostgreSQLCommand.java           |  5 ++---
 .../command/query/PostgreSQLCommandTest.java       |  7 ------
 6 files changed, 5 insertions(+), 42 deletions(-)

diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussTCLStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussTCLStatementVisitor.java
index 62dd6f4b9c4..ebead7204d6 100644
--- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussTCLStatementVisitor.java
+++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussTCLStatementVisitor.java
@@ -40,7 +40,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.Rollbac
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SavepointStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetConstraintsStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetTransactionStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.StartTransactionStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.xa.XACommitStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.xa.XARollbackStatement;
 
@@ -91,7 +90,7 @@ public final class OpenGaussTCLStatementVisitor extends OpenGaussStatementVisito
     
     @Override
     public ASTNode visitStartTransaction(final StartTransactionContext ctx) {
-        return new StartTransactionStatement();
+        return new BeginTransactionStatement();
     }
     
     @Override
diff --git a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLTCLStatementVisitor.java b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLTCLStatementVisitor.java
index cdfc17758f9..65be0ed2bc8 100644
--- a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLTCLStatementVisitor.java
+++ b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLTCLStatementVisitor.java
@@ -49,7 +49,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.Rollbac
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SavepointStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetConstraintsStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetTransactionStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.StartTransactionStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.xa.XACommitStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.xa.XAPrepareStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.xa.XARollbackStatement;
@@ -143,7 +142,7 @@ public final class PostgreSQLTCLStatementVisitor extends PostgreSQLStatementVisi
     
     @Override
     public ASTNode visitStartTransaction(final StartTransactionContext ctx) {
-        return new StartTransactionStatement();
+        return new BeginTransactionStatement();
     }
     
     @Override
diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/tcl/StartTransactionStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/tcl/StartTransactionStatement.java
deleted file mode 100644
index ab891862860..00000000000
--- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/tcl/StartTransactionStatement.java
+++ /dev/null
@@ -1,26 +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.core.statement.tcl;
-
-import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
-
-/**
- * Start transaction statement.
- */
-public final class StartTransactionStatement extends AbstractSQLStatement implements TCLStatement {
-}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactory.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactory.java
index 977db9c488a..2df9dda5e8d 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactory.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactory.java
@@ -34,7 +34,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.Rollbac
 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.StartTransactionStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.TCLStatement;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.xa.XAStatement;
 import org.apache.shardingsphere.transaction.core.TransactionOperationType;
@@ -57,7 +56,7 @@ public final class TCLBackendHandlerFactory {
      */
     public static ProxyBackendHandler newInstance(final SQLStatementContext sqlStatementContext, final String sql, final ConnectionSession connectionSession) {
         TCLStatement tclStatement = (TCLStatement) sqlStatementContext.getSqlStatement();
-        if (tclStatement instanceof BeginTransactionStatement || tclStatement instanceof StartTransactionStatement) {
+        if (tclStatement instanceof BeginTransactionStatement) {
             return new TCLBackendHandler(tclStatement, TransactionOperationType.BEGIN, connectionSession);
         }
         if (tclStatement instanceof SetAutoCommitStatement) {
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
index e96b56962f2..25ac01b65a4 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
@@ -68,7 +68,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.Release
 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.SetTransactionStatement;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.StartTransactionStatement;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -120,7 +119,7 @@ public enum PostgreSQLCommand {
     DROP_VIEW(DropViewStatement.class),
     TRUNCATE_TABLE(TruncateStatement.class),
     BEGIN(BeginTransactionStatement.class),
-    START_TRANSACTION(StartTransactionStatement.class),
+    START_TRANSACTION(BeginTransactionStatement.class),
     COMMIT(CommitStatement.class),
     SAVEPOINT(SavepointStatement.class),
     ROLLBACK(RollbackStatement.class),
@@ -163,7 +162,7 @@ public enum PostgreSQLCommand {
     }
     
     private static CachedResult compute(final Class<? extends SQLStatement> target) {
-        Optional<PostgreSQLCommand> result = Arrays.stream(PostgreSQLCommand.values()).filter(each -> matches(target, each)).findAny();
+        Optional<PostgreSQLCommand> result = Arrays.stream(values()).filter(each -> matches(target, each)).findAny();
         return result.map(CachedResult::new).orElse(CachedResult.EMPTY);
     }
     
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java
index a6eadf99750..1d358ffa7fb 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java
@@ -64,7 +64,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.CommitS
 import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.ReleaseSavepointStatement;
 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.StartTransactionStatement;
 import org.junit.jupiter.api.Test;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -284,12 +283,6 @@ class PostgreSQLCommandTest {
         assertThat(PostgreSQLCommand.BEGIN.getTag(), is("BEGIN"));
     }
     
-    @Test
-    void assertValueOfStartTransactionStatement() {
-        assertThat(PostgreSQLCommand.valueOf(StartTransactionStatement.class).orElse(null), is(PostgreSQLCommand.START_TRANSACTION));
-        assertThat(PostgreSQLCommand.START_TRANSACTION.getTag(), is("START TRANSACTION"));
-    }
-    
     @Test
     void assertValueOfCommitStatement() {
         assertThat(PostgreSQLCommand.valueOf(CommitStatement.class).orElse(null), is(PostgreSQLCommand.COMMIT));