This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ch06] Transaction code with ProxyFactoryBean.
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ch01.springbook.user; | ||
|
||
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; | ||
|
||
public class TransactionAdvice implements MethodInterceptor { | ||
|
||
private PlatformTransactionManager transactionManager; | ||
|
||
public void setTransactionManager(PlatformTransactionManager transactionManager) { | ||
this.transactionManager = transactionManager; | ||
} | ||
|
||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
|
||
TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); | ||
|
||
try { | ||
|
||
Object ret = invocation.proceed(); | ||
transactionManager.commit(status); | ||
return ret; | ||
|
||
} catch (RuntimeException e) { | ||
transactionManager.rollback(status); | ||
throw 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