From 50fbb77ce7cd480d2ed857050c553768cf73a8f3 Mon Sep 17 00:00:00 2001 From: kwonyj1022 Date: Tue, 10 Oct 2023 10:55:43 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/techcourse/dao/UserDao.java | 8 -------- .../com/techcourse/dao/UserHistoryDao.java | 18 +----------------- .../techcourse/service/MockUserHistoryDao.java | 7 ------- .../jdbc/core/JdbcExecutor.java | 18 ------------------ .../jdbc/core/JdbcTemplate.java | 14 -------------- 5 files changed, 1 insertion(+), 64 deletions(-) diff --git a/app/src/main/java/com/techcourse/dao/UserDao.java b/app/src/main/java/com/techcourse/dao/UserDao.java index 41457eefef..666656f581 100644 --- a/app/src/main/java/com/techcourse/dao/UserDao.java +++ b/app/src/main/java/com/techcourse/dao/UserDao.java @@ -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 { @@ -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 findAll() { final String sql = "select id, account, password, email from users"; final List findUsers = jdbcTemplate.query(sql, userRowMapper); diff --git a/app/src/main/java/com/techcourse/dao/UserHistoryDao.java b/app/src/main/java/com/techcourse/dao/UserHistoryDao.java index 5247c54f39..8c8c3b7ef2 100644 --- a/app/src/main/java/com/techcourse/dao/UserHistoryDao.java +++ b/app/src/main/java/com/techcourse/dao/UserHistoryDao.java @@ -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 { @@ -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() - ); - } } diff --git a/app/src/test/java/com/techcourse/service/MockUserHistoryDao.java b/app/src/test/java/com/techcourse/service/MockUserHistoryDao.java index 3b8abb9864..2ee12b195f 100644 --- a/app/src/test/java/com/techcourse/service/MockUserHistoryDao.java +++ b/app/src/test/java/com/techcourse/service/MockUserHistoryDao.java @@ -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) { @@ -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(); - } } diff --git a/jdbc/src/main/java/org/springframework/jdbc/core/JdbcExecutor.java b/jdbc/src/main/java/org/springframework/jdbc/core/JdbcExecutor.java index 2ff77dbf50..2116a0e6b3 100644 --- a/jdbc/src/main/java/org/springframework/jdbc/core/JdbcExecutor.java +++ b/jdbc/src/main/java/org/springframework/jdbc/core/JdbcExecutor.java @@ -41,24 +41,6 @@ public T execute( } } - public T execute( - final Connection connection, - final String sql, - final Object[] args, - final Function 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 diff --git a/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 60379d8b89..18e38d489d 100644 --- a/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -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; @@ -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 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 List query(final String sql, final RowMapper rowMapper, final Object... args) { final Function> function = pstmt -> { try {