Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JDBC 라이브러리 구현하기 - 3단계] 성하(김성훈) 미션 제출합니다. #425

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

sh111-coder
Copy link

안녕하세요! 루쿠! 성하입니다! 👋🏻

이번 3단계에서는 UserService에 Transaction을 적용해봤습니다!
UserDao와 UserHistoryDao의 로직 중 하나라도 실패하면 롤백이 되도록 해야 했는데요!
그래서 UserDao와 UserHistoryDao가 동일한 Connection 객체를 사용해야 했고,
동일한 Connection 객체를 사용하기 위해
메소드를 오버로딩하여 Connection을 파라미터로 받아서 동일한 Connection을 넣어주게 되었습니다!

현재 서비스 코드에서 Connection 객체가 사용되어 비즈니스 로직과 섞이고 있지만
이후 4단계 미션 요구사항을 지키다보면 분리될 것 같아서 3단계는 이렇게 제출하겠습니다!!

리뷰 잘 부탁드려요 루쿠! 👍🏻

@sh111-coder sh111-coder self-assigned this Oct 4, 2023
Copy link

@aiaiaiai1 aiaiaiai1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 성하~
커넥션을 파라미터로 추가하셔서 메서드 오버로딩으로 구현해주셨네요~!
깔끔하게 잘 구현해주셔서 바로 4단계로 넘어가시면 될거같습니다 👍 👍

Comment on lines +33 to +54
DataSource dataSource = DataSourceConfig.getInstance();
Connection connection = null;

try {
connection = dataSource.getConnection();
connection.setAutoCommit(false);

final var user = findById(id);
user.changePassword(newPassword);
userDao.update(connection, user);
userHistoryDao.log(connection, new UserHistory(user, createBy));

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@aiaiaiai1 aiaiaiai1 merged commit d9c451d into woowacourse:sh111-coder Oct 5, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants