Skip to content

Commit 02e2819

Browse files
committed
refactor: 체크 예외에 대해서 명시적으로 commit 하도록 변경
1 parent 4caa733 commit 02e2819

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/src/main/java/com/techcourse/aop/TransactionHandler.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,31 @@ private Throwable handleException(final Connection conn, final InvocationTargetE
7676

7777
if (targetException instanceof RuntimeException || targetException instanceof Error) {
7878
rollback(conn, e);
79+
return targetException;
7980
}
8081

82+
commit(conn, e);
8183
return targetException;
8284
}
8385

8486
private void rollback(Connection conn, Exception originalException) {
8587
try {
8688
conn.rollback();
87-
8889
} catch (SQLException rollbackEx) {
8990
log.error("Rollback failed", rollbackEx);
9091
originalException.addSuppressed(rollbackEx);
9192
}
9293
}
9394

95+
private void commit(Connection conn, Exception originalException) {
96+
try {
97+
conn.commit();
98+
} catch (SQLException commitEx) {
99+
log.error("Commit failed", commitEx);
100+
originalException.addSuppressed(commitEx);
101+
}
102+
}
103+
94104
private void cleanUpConnection(final Connection conn, final boolean originalAutoCommit) {
95105
if (conn == null) {
96106
return;

0 commit comments

Comments
 (0)