-
Notifications
You must be signed in to change notification settings - Fork 379
[3단계 - Transaction 적용하기] 벨로(방예혁) 미션 제출합니다. #1137
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
Open
YehyeokBang
wants to merge
5
commits into
woowacourse:yehyeokbang
Choose a base branch
from
YehyeokBang:step3
base: yehyeokbang
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e653da
chore: Poling 오타 수정 (#928)
Dompoo 555788a
DriverManager 오타 수정 (#960)
yeezy-com 2f88450
Merge branch 'yehyeokbang' of https://github.com/woowacourse/java-jdbc
YehyeokBang d7ebcee
feat: 사용자 비밀번호 변경 기능에 트랜잭션 적용
YehyeokBang c68b0c3
feat: SQL 파라미터 개수 검증 기능 추가 및 테스트 케이스 작성
YehyeokBang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,53 @@ | ||
| package com.techcourse.dao; | ||
|
|
||
| import com.techcourse.domain.UserHistory; | ||
| import com.interface21.jdbc.core.JdbcTemplate; | ||
| import com.techcourse.domain.UserHistory; | ||
| import java.sql.Connection; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import javax.sql.DataSource; | ||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
|
|
||
| public class UserHistoryDao { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(UserHistoryDao.class); | ||
|
|
||
| private final DataSource dataSource; | ||
|
|
||
| public UserHistoryDao(final DataSource dataSource) { | ||
| this.dataSource = dataSource; | ||
| } | ||
| private final JdbcTemplate jdbcTemplate; | ||
|
|
||
| public UserHistoryDao(final JdbcTemplate jdbcTemplate) { | ||
| this.dataSource = null; | ||
| this.jdbcTemplate = jdbcTemplate; | ||
| } | ||
|
|
||
| public void log(final UserHistory userHistory) { | ||
| final var sql = "insert into user_history (user_id, account, password, email, created_at, created_by) values (?, ?, ?, ?, ?, ?)"; | ||
|
|
||
| Connection conn = null; | ||
| PreparedStatement pstmt = null; | ||
| try { | ||
| conn = dataSource.getConnection(); | ||
| pstmt = conn.prepareStatement(sql); | ||
|
|
||
| log.debug("query : {}", sql); | ||
|
|
||
| pstmt.setLong(1, userHistory.getUserId()); | ||
| pstmt.setString(2, userHistory.getAccount()); | ||
| pstmt.setString(3, userHistory.getPassword()); | ||
| pstmt.setString(4, userHistory.getEmail()); | ||
| pstmt.setObject(5, userHistory.getCreatedAt()); | ||
| pstmt.setString(6, userHistory.getCreateBy()); | ||
| pstmt.executeUpdate(); | ||
| } catch (SQLException e) { | ||
| log.error(e.getMessage(), e); | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| try { | ||
| if (pstmt != null) { | ||
| pstmt.close(); | ||
| } | ||
| } catch (SQLException ignored) {} | ||
| final var sql = """ | ||
| INSERT INTO user_history (user_id, account, password, email, created_at, created_by) | ||
| VALUES (?, ?, ?, ?, ?, ?) | ||
| """; | ||
| log.debug("User history log: {}", userHistory); | ||
| jdbcTemplate.update(sql, | ||
| userHistory.getUserId(), | ||
| userHistory.getAccount(), | ||
| userHistory.getPassword(), | ||
| userHistory.getEmail(), | ||
| userHistory.getCreatedAt(), | ||
| userHistory.getCreateBy() | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| if (conn != null) { | ||
| conn.close(); | ||
| } | ||
| } catch (SQLException ignored) {} | ||
| } | ||
| public void log( | ||
| final Connection connection, | ||
| final UserHistory userHistory | ||
| ) { | ||
| final String sql = """ | ||
| INSERT INTO user_history (user_id, account, password, email, created_at, created_by) | ||
| VALUES (?, ?, ?, ?, ?, ?) | ||
| """; | ||
| log.debug("User history log: {}", userHistory); | ||
| jdbcTemplate.update(connection, sql, | ||
| userHistory.getUserId(), | ||
| userHistory.getAccount(), | ||
| userHistory.getPassword(), | ||
| userHistory.getEmail(), | ||
| userHistory.getCreatedAt(), | ||
| userHistory.getCreateBy() | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.