欢迎来到天天文库
浏览记录
ID:39468349
大小:56.00 KB
页数:5页
时间:2019-07-04
《Spring事务源码解析小结》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、TransactionInterceptor继承TransactionAspectSupport通过事务TransactionInterceptor事务拦截器生成目标Bean的代理对象TransactionInterceptor事务拦截器(声明式事务)finalTransactionAttributetxAttr=getTransactionAttributeSource().getTransactionAttribute(invocation.getMethod(),targetClass);//拦截到方法的事务属性txAttr如:PROPAGATION_RE
2、QUIRED,ISOLATION_DEFAULTSpring拦截器默认事务属性PROPAGATION_REQUIRED,ISOLATION_DEFAULTfinalStringjoinpointIdentification=methodIdentification(invocation.getMethod());通过ClassUtils.getQualifiedMethodName(method);获取拦截到的方法名称//在切面上添加事务的方法jdk动态代理publicObjectinvoke(finalMethodInvocationinvocation)th
3、rowsThrowable{//Workoutthetargetclass:maybenull.//TheTransactionAttributeSourceshouldbepassedthetargetclass//aswellasthemethod,whichmaybefromaninterface.ClasstargetClass=(invocation.getThis()!=null?invocation.getThis().getClass():null);//Ifthetransactionattributeisnull,t
null
4、hemethodisnon-transactional.finalTransactionAttributetxAttr=getTransactionAttributeSource().getTransactionAttribute(invocation.getMethod(),targetClass);//拦截到方法的事务属性txAttr如:PROPAGATION_REQUIRED,ISOLATION_DEFAULTfinalStringjoinpointIdentification=methodIdentification(invocation.getMeth
5、od());if(txAttr==null
6、
7、!(getTransactionManager()instanceofCallbackPreferringPlatformTransactionManager)){//StandardtransactiondemarcationwithgetTransactionandcommit/rollbackcalls.TransactionInfotxInfo=createTransactionIfNecessary(txAttr,joinpointIdentification);//包括(txAttr,拦截到的方法join
8、Point,transactionStatus)调用底层Objecttransaction=doGetTransaction();开启事务。ObjectretVal=null;try{//Thisisanaroundadvice:Invokethenextinterceptorinthechain.//Thiswillnormallyresultinatargetobjectbeinginvoked.retVal=invocation.proceed();}catch(Throwableex){//targetinvocationexceptioncomplet
9、eTransactionAfterThrowing(txInfo,ex);throwex;}finally{cleanupTransactionInfo(txInfo);}commitTransactionAfterReturning(txInfo);//调用父类TransactionAspectSupport(含transactionManager,transactionAttributeSource)//this.transactionManager.commit(txInfo.getTransactionStatus());returnretVal;}el
10、se{//It'saCa
此文档下载收益归作者所有