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,4단계] 호이(이건호) 미션 제출합니다. #603

Merged
merged 14 commits into from
Oct 12, 2023

Conversation

This2sho
Copy link

@This2sho This2sho commented Oct 10, 2023

나이스 투 매튜... 🙇‍♂️
죄송합니다.. 휴일에 정신 못차리고 놀다보니 많이 늦어버렸네요..

3단계에서는 트랜잭션의 경계를 두고 {커밋 | 롤백 }이 가능하게 구현했습니다.

3단계 커밋 내용

4단계에서는 3단계에서 구현한 부분을 주어진 DataSourceUtilsTransactionSynchronizationManager로 수정하고 TransactionManager를 통해 리팩토링 하였습니다...

4단계 커밋 내용

Copy link

@kpeel5839 kpeel5839 left a comment

Choose a reason for hiding this comment

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

my gun ho zzang...

너무나도 기가막힌 코드인 것 같습니다.

그래서 정말 죄송하지만, 작은 제안 하나 정도만 남겼습니다.

해당 코멘트 읽어봐주시고 답변해주신다면 바로 Approve 해드리도록 할게요!

함께 할 수 있어서 아주 즐거웠습니다. my gun ho zzang pu san university

- [x] JDBC 탬플릿의 중복된 try catch문 제거

## 3단계
- [x] 매튜 리뷰 반영

Choose a reason for hiding this comment

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

my gun ho ... 의 readme 에 저의 닉네임이 들어가다니 이렇게 감동적일 수가 없습니다..

Copy link
Author

Choose a reason for hiding this comment

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

oh jae yun ... u r so kind~

Comment on lines +11 to 16
private static final RowMapper<User> USER_ROW_MAPPER = rs -> new User(
rs.getLong("id"),
rs.getString("account"),
rs.getString("password"),
rs.getString("email"));

Choose a reason for hiding this comment

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

사실 1, 2, 3, 4 보다 이렇게 직접적으로 column 명을 명시해주는 것이 좋아보이긴 했는데 이렇게 바꿔주셨군요! 멋집니다

Copy link
Author

Choose a reason for hiding this comment

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

u 2


public class UserHistoryDao {

private static final Logger log = LoggerFactory.getLogger(UserHistoryDao.class);

Choose a reason for hiding this comment

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

사용하지 않는 로그들도 다 지워주셨네요 역시 my gun ho zzang ..

Copy link
Author

Choose a reason for hiding this comment

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

ur jae yun zzang too

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Map;

public abstract class TransactionSynchronizationManager {

private static final ThreadLocal<Map<DataSource, Connection>> resources = new ThreadLocal<>();
private static final ThreadLocal<Map<DataSource, Connection>> resources = init();

Choose a reason for hiding this comment

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

저는 이 부분에서 ThreadLocal 이 알아서 초기화 해주는 줄 알고 많이 해맸었는데요!

그러다가 아래와 같은 방법을 찾을 수 있었습니다.

ThreadLocal.withInitial(HashMap::new);

꼭 코드량을 줄여야 하는 것은 아니지만, 해당 방법으로 진행하게 되면, 한 줄로 thread local 을 원하는대로 초기화 해줄 수 있어요!

Copy link
Author

Choose a reason for hiding this comment

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

이런 방법이 있었네요..!
오우.. 역시 매튜 👍
바로 적용하겠습니다!

Comment on lines 20 to 22
runnable.run();
return null;
});

Choose a reason for hiding this comment

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

조회, 업데이트를 나누어 해당 execute 메서드에서 return null 을 없애주는 방법은 어떨까요??

Copy link
Author

Choose a reason for hiding this comment

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

좋습니다!

Copy link
Author

Choose a reason for hiding this comment

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

지금 반영을 했는데 메튜가 원하는 방향이 맞을까요?!
(뭔가 결과를 반환하고 안하고를 제외하면 중복적인거 같아서)

final var pss = newArgumentPreparedStatementSetter(parameters);
pss.setValues(ps);
return ps.executeUpdate();
execute(new PreparedStatementCreator(sql), statement -> {

Choose a reason for hiding this comment

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

훨씬 이해하기 좋아진 것 같아요 my gun ho !

Copy link
Author

Choose a reason for hiding this comment

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

덕분입니다 ur jae yun !

Comment on lines +37 to +40
public List<UserHistory> findLogsByUserId(final long id) {
return userHistoryDao.findByUserId(id);
}
}

Choose a reason for hiding this comment

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

테스트를 위해 메서들르 추가해주셨군요! 좋습니다

eunbii0213

This comment was marked as spam.

Copy link

@kpeel5839 kpeel5839 left a comment

Choose a reason for hiding this comment

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

hyohoyohyohoyhoyhoyhohyohyohyo

지금까지 코드 리뷰하면서 정말 많이 배울 수 있었습니다.

당신 정말 멋져요우..

앞으로도 계속 선한 영향력을 주시기를...

@@ -7,16 +7,10 @@

public abstract class TransactionSynchronizationManager {

private static final ThreadLocal<Map<DataSource, Connection>> resources = init();
private static final ThreadLocal<Map<DataSource, Connection>> resources = ThreadLocal.withInitial(HashMap::new);

Choose a reason for hiding this comment

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

바로 반영해주셨군요 아주 기모찌 합니다.

Comment on lines 19 to 29
final Connection connection = DataSourceUtils.getConnection(dataSource);
try {
connection.setAutoCommit(false);
runnable.run();
return null;
});
connection.commit();
} catch (SQLException e) {
rollback(connection);
throw new DataAccessException(e);
} 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.

제가 말한게 정확히 맞습니다! 역시 hoyhoy gun ho zzang..

Comment on lines 31 to 37
public static boolean isActiveTransaction(Connection connection) {
return activeTransactions.get().getOrDefault(connection, false);
}

public static void setActiveTransaction(Connection connection, boolean status) {
activeTransactions.get().put(connection, status);
}

Choose a reason for hiding this comment

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

오 setActiveTransaction 과 isActiveTransaction 이 추가되면서 훨씬 로직들이 단단해진 느낌이네요! 아주 좋습니다

@kpeel5839 kpeel5839 merged commit b899b46 into woowacourse:this2sho Oct 12, 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.

3 participants