1 package org.openejb.core.stateless; 2 3 import java.rmi.RemoteException ; 4 5 import javax.ejb.EnterpriseBean ; 6 import javax.transaction.Status ; 7 8 import org.openejb.ApplicationException; 9 import org.openejb.core.transaction.TransactionContainer; 10 import org.openejb.core.transaction.TransactionContext; 11 import org.openejb.core.transaction.TransactionPolicy; 12 13 20 public class StatelessBeanManagedTxPolicy extends TransactionPolicy { 21 22 public StatelessBeanManagedTxPolicy(TransactionContainer container){ 23 this(); 24 if(container instanceof org.openejb.Container && 25 ((org.openejb.Container)container).getContainerType()!=org.openejb.Container.STATELESS) { 26 throw new IllegalArgumentException (); 27 } 28 29 this.container = container; 30 } 31 32 public StatelessBeanManagedTxPolicy(){ 33 policyType = BeanManaged; 34 } 35 36 public String policyToString() { 37 return "TX_BeanManaged: "; 38 } 39 49 public void beforeInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.SystemException, org.openejb.ApplicationException{ 50 context.clientTx = suspendTransaction(); 52 } 53 54 73 public void afterInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 74 try { 75 79 context.currentTx = getTxMngr().getTransaction(); 80 81 if (context.currentTx == null) return; 82 83 if (context.currentTx.getStatus() != Status.STATUS_ROLLEDBACK && context.currentTx.getStatus() != Status.STATUS_COMMITTED ) { 84 String message = "The stateless session bean started a transaction but did not complete it."; 85 86 87 logger.error( message ); 88 89 90 try { 91 rollbackTransaction( context.currentTx ); 92 } catch (Throwable t){ 93 } 95 96 97 throwAppExceptionToServer( new RemoteException ( message )); 98 } 99 100 } catch (javax.transaction.SystemException e){ 101 throw new org.openejb.SystemException( e ); 102 } finally { 103 resumeTransaction( context.clientTx ); 104 } 105 } 106 107 120 public void handleApplicationException( Throwable appException, TransactionContext context) throws ApplicationException{ 121 throw new ApplicationException( appException ); 123 } 124 125 156 public void handleSystemException( Throwable sysException, EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 157 try { 158 context.currentTx = getTxMngr().getTransaction(); 159 } catch (javax.transaction.SystemException e ){ 160 context.currentTx = null; 161 } 162 163 logSystemException( sysException ); 165 166 if ( context.currentTx != null ) markTxRollbackOnly( context.currentTx ); 168 169 discardBeanInstance( instance, context.callContext); 171 172 throwExceptionToServer( sysException ); 174 175 } 176 177 } 178 179 | Popular Tags |