1 25 26 package org.objectweb.easybeans.transaction.interceptors; 27 28 import javax.ejb.EJBException ; 29 import javax.transaction.InvalidTransactionException ; 30 import javax.transaction.SystemException ; 31 import javax.transaction.Transaction ; 32 33 import org.objectweb.easybeans.api.EasyBeansInvocationContext; 34 import org.objectweb.easybeans.log.JLog; 35 import org.objectweb.easybeans.log.JLogFactory; 36 37 41 public class CMTNotSupportedTransactionInterceptor extends AbsTransactionInterceptor { 42 43 46 private JLog logger = JLogFactory.getLog(CMTNotSupportedTransactionInterceptor.class); 47 48 52 public CMTNotSupportedTransactionInterceptor() { 53 super(); 54 } 55 56 65 @Override 66 public Object intercept(final EasyBeansInvocationContext invocationContext) throws Exception { 67 logger.debug("Calling Not Supported TX interceptor"); 68 69 Transaction transaction; 71 try { 72 transaction = getTransactionManager().getTransaction(); 73 } catch (SystemException se) { 74 throw new EJBException ("Cannot get the current transaction on transaction manager.", se); 75 } 76 77 logger.debug("Transaction found = {0}", transaction); 78 79 84 85 Transaction suspendedTransaction = null; 86 if (transaction != null) { 87 try { 88 logger.debug("Suspending transaction {0}", transaction); 89 suspendedTransaction = getTransactionManager().suspend(); 90 } catch (SystemException se) { 91 throw new EJBException ("Cannot call suspend() on the transaction manager.", se); 92 } 93 } 94 95 100 try { 101 return invocationContext.proceed(); 102 } catch (Exception e) { 103 handleUnspecifiedTransactionContext(invocationContext, e); 104 return null; 106 } finally { 107 108 112 if (suspendedTransaction != null) { 113 114 logger.debug("Resuming transaction {0}", transaction); 115 116 try { 117 getTransactionManager().resume(suspendedTransaction); 118 } catch (InvalidTransactionException ite) { 119 throw new EJBException ( 120 "Cannot call resume() on the given transaction. There is an invalid transaction", ite); 121 } catch (IllegalStateException ise) { 122 throw new EJBException ( 123 "Cannot call resume() on the given transaction. There is another associated transaction", 124 ise); 125 } catch (SystemException se) { 126 throw new EJBException ("Cannot call resume() on the given transaction. Unexpected error condition", 127 se); 128 } 129 } 130 } 131 } 132 133 } 134 | Popular Tags |