1 21 package oracle.toplink.essentials.internal.sessions; 23 24 import java.util.*; 25 26 import oracle.toplink.essentials.descriptors.ClassDescriptor; 27 import oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork; 28 import oracle.toplink.essentials.internal.identitymaps.*; 29 import oracle.toplink.essentials.internal.sessions.IdentityMapAccessor; 30 import oracle.toplink.essentials.expressions.*; 31 import oracle.toplink.essentials.exceptions.*; 32 import oracle.toplink.essentials.internal.queryframework.JoinedAttributeManager; 33 import oracle.toplink.essentials.queryframework.*; 34 35 41 public class UnitOfWorkIdentityMapAccessor extends IdentityMapAccessor { 42 public UnitOfWorkIdentityMapAccessor(AbstractSession session, IdentityMapManager identityMapManager) { 43 super(session, identityMapManager); 44 } 45 46 50 public boolean containsObjectInIdentityMap(Vector primaryKey, Class theClass, ClassDescriptor descriptor) { 51 if (getIdentityMapManager().containsKey(primaryKey, theClass, descriptor)) { 52 return true; 53 } 54 return ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().containsObjectInIdentityMap(primaryKey, theClass, descriptor); 55 } 56 57 62 public Vector getAllFromIdentityMap(Expression selectionCriteria, Class theClass, AbstractRecord translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean shouldReturnInvalidatedObjects) throws QueryException { 63 return super.getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, true); 64 } 65 66 71 public Object getFromIdentityMapWithDeferredLock(Vector primaryKey, Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor) { 72 return super.getFromIdentityMapWithDeferredLock(primaryKey, theClass, true, descriptor); 73 } 74 75 83 public Object getFromIdentityMap(Vector primaryKey, Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor, JoinedAttributeManager joinedAttributeManager) { 84 Object objectFromCache = super.getFromIdentityMap(primaryKey, theClass, true, descriptor, joinedAttributeManager); 85 86 if (objectFromCache != null) { 87 return objectFromCache; 88 } 89 return getAndCloneCacheKeyFromParent(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor, joinedAttributeManager); 91 } 92 93 100 protected Object getAndCloneCacheKeyFromParent(Vector primaryKey, Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor, JoinedAttributeManager joinedAttributeManager) { 101 CacheKey cacheKey = ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, theClass, descriptor); 105 if ((cacheKey == null) && ((UnitOfWorkImpl)getSession()).getParent().isUnitOfWork()) { ((UnitOfWorkIdentityMapAccessor)((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance()).getAndCloneCacheKeyFromParent(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor, joinedAttributeManager); 108 cacheKey = ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, theClass, descriptor); 110 } 111 112 Object objectFromCache = null; 113 114 if ((cacheKey != null) && (shouldReturnInvalidatedObjects || !descriptor.getCacheInvalidationPolicy().isInvalidated(cacheKey, System.currentTimeMillis()))) { 118 synchronized (cacheKey.getMutex()) { 119 objectFromCache = cacheKey.getObject(); 125 try { 126 while (cacheKey.isAcquired() && (objectFromCache == null)) { 127 cacheKey.getMutex().wait(5); 128 } 129 } catch (InterruptedException ex) { 130 } 131 if (objectFromCache == null) { 132 return null; 133 } 134 } 135 } else { 136 return null; 137 } 138 139 if (getSession().isClassReadOnly(theClass, descriptor)) { 141 return objectFromCache; 143 } 144 145 if(getSession() instanceof RepeatableWriteUnitOfWork ) { 146 Object unregisteredDeletedClone = ((RepeatableWriteUnitOfWork)getSession()).getUnregisteredDeletedCloneForOriginal(objectFromCache); 147 if(unregisteredDeletedClone != null) { 148 return unregisteredDeletedClone; 149 } 150 } 151 152 return ((UnitOfWorkImpl)getSession()).cloneAndRegisterObject(objectFromCache, cacheKey, joinedAttributeManager); 153 } 154 155 166 public void initializeAllIdentityMaps() { 167 super.initializeAllIdentityMaps(); 168 ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessor().initializeAllIdentityMaps(); 169 } 170 } 171 | Popular Tags |