From 368769862088988a45e2540701644833ebcac296 Mon Sep 17 00:00:00 2001 From: ZhangCheng Date: Wed, 17 Apr 2024 19:29:19 +0800 Subject: [PATCH] Fix transaction auto commit (#30940) * Fix transaction auto commit * Fix transaction auto commit --- .github/workflows/resources/filter/filters.yml | 6 +++--- .../jdbc/core/connection/ShardingSphereConnection.java | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/resources/filter/filters.yml b/.github/workflows/resources/filter/filters.yml index 0850fbc9c2924..bd1e45014be53 100644 --- a/.github/workflows/resources/filter/filters.yml +++ b/.github/workflows/resources/filter/filters.yml @@ -26,7 +26,7 @@ pipeline: - 'features/readwrite-splitting/**/src/main/**' - 'features/sharding/**/src/main/**' - 'proxy/**/src/main/**' - - 'jdbc/core/src/main/**' + - 'jdbc/src/main/**' - '**/*-distsql*/**/src/main/**' - 'kernel/data-pipeline/**/src/main/**' - 'kernel/data-pipeline/**/pom.xml' @@ -42,7 +42,7 @@ showprocesslist: - 'infra/common/src/main/**' - 'mode/**/src/main/**' - 'proxy/**/src/main/**' - - 'jdbc/core/src/main/**' + - 'jdbc/src/main/**' - 'test/pom.xml' - 'test/e2e/fixture/**' - 'test/e2e/env/**' @@ -53,7 +53,7 @@ transaction: - 'infra/common/src/main/**' - 'mode/**/src/main/**' - 'proxy/**/src/main/**' - - 'jdbc/core/src/main/**' + - 'jdbc/src/main/**' - 'kernel/transaction/**/src/main/**' - 'kernel/transaction/**/pom.xml' - 'test/pom.xml' diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java index 07ca9d485907e..e356a7b5b6de6 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java @@ -203,7 +203,9 @@ public void handleAutoCommit() throws SQLException { if (TransactionType.isDistributedTransaction(databaseConnectionManager.getConnectionTransaction().getTransactionType())) { beginDistributedTransaction(); } else { - getConnectionContext().getTransactionContext().beginTransaction(String.valueOf(databaseConnectionManager.getConnectionTransaction().getTransactionType())); + if (!getConnectionContext().getTransactionContext().isInTransaction()) { + getConnectionContext().getTransactionContext().beginTransaction(String.valueOf(databaseConnectionManager.getConnectionTransaction().getTransactionType())); + } } } } @@ -309,6 +311,9 @@ public boolean isClosed() { @Override public void close() throws SQLException { + if (databaseConnectionManager.getConnectionTransaction().isInTransaction()) { + databaseConnectionManager.getConnectionTransaction().rollback(); + } closed = true; databaseConnectionManager.close(); processEngine.disconnect(processId);