1 2 12 package com.versant.core.jdo; 13 14 import java.lang.ref.Reference ; 15 import java.lang.ref.ReferenceQueue ; 16 17 import com.versant.core.common.*; 18 19 24 public class PMCacheEntry { 25 26 29 private Object ref; 30 33 public PMCacheEntry processListNext; 34 public PMCacheEntry processListPrev; 35 36 public PMCacheEntry next; 37 public PMCacheEntry prev; 38 39 public int hash; 40 46 private int type; 47 50 public OID mappedOID; 51 52 public PMCacheEntry() { 53 } 54 55 public PMCacheEntry(int type, PCStateMan sm, ReferenceQueue queue) { 56 LocalPMCache.checkRefType(type); 57 this.type = type; 58 if (sm.oid.getRealOID() == null) { 59 this.hash = sm.oid.hashCode(); 60 this.mappedOID = sm.oid; 61 } else { 62 this.mappedOID = sm.oid.getRealOID(); 63 this.hash = sm.oid.getRealOID().hashCode(); 64 } 65 66 switch (type) { 67 case VersantPersistenceManager.PM_CACHE_REF_TYPE_STRONG: 68 ref = sm; 69 break; 70 case VersantPersistenceManager.PM_CACHE_REF_TYPE_SOFT: 71 ref = new SoftCacheEntryRef(sm, queue, this); 72 break; 73 case VersantPersistenceManager.PM_CACHE_REF_TYPE_WEAK: 74 ref = new WeakCacheEntryRef(sm, queue, this); 75 break; 76 default: 77 throw BindingSupportImpl.getInstance().internal("Unknown option: " + type); 78 } 79 } 80 81 public PMCacheEntry(int type, OID oid, State state, ReferenceQueue queue) { 82 LocalPMCache.checkRefType(type); 83 this.type = type; 84 this.hash = oid.hashCode(); 85 this.mappedOID = oid; 86 if (mappedOID == null) { 87 throw BindingSupportImpl.getInstance().internal(""); 88 } 89 switch (type) { 90 case VersantPersistenceManager.PM_CACHE_REF_TYPE_STRONG: 91 ref = state; 92 break; 93 case VersantPersistenceManager.PM_CACHE_REF_TYPE_SOFT: 94 ref = new SoftCacheEntryRef(state, queue, this); 95 break; 96 case VersantPersistenceManager.PM_CACHE_REF_TYPE_WEAK: 97 ref = new WeakCacheEntryRef(state, queue, this); 98 break; 99 default: 100 throw BindingSupportImpl.getInstance().internal("Unknown option: " + type); 101 } 102 } 103 104 public void unlinkProcessList() { 105 if (processListNext != null) { 106 processListNext.processListPrev = null; 107 } 108 if (processListPrev != null) { 109 processListPrev.processListNext = null; 110 } 111 112 processListNext = null; 113 processListPrev = null; 114 } 115 116 public void unlinkNextList() { 117 if (prev != null) { 118 prev.next = next; 119 } 120 if (next != null) { 121 next.prev = prev; 122 } 123 next = null; 124 prev = null; 125 } 126 127 130 public PCStateMan upgradeToSm(PCStateMan sm, ReferenceQueue queue) { 131 sm.cacheEntry = this; 132 switch (type) { 133 case VersantPersistenceManager.PM_CACHE_REF_TYPE_STRONG: 134 ref = sm; 135 break; 136 case VersantPersistenceManager.PM_CACHE_REF_TYPE_SOFT: 137 ((Reference )ref).clear(); 138 ref = new SoftCacheEntryRef(sm, queue, this); 139 break; 140 case VersantPersistenceManager.PM_CACHE_REF_TYPE_WEAK: 141 ((Reference )ref).clear(); 142 ref = new WeakCacheEntryRef(sm, queue, this); 143 break; 144 default: 145 throw BindingSupportImpl.getInstance().internal("Unknown option: " + type); 146 } 147 return sm; 148 } 149 150 public void setNext(PMCacheEntry nextEntry) { 151 if (Debug.DEBUG) { 152 if (nextEntry == this) { 153 throw BindingSupportImpl.getInstance().internal(""); 154 } 155 } 156 next = nextEntry; 157 if (next != null) { 158 next.prev = this; 159 } 160 } 161 162 public int hashCode() { 163 return hash; 164 } 165 166 169 public void reHash(OID newOID) { 170 mappedOID = newOID; 171 hash = newOID.hashCode(); 172 } 173 174 178 public Object get() { 179 if (ref instanceof Reference ) { 180 return ((Reference )ref).get(); 181 } 182 return ref; 183 } 184 185 public boolean hasReference(Object obj) { 186 return (obj == ref); 187 } 188 189 public void clear() { 190 if (ref instanceof Reference ) { 191 ((Reference )ref).clear(); 192 } 193 ref = null; 194 } 195 196 public void reset() { 197 clear(); 198 next = null; 199 prev = null; 200 processListNext = null; 201 processListPrev = null; 202 } 203 204 public String toString() { 205 return "CacheEntryBase@" + System.identityHashCode(this) + " oid " + (mappedOID == null ? "null" : mappedOID.toStringImp()); 206 } 207 208 public void changeToRefType(ReferenceQueue queue, int newType) { 209 LocalPMCache.checkRefType(newType); 210 211 if (this.type == newType) return; 212 Object oldRef = get(); 213 clear(); 214 215 this.type = newType; 216 switch (newType) { 217 case VersantPersistenceManager.PM_CACHE_REF_TYPE_STRONG: 218 ref = oldRef; 219 break; 220 case VersantPersistenceManager.PM_CACHE_REF_TYPE_SOFT: 221 ref = new SoftCacheEntryRef(oldRef, queue, this); 222 break; 223 case VersantPersistenceManager.PM_CACHE_REF_TYPE_WEAK: 224 ref = new WeakCacheEntryRef(oldRef, queue, this); 225 break; 226 default: 227 throw BindingSupportImpl.getInstance().internal("Unknown option: " + type); 228 } 229 } 230 } 231 | Popular Tags |