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단계] 후디(조동현) 미션 제출합니다. #115

Merged
merged 13 commits into from
Oct 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions jdbc/src/main/java/nextstep/jdbc/JdbcTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class JdbcTemplate {

private static final Logger log = LoggerFactory.getLogger(JdbcTemplate.class);
Comment on lines 13 to 15
Copy link

Choose a reason for hiding this comment

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

log가 사용되지 않고 있네요~

JdbcTemplate 내부는 예외가 많이 발생할 수 있는 지점이고
라이브러리 특성 상 사용자가 직접 구현하지 않은 부분에서 예외가 발생한다면
상세한 로그를 기록해주는 게 사용성 측면에서 긍정적일 것 같아요

예외가 발생했을 때 예외 정보를 로깅해보면 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

로그를 사용해야할 것 같네요! 로깅을 추가해보겠습니다 🙂

private static final int FIRST_RESULT_INDEX = 0;

private final DataSource dataSource;

Expand Down Expand Up @@ -51,20 +52,8 @@ public <T> List<T> query(final String sql, final RowMapper<T> rowMapper, final O
}

public <T> T queryForObject(final String sql, final RowMapper<T> rowMapper, final Object... args) {
return usePreparedStatement(sql, pstmt -> {
try {
T result = null;
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
result = rowMapper.run(rs);
}

return result;
} catch (SQLException e) {
throw new DataAccessException(e.getMessage(), e);
// TODO: 더 추상화된 예외 메시지를 사용해야함
}
}, args);
List<T> results = query(sql, rowMapper, args);
return results.get(FIRST_RESULT_INDEX);
Comment on lines +44 to +45
Copy link

Choose a reason for hiding this comment

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

처음부터 아키텍처가 좋아서 리팩터링이 뚝딱뚝딱 되네요!! 🔨

결과값이 1개여야 하는데 아닐 때는 예외를 발생시켜보면 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

좋은 의견이네요! 다음번 단계에서 바로 반영하겠습니다!

}

public <T> T usePreparedStatement(final String sql, final Function<PreparedStatement, T> function,
Expand Down