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 라이브러리 구현하기 - 1단계] 허브(방대의) 미션 제출합니다. #267

Merged
merged 6 commits into from
Sep 30, 2023

Conversation

greeng00se
Copy link
Member

@greeng00se greeng00se commented Sep 26, 2023

안녕하세요 호이!

미션 간단하게 진행해보았습니다!
간단하게 JdbcTemplate으로 코드를 이동시켜보았습니다!

이번 미션 잘 부탁드립니다! 👍

리뷰 범위는 다음과 같습니다.
리뷰 범위


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);
Copy link
Member

Choose a reason for hiding this comment

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

그저 감탄입니다... 허브센세...ㅠㅠ

Choose a reason for hiding this comment

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

try with resources 정말 깔끔합니다 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

준팍센세.. 반갑습니다 ✋

Copy link

Choose a reason for hiding this comment

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

와우,,,, 퍼가요@@@@

Copy link

@This2sho This2sho left a 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 인터페이스를 추가한다.

Choose a reason for hiding this comment

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

!!
허브는 기능 명세 작성할 때부터 RowMapper를 사용해야겠다는 걸 알고 계셨나요?!
(저는 처음에 Reflection으로 sql의 파라미터수에 맞는 생성자를 찾아서 일일히 타입 맞춰서 넣어주는 건 줄 알고..;; ㅋ)

Copy link
Member Author

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 = ?";

Choose a reason for hiding this comment

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

앗 이렇게도 묶어서 되는거였군요..!

Copy link
Member Author

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);

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;

Choose a reason for hiding this comment

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

호옥시 null을 반환하는 허브의 기준이 있을까유?!

Copy link
Member Author

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

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);

Choose a reason for hiding this comment

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

만약 쿼리 실행 결과가 하나가 아니면 어떻게 되는걸까여?!

Copy link
Member Author

Choose a reason for hiding this comment

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

하나면 조회 결과 중 제일 처음 부분만 반환될 것 같습니다!
이 부분도 조회 결과가 2개 이상이라면 예외를 던지도록 수정해볼게요 👍

@This2sho This2sho merged commit 851fa3d into woowacourse:greeng00se Sep 30, 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.

5 participants