Skip to content

Commit

Permalink
feat: findById 트랜잭션 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
eunbii0213 committed Oct 13, 2023
1 parent c9cd8f8 commit 27379b0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/main/java/com/techcourse/service/TxUserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,27 @@ public TxUserService(final UserService userService) {

@Override
public User findById(final long id) {
return userService.findById(id);
User user;

final var dataSource = DataSourceConfig.getInstance();
final var connection = DataSourceUtils.getConnection(dataSource);
try {
connection.setAutoCommit(false);
user = userService.findById(id);

connection.commit();
} catch (final Exception e) {
try {
connection.rollback();
} catch (SQLException ex) {
throw new DataAccessException(ex);
}
throw new DataAccessException(e);
} finally {
DataSourceUtils.releaseConnection(connection, dataSource);
}

return user;
}

@Override
Expand Down

0 comments on commit 27379b0

Please sign in to comment.