Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 208   Methods: 20
NCLOC: 133   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DelegatingCacheLoader.java 60% 75% 85% 75.9%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 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.apache.commons.logging.Log;
 10    import org.apache.commons.logging.LogFactory;
 11    import org.jboss.cache.Fqn;
 12    import org.jboss.cache.Modification;
 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    * CacheLoader implementation which delegates to another CacheImpl. This allows to stack caches on top of each
 23    * other, allowing for hierarchical cache levels. For example, first level cache delegates to a second level cache,
 24    * which delegates to a persistent cache.
 25    *
 26    * @author Bela Ban
 27    * @author Daniel Gredler
 28    * @version $Id: DelegatingCacheLoader.java,v 1.13 2006/12/30 17:50:01 msurtani Exp $
 29    */
 30    public abstract class DelegatingCacheLoader extends AbstractCacheLoader
 31    {
 32    Log log = LogFactory.getLog(getClass());
 33    /**
 34    * HashMap<Object,List<Modification>>. List of open transactions. Note that this is purely transient, as
 35    * we don't use a log, recovery is not available
 36    */
 37    HashMap<Object, List<Modification>> transactions = new HashMap<Object, List<Modification>>();
 38   
 39    public static final int delegateGetChildrenNames = 1;
 40    public static final int delegateGetKey = 2;
 41    public static final int delegateGet = 3;
 42    public static final int delegateExists = 4;
 43    public static final int delegatePutKeyVal = 5;
 44    public static final int delegatePut = 6;
 45    public static final int delegateRemoveKey = 7;
 46    public static final int delegateRemove = 8;
 47    public static final int delegateRemoveData = 9;
 48    public static final int delegateLoadEntireState = 10;
 49    public static final int delegateStoreEntireState = 11;
 50    public static final int putList = 12;
 51   
 52  2153 public Set<String> getChildrenNames(Fqn fqn) throws Exception
 53    {
 54  2153 Set<String> retval = delegateGetChildrenNames(fqn);
 55  2153 return retval == null ? null : (retval.size() == 0 ? null : retval);
 56    }
 57   
 58    // See http://jira.jboss.com/jira/browse/JBCACHE-118 for why this is commented out.
 59   
 60    // public Object get(Fqn name, Object key) throws Exception {
 61    // return delegateGet(name, key);
 62    // }
 63   
 64  2837 public Map get(Fqn name) throws Exception
 65    {
 66    // See http://jira.jboss.com/jira/browse/JBCACHE-118
 67  2837 return delegateGet(name);
 68    }
 69   
 70  426 public boolean exists(Fqn name) throws Exception
 71    {
 72  426 return delegateExists(name);
 73    }
 74   
 75  2295 public Object put(Fqn name, Object key, Object value) throws Exception
 76    {
 77  2295 return delegatePut(name, key, value);
 78    }
 79   
 80  2194 public void put(Fqn name, Map attributes) throws Exception
 81    {
 82  2194 delegatePut(name, attributes);
 83    }
 84   
 85   
 86  0 public void put(Fqn fqn, Map attributes, boolean erase) throws Exception
 87    {
 88  0 if (erase)
 89    {
 90  0 removeData(fqn);
 91    }
 92  0 put(fqn, attributes);
 93    }
 94   
 95  2070 public Object remove(Fqn name, Object key) throws Exception
 96    {
 97  2070 return delegateRemove(name, key);
 98    }
 99   
 100  2450 public void remove(Fqn name) throws Exception
 101    {
 102  2450 delegateRemove(name);
 103    }
 104   
 105  13 public void removeData(Fqn name) throws Exception
 106    {
 107  13 delegateRemoveData(name);
 108    }
 109   
 110  13 public void prepare(Object tx, List<Modification> modifications, boolean one_phase) throws Exception
 111    {
 112  13 if (one_phase)
 113    {
 114  3 put(modifications);
 115    }
 116    else
 117    {
 118  10 transactions.put(tx, modifications);
 119    }
 120    }
 121   
 122  7 public void commit(Object tx) throws Exception
 123    {
 124  7 List modifications = transactions.get(tx);
 125  7 if (modifications == null)
 126    {
 127  0 throw new Exception("transaction " + tx + " not found in transaction table");
 128    }
 129  7 put(modifications);
 130    }
 131   
 132  3 public void rollback(Object tx)
 133    {
 134  3 transactions.remove(tx);
 135    }
 136   
 137  9 public void loadEntireState(ObjectOutputStream os) throws Exception
 138    {
 139  9 delegateLoadEntireState(os);
 140   
 141    }
 142   
 143  0 public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
 144    {
 145  0 delegateLoadState(subtree, os);
 146    }
 147   
 148  1 public void storeEntireState(ObjectInputStream is) throws Exception
 149    {
 150  1 delegateStoreEntireState(is);
 151    }
 152   
 153  0 public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
 154    {
 155  0 delegateStoreState(subtree, is);
 156    }
 157   
 158  170 public void create() throws Exception
 159    {
 160    // Empty.
 161    }
 162   
 163  106 public void start() throws Exception
 164    {
 165    // Empty.
 166    }
 167   
 168  106 public void stop()
 169    {
 170    // Empty.
 171    }
 172   
 173  170 public void destroy()
 174    {
 175    // Empty.
 176    }
 177   
 178    /*------------------------------ Delegating Methods ------------------------------*/
 179   
 180   
 181    protected abstract Set delegateGetChildrenNames(Fqn fqn) throws Exception;
 182   
 183    // See http://jira.jboss.com/jira/browse/JBCACHE-118 for why this is commented out.
 184   
 185    // protected abstract Object delegateGet(Fqn name, Object key) throws Exception;
 186   
 187    protected abstract Map delegateGet(Fqn name) throws Exception;
 188   
 189    protected abstract boolean delegateExists(Fqn name) throws Exception;
 190   
 191    protected abstract Object delegatePut(Fqn name, Object key, Object value) throws Exception;
 192   
 193    protected abstract void delegatePut(Fqn name, Map attributes) throws Exception;
 194   
 195    protected abstract Object delegateRemove(Fqn name, Object key) throws Exception;
 196   
 197    protected abstract void delegateRemove(Fqn name) throws Exception;
 198   
 199    protected abstract void delegateRemoveData(Fqn name) throws Exception;
 200   
 201    protected abstract void delegateLoadEntireState(ObjectOutputStream os) throws Exception;
 202   
 203    protected abstract void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception;
 204   
 205    protected abstract void delegateStoreEntireState(ObjectInputStream is) throws Exception;
 206   
 207    protected abstract void delegateStoreState(Fqn subtree, ObjectInputStream is) throws Exception;
 208    }