1 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 30 public abstract class DelegatingCacheLoader extends AbstractCacheLoader 31 { 32 Log log = LogFactory.getLog(getClass()); 33 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 public Set <String > getChildrenNames(Fqn fqn) throws Exception 53 { 54 Set <String > retval = delegateGetChildrenNames(fqn); 55 return retval == null ? null : (retval.size() == 0 ? null : retval); 56 } 57 58 60 64 public Map get(Fqn name) throws Exception 65 { 66 return delegateGet(name); 68 } 69 70 public boolean exists(Fqn name) throws Exception 71 { 72 return delegateExists(name); 73 } 74 75 public Object put(Fqn name, Object key, Object value) throws Exception 76 { 77 return delegatePut(name, key, value); 78 } 79 80 public void put(Fqn name, Map attributes) throws Exception 81 { 82 delegatePut(name, attributes); 83 } 84 85 86 public void put(Fqn fqn, Map attributes, boolean erase) throws Exception 87 { 88 if (erase) 89 { 90 removeData(fqn); 91 } 92 put(fqn, attributes); 93 } 94 95 public Object remove(Fqn name, Object key) throws Exception 96 { 97 return delegateRemove(name, key); 98 } 99 100 public void remove(Fqn name) throws Exception 101 { 102 delegateRemove(name); 103 } 104 105 public void removeData(Fqn name) throws Exception 106 { 107 delegateRemoveData(name); 108 } 109 110 public void prepare(Object tx, List <Modification> modifications, boolean one_phase) throws Exception 111 { 112 if (one_phase) 113 { 114 put(modifications); 115 } 116 else 117 { 118 transactions.put(tx, modifications); 119 } 120 } 121 122 public void commit(Object tx) throws Exception 123 { 124 List modifications = transactions.get(tx); 125 if (modifications == null) 126 { 127 throw new Exception ("transaction " + tx + " not found in transaction table"); 128 } 129 put(modifications); 130 } 131 132 public void rollback(Object tx) 133 { 134 transactions.remove(tx); 135 } 136 137 public void loadEntireState(ObjectOutputStream os) throws Exception 138 { 139 delegateLoadEntireState(os); 140 141 } 142 143 public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception 144 { 145 delegateLoadState(subtree, os); 146 } 147 148 public void storeEntireState(ObjectInputStream is) throws Exception 149 { 150 delegateStoreEntireState(is); 151 } 152 153 public void storeState(Fqn subtree, ObjectInputStream is) throws Exception 154 { 155 delegateStoreState(subtree, is); 156 } 157 158 public void create() throws Exception 159 { 160 } 162 163 public void start() throws Exception 164 { 165 } 167 168 public void stop() 169 { 170 } 172 173 public void destroy() 174 { 175 } 177 178 179 180 181 protected abstract Set delegateGetChildrenNames(Fqn fqn) throws Exception ; 182 183 185 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 } 209 | Popular Tags |