Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 302   Methods: 29
NCLOC: 150   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DummyCacheLoader.java 33.3% 61.5% 62.1% 59.5%
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.loader;
 8   
 9    import org.jboss.cache.CacheImpl;
 10    import org.jboss.cache.Fqn;
 11    import org.jboss.cache.Modification;
 12    import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
 13   
 14    import java.io.ObjectInputStream;
 15    import java.io.ObjectOutputStream;
 16    import java.util.HashMap;
 17    import java.util.List;
 18    import java.util.Map;
 19    import java.util.Set;
 20   
 21    /**
 22    * Dummy cache loader that captures the number of times each method is called.
 23    *
 24    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 25    */
 26    public class DummyCacheLoader extends AbstractCacheLoader
 27    {
 28    private int getChildrenNamesCount = 0, getCount = 0, putCount = 0, existsCount = 0, removeCount = 0;
 29    private Map m_transactions = new HashMap();
 30   
 31  3 public int getGetChildrenNamesCount()
 32    {
 33  3 return getChildrenNamesCount;
 34    }
 35   
 36  5 public int getGetCount()
 37    {
 38  5 return getCount;
 39    }
 40   
 41  6 public int getPutCount()
 42    {
 43  6 return putCount;
 44    }
 45   
 46  4 public int getExistsCount()
 47    {
 48  4 return existsCount;
 49    }
 50   
 51  4 public int getRemoveCount()
 52    {
 53  4 return removeCount;
 54    }
 55   
 56   
 57    /**
 58    * Sets the configuration. Will be called before {@link #create()} and {@link #start()}
 59    */
 60  8 public void setConfig(IndividualCacheLoaderConfig config)
 61    {
 62    }
 63   
 64  8 public IndividualCacheLoaderConfig getConfig()
 65    {
 66  8 return null;
 67    }
 68   
 69    /**
 70    * This method allows the CacheLoader to set the CacheImpl, therefore allowing the CacheLoader to invoke
 71    * methods of the CacheImpl. It can also use the CacheImpl to fetch configuration information. Alternatively,
 72    * the CacheLoader could maintain its own configuration<br/>
 73    * This method will be called directly after the CacheLoader instance has been created
 74    *
 75    * @param c The cache on which this loader works
 76    */
 77  0 public void setCache(CacheImpl c)
 78    {
 79    }
 80   
 81    /**
 82    * Returns a list of children names, all names are <em>relative</em>. Returns null if the parent node is not found.
 83    * The returned set must not be modified, e.g. use Collections.unmodifiableSet(s) to return the result
 84    *
 85    * @param fqn The FQN of the parent
 86    * @return Set<String>. A list of children. Returns null if no children nodes are present, or the parent is
 87    * not present
 88    */
 89  0 public Set getChildrenNames(Fqn fqn) throws Exception
 90    {
 91  0 getChildrenNamesCount++;
 92  0 return null;
 93    }
 94   
 95    /**
 96    * Returns the value for a given key. Returns null if the node doesn't exist, or the value is not bound
 97    *
 98    * @param name
 99    * @return
 100    * @throws Exception
 101    */
 102  0 public Object get(Fqn name, Object key) throws Exception
 103    {
 104  0 getCount++;
 105  0 return null;
 106    }
 107   
 108    /**
 109    * Returns all keys and values from the persistent store, given a fully qualified name
 110    *
 111    * @param name
 112    * @return Map<Object,Object> of keys and values for the given node. Returns null if the node was not found, or
 113    * if the node has no attributes
 114    * @throws Exception
 115    */
 116  4 public Map get(Fqn name) throws Exception
 117    {
 118  4 getCount++;
 119  4 return null;
 120    }
 121   
 122    /**
 123    * Checks whether the CacheLoader has a node with Fqn
 124    *
 125    * @param name
 126    * @return True if node exists, false otherwise
 127    */
 128  0 public boolean exists(Fqn name) throws Exception
 129    {
 130  0 existsCount++;
 131  0 return false;
 132    }
 133   
 134    /**
 135    * Inserts key and value into the attributes hashmap of the given node. If the node does not exist, all
 136    * parent nodes from the root down are created automatically. Returns the old value
 137    */
 138  3 public Object put(Fqn name, Object key, Object value) throws Exception
 139    {
 140  3 putCount++;
 141  3 return null;
 142    }
 143   
 144    /**
 145    * Inserts all elements of attributes into the attributes hashmap of the given node, overwriting existing
 146    * attributes, but not clearing the existing hashmap before insertion (making it a union of existing and
 147    * new attributes)
 148    * If the node does not exist, all parent nodes from the root down are created automatically
 149    *
 150    * @param name The fully qualified name of the node
 151    * @param attributes A Map of attributes. Can be null
 152    */
 153  0 public void put(Fqn name, Map attributes) throws Exception
 154    {
 155  0 putCount++;
 156    }
 157   
 158    /**
 159    * Inserts all modifications to the backend store. Overwrite whatever is already in
 160    * the datastore.
 161    *
 162    * @param modifications A List<Modification> of modifications
 163    * @throws Exception
 164    */
 165  20000 public void put(List<Modification> modifications) throws Exception
 166    {
 167  20000 putCount++;
 168    }
 169   
 170    /**
 171    * Removes the given key and value from the attributes of the given node. No-op if node doesn't exist
 172    */
 173  1 public Object remove(Fqn name, Object key) throws Exception
 174    {
 175  1 removeCount++;
 176  1 return null;
 177    }
 178   
 179    /**
 180    * Removes the given node. If the node is the root of a subtree, this will recursively remove all subnodes,
 181    * depth-first
 182    */
 183  0 public void remove(Fqn name) throws Exception
 184    {
 185  0 removeCount++;
 186    }
 187   
 188    /**
 189    * Removes all attributes from a given node, but doesn't delete the node itself
 190    *
 191    * @param name
 192    * @throws Exception
 193    */
 194  0 public void removeData(Fqn name) throws Exception
 195    {
 196  0 removeCount++;
 197    }
 198   
 199    /**
 200    * Prepare the modifications. For example, for a DB-based CacheLoader:
 201    * <ol>
 202    * <li>Create a local (JDBC) transaction
 203    * <li>Associate the local transaction with <code>tx</code> (tx is the key)
 204    * <li>Execute the coresponding SQL statements against the DB (statements derived from modifications)
 205    * </ol>
 206    * For non-transactional CacheLoader (e.g. file-based), this could be a null operation
 207    *
 208    * @param tx The transaction, just used as a hashmap key
 209    * @param modifications List<Modification>, a list of all modifications within the given transaction
 210    * @param one_phase Persist immediately and (for example) commit the local JDBC transaction as well. When true,
 211    * we won't get a {@link #commit(Object)} or {@link #rollback(Object)} method call later
 212    * @throws Exception
 213    */
 214  20000 public void prepare(Object tx, List<Modification> modifications, boolean one_phase) throws Exception
 215    {
 216  20000 if (one_phase)
 217    {
 218  0 put(modifications);
 219    }
 220    else
 221    {
 222  20000 m_transactions.put(tx, modifications);
 223    }
 224    }
 225   
 226    /**
 227    * Commit the transaction. A DB-based CacheLoader would look up the local JDBC transaction asociated
 228    * with <code>tx</code> and commit that transaction<br/>
 229    * Non-transactional CacheLoaders could simply write the data that was previously saved transiently under the
 230    * given <code>tx</code> key, to (for example) a file system (note this only holds if the previous prepare() did
 231    * not define one_phase=true
 232    *
 233    * @param tx
 234    */
 235  20000 public void commit(Object tx) throws Exception
 236    {
 237  20000 List modifications = (List) m_transactions.get(tx);
 238  20000 if (modifications == null)
 239    {
 240  0 return;
 241    }
 242  20000 put(modifications);
 243  20000 m_transactions.remove(tx);
 244    }
 245   
 246    /**
 247    * Roll the transaction back. A DB-based CacheLoader would look up the local JDBC transaction asociated
 248    * with <code>tx</code> and roll back that transaction
 249    *
 250    * @param tx
 251    */
 252  0 public void rollback(Object tx)
 253    {
 254  0 List modifications = (List) m_transactions.get(tx);
 255  0 if (modifications == null)
 256    {
 257  0 return;
 258    }
 259  0 m_transactions.remove(tx);
 260    }
 261   
 262  0 public void loadEntireState(ObjectOutputStream os) throws Exception
 263    {
 264    //intentional no-op
 265    }
 266   
 267  0 public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
 268    {
 269    // intentional no-op
 270    }
 271   
 272  1 public void storeEntireState(ObjectInputStream is) throws Exception
 273    {
 274    // intentional no-op
 275    }
 276   
 277  0 public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
 278    {
 279    // intentional no-op
 280    }
 281   
 282  8 public void create() throws Exception
 283    {
 284    }
 285   
 286  8 public void start() throws Exception
 287    {
 288    }
 289   
 290  8 public void stop()
 291    {
 292    }
 293   
 294  8 public void destroy()
 295    {
 296  8 getChildrenNamesCount = 0;
 297  8 getCount = 0;
 298  8 putCount = 0;
 299  8 existsCount = 0;
 300  8 removeCount = 0;
 301    }
 302    }