You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/04/04 04:27:14 UTC
[shardingsphere] branch master updated: Fix release savepoint in MySQL (#25001)
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 986c5c0ded7 Fix release savepoint in MySQL (#25001)
986c5c0ded7 is described below
commit 986c5c0ded714cfd3a31fe436237e6e7c03a9a70
Author: ZhangCheng <fl...@outlook.com>
AuthorDate: Tue Apr 4 12:27:06 2023 +0800
Fix release savepoint in MySQL (#25001)
* Fix release savepoint in MySQL
* Fix release savepoint in MySQL
* Fix release savepoint in MySQL
---
.../impl/MySQLTCLStatementSQLVisitor.java | 9 ++++++++
.../mysql/tcl/MySQLReleaseSavepointStatement.java | 27 ++++++++++++++++++++++
.../cases/savepoint/BaseSavePointTestCase.java | 12 ++++++++++
3 files changed, 48 insertions(+)
diff --git a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLTCLStatementSQLVisitor.java b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLTCLStatementSQLVisitor.java
index 2c6c560ce6d..acdfd2540cf 100644
--- a/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLTCLStatementSQLVisitor.java
+++ b/sql-parser/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLTCLStatementSQLVisitor.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.sql.parser.api.visitor.type.TCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BeginTransactionContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CommitContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LockContext;
+import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ReleaseSavepointContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.RollbackContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SavepointContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetAutoCommitContext;
@@ -42,6 +43,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.Identifi
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLBeginTransactionStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLCommitStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLLockStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLReleaseSavepointStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLRollbackStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLSavepointStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.tcl.MySQLSetAutoCommitStatement;
@@ -139,6 +141,13 @@ public final class MySQLTCLStatementSQLVisitor extends MySQLStatementSQLVisitor
return result;
}
+ @Override
+ public ASTNode visitReleaseSavepoint(final ReleaseSavepointContext ctx) {
+ MySQLReleaseSavepointStatement result = new MySQLReleaseSavepointStatement();
+ result.setSavepointName(((IdentifierValue) visit(ctx.identifier())).getValue());
+ return result;
+ }
+
@Override
public ASTNode visitXa(final XaContext ctx) {
MySQLXAStatement result = new MySQLXAStatement();
diff --git a/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/tcl/MySQLReleaseSavepointStatement.java b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/tcl/MySQLReleaseSavepointStatement.java
new file mode 100644
index 00000000000..2044439d209
--- /dev/null
+++ b/sql-parser/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/tcl/MySQLReleaseSavepointStatement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sql.dialect.statement.mysql.tcl;
+
+import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.ReleaseSavepointStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
+
+/**
+ * MySQL release savepoint statement.
+ */
+public final class MySQLReleaseSavepointStatement extends ReleaseSavepointStatement implements MySQLStatement {
+}
diff --git a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java
index 4bc354cb510..8d5d688ddb5 100644
--- a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java
+++ b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/savepoint/BaseSavePointTestCase.java
@@ -64,5 +64,17 @@ public abstract class BaseSavePointTestCase extends BaseTransactionTestCase {
connection.commit();
assertAccountRowCount(connection, 3);
}
+ try (Connection connection = getDataSource().getConnection()) {
+ connection.setAutoCommit(false);
+ assertAccountRowCount(connection, 3);
+ executeWithLog(connection, "insert into account(id, balance, transaction_id) values(4, 4, 4);");
+ executeWithLog(connection, "SAVEPOINT point1");
+ assertAccountRowCount(connection, 4);
+ executeWithLog(connection, "insert into account(id, balance, transaction_id) values(5, 5, 5);");
+ assertAccountRowCount(connection, 5);
+ executeWithLog(connection, "RELEASE SAVEPOINT point1");
+ assertAccountRowCount(connection, 5);
+ connection.commit();
+ }
}
}