-
Notifications
You must be signed in to change notification settings - Fork 300
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 라이브러리 구현하기 - 3,4단계] 호이(이건호) 미션 제출합니다. #603
Conversation
- 변수 네이밍 명확하게 수정 - 사용하지 않는 log 제거
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my gun ho zzang...
너무나도 기가막힌 코드인 것 같습니다.
그래서 정말 죄송하지만, 작은 제안 하나 정도만 남겼습니다.
해당 코멘트 읽어봐주시고 답변해주신다면 바로 Approve 해드리도록 할게요!
함께 할 수 있어서 아주 즐거웠습니다. my gun ho zzang pu san university
- [x] JDBC 탬플릿의 중복된 try catch문 제거 | ||
|
||
## 3단계 | ||
- [x] 매튜 리뷰 반영 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my gun ho ... 의 readme 에 저의 닉네임이 들어가다니 이렇게 감동적일 수가 없습니다..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh jae yun ... u r so kind~
private static final RowMapper<User> USER_ROW_MAPPER = rs -> new User( | ||
rs.getLong("id"), | ||
rs.getString("account"), | ||
rs.getString("password"), | ||
rs.getString("email")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사실 1, 2, 3, 4 보다 이렇게 직접적으로 column 명을 명시해주는 것이 좋아보이긴 했는데 이렇게 바꿔주셨군요! 멋집니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u 2
|
||
public class UserHistoryDao { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(UserHistoryDao.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용하지 않는 로그들도 다 지워주셨네요 역시 my gun ho zzang ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ur jae yun zzang too
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.util.Map; | ||
|
||
public abstract class TransactionSynchronizationManager { | ||
|
||
private static final ThreadLocal<Map<DataSource, Connection>> resources = new ThreadLocal<>(); | ||
private static final ThreadLocal<Map<DataSource, Connection>> resources = init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 이 부분에서 ThreadLocal
이 알아서 초기화 해주는 줄 알고 많이 해맸었는데요!
그러다가 아래와 같은 방법을 찾을 수 있었습니다.
ThreadLocal.withInitial(HashMap::new);
꼭 코드량을 줄여야 하는 것은 아니지만, 해당 방법으로 진행하게 되면, 한 줄로 thread local 을 원하는대로 초기화 해줄 수 있어요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 방법이 있었네요..!
오우.. 역시 매튜 👍
바로 적용하겠습니다!
runnable.run(); | ||
return null; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조회, 업데이트를 나누어 해당 execute 메서드에서 return null 을 없애주는 방법은 어떨까요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금 반영을 했는데 메튜가 원하는 방향이 맞을까요?!
(뭔가 결과를 반환하고 안하고를 제외하면 중복적인거 같아서)
final var pss = newArgumentPreparedStatementSetter(parameters); | ||
pss.setValues(ps); | ||
return ps.executeUpdate(); | ||
execute(new PreparedStatementCreator(sql), statement -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
훨씬 이해하기 좋아진 것 같아요 my gun ho !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
덕분입니다 ur jae yun !
public List<UserHistory> findLogsByUserId(final long id) { | ||
return userHistoryDao.findByUserId(id); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트를 위해 메서들르 추가해주셨군요! 좋습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hyohoyohyohoyhoyhoyhohyohyohyo
지금까지 코드 리뷰하면서 정말 많이 배울 수 있었습니다.
당신 정말 멋져요우..
앞으로도 계속 선한 영향력을 주시기를...
@@ -7,16 +7,10 @@ | |||
|
|||
public abstract class TransactionSynchronizationManager { | |||
|
|||
private static final ThreadLocal<Map<DataSource, Connection>> resources = init(); | |||
private static final ThreadLocal<Map<DataSource, Connection>> resources = ThreadLocal.withInitial(HashMap::new); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
바로 반영해주셨군요 아주 기모찌 합니다.
final Connection connection = DataSourceUtils.getConnection(dataSource); | ||
try { | ||
connection.setAutoCommit(false); | ||
runnable.run(); | ||
return null; | ||
}); | ||
connection.commit(); | ||
} catch (SQLException e) { | ||
rollback(connection); | ||
throw new DataAccessException(e); | ||
} finally { | ||
DataSourceUtils.releaseConnection(connection, dataSource); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 말한게 정확히 맞습니다! 역시 hoyhoy gun ho zzang..
public static boolean isActiveTransaction(Connection connection) { | ||
return activeTransactions.get().getOrDefault(connection, false); | ||
} | ||
|
||
public static void setActiveTransaction(Connection connection, boolean status) { | ||
activeTransactions.get().put(connection, status); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 setActiveTransaction 과 isActiveTransaction 이 추가되면서 훨씬 로직들이 단단해진 느낌이네요! 아주 좋습니다
나이스 투 매튜... 🙇♂️
죄송합니다.. 휴일에 정신 못차리고 놀다보니 많이 늦어버렸네요..
3단계에서는 트랜잭션의 경계를 두고 {커밋 | 롤백 }이 가능하게 구현했습니다.
3단계 커밋 내용
4단계에서는 3단계에서 구현한 부분을 주어진
DataSourceUtils
와TransactionSynchronizationManager
로 수정하고TransactionManager
를 통해 리팩토링 하였습니다...4단계 커밋 내용