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단계] 다즐(최우창) 미션 제출합니다. #481

Merged
merged 2 commits into from
Oct 8, 2023

Conversation

woo-chang
Copy link
Member

안녕하세요 헙크 ㅎㅎ
프로젝트 일정을 처리하다 보니 미션을 주말에서야 진행하게 되었네요 🥲

3단계 미션은 TransactionTemplate을 구현해 보았습니다!
구현 세부 사항은 아래와 같아요 :)

  1. TransactionManager에서 ThreadLocal을 통해 같은 Connection을 공유할 수 있도록 하였습니다.
  2. TranactionCallBack을 통해 하나의 트랜잭션에서 동작해야 하는 행위를 콜백으로 전달하였습니다.

#375

2단계 미션에서 남겨주신 커멘트에 대한 답변도 달아두었습니다 !
3단계 미션도 잘 부탁드립니다 🙇🏻‍♂️

@woo-chang woo-chang self-assigned this Oct 7, 2023
Comment on lines +30 to +36
transactionTemplate.execute(() -> {
var user = findById(id);
user.changePassword(newPassword);
userDao.update(user);
userHistoryDao.log(new UserHistory(user, createBy));
return null;
});
Copy link
Member

Choose a reason for hiding this comment

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

트랜잭션 템플릿으로 구현하니까 확실히 트랜잭션 시작과 종료를 핸들링하는 코드가 없어져, 서비스 레이어가 깔끔하네요!ㅎㅎㅎ

Comment on lines +9 to +10
private static final ThreadLocal<Connection> connectionHolder = new ThreadLocal<>();

Copy link
Member

Choose a reason for hiding this comment

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

아하 쓰레드 로컬을 사용하면 해당 스레드가 어디에서든 동일한 커넥션을 가져와서 사용할 수 있겠네요ㅎㅎㅎ 쿠우우울

Copy link
Member

@HubCreator HubCreator left a comment

Choose a reason for hiding this comment

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

이번에도 코드 잘 봤습니다 ㅎㅎㅎ 트랜잭션 템플릿 패턴 역시 배울점이 많았네요. 쓰레드 로컬 사용한 것이 인상 깊었어요!

@HubCreator HubCreator merged commit bdab7c4 into woowacourse:woo-chang Oct 8, 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.

2 participants