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 BMTTransactionInterceptor extends AbsTransactionInterceptor { 42 43 46 private JLog logger = JLogFactory.getLog(BMTTransactionInterceptor.class); 47 48 52 public BMTTransactionInterceptor() { 53 super(); 54 } 55 56 65 @Override 66 public Object intercept(final EasyBeansInvocationContext invocationContext) throws Exception { 67 logger.debug("Calling BMT 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 90 91 Transaction suspendedTransaction = null; 92 if (transaction != null) { 93 try { 94 logger.debug("Suspending transaction {0}", transaction); 95 suspendedTransaction = getTransactionManager().suspend(); 96 } catch (SystemException se) { 97 throw new EJBException ("Cannot call suspend() on the transaction manager.", se); 98 } 99 } 100 101 102 try { 103 return invocationContext.proceed(); 104 } finally { 105 106 110 if (suspendedTransaction != null) { 111 112 logger.debug("Resuming transaction {0}", transaction); 113 114 try { 115 getTransactionManager().resume(suspendedTransaction); 116 } catch (InvalidTransactionException ite) { 117 throw new EJBException ( 118 "Cannot call resume() on the given transaction. There is an invalid transaction", ite); 119 } catch (IllegalStateException ise) { 120 throw new EJBException ( 121 "Cannot call resume() on the given transaction. There is another associated transaction", 122 ise); 123 } catch (SystemException se) { 124 throw new EJBException ("Cannot call resume() on the given transaction. Unexpected error condition", 125 se); 126 } 127 } 128 } 129 } 130 131 } 132 | Popular Tags |