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 75 public class TxRequired extends TransactionPolicy { 76 77 public TxRequired(TransactionContainer container){ 78 this(); 79 this.container = container; 80 } 81 82 public TxRequired(){ 83 policyType = Required; 84 } 85 86 public String policyToString() { 87 return "TX_Required: "; 88 } 89 90 public void beforeInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.SystemException, org.openejb.ApplicationException{ 91 92 try { 93 94 context.clientTx = getTxMngr().getTransaction(); 95 96 if ( context.clientTx == null ) { 97 beginTransaction(); 98 } 99 100 context.currentTx = getTxMngr().getTransaction(); 101 102 } catch ( javax.transaction.SystemException se ) { 103 logger.error("Exception during getTransaction()", se); 104 throw new org.openejb.SystemException(se); 105 } 106 } 107 108 public void afterInvoke(EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 109 110 try { 111 if ( context.clientTx != null ) return; 112 if ( context.currentTx.getStatus() == Status.STATUS_ACTIVE ) { 114 commitTransaction( context.currentTx ); 115 } else { 116 rollbackTransaction( context.currentTx ); 117 } 118 119 } catch ( javax.transaction.SystemException se ) { 120 logger.error("Exception during getTransaction()", se); 121 throw new org.openejb.SystemException(se); 122 } 123 } 124 125 140 public void handleApplicationException( Throwable appException, TransactionContext context) throws ApplicationException{ 141 throw new ApplicationException( appException ); 143 } 144 145 180 public void handleSystemException( Throwable sysException, EnterpriseBean instance, TransactionContext context) throws org.openejb.ApplicationException, org.openejb.SystemException{ 181 182 183 logSystemException( sysException ); 184 185 boolean runningInContainerTransaction = (!context.currentTx.equals( context.clientTx )); 186 if (runningInContainerTransaction) { 187 188 markTxRollbackOnly( context.currentTx ); 189 190 191 discardBeanInstance( instance, context.callContext); 192 193 194 throwExceptionToServer( sysException ); 195 } else { 196 197 markTxRollbackOnly( context.clientTx ); 198 199 200 discardBeanInstance( instance, context.callContext); 201 202 203 throwTxExceptionToServer( sysException ); 204 } 205 } 206 } 207 | Popular Tags |