Skip to content

Commit

Permalink
refactor: 사용하지 않는 메서드 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonyj1022 committed Oct 10, 2023
1 parent 6ec8ebb commit 50fbb77
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 64 deletions.
8 changes: 0 additions & 8 deletions app/src/main/java/com/techcourse/dao/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.jdbc.core.RowMapper;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.List;

public class UserDao {
Expand Down Expand Up @@ -45,13 +44,6 @@ public void update(final User user) {
log.info("update(): {}", user);
}

public void update(final Connection connection, final User user) {
final String sql = "update users set (account, password, email) = (?, ?, ?) where id = ?";
jdbcTemplate.update(connection, sql, user.getAccount(), user.getPassword(), user.getEmail(), user.getId());

log.info("update(): {}", user);
}

public List<User> findAll() {
final String sql = "select id, account, password, email from users";
final List<User> findUsers = jdbcTemplate.query(sql, userRowMapper);
Expand Down
18 changes: 1 addition & 17 deletions app/src/main/java/com/techcourse/dao/UserHistoryDao.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.techcourse.dao;

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

import javax.sql.DataSource;
import java.sql.Connection;

public class UserHistoryDao {

Expand Down Expand Up @@ -36,19 +35,4 @@ public void log(final UserHistory userHistory) {
userHistory.getCreateBy()
);
}

public void log(final Connection connection, final UserHistory userHistory) {
final var sql = "insert into user_history (user_id, account, password, email, created_at, created_by) values (?, ?, ?, ?, ?, ?)";

log.info("log(): {}", userHistory);

jdbcTemplate.update(connection, sql,
userHistory.getUserId(),
userHistory.getAccount(),
userHistory.getPassword(),
userHistory.getEmail(),
userHistory.getCreatedAt(),
userHistory.getCreateBy()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Connection;

public class MockUserHistoryDao extends UserHistoryDao {

public MockUserHistoryDao(final JdbcTemplate jdbcTemplate) {
Expand All @@ -17,9 +15,4 @@ public MockUserHistoryDao(final JdbcTemplate jdbcTemplate) {
public void log(final UserHistory userHistory) {
throw new DataAccessException();
}

@Override
public void log(final Connection connection, final UserHistory userHistory) {
throw new DataAccessException();
}
}
18 changes: 0 additions & 18 deletions jdbc/src/main/java/org/springframework/jdbc/core/JdbcExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ public <T> T execute(
}
}

public <T> T execute(
final Connection connection,
final String sql,
final Object[] args,
final Function<PreparedStatement, T> action) {

try (final PreparedStatement pstmt = connection.prepareStatement(sql)) {
log.debug("query : {}", sql);

processPreparedStatementParameter(pstmt, args);

return action.apply(pstmt);
} catch (SQLException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}

private void processPreparedStatementParameter(
final PreparedStatement pstmt,
final Object[] args
Expand Down
14 changes: 0 additions & 14 deletions jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.jdbc.exception.IncorrectResultSizeDataAccessException;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -36,19 +35,6 @@ public int update(final String sql, final Object... args) {
return executor.execute(sql, args, fuction);
}

public int update(final Connection connection, final String sql, final Object... args) {
final Function<PreparedStatement, Integer> fuction = pstmt -> {
try {
return pstmt.executeUpdate();
} catch (SQLException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
};

return executor.execute(connection, sql, args, fuction);
}

public <T> List<T> query(final String sql, final RowMapper<T> rowMapper, final Object... args) {
final Function<PreparedStatement, List<T>> function = pstmt -> {
try {
Expand Down

0 comments on commit 50fbb77

Please sign in to comment.