-
Notifications
You must be signed in to change notification settings - Fork 301
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구현하기 - 2단계] 도기(김동호) 미션 제출합니다. #412
Conversation
- 중복 로직 메서드 추출 - 빠진 final 키워드 추가 - 결과 List로 생성하는 로직 변경
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 도기~ 🙌
재택 잘하고 계신가요!?(추가 휴가 ㅎㅎㅎ) 도기라면 건강하게 잘 보내셨을거 같아요. 저는 점점 야생형 부엉이가 되어가는 거 같습니다.. 한번 꽂히면 놓는 게 쉽지 않네요 🫠
2단계에 한번 적용해보면 좋을거 같은 것 리뷰 달아놨습니다.
한번 생각해보시고 자유롭게 반영해주세요!
jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
Outdated
Show resolved
Hide resolved
app/src/main/java/com/techcourse/support/jdbc/init/DatabasePopulatorUtils.java
Show resolved
Hide resolved
@@ -24,19 +24,22 @@ public void executeQuery(final String sql, final Object... params) { | |||
try (final var conn = dataSource.getConnection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 사용하는 메서드들에서 공통된 부분이 보이는데요. 한번 제거해보는 고민을 해보고 적용하는 것도 재밌을거 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추상화할 부분은 보이지만, 막상 추상화하는게 너무 어렵더라구요😢
그래서 무민의 코드를 보고 선감탄 후복붙 했습니다 ㅋㅋㅋㅋ..
물론 무지성 복붙말고 제 나름대로 이해를 하면서 적용했는데요.
완성하고도 이해하는 게 쉽진 않았네요.. 혹시 추상화 직접 하신건가요?????? 맞다면 어떤 사고의 흐름으로 추상화하신건지 배우고 싶어요 !!!!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우선 해당 로직들에 어떠한 과정이 있는지 파악을 하였더니
- 자원 셋팅
- 파라미터 셋팅
- preparedStatement 실행
- 자원 반납
과 같은 과정들을 가지고 있었습니다. 이 중 1, 2, 4번은 같은 과정이였고 3번만 다른 행동이여서 바꿔주려고 설계를 생각했습니다. 그래서 전체 try catch 부분을 하나의 메서드(execute)로 빼고 3번 부분만 함수형 인터페이스(Processor)로 받아서 다른 행동을 실행시켜주려고 했습니다. 이거를 JdbcTemplate 클래스 하니깐 에러를 한 곳에서 잡지 못해서(try catch가 여러개 생김) 코드가 지저분해지더라구요.
그래서 실행해주는 Executor를 생성해주었고 그에 따라 generatePreparedStatement 와 setParameter도 이쪽으로 가게 되었네요.
확실히, 이번에 추상화를 좀 응용해보면서 느낀점이 확장성과 코드를 좀 더 깔끔하게 작성할 수 있지만 복잡성이 증가한다는 걸 제대로 깨닫게 된거 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
덕분에 많이 배웁니다 🙇♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RC 대신 Comment로 남겨서 다시 보냅니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 도기~
2단계도 고생많으셨습니다!!
코멘트 한번 확인해주시면 좋을 것 같고 2단계 요구사항은 만족된 거 같아서 머지하겠습니다.
다음 단계에서 봐요 🙌
} | ||
|
||
@Test | ||
void 단일_조회시에_조회_결과가_1개가_아니면_예외가_발생한다() throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
예외까지 테스트 👍🏻
import org.springframework.dao.DataAccessException; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
class JdbcTemplateTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 목으로 테스트를 할까 고민했었는데요.
혹시 테스트 해보시면서 어떠셨는지 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아무래도 세팅하는 과정에서 종종 NPE가 터져 불편함이 있었어요. 그 외에는 불편함을 느끼지 못했습니다.
전 처음에 실제 DB를 사용해서 테스트하려고 했는데요. jdbc 패키지에 h2 의존성이 붙는게 조금 걸리더라구요.
지금 생각해봐도 라이브러리가 구현체를 직접 사용해서 테스트하는게 어색하다고 생각되네요!
@@ -24,19 +24,22 @@ public void executeQuery(final String sql, final Object... params) { | |||
try (final var conn = dataSource.getConnection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우선 해당 로직들에 어떠한 과정이 있는지 파악을 하였더니
- 자원 셋팅
- 파라미터 셋팅
- preparedStatement 실행
- 자원 반납
과 같은 과정들을 가지고 있었습니다. 이 중 1, 2, 4번은 같은 과정이였고 3번만 다른 행동이여서 바꿔주려고 설계를 생각했습니다. 그래서 전체 try catch 부분을 하나의 메서드(execute)로 빼고 3번 부분만 함수형 인터페이스(Processor)로 받아서 다른 행동을 실행시켜주려고 했습니다. 이거를 JdbcTemplate 클래스 하니깐 에러를 한 곳에서 잡지 못해서(try catch가 여러개 생김) 코드가 지저분해지더라구요.
그래서 실행해주는 Executor를 생성해주었고 그에 따라 generatePreparedStatement 와 setParameter도 이쪽으로 가게 되었네요.
확실히, 이번에 추상화를 좀 응용해보면서 느낀점이 확장성과 코드를 좀 더 깔끔하게 작성할 수 있지만 복잡성이 증가한다는 걸 제대로 깨닫게 된거 같아요!
안녕하세요 무민! 그동안 있던 연휴동안 좀 쉬셨나요?? 쉴 땐 같이 쉬어요 😂
2단계에서 새롭게 적용할 사항이 많이 없어보여서 사실상 1단계 리뷰 반영이 되었네요!
그럼 2단계에도 잘 부탁드립니다 🙇♂️