Skip to content

Commit

Permalink
fix: autoCommit 모드에서 Connection이 닫히지 않는 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
yujamint committed Oct 12, 2023
1 parent c11f4f4 commit c2efb84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@

### 2차
- [x] TransactionCallback 대신 Supplier 사용
- [ ] isTransactional 문제 해결
- [x] isTransactional 문제 해결
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ public static void releaseConnection(Connection connection) {
}

public static void closeNotTransactional(final DataSource dataSource, final Connection connection) {
if (isTransactional(dataSource, connection)) {
return;
try {
if (connection.getAutoCommit()) {
TransactionSynchronizationManager.unbindResource(dataSource);
releaseConnection(connection);
}
} catch (SQLException e) {
throw new CannotGetJdbcConnectionException("Failed to close JDBC Connection");
}
TransactionSynchronizationManager.unbindResource(dataSource);
releaseConnection(connection);
}

private static boolean isTransactional(final DataSource dataSource, final Connection connection) {
if (TransactionSynchronizationManager.hasResource(dataSource)) {
return TransactionSynchronizationManager.getResource(dataSource) == connection;
}
return false;
}
}

0 comments on commit c2efb84

Please sign in to comment.