1 2 12 package com.versant.core.jdo; 13 14 import com.versant.core.common.OID; 15 import com.versant.core.common.State; 16 17 import java.util.HashSet ; 18 import java.util.Collection ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import com.versant.core.common.BindingSupportImpl; 23 24 27 public class AttachStateContainer { 28 29 private static final int INITIAL_SIZE = 16; 30 31 private OID[] oids = new OID[INITIAL_SIZE]; 32 private VersantDetachable[] detachables = new VersantDetachable[INITIAL_SIZE]; 33 private PCStateMan[] stateMans = new PCStateMan[INITIAL_SIZE]; 34 private Map oidMap = new HashMap (); 35 private int capacity = INITIAL_SIZE; 36 private int size; 37 private VersantPersistenceManagerImp pm; 38 private HashSet deleted = new HashSet (); 39 40 public AttachStateContainer(VersantPersistenceManagerImp pm) { 41 this.pm = pm; 42 } 43 44 public int addVersantDetachable(VersantDetachable detachable) { 45 VersantDetachedStateManager sm = detachable.versantGetDetachedStateManager(); 46 if (sm != null) { 47 Collection delOIDs = ((VersantDetachedStateManager)sm).versantGetDeleted(); 48 if (!delOIDs.isEmpty()) { 49 deleted.addAll(delOIDs); 50 delOIDs.clear(); 51 } 52 } 53 OID oid = pm.getOID(detachable); 54 Integer integer = (Integer )oidMap.get(oid); 55 if (integer != null) { 56 int index = integer.intValue(); 57 VersantDetachable oldDetachable = detachables[index]; 58 if (oldDetachable == detachable) return index; 59 if (detachable.versantIsDirty()) { 60 if (oldDetachable.versantIsDirty()) { 61 throw BindingSupportImpl.getInstance().concurrentUpdate("Duplicate oid(" + 62 oid + ") in attach graph", oid); 63 } else { 64 detachables[index] = detachable; 65 } 66 } else { 67 return index; 68 } 69 } 70 if (size == capacity) { 71 capacity = (capacity * 3) / 2 + 1; 72 VersantDetachable[] nd = new VersantDetachable[capacity]; 73 System.arraycopy(detachables, 0, nd, 0, size); 74 detachables = nd; 75 OID[] noids = new OID[capacity]; 76 System.arraycopy(oids, 0, noids, 0, size); 77 oids = noids; 78 PCStateMan[] nsm = new PCStateMan[capacity]; 79 System.arraycopy(stateMans, 0, nsm, 0, size); 80 stateMans = nsm; 81 } 82 oids[size] = oid; 83 detachables[size] = detachable; 84 oidMap.put(oid, new Integer (size)); 85 return size++; 86 } 87 88 public int getDetachedSize() { 89 return size; 90 } 91 92 public VersantDetachable getVersantDetachable(int c) { 93 return detachables[c]; 94 } 95 96 public OID[] getOIDs() { 97 return oids; 98 } 99 100 public State getState(int c) { 101 return null; 102 } 103 104 public OID getOID(int c) { 105 return oids[c]; 106 } 107 108 public State getState(int c, 109 VersantPersistenceManagerImp pm) { 110 return pm.getStateFromLocalCacheById(getOID(c)); 111 112 } 113 114 public void addPCStateMan(OID oid, PCStateMan sm) { 115 Integer integer = (Integer )oidMap.get(oid); 116 if (integer != null) { 117 stateMans[integer.intValue()] = sm; 118 } 119 } 120 121 public HashSet getDeleted() { 122 return deleted; 123 } 124 } 125 | Popular Tags |