From 6fb201c21b40df0664f23fb0e63e75b8391690c9 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Tue, 10 Oct 2023 13:31:05 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20TransactionSynchronizationManager=20?= =?UTF-8?q?=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=ED=99=9C=EC=84=B1?= =?UTF-8?q?=ED=99=94=20=EC=97=AC=EB=B6=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/TransactionSynchronizationManager.java | 2 +- .../TransactionSynchronizationManagerTest.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java b/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java index 8cfc28e4a6..621bbae614 100644 --- a/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java +++ b/jdbc/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java @@ -32,7 +32,7 @@ public static Connection unbindResource(final DataSource key) { public static boolean isTransactionActive(final DataSource dataSource) { try { - return resources.get().get(dataSource).getAutoCommit(); + return !resources.get().get(dataSource).getAutoCommit(); } catch (final SQLException e) { throw new TransactionSynchronizationManagerException(e); } diff --git a/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java b/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java index 1cae78ae81..cc9234f27e 100644 --- a/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java +++ b/jdbc/src/test/java/org/springframework/transaction/support/TransactionSynchronizationManagerTest.java @@ -65,15 +65,24 @@ class IsTransactionActive { @DisplayName("실행한 경우") void trueCase() throws SQLException { final DataSource datasource = getInstance(); - TransactionSynchronizationManager.bindResource(datasource, datasource.getConnection()); + final Connection connection = datasource.getConnection(); + connection.setAutoCommit(false); + + TransactionSynchronizationManager.bindResource(datasource, connection); assertTrue(isTransactionActive(getInstance())); + connection.close(); } @Test @DisplayName("실행하지 않은 경우") void falseCase() throws SQLException { + final DataSource datasource = getInstance(); + final Connection connection = datasource.getConnection(); + TransactionSynchronizationManager.bindResource(datasource, connection); + assertFalse(isTransactionActive(getInstance())); + connection.close(); } }