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 6280df46f4e Merge PostgreSQLPrepareTransactionStatement and XAPrepareStatement (#35615) 6280df46f4e is described below commit 6280df46f4ebd964d8b238dc7174eb7457877ac3 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Sat Jun 7 06:19:08 2025 +0800 Merge PostgreSQLPrepareTransactionStatement and XAPrepareStatement (#35615) --- .../main/antlr4/imports/opengauss/TCLStatement.g4 | 8 ++--- .../type/OpenGaussTCLStatementVisitor.java | 4 +-- .../main/antlr4/imports/postgresql/TCLStatement.g4 | 14 ++++---- .../type/PostgreSQLTCLStatementVisitor.java | 8 ++--- .../tcl/PostgreSQLPrepareTransactionStatement.java | 27 -------------- .../asserts/statement/tcl/TCLStatementAssert.java | 5 --- .../impl/PrepareTransactionStatementAssert.java | 41 ---------------------- 7 files changed, 17 insertions(+), 90 deletions(-) diff --git a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/TCLStatement.g4 b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/TCLStatement.g4 index 0a81beb4b9c..540900c28b1 100644 --- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/TCLStatement.g4 +++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/TCLStatement.g4 @@ -61,18 +61,18 @@ rollbackToSavepoint ; prepareTransaction - : PREPARE TRANSACTION STRING_ + : PREPARE TRANSACTION gid ; commitPrepared - : COMMIT PREPARED xid + : COMMIT PREPARED gid ; rollbackPrepared - : ROLLBACK PREPARED xid + : ROLLBACK PREPARED gid ; -xid +gid : STRING_ ; 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 6202342fb9c..c09338db79d 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 @@ -108,12 +108,12 @@ public final class OpenGaussTCLStatementVisitor extends OpenGaussStatementVisito @Override public ASTNode visitCommitPrepared(final CommitPreparedContext ctx) { - return new XACommitStatement(ctx.xid().getText()); + return new XACommitStatement(ctx.gid().getText()); } @Override public ASTNode visitRollbackPrepared(final RollbackPreparedContext ctx) { - return new XARollbackStatement(ctx.xid().getText()); + return new XARollbackStatement(ctx.gid().getText()); } @Override diff --git a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/TCLStatement.g4 b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/TCLStatement.g4 index eed7a9ec549..e9345258167 100644 --- a/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/TCLStatement.g4 +++ b/parser/sql/dialect/postgresql/src/main/antlr4/imports/postgresql/TCLStatement.g4 @@ -64,15 +64,19 @@ rollbackToSavepoint : ROLLBACK (WORK | TRANSACTION)? TO SAVEPOINT? colId ; +prepareTransaction + : PREPARE TRANSACTION gid + ; + commitPrepared - : COMMIT PREPARED xid + : COMMIT PREPARED gid ; rollbackPrepared - : ROLLBACK PREPARED xid + : ROLLBACK PREPARED gid ; -xid +gid : STRING_ ; @@ -103,10 +107,6 @@ lockType | ACCESS EXCLUSIVE ; -prepareTransaction - : PREPARE TRANSACTION STRING_ - ; - checkpoint : CHECKPOINT ; 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 24438f23e62..9fd0d189c0f 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 @@ -53,8 +53,8 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.SetCons 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; -import org.apache.shardingsphere.sql.parser.statement.postgresql.tcl.PostgreSQLPrepareTransactionStatement; import java.util.Collection; import java.util.Collections; @@ -160,12 +160,12 @@ public final class PostgreSQLTCLStatementVisitor extends PostgreSQLStatementVisi @Override public ASTNode visitCommitPrepared(final CommitPreparedContext ctx) { - return new XACommitStatement(ctx.xid().getText()); + return new XACommitStatement(ctx.gid().getText()); } @Override public ASTNode visitRollbackPrepared(final RollbackPreparedContext ctx) { - return new XARollbackStatement(ctx.xid().getText()); + return new XARollbackStatement(ctx.gid().getText()); } @Override @@ -179,7 +179,7 @@ public final class PostgreSQLTCLStatementVisitor extends PostgreSQLStatementVisi @Override public ASTNode visitPrepareTransaction(final PrepareTransactionContext ctx) { - return new PostgreSQLPrepareTransactionStatement(); + return new XAPrepareStatement(ctx.gid().getText()); } @Override diff --git a/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/tcl/PostgreSQLPrepareTransactionStatement.java b/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/tcl/PostgreSQLPrepareTransactionStatement.java deleted file mode 100644 index 2c41b02b1ba..00000000000 --- a/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/tcl/PostgreSQLPrepareTransactionStatement.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.postgresql.tcl; - -import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.TCLStatement; - -/** - * PostgreSQL prepare transaction statement. - */ -public final class PostgreSQLPrepareTransactionStatement extends AbstractSQLStatement implements TCLStatement { -} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/tcl/TCLStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/tcl/TCLStatementAssert.java index 6c0b7461e68..15acabbce2c 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/tcl/TCLStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/tcl/TCLStatementAssert.java @@ -22,7 +22,6 @@ import lombok.NoArgsConstructor; 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.LockStatement; -import org.apache.shardingsphere.sql.parser.statement.postgresql.tcl.PostgreSQLPrepareTransactionStatement; 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; @@ -34,7 +33,6 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAsse import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.tcl.impl.BeginTransactionStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.tcl.impl.CommitStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.tcl.impl.LockStatementAssert; -import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.tcl.impl.PrepareTransactionStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.tcl.impl.RollbackStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.tcl.impl.SavepointStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.tcl.impl.SetAutoCommitStatementAssert; @@ -45,7 +43,6 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.S import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.BeginTransactionStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.CommitStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.LockStatementTestCase; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.PrepareTransactionTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.RollbackStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.SavepointStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.SetAutoCommitStatementTestCase; @@ -85,8 +82,6 @@ public final class TCLStatementAssert { UnlockStatementAssert.assertIs(assertContext, (UnlockStatement) actual, (UnlockStatementTestCase) expected); } else if (actual instanceof LockStatement) { LockStatementAssert.assertIs(assertContext, (LockStatement) actual, (LockStatementTestCase) expected); - } else if (actual instanceof PostgreSQLPrepareTransactionStatement) { - PrepareTransactionStatementAssert.assertIs(assertContext, (PostgreSQLPrepareTransactionStatement) actual, (PrepareTransactionTestCase) expected); } } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/tcl/impl/PrepareTransactionStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/tcl/impl/PrepareTransactionStatementAssert.java deleted file mode 100644 index 2449d78c04e..00000000000 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/tcl/impl/PrepareTransactionStatementAssert.java +++ /dev/null @@ -1,41 +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.test.it.sql.parser.internal.asserts.statement.tcl.impl; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.sql.parser.statement.postgresql.tcl.PostgreSQLPrepareTransactionStatement; -import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.tcl.PrepareTransactionTestCase; - -/** - * Prepare transaction statement assert. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class PrepareTransactionStatementAssert { - - /** - * Assert prepare transaction statement is correct with expected parser result. - * - * @param assertContext assert context - * @param actual actual prepare transaction statement - * @param expected expected prepare transaction statement test case - */ - public static void assertIs(final SQLCaseAssertContext assertContext, final PostgreSQLPrepareTransactionStatement actual, final PrepareTransactionTestCase expected) { - } -}