1 4 package com.tc.object.tx.optimistic; 5 6 import com.tc.object.TCObject; 7 import com.tc.object.bytecode.Manageable; 8 import com.tc.object.bytecode.ManagerUtil; 9 import com.tc.object.change.TCChangeBuffer; 10 import com.tc.object.change.TCChangeBufferImpl; 11 12 import java.util.HashMap ; 13 import java.util.IdentityHashMap ; 14 import java.util.Map ; 15 16 public class OptimisticTransaction { 17 private final Map objectChanges = new HashMap (); 18 private final Map clones = new IdentityHashMap (); 19 20 public boolean hasClone(Object obj) { 21 return clones.containsValue(obj); 22 } 23 24 public TCObject getTCObjectFor(Object obj) { 25 if (obj.getClass().isArray()) { 26 return ManagerUtil.getObject(obj); 27 } else { 28 return ((Manageable) obj).__tc_managed(); 29 } 30 } 31 32 public void addAll(Map newClones) { 33 clones.putAll(newClones); 34 } 35 36 public boolean hasChanges() { 37 return !objectChanges.isEmpty(); 38 } 39 40 public Map getChangeBuffers() { 41 return this.objectChanges; 42 } 43 44 public void objectFieldChanged(TCObject source, String classname, String fieldname, Object newValue, int index) { 45 getOrCreateChangeBuffer(source).fieldChanged(classname, fieldname, newValue, index); 46 } 47 48 public void logicalInvoke(TCObject source, int method, Object [] parameters) { 49 getOrCreateChangeBuffer(source).logicalInvoke(method, parameters); 50 } 51 52 private TCChangeBuffer getOrCreateChangeBuffer(TCObject object) { 53 54 TCChangeBuffer cb = (TCChangeBuffer) objectChanges.get(object); 55 if (cb == null) { 56 cb = new TCChangeBufferImpl(object); 57 objectChanges.put(object, cb); 58 } 59 60 return cb; 61 } 62 } 63 | Popular Tags |