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 b6039ebd41d Refactor DriverTransactionSQLStatementExecutor (#36795)
b6039ebd41d is described below
commit b6039ebd41dcf0db8e58b3bab62d1bf735753503
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Oct 6 00:52:00 2025 +0800
Refactor DriverTransactionSQLStatementExecutor (#36795)
---
.../DriverTransactionSQLStatementExecutor.java | 35 +++++++---------------
.../transaction/core/TransactionOperationType.java | 26 ----------------
2 files changed, 11 insertions(+), 50 deletions(-)
diff --git
a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/transaction/DriverTransactionSQLStatementExecutor.java
b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/transaction/DriverTransactionSQLStatementExecutor.java
index cb3002b09a9..d9a161055c1 100644
---
a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/transaction/DriverTransactionSQLStatementExecutor.java
+++
b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/transaction/DriverTransactionSQLStatementExecutor.java
@@ -17,29 +17,25 @@
package org.apache.shardingsphere.driver.executor.engine.transaction;
+import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import
org.apache.shardingsphere.driver.jdbc.core.savepoint.ShardingSphereSavepoint;
import org.apache.shardingsphere.infra.session.query.QueryContext;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.ReleaseSavepointStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.SavepointStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.TCLStatement;
-import org.apache.shardingsphere.transaction.core.TransactionOperationType;
import java.sql.SQLException;
/**
* Driver transaction statement executor.
*/
+@RequiredArgsConstructor
public final class DriverTransactionSQLStatementExecutor {
private final ShardingSphereConnection connection;
- private TransactionOperationType operationType;
-
- public DriverTransactionSQLStatementExecutor(final
ShardingSphereConnection connection) {
- this.connection = connection;
- }
-
/**
* Decide whether to execute TCL statement.
*
@@ -50,34 +46,25 @@ public final class DriverTransactionSQLStatementExecutor {
if (!(queryContext.getSqlStatementContext().getSqlStatement()
instanceof TCLStatement)) {
return false;
}
- TCLStatement tclStatement = (TCLStatement)
queryContext.getSqlStatementContext().getSqlStatement();
- if (tclStatement instanceof SavepointStatement) {
- operationType = TransactionOperationType.SAVEPOINT;
- return true;
- }
- if (tclStatement instanceof ReleaseSavepointStatement) {
- operationType = TransactionOperationType.RELEASE_SAVEPOINT;
- return true;
- }
+ SQLStatement sqlStatement =
queryContext.getSqlStatementContext().getSqlStatement();
+ return sqlStatement instanceof SavepointStatement || sqlStatement
instanceof ReleaseSavepointStatement;
// TODO support more TCL statements
- return false;
}
/**
* Execute TCL statement.
*
- * @param tclStatement SQL statement
+ * @param sqlStatement SQL statement
* @return whether to execute TCL statement or not
* @throws SQLException SQL exception
*/
- public boolean execute(final TCLStatement tclStatement) throws
SQLException {
- if (TransactionOperationType.SAVEPOINT == operationType) {
- connection.setSavepoint(((SavepointStatement)
tclStatement).getSavepointName());
+ public boolean execute(final TCLStatement sqlStatement) throws
SQLException {
+ if (sqlStatement instanceof SavepointStatement) {
+ connection.setSavepoint(((SavepointStatement)
sqlStatement).getSavepointName());
return true;
}
- if (TransactionOperationType.RELEASE_SAVEPOINT == operationType) {
- ShardingSphereSavepoint savepoint = new
ShardingSphereSavepoint(((ReleaseSavepointStatement)
tclStatement).getSavepointName());
- connection.releaseSavepoint(savepoint);
+ if (sqlStatement instanceof ReleaseSavepointStatement) {
+ connection.releaseSavepoint(new
ShardingSphereSavepoint(((ReleaseSavepointStatement)
sqlStatement).getSavepointName()));
return true;
}
return false;
diff --git
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/core/TransactionOperationType.java
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/core/TransactionOperationType.java
deleted file mode 100644
index bc30e9173ed..00000000000
---
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/core/TransactionOperationType.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.transaction.core;
-
-/**
- * Transaction operation type.
- */
-public enum TransactionOperationType {
-
- BEGIN, COMMIT, ROLLBACK, SAVEPOINT, ROLLBACK_TO_SAVEPOINT,
RELEASE_SAVEPOINT, SET_AUTOCOMMIT
-}