1 45 package org.openejb.core.transaction; 46 47 import javax.ejb.EnterpriseBean ; 48 import javax.transaction.Status ; 49 50 import org.openejb.ApplicationException; 51 52 77 public class TxRequiresNew extends TransactionPolicy { 78 79 public TxRequiresNew(TransactionContainer container){ 80 this(); 81 this.container = container; 82 } 83 84 public TxRequiresNew(){ 85 policyType = RequiresNew; 86 } 87 88 public String policyToString() { 89 return "TX_RequiresNew: "; 90 } 91 92 public void beforeInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.SystemException, org.openejb.ApplicationException{ 93 94 try { 95 96 context.clientTx = suspendTransaction(); 98 beginTransaction(); 99 context.currentTx = getTxMngr().getTransaction(); 100 101 } catch ( javax.transaction.SystemException se ) { 102 throw new org.openejb.SystemException(se); 103 } 104 105 } 106 107 public void afterInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 108 109 try { 110 if ( context.currentTx.getStatus() == Status.STATUS_ACTIVE ) { 112 commitTransaction( context.currentTx ); 113 } else { 114 rollbackTransaction( context.currentTx ); 115 } 116 117 } catch ( javax.transaction.SystemException se ) { 118 throw new org.openejb.SystemException(se); 119 } finally { 120 if ( context.clientTx != null ) { 121 resumeTransaction( context.clientTx ); 122 } else if(txLogger.isInfoEnabled()) { 123 txLogger.info(policyToString()+"No transaction to resume"); 124 } 125 } 126 } 127 128 148 public void handleApplicationException( Throwable appException, TransactionContext context) throws ApplicationException{ 149 throw new ApplicationException( appException ); 150 } 151 152 187 public void handleSystemException( Throwable sysException, EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 188 189 190 logSystemException( sysException ); 191 192 193 markTxRollbackOnly( context.currentTx ); 194 195 196 discardBeanInstance( instance, context.callContext); 197 198 199 throwExceptionToServer( sysException ); 200 201 } 202 } 203 204 | Popular Tags |