Clover coverage report -
Coverage timestamp: Thu Jun 22 2006 14:24:50 CEST
file stats: LOC: 131   Methods: 2
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BMTTransactionInterceptor.java 0% 0% 0% 0%
coverage
 1    /**
 2    * EasyBeans
 3    * Copyright (C) 2006 Bull S.A.S.
 4    * Contact: easybeans@objectweb.org
 5    *
 6    * This library is free software; you can redistribute it and/or
 7    * modify it under the terms of the GNU Lesser General Public
 8    * License as published by the Free Software Foundation; either
 9    * version 2.1 of the License, or any later version.
 10    *
 11    * This library is distributed in the hope that it will be useful,
 12    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 14    * Lesser General Public License for more details.
 15    *
 16    * You should have received a copy of the GNU Lesser General Public
 17    * License along with this library; if not, write to the Free Software
 18    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 19    * USA
 20    *
 21    * --------------------------------------------------------------------------
 22    * $Id: BMTTransactionInterceptor.java 9 2006-02-19 18:53:32Z benoitf $
 23    * --------------------------------------------------------------------------
 24    */
 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    /**
 38    * Defines an interceptor for method that are in Bean managed mode and then in Bean Managed Transaction.
 39    * @author Florent Benoit
 40    */
 41    public class BMTTransactionInterceptor extends AbsTransactionInterceptor {
 42   
 43    /**
 44    * Logger.
 45    */
 46    private JLog logger = JLogFactory.getLog(BMTTransactionInterceptor.class);
 47   
 48    /**
 49    * Constructor.<br>
 50    * Acquire the transaction manager.
 51    */
 52  0 public BMTTransactionInterceptor() {
 53  0 super();
 54    }
 55   
 56    /**
 57    * Execute transaction as specified for BMT.
 58    * @param invocationContext context with useful attributes on the current
 59    * invocation
 60    * @return result of the next invocation (to chain interceptors)
 61    * @throws Exception if interceptor fails
 62    * @see <a href="http://www.jcp.org/en/jsr/detail?id=220">EJB 3.0
 63    * specification ?12.6.1</a>
 64    */
 65  0 @Override
 66    public Object intercept(final EasyBeansInvocationContext invocationContext) throws Exception {
 67  0 logger.debug("Calling BMT TX interceptor");
 68   
 69    // Get current transaction
 70  0 Transaction transaction;
 71  0 try {
 72  0 transaction = getTransactionManager().getTransaction();
 73    } catch (SystemException se) {
 74  0 throw new EJBException("Cannot get the current transaction on transaction manager.", se);
 75    }
 76   
 77  0 logger.debug("Transaction found = {0}", transaction);
 78   
 79    /*
 80    * When a client invokes a business method via one of the enterprise
 81    * bean?s client view interfaces, the container suspends any transaction
 82    * that may be associated with the client request. If there is a
 83    * transaction associated with the instance (this would happen if a
 84    * stateful session bean instance started the transaction in some
 85    * previous business method), the container associates the method
 86    * execution with this transaction. If there are interceptor methods
 87    * associated with the bean instances, these actions are taken before
 88    * the interceptor methods are invoked.
 89    */
 90   
 91  0 Transaction suspendedTransaction = null;
 92  0 if (transaction != null) {
 93  0 try {
 94  0 logger.debug("Suspending transaction {0}", transaction);
 95  0 suspendedTransaction = getTransactionManager().suspend();
 96    } catch (SystemException se) {
 97  0 throw new EJBException("Cannot call suspend() on the transaction manager.", se);
 98    }
 99    }
 100   
 101   
 102  0 try {
 103  0 return invocationContext.proceed();
 104    } finally {
 105   
 106    /*
 107    * The container resumes the suspended association when the business
 108    * method has completed.
 109    */
 110  0 if (suspendedTransaction != null) {
 111   
 112  0 logger.debug("Resuming transaction {0}", transaction);
 113   
 114  0 try {
 115  0 getTransactionManager().resume(suspendedTransaction);
 116    } catch (InvalidTransactionException ite) {
 117  0 throw new EJBException(
 118    "Cannot call resume() on the given transaction. There is an invalid transaction", ite);
 119    } catch (IllegalStateException ise) {
 120  0 throw new EJBException(
 121    "Cannot call resume() on the given transaction. There is another associated transaction",
 122    ise);
 123    } catch (SystemException se) {
 124  0 throw new EJBException("Cannot call resume() on the given transaction. Unexpected error condition",
 125    se);
 126    }
 127    }
 128    }
 129    }
 130   
 131    }