Skip to content

Commit

Permalink
[라이브러리 구현하기 - 2단계] 헙크(정현승) 미션 제출합니다. (#351)
Browse files Browse the repository at this point in the history
* refactor: `PreparedStatementSetter` 구현

* refactor: 기존 코드로 원복
  • Loading branch information
HubCreator authored Oct 2, 2023
1 parent bf8a6f1 commit ef9baaa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/com/techcourse/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.techcourse.dao;

import com.techcourse.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public JdbcTemplate(final DataSource dataSource) {
this.dataSource = dataSource;
}

public <T> Optional<T> queryForObject(final String sql, final RowMapper<T> rowMapper, Object... args) {
public <T> Optional<T> queryForObject(final String sql, final RowMapper<T> rowMapper, final Object... args) {
try (final Connection conn = dataSource.getConnection();
final PreparedStatement pstmt = conn.prepareStatement(sql)) {
for (int i = 0; i < args.length; i++) {
Expand All @@ -35,7 +35,7 @@ public <T> Optional<T> queryForObject(final String sql, final RowMapper<T> rowMa
}
}

public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException {
public <T> List<T> query(final String sql, final RowMapper<T> rowMapper) throws DataAccessException {
try (final Connection conn = dataSource.getConnection();
final PreparedStatement pstmt = conn.prepareStatement(sql)) {
final List<T> result = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.springframework.jdbc.core.exception;

/**
* ResultSet이 잘못된 방식으로 접근되었을 때 발생하는 예외.
* 이는 일반적으로 잘못된 ResultSet 열 인덱스 또는 이름이 지정되었을 때 발생합니다.
* 또한 연결이 끊긴 SqlRowSets에 의해 발생되기도 합니다.
*/
public class InvalidResultSetAccessException extends RuntimeException {
public InvalidResultSetAccessException(final String reason) {
super(reason);
}

public InvalidResultSetAccessException() {
super();
}

public InvalidResultSetAccessException(final String reason, final Throwable cause) {
super(reason, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PoolingVsNoPoolingTest {

private final Logger log = LoggerFactory.getLogger(PoolingVsNoPoolingTest.class);

private static final int COUNT = 1000;
private static final int COUNT = 10000;

private static MySQLContainer<?> container;

Expand Down Expand Up @@ -78,9 +78,12 @@ void pooling() throws SQLException {
config.setJdbcUrl(container.getJdbcUrl());
config.setUsername(container.getUsername());
config.setPassword(container.getPassword());
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setMinimumIdle(10);
config.setMaximumPoolSize(10);
config.setConnectionTimeout(1000);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.setAutoCommit(false);
config.setReadOnly(false);
final var hikariDataSource = new HikariDataSource(config);
Expand Down

0 comments on commit ef9baaa

Please sign in to comment.