FileDocCategorySizeDatePackage
FullIdentityMap.javaAPI DocGlassfish v2 API8028Tue May 22 16:54:34 BST 2007oracle.toplink.essentials.internal.identitymaps

FullIdentityMap

public class FullIdentityMap extends IdentityMap

Purpose: A FullIdentityMap holds all objects stored within it for the life of the application

Responsibilities:

  • Guarantees identity
  • Holds all cached objects indefinetly.
since
TOPLink/Java 1.0

Fields Summary
protected Hashtable
cacheKeys
Hashtable of CacheKeys stored using their key
Constructors Summary
public FullIdentityMap(int size)

        super(size);
        cacheKeys = new Hashtable(size);
    
Methods Summary
public java.lang.Objectclone()
INTERNAL: Clones itself.

        FullIdentityMap clone = (FullIdentityMap)super.clone();
        clone.setCacheKeys(new Hashtable(getCacheKeys().size()));

        for (Enumeration cacheKeysEnum = getCacheKeys().elements();
                 cacheKeysEnum.hasMoreElements();) {
            CacheKey key = (CacheKey)((CacheKey)cacheKeysEnum.nextElement()).clone();
            clone.getCacheKeys().put(key, key);
        }

        return clone;
    
public voidcollectLocks(java.util.HashMap threadList)
INTERNAL: Used to print all the Locks in every identity map in this session. The output of this method will go to log passed in as a parameter.

        Iterator cacheKeyIterator = this.cacheKeys.values().iterator();
        while (cacheKeyIterator.hasNext()) {
            CacheKey cacheKey = (CacheKey)cacheKeyIterator.next();
            if (cacheKey.isAcquired()) {
                Thread activeThread = cacheKey.getMutex().getActiveThread();
                Set set = (Set)threadList.get(activeThread);
                if (set == null) {
                    set = new HashSet();
                    threadList.put(activeThread, set);
                }
                set.add(cacheKey);
            }
        }
    
public java.util.Enumerationelements()
Allow for the cache to be iterated on.

        return new IdentityMapEnumeration(this);
    
protected synchronized oracle.toplink.essentials.internal.identitymaps.CacheKeygetCacheKey(oracle.toplink.essentials.internal.identitymaps.CacheKey searchKey)
Return the object indexed in the recevier at the cache key. If now object for the key exists, return null.

return
a CacheKey for the primary key or null

        return (CacheKey)getCacheKeys().get(searchKey);
    
public java.util.HashtablegetCacheKeys()

        return cacheKeys;
    
public intgetSize()
Return the number of objects in the IdentityMap.

        return cacheKeys.size();
    
public intgetSize(java.lang.Class myClass, boolean recurse)
Return the number of actual objects of type myClass in the IdentityMap. Recurse = true will include subclasses of myClass in the count.

        int i = 0;
        Enumeration keys = getCacheKeys().keys();

        while (keys.hasMoreElements()) {
            CacheKey key = (CacheKey)keys.nextElement();
            Object obj = key.getObject();

            if (obj != null) {
                if (recurse && myClass.isInstance(obj)) {
                    i++;
                } else if (obj.getClass().equals(myClass)) {
                    i++;
                }
            }
        }

        return i;
    
public java.util.Enumerationkeys()
Allow for the cache keys to be iterated on.

        return new IdentityMapKeyEnumeration(this);
    
public oracle.toplink.essentials.internal.identitymaps.CacheKeyput(java.util.Vector primaryKey, java.lang.Object object, java.lang.Object writeLockValue, long readTime)
Store the object in the cache at its primary key.

param
primaryKey is the primary key for the object.
param
object is the domain object to cache.
param
writeLockValue is the current write lock value of object, if null the version is ignored.

        CacheKey cacheKey = getCacheKey(primaryKey);

        // Find the cache key in the hashtable, reset it.
        if (cacheKey != null) {
            // The cache key has to be locked during the re-setting, keep other threads from accessing the object.
            resetCacheKey(cacheKey, object, writeLockValue);

            // Still must put the object to ensure the LRU caching.
            put(cacheKey);
        } else {
            // Cache key not found, create a new one and put it into the hashtable.
            cacheKey = createCacheKey(primaryKey, object, writeLockValue, readTime);

            put(cacheKey);
        }

        return cacheKey;
    
protected voidput(oracle.toplink.essentials.internal.identitymaps.CacheKey cacheKey)
Store the object in the cache with the cache key.

        //synchronized because subclasses may not sync around call
        synchronized(this){
            getCacheKeys().put(cacheKey, cacheKey);
        }
        cacheKey.setOwningMap(this);
    
public java.lang.Objectremove(oracle.toplink.essentials.internal.identitymaps.CacheKey cacheKey)
Removes the CacheKey from the Hashtable.

return
The object held within the CacheKey or null if no object cached for given primaryKey

        if (cacheKey != null) {
            //Cache key needs to be locked when removing from the Hashtable
            cacheKey.acquire();

            //remove opration from the hashtable has to be synchronized
            synchronized (this) {
                getCacheKeys().remove(cacheKey);
            }

            //Cache key needs to be released after removing from the Hashtable
            cacheKey.release();
        } else {
            return null;
        }

        return cacheKey.getObject();
    
public voidresetCacheKey(oracle.toplink.essentials.internal.identitymaps.CacheKey key, java.lang.Object object, java.lang.Object writeLockValue)

        resetCacheKey(key, object, writeLockValue, 0);
    
public voidresetCacheKey(oracle.toplink.essentials.internal.identitymaps.CacheKey key, java.lang.Object object, java.lang.Object writeLockValue, long readTime)

        key.acquire();
        key.setObject(object);
        key.setWriteLockValue(writeLockValue);
        key.setReadTime(readTime);
        key.release();
    
protected voidsetCacheKeys(java.util.Hashtable cacheKeys)

        this.cacheKeys = cacheKeys;