1 17 18 package org.objectweb.jac.aspects.distrans; 19 20 import javax.transaction.HeuristicMixedException ; 21 import javax.transaction.HeuristicRollbackException ; 22 import javax.transaction.RollbackException ; 23 import javax.transaction.SystemException ; 24 import javax.transaction.UserTransaction ; 25 26 import org.aopalliance.intercept.ConstructorInvocation; 27 import org.aopalliance.intercept.MethodInvocation; 28 import org.objectweb.jac.core.AspectComponent; 29 import org.objectweb.jac.core.Interaction; 30 import org.objectweb.jac.core.Wrapper; 31 32 40 public abstract class EndTransactionWrapper extends Wrapper { 41 42 43 private UserTransaction usertx; 44 45 public EndTransactionWrapper(AspectComponent ac) { 46 super(ac); 47 usertx = JOTMHelper.get().getUserTransaction(); 48 } 49 50 56 public abstract boolean decide(); 57 58 61 public Object invoke(MethodInvocation invocation) throws Throwable { 62 Interaction interaction = (Interaction) invocation; 63 try { 64 return _end(interaction); 65 } catch (Exception e) { 66 e.printStackTrace(); 67 } 68 69 return null; 70 } 71 72 private Object _end(Interaction interaction) 73 throws SecurityException , RollbackException , HeuristicMixedException , 74 HeuristicRollbackException , SystemException 75 { 76 Object ret = proceed(interaction); 77 78 if (decide()) { 79 usertx.commit(); 80 } 81 else { 82 usertx.rollback(); 83 } 84 85 return ret; 86 } 87 88 public Object construct(ConstructorInvocation invocation) throws Throwable { 89 throw new Exception ("This wrapper does not support constructor wrapping"); 90 } 91 } 92 | Popular Tags |