Skip to content

[2단계 - JDBC 라이브러리 구현하기] 조조(조은별) 미션 제출합니다.#658

Merged
cutehumanS2 merged 25 commits intowoowacourse:eun-byeolfrom
eun-byeol:step2
Oct 8, 2024
Merged

[2단계 - JDBC 라이브러리 구현하기] 조조(조은별) 미션 제출합니다.#658
cutehumanS2 merged 25 commits intowoowacourse:eun-byeolfrom
eun-byeol:step2

Conversation

@eun-byeol
Copy link
Copy Markdown

@eun-byeol eun-byeol commented Oct 5, 2024

냥인😽 안녕하세요~

이번 미션은 2단계에서 제시한 리팩터링 순서를 따라가면서 단계적으로 구현했습니다.
기존 구현한 JdbcTemplate(현재 LegacyJdbcTemplate)를 리팩터링 하지 않았고,
JdbcTemplate을 사용하지 않았던 순수한 UserDaoImpl를 리팩터링 하여, 새로운 JdbcTemplate을 구현했어요.

질문이 있어요!

1. Unchecked Exception 요구사항 관련

SQLException은 Checked Exception이다. 커스텀 Exception을 추가해서 사용자는 Unchecked Exception이 되도록 변경하자.

요구사항 의도를 정확히 이해하지 못했어요.
JdbcTemplate에서 SQLException을 캐치해서 RuntimeException을 던지는 코드 -> DataAccessException로 던져주는 코드로 수정한게 전부입니다. 사실 이건 둘다 Unchecked라서 의도가 아닐것 같은데, 혹시 알고계시다면 공유 부탁드려요~

2. JdbcTemplate 추상 클래스인 이유
image
그림에서는 JdbcTemplate에서 getDataSouce() 추상 메서드를 갖고 있어요. 의도를 이해하지 못했어요.
그래서 전 추상 메서드를 만들지 않았습니다ㅎㅎ getter를 추상 메서드로 두면, 구현하는 쪽에서 계속 override 해줘야 하는데 큰 의미가 없는 코드였어요. 대신 JdbcTemplate에서 DataSource를 필드로 갖고 사용하는 구조가 더 깔끔했어요. 이에 대해 냥인은 어떻게 생각하시나요? 제가 놓친 부분이 있다면 편하게 말씀해주세요~

@eun-byeol eun-byeol requested a review from cutehumanS2 October 5, 2024 15:32
@cutehumanS2
Copy link
Copy Markdown
Member

요구사항 의도를 정확히 이해하지 못했어요.

JdbcTemplate에서 SQLException을 캐치해서 RuntimeException을 던지는 코드 -> DataAccessException로 던져주는 코드로 수정한게 전부입니다. 사실 이건 둘다 Unchecked라서 의도가 아닐것 같은데, 혹시 알고계시다면 공유 부탁드려요

→ 저는 조조가 이미 요구사항에 맞게 작성했다고 생각합니다. ㅎ ㅎ

처음에 조조가 SQLException을 RuntimeException으로 변환해 준 순간부터 이미 이 요구사항을 만족한 게 아닐까요? 예외의 의미를 더 명확하게 하기 위해 DataAccessException으로 변경해 준 거고요~~
제가 너무 단순하게 생각하는 것일까요? 😅

그림에서는 JdbcTemplate에서 getDataSouce() 추상 메서드를 갖고 있어요. 의도를 이해하지 못했어요. 그래서 전 추상 메서드를 만들지 않았습니다ㅎㅎ getter를 추상 메서드로 두면, 구현하는 쪽에서 계속 override 해줘야 하는데 큰 의미가 없는 코드였어요. 대신 JdbcTemplate에서 DataSource를 필드로 갖고 사용하는 구조가 더 깔끔했어요. 이에 대해 냥인은 어떻게 생각하시나요? 제가 놓친 부분이 있다면 편하게 말씀해주세요~

→ 조조의 의견에 동의합니다.
JdbcTemplate에서 DataSource를 필드로 갖게 하고 생성자로 주입받는 방식이 확실히 불필요한 중복 코드도 줄이고, 가독성도 좋다고 생각해요.
getDataSource()를 추상 메서드로 둔 의도는 솔직히 잘 모르겠어요… ㅎ ㅎ 만약 알게 된다면 조조에게 첫 번째로 공유하겠습니다. 😹

Copy link
Copy Markdown
Member

@cutehumanS2 cutehumanS2 left a comment

Choose a reason for hiding this comment

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

조조 안녕하세요 ! 냥인입니다.
2단계 빨리 구현하셨네요. 정말 고수시군요 ~ 👍 
코멘트 몇 가지 남겨 두었으니 확인 부탁드려요. 🤍

질문에 대한 답변은 위에 별도로 코멘트 남겨 둘게요.
+) LMS에 있는 대로 처음부터 하나하나 다시 진행해 보셨군요. 역시 조조. . . 넘 멋져요. 🥺

남은 주말도 즐거운 시간 되세요. ㅎ‿ㅎ

Comment thread app/src/main/java/com/techcourse/dao/UserDaoImpl.java Outdated
Comment thread app/src/main/java/com/techcourse/dao/UserDaoImpl.java Outdated
Comment thread jdbc/src/main/java/com/interface21/jdbc/core/JdbcTemplate.java
Comment thread jdbc/src/main/java/com/interface21/jdbc/core/PreparedStatementSetter.java Outdated
Comment thread jdbc/src/main/java/com/interface21/jdbc/core/RowMapper.java
@eun-byeol
Copy link
Copy Markdown
Author

냥인😽 리뷰 반영 후 다시 요청드려요~
Files changed는 여기를 참고하시면 좋아요!

덕분에 이번에도 많이 배울 수 있었어요 감사해오☺️
내일도 즐거운 하루 되세요~🍀🍀

리뷰 외 주요 변경 사항 - query 메서드 변경

before: PreparedStatementSetter 존재 유무에 따른 메서드 분리
<T> T query(String sql, RowMapper<T> rowMapper)
<T> T query(String sql, PreparedStatementSetter setter, RowMapper<T> rowMapper)

after: 반환형(List, Optional)에 따른 메서드 분리
<T> List<T> query(String sql, RowMapper<T> rowMapper, Object... params) - 여러건 조회
<T> Optional<T> queryForObject(String sql, RowMapper<T> rowMapper, Object... params) - 단건 조회

Copy link
Copy Markdown
Member

@cutehumanS2 cutehumanS2 left a comment

Choose a reason for hiding this comment

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

안녕하세요 조조~~ 🤍 냥인입니다.
반영도 굉장히 잘 해주시고 코멘트도 정성껏 달아주셔서 너무 감사합니다. 😸

리팩터링 너어무 잘 해주셔서 이만 머지해도 될 듯싶지만 !
조조가 혹시라도 아쉬워하실까 봐(…ㅋ.ㅋ) 코멘트 몇 가지 더 달아보았어요.

이번 미션 학습 목표 중 하나가 “중복을 제거하는 연습을 한다.”인 만큼 JdbcTemplate에 관해 세세하게 물어보기보다는 리팩터링 위주로 리뷰하려고 노력했어요. 그리고 간단한 질문 몇 가지도 같이 남겨 두었습니다.

가볍게 한 번 쭉 읽어 보시고,
조조가 필요하신 부분만 반영 & 답변하신 뒤 리뷰 요청 주십셔~~
다음 요청 땐 머지할 것 같아요~ ~ ~

조조 이번 주도 파이팅입니다. ㅎ‿ㅎ

Comment thread jdbc/src/main/java/com/interface21/jdbc/core/JdbcTemplate.java
Comment thread jdbc/src/main/java/com/interface21/jdbc/core/JdbcTemplate.java
Comment thread jdbc/src/main/java/com/interface21/jdbc/core/JdbcTemplate.java
Comment thread jdbc/src/main/java/com/interface21/jdbc/core/JdbcTemplate.java
log.error(e.getMessage(), e);
throw new DataAccessException(e);
}
public final void update(String sql, Object... params) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

진짜 간단한 질문 ㅎ ㅎ
가변 인자를 사용한 메서드에 인자를 전달하지 않으면 어떻게 되나요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🚨에러 발생합니다~

org.h2.jdbc.JdbcSQLDataException: Parameter "#1" is not set; SQL statement:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

가변 인자를 사용한 메서드에 인자를 전달하지 않으면 기본적으로는 빈 배열을 전달하는데,
이제 파라미터 수에 대한 검증을 추가해 줬으니 조조가 말씀하신 대로 SQLException이 발생하겠죠?!

@eun-byeol
Copy link
Copy Markdown
Author

냥인~ 리뷰 반영 후 다시 요청드려요

정성스런 리뷰에 감동했어요..!!😽
미션인만큼 최대한 여러 시도해보는 게 도움이 돼요~~ 감사합니다ㅎㅎ
다음 PR에는 학습테스트 추가해 올릴게요

즐거운 한글날 보내세요~~🍀

Copy link
Copy Markdown
Member

@cutehumanS2 cutehumanS2 left a comment

Choose a reason for hiding this comment

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

조조 ⭐️
반영 사항과 답변 모두 확인 완료하였습니다.
저 또한 조조에게 감동 .. . 🥺

이번 단계에서는 충분히 이야기를 나눠본 듯하니
다음 단계에서 또 이야기 나눠봐요.
이만 머지하겠습니다. 👋

조조도 즐거운 한글날 보내세요. ㅎ ㅎ🤍

@cutehumanS2 cutehumanS2 merged commit 23e3c23 into woowacourse:eun-byeol Oct 8, 2024
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