1 22 package org.jboss.ejb3.tx; 23 24 import java.rmi.RemoteException ; 25 26 import javax.ejb.ApplicationException ; 27 import javax.ejb.EJBException ; 28 import javax.ejb.EJBTransactionRequiredException ; 29 import javax.ejb.EJBTransactionRolledbackException ; 30 import javax.transaction.Transaction ; 31 32 import org.jboss.aop.joinpoint.Invocation; 33 import org.jboss.aop.joinpoint.MethodInvocation; 34 35 41 public class Ejb3TxPolicy extends org.jboss.aspects.tx.TxPolicy 42 { 43 public void throwMandatory(Invocation invocation) 44 { 45 throw new EJBTransactionRequiredException (((MethodInvocation) invocation).getActualMethod().toString()); 46 } 47 48 public void handleExceptionInOurTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable 49 { 50 ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation); 51 if (ae != null) 52 { 53 if (ae.rollback()) setRollbackOnly(tx); 54 throw t; 55 } 56 if (!(t instanceof RuntimeException || t instanceof RemoteException )) 57 { 58 throw t; 59 } 60 setRollbackOnly(tx); 61 if (t instanceof RuntimeException && !(t instanceof EJBException )) 62 { 63 throw new EJBException ((Exception ) t); 64 } 65 throw t; 66 } 67 68 public void handleInCallerTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable 69 { 70 ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation); 71 72 if (ae != null) 73 { 74 if (ae.rollback()) setRollbackOnly(tx); 75 throw t; 76 } 77 if (!(t instanceof RuntimeException || t instanceof RemoteException )) 78 { 79 throw t; 80 } 81 setRollbackOnly(tx); 82 84 if (t instanceof EJBTransactionRolledbackException ) 85 throw t; 86 else 87 throw new EJBTransactionRolledbackException ((Exception ) t); 88 } 89 90 } 91 | Popular Tags |