FileDocCategorySizeDatePackage
UnitOfWorkIdentityMapAccessor.javaAPI DocGlassfish v2 API9865Tue May 22 16:54:44 BST 2007oracle.toplink.essentials.internal.sessions

UnitOfWorkIdentityMapAccessor

public class UnitOfWorkIdentityMapAccessor extends IdentityMapAccessor
INTERNAL: IdentityMapAccessor subclass for UnitOfWork Overrides some initialization functionality and some behavoir having to do with getting objects from identity maps.

Fields Summary
Constructors Summary
public UnitOfWorkIdentityMapAccessor(AbstractSession session, IdentityMapManager identityMapManager)

        super(session, identityMapManager);
    
Methods Summary
public booleancontainsObjectInIdentityMap(java.util.Vector primaryKey, java.lang.Class theClass, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Return if their is an object for the primary key.

        if (getIdentityMapManager().containsKey(primaryKey, theClass, descriptor)) {
            return true;
        }
        return ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().containsObjectInIdentityMap(primaryKey, theClass, descriptor);
    
public java.util.VectorgetAllFromIdentityMap(oracle.toplink.essentials.expressions.Expression selectionCriteria, java.lang.Class theClass, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow, oracle.toplink.essentials.queryframework.InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean shouldReturnInvalidatedObjects)
INTERNAL: This method overrides the getAllFromIdentityMap method in Session. Invalidated Objects will always be returned from a UnitOfWork.

        return super.getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, true);
    
protected java.lang.ObjectgetAndCloneCacheKeyFromParent(java.util.Vector primaryKey, java.lang.Class theClass, boolean shouldReturnInvalidatedObjects, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, oracle.toplink.essentials.internal.queryframework.JoinedAttributeManager joinedAttributeManager)
INTERNAL: This method will return the object from the parent and clone it. If the uow is RepeatableWriteUnitOfWork and the original object from the parent corresponds to deleted unregistered object clone, then the latter returned.

        // Note: Objects returned from the parent's identity map should include invalidated
        // objects. This is important because this internal method is used in the existence
        // check in the UnitOfWork.
        CacheKey cacheKey = ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, theClass, descriptor);
        if ((cacheKey == null) && ((UnitOfWorkImpl)getSession()).getParent().isUnitOfWork()) {//for nested unit of work
            //make parent clone and register object
            ((UnitOfWorkIdentityMapAccessor)((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance()).getAndCloneCacheKeyFromParent(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor, joinedAttributeManager);
            //get the cachekey that was created in the parent.
            cacheKey = ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, theClass, descriptor);
        }

        Object objectFromCache = null;

        // this check could be simplfied to one line but would create a window
        // in which GC could remove the object and we would end up with a null pointer
        // as well we must inspect the cacheKey without locking on it.
        if ((cacheKey != null) && (shouldReturnInvalidatedObjects || !descriptor.getCacheInvalidationPolicy().isInvalidated(cacheKey, System.currentTimeMillis()))) {
            synchronized (cacheKey.getMutex()) {
                //if the object in the cachekey is null but the key is acquired then
                //someone must be rebuilding it or creating a new one.  Sleep until
                // it's finished. A plain wait here would be more efficient but we may not
                // get notified for quite some time (ie deadlock) if the other thread
                //is building the object.  Must wait and not sleep in order for the monitor to be released
                objectFromCache = cacheKey.getObject();
                try {
                    while (cacheKey.isAcquired() && (objectFromCache == null)) {
                        cacheKey.getMutex().wait(5);
                    }
                } catch (InterruptedException ex) {
                }
                if (objectFromCache == null) {
                    return null;
                }
            }
        } else {
            return null;
        }

        // Consider read-only class CR#4094
        if (getSession().isClassReadOnly(theClass, descriptor)) {
            // PERF: Just return the original object.
            return objectFromCache;
        }

        if(getSession() instanceof RepeatableWriteUnitOfWork ) {
            Object unregisteredDeletedClone = ((RepeatableWriteUnitOfWork)getSession()).getUnregisteredDeletedCloneForOriginal(objectFromCache);
            if(unregisteredDeletedClone != null) {
                return unregisteredDeletedClone;
            }
        }
        
        return ((UnitOfWorkImpl)getSession()).cloneAndRegisterObject(objectFromCache, cacheKey, joinedAttributeManager);
    
public java.lang.ObjectgetFromIdentityMap(java.util.Vector primaryKey, java.lang.Class theClass, boolean shouldReturnInvalidatedObjects, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, oracle.toplink.essentials.internal.queryframework.JoinedAttributeManager joinedAttributeManager)
INTERNAL: Return the object from the identity map with the primary key and class. The parent's cache must be checked after the child's, if found in the parent, it must be registered/cloned (but must avoid looping). Note: in a UnitOfWork, invalidated objects will always be returned from the identity map In the parent session, only return the object if it has not been Invalidated

        Object objectFromCache = super.getFromIdentityMap(primaryKey, theClass, true, descriptor, joinedAttributeManager);

        if (objectFromCache != null) {
            return objectFromCache;
        }
        //Bug#4613774  In the parent session, only return the object if it has not been Invalidated
        return getAndCloneCacheKeyFromParent(primaryKey, theClass, shouldReturnInvalidatedObjects, descriptor, joinedAttributeManager);
    
public java.lang.ObjectgetFromIdentityMapWithDeferredLock(java.util.Vector primaryKey, java.lang.Class theClass, boolean shouldReturnInvalidatedObjects, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Overide the getFromIdentityMapWithDeferredLock method on the session to ensure that invalidated objects are always returned since this is a UnitOfWork

        return super.getFromIdentityMapWithDeferredLock(primaryKey, theClass, true, descriptor);
    
public voidinitializeAllIdentityMaps()
INTERNAL: Reset the entire object cache, ** be careful using this. This method blows away both this session's and its parents caches, this includes the server cache or any other cache. This throws away any objects that have been read in. Extreme caution should be used before doing this because object identity will no longer be maintained for any objects currently read in. This should only be called if the application knows that it no longer has references to object held in the cache.

        super.initializeAllIdentityMaps();
        ((UnitOfWorkImpl)getSession()).getParent().getIdentityMapAccessor().initializeAllIdentityMaps();