java - Make a transaction inside aspect -


i have aspect method, annotated @around, there following lines:

@around("@annotation(customannotation)") public void handle(proceedingjoinpoint joinpoint) {     methodsignature ms = (methodsignature) joinpoint.getsignature();     customannotation m = ms.getmethod().getannotation(customannotation.class);     processor processor = appcontext.getbean(m.value());     object argument = joinpoint.getargs()[0];       processor.preprocess(argument);     joinpoint.proceed();     processor.postprocess(argument); } 

method interrupted aspect:

@customannotation(value = "createprocessor") public void create(user user) {     createorupdate(user); //in method user in "users" created or updated } 

processor.preprocess() empty.

processor.postprocess():

@override public void postprocess(object obj) {     //add obj "objects" table in db } 

all these methods (preprocess, postprocess, proceed) interact separate database tables. want make transaction these 3 method calls, i.e. when 1 of them isn't executed successfully, changes made previous ones should reverted. how can achieve goal?

upd. have tried next steps:

added following rows context file:

<tx:annotation-driven transaction-manager="txmanager"/>  <bean id="txmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager">     <property name="datasource" ref="datasource"/> </bean> 

and added @transactional annotation on handle() method.

to check if rollback performed, added exception throwing:

@override public void postprocess(object obj) {     throw new runtimeexception("test");     //add obj "objects" table in db } 

though exception thrown , there no new row in "objects" table, new row in "users" appears.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -