1 21 package oracle.toplink.essentials.internal.sessions; 23 24 import java.util.*; 25 import oracle.toplink.essentials.internal.identitymaps.*; 26 import oracle.toplink.essentials.queryframework.*; 27 import oracle.toplink.essentials.expressions.*; 28 import oracle.toplink.essentials.exceptions.*; 29 import oracle.toplink.essentials.internal.sessions.AbstractSession; 30 import oracle.toplink.essentials.descriptors.ClassDescriptor; 31 import oracle.toplink.essentials.sessions.Record; 32 import oracle.toplink.essentials.logging.SessionLog; 33 import oracle.toplink.essentials.internal.helper.WriteLockManager; 34 import oracle.toplink.essentials.internal.queryframework.JoinedAttributeManager; 35 36 45 public class IsolatedClientSessionIdentityMapAccessor extends oracle.toplink.essentials.internal.sessions.IdentityMapAccessor { 46 47 52 public IsolatedClientSessionIdentityMapAccessor(AbstractSession session, IdentityMapManager identityMapManager) { 53 super(session, identityMapManager); 54 } 55 56 61 public CacheKey acquireDeferredLock(Vector primaryKey, Class javaClass, ClassDescriptor descriptor) { 62 if (descriptor.isIsolated()) { 63 return getIdentityMapManager().acquireDeferredLock(primaryKey, javaClass, descriptor); 64 } else { 65 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireDeferredLock(primaryKey, javaClass, descriptor); 66 } 67 } 68 69 75 public CacheKey acquireLock(Vector primaryKey, Class domainClass, boolean forMerge, ClassDescriptor descriptor) { 76 if (descriptor.isIsolated()) { 77 return getIdentityMapManager().acquireLock(primaryKey, domainClass, forMerge, descriptor); 78 } else { 79 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireLock(primaryKey, domainClass, forMerge, descriptor); 80 } 81 } 82 83 89 public CacheKey acquireLockNoWait(Vector primaryKey, Class domainClass, boolean forMerge, ClassDescriptor descriptor) { 90 if (descriptor.isIsolated()) { 91 return getIdentityMapManager().acquireLockNoWait(primaryKey, domainClass, forMerge, descriptor); 92 } else { 93 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireLockNoWait(primaryKey, domainClass, forMerge, descriptor); 94 } 95 } 96 97 103 public CacheKey acquireReadLockOnCacheKey(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { 104 if (descriptor.isIsolated()) { 105 return getIdentityMapManager().acquireReadLockOnCacheKey(primaryKey, domainClass, descriptor); 106 } else { 107 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireReadLockOnCacheKey(primaryKey, domainClass, descriptor); 108 } 109 } 110 111 118 public CacheKey acquireReadLockOnCacheKeyNoWait(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { 119 if (descriptor.isIsolated()) { 120 return getIdentityMapManager().acquireReadLockOnCacheKeyNoWait(primaryKey, domainClass, descriptor); 121 } else { 122 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireReadLockOnCacheKeyNoWait(primaryKey, domainClass, descriptor); 123 } 124 } 125 126 132 public boolean acquireWriteLock() { 133 getIdentityMapManager().acquireWriteLock(); 134 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().acquireWriteLock(); 136 } 137 138 142 public boolean containsKey(Vector key, Class theClass, ClassDescriptor descriptor) { 143 if (descriptor.isIsolated()) { 144 return getIdentityMapManager().containsKey(key, theClass, descriptor); 145 } else { 146 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().containsKey(key, theClass, descriptor); 147 } 148 } 149 150 154 public boolean containsObjectInIdentityMap(Vector primaryKey, Class theClass, ClassDescriptor descriptor) { 155 if (descriptor.isIsolated()) { 156 return getIdentityMapManager().containsKey(primaryKey, theClass, descriptor); 157 } else { 158 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().containsObjectInIdentityMap(primaryKey, theClass, descriptor); 159 } 160 } 161 162 166 public Vector getClassesRegistered() { 167 Vector results = getIdentityMapManager().getClassesRegistered(); 168 results.addAll(((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getClassesRegistered()); 169 return results; 170 } 171 172 178 public Vector getAllFromIdentityMap(Expression selectionCriteria, Class theClass, Record translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean shouldReturnInvalidatedObjects) throws QueryException { 179 if (session.getDescriptor(theClass).isIsolated()) { 180 return getIdentityMapManager().getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, shouldReturnInvalidatedObjects); 181 } else { 182 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, shouldReturnInvalidatedObjects); 183 } 184 } 185 186 193 public CacheKey getCacheKeyForObject(Vector primaryKey, Class myClass, ClassDescriptor descriptor) { 194 if (descriptor.isIsolated()) { 195 return getIdentityMapManager().getCacheKeyForObject(primaryKey, myClass, descriptor); 196 } else { 197 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, myClass, descriptor); 198 } 199 } 200 201 205 public Object getFromIdentityMap(Vector primaryKey, Class theClass, ClassDescriptor descriptor, JoinedAttributeManager joinedAttributeManager) { 206 if (descriptor.isIsolated()) { 207 return getIdentityMapManager().getFromIdentityMap(primaryKey, theClass, descriptor); 208 } else { 209 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, theClass, descriptor, joinedAttributeManager); 210 } 211 } 212 213 219 public Object getFromIdentityMap(Expression selectionCriteria, Class theClass, Record translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean conforming, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor) { 220 if (descriptor.isIsolated()) { 221 return getIdentityMapManager().getFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, conforming, shouldReturnInvalidatedObjects, descriptor); 222 } else { 223 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, conforming, shouldReturnInvalidatedObjects, descriptor); 224 } 225 } 226 227 232 public Object getFromIdentityMapWithDeferredLock(Vector primaryKey, Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor) { 233 if (descriptor.isIsolated()) { 234 return getIdentityMapManager().getFromIdentityMapWithDeferredLock(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor); 235 } else { 236 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getFromIdentityMapWithDeferredLock(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor); 237 } 238 } 239 240 246 public IdentityMapManager getIdentityMapManager() { 247 return identityMapManager; 248 } 249 250 254 public IdentityMap getIdentityMap(ClassDescriptor descriptor) { 255 if (descriptor.isIsolated()) { 256 return getIdentityMapManager().getIdentityMap(descriptor); 257 } else { 258 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getIdentityMap(descriptor); 259 } 260 } 261 262 268 public long getRemainingValidTime(Object object) { 269 ClassDescriptor descriptor = getSession().getDescriptor(object); 270 CacheKey key = this.getCacheKeyForObject(object, descriptor); 271 if (key == null) { 272 throw QueryException.objectDoesNotExistInCache(object); 273 } 274 return descriptor.getCacheInvalidationPolicy().getRemainingValidTime(key); 275 } 276 277 281 public AbstractSession getSession() { 282 return session; 283 } 284 285 290 public Object getWrapper(Vector primaryKey, Class theClass) { 291 if (session.getDescriptor(theClass).isIsolated()) { 292 return getIdentityMapManager().getWrapper(primaryKey, theClass); 293 } else { 294 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getWrapper(primaryKey, theClass); 295 } 296 } 297 298 302 public WriteLockManager getWriteLockManager() { 303 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getWriteLockManager(); 306 } 307 308 312 public Object getWriteLockValue(Vector primaryKey, Class theClass, ClassDescriptor descriptor) { 313 if (descriptor.isIsolated()) { 314 return getIdentityMapManager().getWriteLockValue(primaryKey, theClass, descriptor); 315 } else { 316 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, theClass, descriptor); 317 } 318 } 319 320 329 public void initializeAllIdentityMaps() { 330 getSession().log(SessionLog.FINER, SessionLog.CACHE, "initialize_all_local_identitymaps"); 331 getIdentityMapManager().initializeIdentityMaps(); 332 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().initializeIdentityMaps(); 333 } 334 335 342 public void initializeIdentityMap(Class theClass) { 343 getSession().log(SessionLog.FINER, SessionLog.CACHE, "initialize_identitymap", theClass); 344 if (session.getDescriptor(theClass).isIsolated()) { 345 getIdentityMapManager().initializeIdentityMap(theClass); 346 } else { 347 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().initializeIdentityMap(theClass); 348 } 349 } 350 351 359 public void initializeIdentityMaps() { 360 getSession().log(SessionLog.FINER, SessionLog.CACHE, "initialize_identitymaps"); 361 getIdentityMapManager().initializeIdentityMaps(); 362 getSession().getCommitManager().reinitialize(); 363 } 364 365 370 public void printIdentityMap(Class businessClass) { 371 if (getSession().shouldLog(SessionLog.SEVERE, SessionLog.CACHE)) { 372 if (session.getDescriptor(businessClass).isIsolated()) { 373 getIdentityMapManager().printIdentityMap(businessClass); 374 } else { 375 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().printIdentityMap(businessClass); 376 } 377 } 378 } 379 380 385 public void printIdentityMaps() { 386 if (getSession().shouldLog(SessionLog.SEVERE, SessionLog.CACHE)) { 387 getIdentityMapManager().printIdentityMaps(); 388 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().printIdentityMaps(); 389 } 390 } 391 392 397 public void printIdentityMapLocks() { 398 if (getSession().shouldLog(SessionLog.FINEST, SessionLog.CACHE)) { 399 getIdentityMapManager().printLocks(); 400 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().printIdentityMapLocks(); 401 } 402 } 403 404 410 public CacheKey internalPutInIdentityMap(Object domainObject, Vector key, Object writeLockValue, long readTime, ClassDescriptor descriptor) { 411 if (descriptor.isIsolated()) { 413 return getIdentityMapManager().putInIdentityMap(domainObject, key, writeLockValue, readTime, descriptor); 414 } else { 415 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().internalPutInIdentityMap(domainObject, key, writeLockValue, readTime, descriptor); 416 } 417 } 418 419 425 public void releaseWriteLock() { 426 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().releaseWriteLock(); 428 getIdentityMapManager().releaseWriteLock(); 429 } 430 431 435 public Object removeFromIdentityMap(Vector key, Class theClass, ClassDescriptor descriptor) { 436 if (descriptor.isIsolated()) { 437 return getIdentityMapManager().removeFromIdentityMap(key, theClass, descriptor); 438 } else { 439 return ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().removeFromIdentityMap(key, theClass, descriptor); 440 } 441 } 442 443 447 public void setIdentityMapManager(IdentityMapManager identityMapManager) { 448 this.identityMapManager = identityMapManager; 449 } 450 451 456 public void setWrapper(Vector primaryKey, Class theClass, Object wrapper) { 457 if (getSession().getDescriptor(theClass).isIsolated()) { 458 getIdentityMapManager().setWrapper(primaryKey, theClass, wrapper); 459 } else { 460 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().setWrapper(primaryKey, theClass, wrapper); 461 } 462 } 463 464 468 public void updateWriteLockValue(Vector primaryKey, Class theClass, Object writeLockValue) { 469 if (getSession().getDescriptor(theClass).isIsolated()) { 470 getIdentityMapManager().setWriteLockValue(primaryKey, theClass, writeLockValue); 471 } else { 472 ((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().updateWriteLockValue(primaryKey, theClass, writeLockValue); 473 } 474 } 475 } 476 | Popular Tags |