Spring声明式事务管理源码解读之事务开始与提交Word文档格式.docx
- 文档编号:16156080
- 上传时间:2022-11-21
- 格式:DOCX
- 页数:37
- 大小:38.79KB
Spring声明式事务管理源码解读之事务开始与提交Word文档格式.docx
《Spring声明式事务管理源码解读之事务开始与提交Word文档格式.docx》由会员分享,可在线阅读,更多相关《Spring声明式事务管理源码解读之事务开始与提交Word文档格式.docx(37页珍藏版)》请在冰豆网上搜索。
1./**
2.*Supportacurrenttransaction,createanewoneifnoneexists.
3.*AnalogoustoEJBtransactionattributeofthesamename.
4.*<
p>
Thisistypicallythedefaultsettingofatransactiondefinition.
5.*/
6.intPROPAGATION_REQUIRED=0;
/**
*Supportacurrenttransaction,createanewoneifnoneexists.
*AnalogoustoEJBtransactionattributeofthesamename.
*<
Thisistypicallythedefaultsettingofatransactiondefinition.
*/
intPROPAGATION_REQUIRED=0;
当然其中也定义了隔离级别
1.*Aconstantindicatingthatdirtyreadsareprevented;
non-repeatablereads
2.*andphantomreadscanoccur.Thislevelonlyprohibitsatransaction
3.*fromreadingarowwithuncommittedchangesinit.
4.*@seejava.sql.Connection#TRANSACTION_READ_COMMITTED
6.intISOLATION_READ_COMMITTED=Connection.TRANSACTION_READ_COMMITTED;
*Aconstantindicatingthatdirtyreadsareprevented;
non-repeatablereads
*andphantomreadscanoccur.Thislevelonlyprohibitsatransaction
*fromreadingarowwithuncommittedchangesinit.
*@seejava.sql.Connection#TRANSACTION_READ_COMMITTED
intISOLATION_READ_COMMITTED=Connection.TRANSACTION_READ_COMMITTED;
同时还有两个对应的方法来得到这样的传播途径和隔离级别
2.*Returnthepropagationbehavior.
3.*MustreturnoneofthePROPAGATIONconstants.
4.*@see#PROPAGATION_REQUIRED
5.*@seeorg.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive()
6.*/
7.intgetPropagationBehavior();
8.
9./**
10.*Returntheisolationlevel.
11.*MustreturnoneoftheISOLATIONconstants.
12.*<
OnlymakessenseincombinationwithPROPAGATION_REQUIREDor
13.*PROPAGATION_REQUIRES_NEW.
14.*<
Notethatatransactionmanagerthatdoesnotsupportcustom
15.*isolationlevelswillthrowanexceptionwhengivenanyotherlevel
16.*thanISOLATION_DEFAULT.
17.*@see#ISOLATION_DEFAULT
18.*/
19.intgetIsolationLevel();
*Returnthepropagationbehavior.
*MustreturnoneofthePROPAGATIONconstants.
*@see#PROPAGATION_REQUIRED
*@seeorg.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive()
intgetPropagationBehavior();
/**
*Returntheisolationlevel.
*MustreturnoneoftheISOLATIONconstants.
OnlymakessenseincombinationwithPROPAGATION_REQUIREDor
*PROPAGATION_REQUIRES_NEW.
Notethatatransactionmanagerthatdoesnotsupportcustom
*isolationlevelswillthrowanexceptionwhengivenanyotherlevel
*thanISOLATION_DEFAULT.
*@see#ISOLATION_DEFAULT
intgetIsolationLevel();
这个接口有一个默认的实现DefaultTransactionDefinition。
然后它还有子类,比如说
DefaultTransactionAttribute。
Spring在判断一个方法是否需要事务体的时候其实是创建一个TransactionAttribute实现的实例.
有了上面的简单介绍就可以进入真正判断是否需要事务的地方了。
这个方法在TransactionAspectSupport类里,
2.*Createatransactionifnecessary.
3.*@parammethodmethodabouttoexecute
4.*@paramtargetClassclassthemethodison
5.*@returnaTransactionInfoobject,whetherornotatransactionwascreated.
6.*ThehasTransaction()methodonTransactionInfocanbeusedtotellifthere
7.*wasatransactioncreated.
8.*/
9.protectedTransactionInfocreateTransactionIfNecessary(Methodmethod,ClasstargetClass){
10.//Ifthetransactionattributeisnull,themethodisnon-transactional.
11.finalTransactionAttributesourceAttr=
12.this.transactionAttributeSource.getTransactionAttribute(method,targetClass);
//就是在这里判断了这个方法的事务属性
13.TransactionAttributetxAttr=sourceAttr;
14.
15.//Ifnonamespecified,applymethodidentificationastransactionname.
16.if(txAttr!
=null&
&
txAttr.getName()==null){
17.finalStringname=methodIdentification(method);
18.txAttr=newDelegatingTransactionAttribute(sourceAttr){
19.publicStringgetName(){
20.returnname;
21.}
22.};
23.}
24.
25.TransactionInfotxInfo=newTransactionInfo(txAttr,method);
26.//TransactionInfo是TransactionAspectSupport的一个内部类,它的主要功能是记录方法和对应的事务属性
27.if(txAttr!
=null){
28.//Weneedatransactionforthismethod
29.if(logger.isDebugEnabled()){
30.logger.debug("
Gettingtransactionfor"
+txInfo.joinpointIdentification());
31.}
32.
33.//Thetransactionmanagerwillflagan
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Spring 声明 事务管理 源码 解读 事务 开始 提交