-
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
[1단계 - JDBC 라이브러리 구현하기] - 몰리(김지민) 미션 제출합니다. #632
Conversation
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.
안녕하세요 몰리~!
캠퍼스 나눠진 이후로 오랜만에 얘기해보는 것 같네요!
대부분 완성된 코드여서 크게 남길 코맨트는 없는 것 같아요! 몇 가지 질문 사항 남깁니다!
public void write(final String sql, final Object... args) { | ||
executeQuery(sql, preparedStatement -> { | ||
preparedStatement.executeUpdate(); | ||
return null; | ||
}, args); | ||
} | ||
|
||
public void update(final String sql, final Object... args) { | ||
executeQuery(sql, preparedStatement -> { | ||
preparedStatement.executeUpdate(); | ||
return null; | ||
}, args); | ||
} |
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.
이 부분에는 아직 중복이 남아있는 것 같습니다!
단순 제안이지만 DB 입장에서는 read, write 두 가지의 분기만 있는 것이 자연스러운 것 같아요!
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.
insert
와 update
는 사용자가 기대하는 바가 다르다고 생각해서 중복을 감안하고 분리를 했습니다.
그런데 insert
가 아니라 write
인 이상 update가 남아져있는데 이상하네요 😅
제거하겠습니다!
private <T> T executeQuery(final String sql, final QueryFunction<PreparedStatement, T> action, final Object... args) { | ||
try (Connection connection = dataSource.getConnection(); | ||
PreparedStatement preparedStatement = connection.prepareStatement(sql)) { | ||
preparedStatementBinder.bindParameters(preparedStatement, args); | ||
return action.apply(preparedStatement); | ||
} catch (SQLException e) { | ||
throw new IllegalArgumentException("쿼리 실행 중 에러가 발생했습니다.", e); | ||
} | ||
} | ||
} |
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.
대부분의 에러핸들링이 IllegalArgumentException 을 반환하고 있네요!
적절한 예외일까요?!
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.
이 부분의 SQLException
는 데이터베이스 엑세스 또는 커넥션을 얻는 중에 발생하는 에러라 다른 에러로 전환이 적절한 것 같네요. 변경하겠습니다~!
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class ResultMapper { |
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.
몰리만의 메서드 순서를 정하는 컨벤션이 있나요?!
저는 public 에서 사용되는 private 메서드가 있으면 바로 밑에 배치하곤 합니다!
몰리만의 기준도 궁금합니다!
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.
저도 동일하게 배치하곤 하고 여러 public에서 사용되는 private이라면 가장 마지막 public 메서드 아래에 위치시킵니다.
existsNext
의 위치가 변경이 필요해보이네요. 변경하겠습니다 😁
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javax.sql.DataSource; | ||
|
||
public class JdbcTemplate { |
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.
(생각해보면 좋을점!) JdbcTemplate 를 사용하게 되면서 개발자는 예외처리, 자원은 반환 보다는 sql 같은 db와 대화하는 것에만 집중할 수 있게 되었습니다!
몰리의 코드를 보다보니 제가 알고 있는 JdbcTemplate 와 거의 유사하게 되었더라구요! 혹시 몰리는 JdbcTemplate 을 만들면서, 혹은 사용하면서 느꼈던 불편한 점이 있나요??
(최근에 JdbcClient 라는 것도 나왔다고 합니다!)
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.
JdbcTemplate를 확인하지 않고 구현했는데, 아무래도 이미 사용해 봤던 터라 닮아져버렸던 것 같네요 🥲
몰리의 코드를 보다보니 제가 알고 있는 JdbcTemplate 와 거의 유사하게 되었더라구요! 혹시 몰리는 JdbcTemplate 을 만들면서, 혹은 사용하면서 느꼈던 불편한 점이 있나요??
만들면서는 자원 관리에 대한 부분이 번거로웠던 것 같아요.
사용하면서는 컴파일 타임에 문법 오류 등을 확인할 수 없었던 점이 가장 치명적인 불편한 점이었던 것 같아요.
생각해보니 제가 불편했던 점을 다음 리팩토링 단계에서 개선을 해보고 싶네요. 좋은 인사이트 감사합니다 👍👍
JdbcClient는 처음 들어봤는데 체이닝으로 파라미터나 반환값을 지정할 수 있군요!
흥미로운 키워드 감사합니다 👍
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.
안녕하세요 몰리~
리뷰 반영과 테스트 잘 동작하는 것 확인했습니다!
이번 미션은 여기서 approve 할께요!
안녕하세요 호기 ~~
오랜만입니다 잘 지내시죠 🙌
벌써 우테코 마지막 미션이네요 🥲
중복을 제거하기 위한 JdbcTemplate이지만,,, JdbcTemplate의 중복 코드도 불편하더라구요,,,,ㅋㅋㅋㅋ
함수형 인터페이스로 중복을 최대한 제거하려고 했어요.
사용이 어색한 부분이나 질문 있다면 편하게 말씀 부탁드립니다.
재미있게 마지막 미션 같이 해봐요 🔥