Skip to content

Commit

Permalink
refactor: 중복 코드 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
zillionme committed Oct 11, 2023
1 parent 237a3a3 commit 6d05798
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void execute(final Runnable logicExecutor) {

public <T> T executeWithResult(final Supplier<T> logicExecutor) {
final Connection conn = DataSourceUtils.getConnection(dataSource);
setTransactionActive(conn);
setTransactionActiveStatus(conn, true);
try {
conn.setAutoCommit(false);
T result = logicExecutor.get();
Expand All @@ -35,20 +35,14 @@ public <T> T executeWithResult(final Supplier<T> logicExecutor) {
rollback(conn);
throw new TransactionException(e);
} finally {
setTransactionInactive(conn);
setTransactionActiveStatus(conn, false);
DataSourceUtils.releaseConnection(conn, dataSource);
}
}

private void setTransactionActive(final Connection conn) {
private void setTransactionActiveStatus(final Connection conn, final boolean isTransactionActive) {
ConnectionHolder connectionHolder = new ConnectionHolder(conn);
connectionHolder.setConnectionTransactionActive(true);
TransactionSynchronizationManager.bindResource(dataSource, connectionHolder);
}

private void setTransactionInactive(final Connection conn) {
ConnectionHolder connectionHolder = new ConnectionHolder(conn);
connectionHolder.setConnectionTransactionActive(false);
connectionHolder.setConnectionTransactionActive(isTransactionActive);
TransactionSynchronizationManager.bindResource(dataSource, connectionHolder);
}

Expand Down

0 comments on commit 6d05798

Please sign in to comment.