-
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 라이브러리 구현하기 - 4단계] 페드로(류형욱) 미션 제출합니다. #918
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
19c95fc
feat(TransactionSynchronizationManager): 트랜잭션에서 사용할 Connection을 관리하는 …
hw0603 099e65a
refactor(TransactionSynchronizationManager): 더 이상 ThreadLocal을 유지할 필요…
hw0603 e2d7414
refactor(DataSourceUtils): Connection 릴리즈 시 unbind()도 함께 수행하도록 변경
hw0603 7e6fdb3
refactor(TransactionManager): Connection 객체를 DataSourceUtils에서 가져오도록 변경
hw0603 b4f906c
refactor(UserService): 트랜잭션 서비스 추상화
hw0603 f9543c0
test: 0단계 학습 테스트 완료
hw0603 e12852d
test: 1단계 학습 테스트 완료
hw0603 95c7f44
test: 2단계 학습 테스트 완료
hw0603 75bf7c8
refactor(TransactionAdvice): train wreck 메서드 호출 제거
hw0603 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 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 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 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,15 +1,34 @@ | ||
package aop.stage1; | ||
|
||
import aop.DataAccessException; | ||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.aopalliance.intercept.MethodInvocation; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.TransactionStatus; | ||
import org.springframework.transaction.support.DefaultTransactionDefinition; | ||
|
||
|
||
/** | ||
* 어드바이스(advice). 부가기능을 담고 있는 클래스 | ||
*/ | ||
public class TransactionAdvice implements MethodInterceptor { | ||
public class TransactionAdvice implements MethodInterceptor { | ||
|
||
private final PlatformTransactionManager platformTransactionManager; | ||
|
||
public TransactionAdvice(PlatformTransactionManager platformTransactionManager) { | ||
this.platformTransactionManager = platformTransactionManager; | ||
} | ||
|
||
@Override | ||
public Object invoke(final MethodInvocation invocation) throws Throwable { | ||
return null; | ||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(new DefaultTransactionDefinition()); | ||
try { | ||
Object result = invocation.getMethod().invoke(invocation.getThis(), invocation.getArguments()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 정보를 이것저것 끄집어 내서 쓰는 것 같아서 뭔가 맘에 안 들었는데 훨씬 깔끔해졌네요! 감사합니다😊 |
||
platformTransactionManager.commit(transactionStatus); | ||
return result; | ||
} catch (Throwable e) { | ||
platformTransactionManager.rollback(transactionStatus); | ||
throw new DataAccessException(e); | ||
} | ||
} | ||
} |
This file contains 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 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.
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.
스프링은 JDK dynamic proxy를 default로 둔 반면에 스프링 부트는 CGLib Proxy를 default로 둔 이유는 무엇일까요?
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.
서로 지향하는 관점이 조금 다르다고 생각합니다. 스프링은 스프링 부트에 비해 등장 시기가 (당연히) 이르기도 하고, 제 기준에서 스프링은 조금 날 것의 기술이예요. CGLib은 태생적으로 리플렉션 기반의 Dynamic Proxy보다 성능이 좋을 수 밖에 없는데, CGLib 등장 초기에는 성능 문제가 있어 오히려 다이나믹 프록시가 성능이 더 좋았다고 해요. 이러한 이유 때문에 Spring Framework에서는 JDK Dynamix Proxy가 기본값이었지 않나 싶어요. DI 컨테이너의 특성상 인터페이스를 권장하는 방향으로 기본값이 설정됐을 수도 있겠네요.
반면 SpringBoot의 경우에는 'Spring Framework의 쉬운 사용'을 컨셉으로 하고 있어요.
JDK 프록시는 다음과 같은 불편을 안고 있습니다.
시간이 지나면서 CGLib방식이 성능과 안정성 면에서 많은 개선이 있었고, 이러한 불편을 해소할 수 있다면 정책을 변경해도 된다고 판단했을 것 같아요. Spring 3.2부터 CGLib이 내장되면서 더 이상 외부 라이브러리를 사용하지 않아도 된다는 점도 선택에 영향을 미쳤을 것 같네요.
우주는 이유가 뭐라고 생각하시나요?
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.
저도 첫번째 이유는 쉽게 사용하기 위함이라고 생각합니다!
그동안 CGLIb를 내장하지 못했던 이유는 스프링 공식 문서에 나와있는
생성자를 2번 호출하는 문제
때문이라고 생각해요.Objenesis 라이브러리의 등장으로 위 문제를 해결하고 그 때부터 CGLib를 default로 설정한 것이라 추측합니다!
Spring Docs: Proxying Mechanisms