Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 88   Methods: 4
NCLOC: 53   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
OptimisticInterceptor.java 66.7% 90% 100% 86.7%
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    package org.jboss.cache.interceptors;
 8   
 9    import org.jboss.cache.CacheException;
 10    import org.jboss.cache.CacheSPI;
 11    import org.jboss.cache.Fqn;
 12    import org.jboss.cache.InvocationContext;
 13    import org.jboss.cache.NodeSPI;
 14    import org.jboss.cache.optimistic.TransactionWorkspace;
 15    import org.jboss.cache.transaction.GlobalTransaction;
 16    import org.jboss.cache.transaction.OptimisticTransactionEntry;
 17    import org.jboss.cache.transaction.TransactionTable;
 18   
 19    import javax.transaction.Transaction;
 20    import javax.transaction.TransactionManager;
 21    import java.util.List;
 22   
 23    /**
 24    * Abstract interceptor for optimistic locking
 25    *
 26    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 27    */
 28    public class OptimisticInterceptor extends Interceptor
 29    {
 30    protected TransactionManager txManager = null;
 31    protected TransactionTable txTable = null;
 32    protected boolean trace;
 33   
 34  3505 public void setCache(CacheSPI cache)
 35    {
 36  3505 super.setCache(cache);
 37  3505 txManager = cache.getTransactionManager();
 38  3505 txTable = cache.getTransactionTable();
 39  3505 trace = log != null && log.isTraceEnabled();
 40    }
 41   
 42  2110165 protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws CacheException
 43    {
 44  2110165 OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry) txTable.get(gtx);
 45   
 46  2110165 if (transactionEntry == null)
 47    {
 48  0 throw new CacheException("Unable to map global transaction " + gtx + " to transaction entry when trying to retrieve transaction workspace.");
 49    }
 50   
 51    // try and get the workspace from the transaction
 52  2110165 return transactionEntry.getTransactionWorkSpace();
 53    }
 54   
 55    /**
 56    * Adds the Fqn of the node as well as all children and childrens children to the list.
 57    *
 58    * @param list
 59    * @param n
 60    */
 61  38 protected void greedyGetFqns(List<Fqn> list, NodeSPI<?, ?> n, Fqn newBase)
 62    {
 63  38 list.add(n.getFqn());
 64  38 Fqn newFqn = new Fqn(newBase, n.getFqn().getLastElement());
 65  38 list.add(newFqn);
 66   
 67  38 for (NodeSPI child : n.getChildrenDirect())
 68    {
 69  10 greedyGetFqns(list, child, newFqn);
 70    }
 71    }
 72   
 73    /**
 74    * @return the {@link org.jboss.cache.transaction.GlobalTransaction}, extracted from the current {@link org.jboss.cache.InvocationContext}.
 75    * @throws CacheException if the {@link org.jboss.cache.transaction.GlobalTransaction} or {@link javax.transaction.Transaction} associated with the
 76    * {@link org.jboss.cache.InvocationContext} is null.
 77    */
 78  3162599 protected GlobalTransaction getGlobalTransaction(InvocationContext ctx) throws CacheException
 79    {
 80  3162599 Transaction tx = ctx.getTransaction();
 81  3 if (tx == null) throw new CacheException("Transaction associated with the current invocation is null!");
 82  3162596 GlobalTransaction gtx = ctx.getGlobalTransaction();
 83  0 if (gtx == null) throw new CacheException("GlobalTransaction associated with the current invocation is null!");
 84  3162596 return gtx;
 85    }
 86   
 87   
 88    }