1 2 12 package com.versant.core.jdo.sco.detached; 13 14 import com.versant.core.jdo.VersantStateManager; 15 import com.versant.core.common.VersantFieldMetaData; 16 import com.versant.core.jdo.sco.VersantSimpleSCO; 17 import com.versant.core.jdo.sco.MapData; 18 import com.versant.core.jdo.VersantStateManager; 19 20 import javax.jdo.spi.PersistenceCapable; 21 import java.io.Serializable ; 22 import java.util.Map ; 23 import java.util.TreeMap ; 24 25 28 public class DetachSCOTreeMap extends TreeMap implements Serializable , VersantSimpleSCO { 29 30 private PersistenceCapable owner; 31 private VersantStateManager stateManager; 32 private int fieldNo; 33 34 private DetachSCOTreeMap(PersistenceCapable owner, 35 VersantFieldMetaData fmd) { 36 super(fmd.getComparator()); 37 this.owner = owner; 38 this.fieldNo = fmd.getManagedFieldNo(); 39 } 40 41 public DetachSCOTreeMap(PersistenceCapable owner, VersantStateManager stateManager, 42 VersantFieldMetaData fmd, Map beforeMap) { 43 this(owner, fmd); 44 putAll(beforeMap); 45 this.stateManager = stateManager; 46 } 47 48 public DetachSCOTreeMap(PersistenceCapable owner, VersantStateManager stateManager, 49 VersantFieldMetaData fmd, MapData mapData) { 50 this(owner, fmd); 51 int n = mapData.entryCount; 52 Object [] keys = mapData.keys; 53 Object [] values = mapData.values; 54 for (int i = 0; i < n; i++) { 55 put(keys[i], values[i]); 56 } 57 this.stateManager = stateManager; 58 } 59 60 public Class getJavaType() { 61 return TreeMap .class; 62 } 63 64 public Object remove(Object key) { 65 return checkModified(super.remove(key)); 66 } 67 68 public Object put(Object key, Object value) { 69 makeDirty(); 70 return super.put(key, value); 71 } 72 73 public void putAll(Map t) { 74 makeDirty(); 75 super.putAll(t); 76 } 77 78 public void clear() { 79 final int size = size(); 80 super.clear(); 81 if (size != 0) makeDirty(); 82 } 83 84 public Object getOwner() { 85 return owner; 86 } 87 88 public void makeTransient() { 89 owner = null; 90 stateManager = null; 91 } 92 93 public void makeDirty() { 94 if (stateManager != null && owner != null) { 95 stateManager.makeDirty(owner, fieldNo); 96 } 97 } 98 99 private Object checkModified(Object obj) { 100 if (obj != null) { 101 makeDirty(); 102 } 103 return obj; 104 } 105 } 106 | Popular Tags |