Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 105   Methods: 1
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PojoTxUndoInterceptor.java 85.7% 95.1% 100% 92.9%
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.Fqn;
 13    import org.jboss.cache.pojo.PojoCacheException;
 14    import org.jboss.cache.pojo.impl.MethodDeclarations;
 15    import org.jboss.cache.pojo.util.MethodCall;
 16   
 17    import java.lang.reflect.Field;
 18    import java.lang.reflect.Method;
 19    import java.util.List;
 20   
 21    /**
 22    * Interceptor (done via aop advice) for transaction rollback. This is is attached to the
 23    * operation that needs a corresponding rollback, e.g., attachInterceptor.
 24    *
 25    * @author Ben Wang
 26    * @version $Id: PojoTxUndoInterceptor.java,v 1.3 2007/05/30 06:08:02 jgreene Exp $
 27    */
 28    public class PojoTxUndoInterceptor extends AbstractInterceptor
 29    {
 30    /// Just that AOP requires an extra key.
 31    public static final String TAG = "PojoCache";
 32   
 33  18019 public Object invoke(Invocation in) throws Throwable
 34    {
 35  18019 if (!(in instanceof MethodInvocation))
 36    {
 37  0 throw new IllegalArgumentException("TxUndoInterceptor.invoke(): invocation not MethodInvocation");
 38    }
 39  18019 MethodInvocation invocation = (MethodInvocation) in;
 40   
 41  18019 PojoTxSynchronizationHandler handler =
 42    PojoTxUndoSynchronizationInterceptor.getSynchronizationHandler();
 43   
 44  18019 if (handler == null)
 45    {
 46  2344 return invocation.invokeNext();
 47    // TODO handler is null can mean we are not calling the right interceptor stack. Need to revisit.
 48    // E.g., a fresh getObject or find will trigger this.
 49    // throw new IllegalStateException("PojoTxUndoInterceptor.invoke(): PojoTxSynchronizationHandler is null");
 50    }
 51   
 52    // Add to the rollback list
 53  15675 String methodName = invocation.getMethod().getName();
 54    // TODO Needs to handle Collection interceptor as well.
 55  15675 if (methodName.equals(MethodDeclarations.attachInterceptor.getName()))
 56    {
 57  2284 Method method = MethodDeclarations.undoAttachInterceptor;
 58  2284 MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
 59  2284 handler.addToList(mc);
 60    }
 61  13391 else if (methodName.equals(MethodDeclarations.detachInterceptor.getName()))
 62    {
 63  1885 Method method = MethodDeclarations.undoDetachInterceptor;
 64  1885 MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
 65  1885 handler.addToList(mc);
 66    }
 67  11506 else if (methodName.equals(MethodDeclarations.inMemorySubstitution.getName()))
 68    {
 69  7334 Method method = MethodDeclarations.undoInMemorySubstitution;
 70  7334 Object obj = invocation.getArguments()[0];
 71  7334 Field field = (Field) invocation.getArguments()[1];
 72  7334 Object oldValue = field.get(obj);
 73  7334 Object[] args = new Object[]{obj, field, oldValue};
 74  7334 MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
 75  7334 handler.addToList(mc);
 76    }
 77  4172 else if (methodName.equals(MethodDeclarations.incrementReferenceCount.getName()))
 78    {
 79  4134 Method method = MethodDeclarations.undoIncrementReferenceCount;
 80  4134 Fqn fqn = (Fqn) invocation.getArguments()[0];
 81  4134 int count = (Integer) invocation.getArguments()[1];
 82  4134 List referenceList = (List) invocation.getArguments()[2];
 83  4134 Object[] args = new Object[]{fqn, count, referenceList};
 84  4134 MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
 85  4134 handler.addToList(mc);
 86    }
 87  38 else if (methodName.equals(MethodDeclarations.decrementReferenceCount.getName()))
 88    {
 89  38 Method method = MethodDeclarations.undoDecrementReferenceCount;
 90  38 Fqn fqn = (Fqn) invocation.getArguments()[0];
 91  38 int count = (Integer) invocation.getArguments()[1];
 92  38 List referenceList = (List) invocation.getArguments()[2];
 93  38 Object[] args = new Object[]{fqn, count, referenceList};
 94  38 MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
 95  38 handler.addToList(mc);
 96    }
 97    else
 98    {
 99  0 throw new PojoCacheException("PojoTxUndoInterceptor: invalid invocation name: " + methodName);
 100    }
 101   
 102  15675 return invocation.invokeNext();
 103    }
 104   
 105    }