Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 92   Methods: 4
NCLOC: 62   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PojoTxUndoSynchronizationInterceptor.java 66.7% 80% 100% 80%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7   
 8    package org.jboss.cache.pojo.interceptors;
 9   
 10    import org.jboss.aop.joinpoint.Invocation;
 11    import org.jboss.aop.joinpoint.MethodInvocation;
 12    import org.jboss.cache.pojo.PojoCacheException;
 13   
 14    import javax.transaction.RollbackException;
 15    import javax.transaction.SystemException;
 16    import javax.transaction.Transaction;
 17   
 18    /**
 19    * Interceptor that handles registration of tx synchronization for rollback
 20    * operations.
 21    *
 22    * @author Ben Wang
 23    * @version $Id: PojoTxUndoSynchronizationInterceptor.java,v 1.3 2007/05/30 06:08:02 jgreene Exp $
 24    */
 25    public class PojoTxUndoSynchronizationInterceptor extends AbstractInterceptor
 26    {
 27    // We stores the handler in thread local since the afterCompletion won't be
 28    // called untill tx.commit(). Note that this is static since it can be
 29    // recursive call to attach/detach.
 30    private static ThreadLocal synchronizationHandler_ = new ThreadLocal();
 31   
 32  25118 public Object invoke(Invocation in) throws Throwable
 33    {
 34  25118 if (!(in instanceof MethodInvocation))
 35    {
 36  0 throw new IllegalArgumentException("TxSyncrhonizationInterceptor.invoke(): invocation not MethodInvocation");
 37    }
 38  25118 MethodInvocation invocation = (MethodInvocation) in;
 39  25118 try
 40    {
 41  25118 registerTxHandler(invocation);
 42  25118 return invocation.invokeNext(); // proceed to next advice or actual call
 43    }
 44    finally
 45    {
 46    }
 47    }
 48   
 49  25118 private void registerTxHandler(MethodInvocation invocation) throws PojoCacheException
 50    {
 51  25118 try
 52    {
 53    // Need to have this in case of rollback
 54  25118 PojoTxSynchronizationHandler handler = (PojoTxSynchronizationHandler) synchronizationHandler_.get();
 55  25118 if (handler == null)
 56    {
 57    // First entry point for this transaction scope.
 58  3208 Transaction tx = (Transaction) invocation.getMetaData(PojoTxInterceptor.TAG, PojoTxInterceptor.TX);
 59  3208 if (tx == null)
 60    {
 61  0 throw new IllegalStateException("PojoCache.registerTxHanlder(). Can't have null tx handle.");
 62    }
 63   
 64  3208 handler = new PojoTxSynchronizationHandler();
 65   
 66  3208 log.debug("Registering PojoTxSynchronizationHandler for rollback if ncessary " + handler);
 67    // Register so we can rollback if necessary
 68  3208 tx.registerSynchronization(handler);
 69   
 70  3208 synchronizationHandler_.set(handler);
 71    }
 72    }
 73    catch (RollbackException e)
 74    {
 75  0 throw new PojoCacheException("PojoTxUndoSynchronizationInterceptor.registerTxHandler(): Exception: " + e);
 76    }
 77    catch (SystemException e)
 78    {
 79  0 throw new PojoCacheException("PojoTxUndoSynchronizationInterceptor.registerTxHandler(): Exception: " + e);
 80    }
 81    }
 82   
 83  18019 public static PojoTxSynchronizationHandler getSynchronizationHandler()
 84    {
 85  18019 return (PojoTxSynchronizationHandler) synchronizationHandler_.get();
 86    }
 87   
 88  3208 public static void reset()
 89    {
 90  3208 synchronizationHandler_.set(null);
 91    }
 92    }