1 package org.openejb.core.stateful; 2 3 import javax.ejb.EnterpriseBean ; 4 import javax.ejb.SessionSynchronization ; 5 6 import org.openejb.ApplicationException; 7 import org.openejb.InvalidateReferenceException; 8 import org.openejb.core.transaction.TransactionContext; 9 import org.openejb.core.transaction.TransactionPolicy; 10 21 public class SessionSynchronizationTxPolicy extends org.openejb.core.transaction.TransactionPolicy { 22 23 protected TransactionPolicy policy; 24 25 public SessionSynchronizationTxPolicy(TransactionPolicy policy){ 26 this.policy = policy; 27 this.container = policy.getContainer(); 28 this.policyType = policy.policyType; 29 if(container instanceof org.openejb.Container && 30 ((org.openejb.Container)container).getContainerType()!=org.openejb.Container.STATEFUL || 31 policyType==TransactionPolicy.Never || 32 policyType==TransactionPolicy.NotSupported) { 33 throw new IllegalArgumentException (); 34 } 35 36 } 37 38 public void beforeInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.SystemException, org.openejb.ApplicationException{ 39 policy.beforeInvoke( instance, context ); 40 41 if( context.currentTx == null ) return; 43 44 try{ 45 SessionSynchronization session = (SessionSynchronization )instance; 46 SessionSynchronizationCoordinator.registerSessionSynchronization( session, context ); 47 } catch (javax.transaction.RollbackException e){ 48 logger.error("Cannot register the SessionSynchronization bean with the transaction, the transaction has been rolled back"); 49 handleSystemException( e, instance, context ); 50 } catch (javax.transaction.SystemException e){ 51 logger.error("Cannot register the SessionSynchronization bean with the transaction, received an unknown system exception from the transaction manager: "+e.getMessage()); 52 handleSystemException( e, instance, context ); 53 } catch (Throwable e){ 54 logger.error("Cannot register the SessionSynchronization bean with the transaction, received an unknown exception: "+e.getClass().getName()+" "+ e.getMessage()); 55 handleSystemException( e, instance, context ); 56 } 57 } 58 59 public void afterInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 60 policy.afterInvoke( instance, context ); 61 } 62 63 public void handleApplicationException( Throwable appException, TransactionContext context) throws ApplicationException{ 64 policy.handleApplicationException( appException, context ); 65 } 66 67 public void handleSystemException( Throwable sysException, EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 68 try { 69 policy.handleSystemException( sysException, instance, context ); 70 } catch ( ApplicationException e ){ 71 throw new InvalidateReferenceException( e.getRootCause() ); 72 } 73 } 74 75 } 76 77 | Popular Tags |