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.Hashtable ; 23 import java.util.Map ; 24 25 public class DetachSCOHashtable extends Hashtable implements Serializable , VersantSimpleSCO { 26 27 private PersistenceCapable owner; 28 private VersantStateManager stateManager; 29 private int fieldNo; 30 31 private DetachSCOHashtable(PersistenceCapable owner, 32 VersantFieldMetaData fmd) { 33 this.owner = owner; 34 this.fieldNo = fmd.getManagedFieldNo(); 35 } 36 37 public DetachSCOHashtable(PersistenceCapable owner, VersantStateManager stateManager, 38 VersantFieldMetaData fmd, Map beforeMap) { 39 this(owner, fmd); 40 putAll(beforeMap); 41 this.stateManager = stateManager; 42 } 43 44 public DetachSCOHashtable(PersistenceCapable owner, VersantStateManager stateManager, 45 VersantFieldMetaData fmd, MapData mapData) { 46 this(owner, fmd); 47 int n = mapData.entryCount; 48 Object [] keys = mapData.keys; 49 Object [] values = mapData.values; 50 for (int i = 0; i < n; i++) { 51 put(keys[i], values[i]); 52 } 53 this.stateManager = stateManager; 54 } 55 56 public Object put(Object key, Object value) { 57 makeDirty(); 58 return super.put(key, value); 59 } 60 61 public Object remove(Object key) { 62 return checkModified(super.remove(key)); 63 } 64 65 public void putAll(Map t) { 66 makeDirty(); 67 super.putAll(t); 68 } 69 70 public void clear() { 71 final int size = size(); 72 super.clear(); 73 if (size != 0) makeDirty(); 74 } 75 76 private void makeDirty() { 77 if (stateManager != null && owner != null) { 78 stateManager.makeDirty(owner, fieldNo); 79 } 80 } 81 82 private Object checkModified(Object obj) { 83 if (obj != null) { 84 makeDirty(); 85 } 86 return obj; 87 } 88 89 public void makeTransient() { 90 owner = null; 91 stateManager = null; 92 } 93 } 94 | Popular Tags |