1 7 package org.jboss.cache; 8 9 import org.jboss.cache.config.Option; 10 import org.jboss.cache.marshall.MethodCall; 11 12 import javax.transaction.Transaction ; 13 import java.util.ArrayList ; 14 import java.util.LinkedList ; 15 import java.util.List ; 16 17 22 public class InvocationContext implements Cloneable 23 { 24 private transient List <MethodCall> cacheListenerEvents = new LinkedList <MethodCall>(); 25 private Transaction transaction; 26 private GlobalTransaction globalTransaction; 27 private Option optionOverrides; 28 private boolean originLocal = true; 30 private boolean txHasMods; 31 private boolean localRollbackOnly; 32 33 InvocationContext() 34 { 35 } 36 37 public void setLocalRollbackOnly(boolean localRollbackOnly) 38 { 39 this.localRollbackOnly = localRollbackOnly; 40 } 41 42 43 48 public Transaction getTransaction() 49 { 50 return transaction; 51 } 52 53 58 public void setTransaction(Transaction transaction) 59 { 60 this.transaction = transaction; 61 } 62 63 68 public GlobalTransaction getGlobalTransaction() 69 { 70 return globalTransaction; 71 } 72 73 78 public void setGlobalTransaction(GlobalTransaction globalTransaction) 79 { 80 this.globalTransaction = globalTransaction; 81 } 82 83 88 public Option getOptionOverrides() 89 { 90 if (optionOverrides == null) 91 { 92 optionOverrides = new Option(); 93 } 94 return optionOverrides; 95 } 96 97 102 public void setOptionOverrides(Option optionOverrides) 103 { 104 this.optionOverrides = optionOverrides; 105 } 106 107 112 public boolean isOriginLocal() 113 { 114 return originLocal; 115 } 116 117 123 public void setOriginLocal(boolean originLocal) 124 { 125 this.originLocal = originLocal; 126 } 127 128 131 public List <MethodCall> getCacheListenerEvents() 132 { 133 return new ArrayList <MethodCall>(cacheListenerEvents); 134 } 135 136 141 public void addCacheListenerEvent(MethodCall event) 142 { 143 cacheListenerEvents.add(event); 144 } 145 146 public void clearCacheListenerEvents() 147 { 148 cacheListenerEvents.clear(); 149 } 150 151 public String toString() 152 { 153 return "InvocationContext{" + 154 "transaction=" + transaction + 155 ", globalTransaction=" + globalTransaction + 156 ", optionOverrides=" + optionOverrides + 157 ", originLocal=" + originLocal + 158 ", txHasMods=" + txHasMods + 159 '}'; 160 } 161 162 public boolean isTxHasMods() 163 { 164 return txHasMods; 165 } 166 167 public void setTxHasMods(boolean b) 168 { 169 txHasMods = b; 170 } 171 172 public boolean isLocalRollbackOnly() 173 { 174 return localRollbackOnly; 175 } 176 177 180 public void reset() 181 { 182 transaction = null; 183 globalTransaction = null; 184 optionOverrides = null; 185 originLocal = true; 186 txHasMods = false; 187 cacheListenerEvents.clear(); 188 } 189 190 public InvocationContext clone() throws CloneNotSupportedException 191 { 192 InvocationContext clone = (InvocationContext) super.clone(); 193 clone.setOptionOverrides(getOptionOverrides().clone()); 194 return clone; 195 } 196 197 202 public void setState(InvocationContext template) 203 { 204 if (template == null) 205 { 206 throw new NullPointerException ("Template InvocationContext passed in to InvocationContext.setState() passed in is null"); 207 } 208 209 this.setGlobalTransaction(template.getGlobalTransaction()); 210 this.setLocalRollbackOnly(template.isLocalRollbackOnly()); 211 this.setOptionOverrides(template.getOptionOverrides()); 212 this.setOriginLocal(template.isOriginLocal()); 213 this.setTransaction(template.getTransaction()); 214 this.setTxHasMods(template.isTxHasMods()); 215 } 216 217 public boolean equals(Object o) 218 { 219 if (this == o) return true; 220 if (o == null || getClass() != o.getClass()) return false; 221 222 final InvocationContext that = (InvocationContext) o; 223 224 if (localRollbackOnly != that.localRollbackOnly) return false; 225 if (originLocal != that.originLocal) return false; 226 if (txHasMods != that.txHasMods) return false; 227 if (globalTransaction != null ? !globalTransaction.equals(that.globalTransaction) : that.globalTransaction != null) 228 { 229 return false; 230 } 231 if (optionOverrides != null ? !optionOverrides.equals(that.optionOverrides) : that.optionOverrides != null) 232 { 233 return false; 234 } 235 if (transaction != null ? !transaction.equals(that.transaction) : that.transaction != null) return false; 236 237 return true; 238 } 239 240 public int hashCode() 241 { 242 int result; 243 result = (transaction != null ? transaction.hashCode() : 0); 244 result = 29 * result + (globalTransaction != null ? globalTransaction.hashCode() : 0); 245 result = 29 * result + (optionOverrides != null ? optionOverrides.hashCode() : 0); 246 result = 29 * result + (originLocal ? 1 : 0); 247 result = 29 * result + (txHasMods ? 1 : 0); 248 result = 29 * result + (localRollbackOnly ? 1 : 0); 249 return result; 250 } 251 } 252 | Popular Tags |