-
Notifications
You must be signed in to change notification settings - Fork 300
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 라이브러리 구현하기 - 1단계] 허브(방대의) 미션 제출합니다. #267
Conversation
|
||
public <T> T queryForObject(final String sql, final RowMapper<T> rowMapper, final Object... parameters) { | ||
try (final Connection connection = dataSource.getConnection(); | ||
final PreparedStatement preparedStatement = getPreparedStatement(sql, connection, parameters); |
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.
try with resources 정말 깔끔합니다 👍
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.
리뷰가 늦었네요 죄송합니다 허브신 ㅜㅜ
코드를 너무 잘 작성하셔서 리뷰할만한 걸 찾기가 어렵네요..;;
질문 몇개만 남긴게 다라 바로 어프로브 하겠습니다..!
|
||
### 1단계 - JDBC 라이브러리 구현하기 | ||
|
||
- [x] RowMapper 인터페이스를 추가한다. |
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.
!!
허브는 기능 명세 작성할 때부터 RowMapper를 사용해야겠다는 걸 알고 계셨나요?!
(저는 처음에 Reflection으로 sql의 파라미터수에 맞는 생성자를 찾아서 일일히 타입 맞춰서 넣어주는 건 줄 알고..;; ㅋ)
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을 간단하게 만들어본 적이 있어서 기억이 났어요!
} | ||
|
||
public void update(final User user) { | ||
// todo | ||
final String sql = "update users set (account, password, email) = (?, ?, ?) where id = ?"; |
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.
박스터한테 배웠습니다 ㅋㅋㅋㅋ
|
||
public <T> T queryForObject(final String sql, final RowMapper<T> rowMapper, final Object... parameters) { | ||
try (final Connection connection = dataSource.getConnection(); | ||
final PreparedStatement preparedStatement = getPreparedStatement(sql, connection, parameters); |
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.
try with resources 정말 깔끔합니다 👍
if (resultSet.next()) { | ||
return rowMapper.mapRow(resultSet); | ||
} | ||
return null; |
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.
호옥시 null을 반환하는 허브의 기준이 있을까유?!
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.
일단 UserDaoTest를 수정하지 않고 동작하게 하려고 null을 반환시켰습니다!
null을 반환하기 보다 사용하는 쪽에서 조금 더 명확하게 처리할 수 있도록, 이 부분은 2단계 제출하면서 Optional을 반환하는 방향으로 수정해볼게요!!
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
@FunctionalInterface |
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.
👍
final ResultSet resultSet = preparedStatement.executeQuery()) { | ||
log.debug("query : {}", sql); | ||
if (resultSet.next()) { | ||
return rowMapper.mapRow(resultSet); |
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.
하나면 조회 결과 중 제일 처음 부분만 반환될 것 같습니다!
이 부분도 조회 결과가 2개 이상이라면 예외를 던지도록 수정해볼게요 👍
안녕하세요 호이!
미션 간단하게 진행해보았습니다!
간단하게 JdbcTemplate으로 코드를 이동시켜보았습니다!
이번 미션 잘 부탁드립니다! 👍
리뷰 범위는 다음과 같습니다.
리뷰 범위