Top Description Fields Constructors Methods
org.eclipse.persistence.internal.identitymaps

public abstract Class AbstractIdentityMap

extends Object
implements IdentityMap, Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable, org.eclipse.persistence.internal.identitymaps.IdentityMap
Known Direct Subclasses
org.eclipse.persistence.internal.identitymaps.FullIdentityMap, org.eclipse.persistence.internal.identitymaps.NoIdentityMap
Imports
java.io.Serializable, java.util.Enumeration, .HashMap, .Map, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.QueryException, org.eclipse.persistence.internal.helper.ClassConstants, .Helper, org.eclipse.persistence.internal.sessions.AbstractSession

Purpose: Caches objects, and allows their retrieval by their primary key.

Responsibilities:

Since
TOPLink/Java 1.0
See Also
CacheKey

Field Summary

Modifier and TypeField and Description
protected transient ClassDescriptor
descriptor

PERF: Store the descriptor to allow lastAccessed cache lookup optimization.

protected boolean
isIsolated

Is this identity map within an IsolatedClientSession

protected int
maxSize

The initial or maximum size of the cache depending upon the concrete implementation.

protected AbstractSession
session

Session that the map is on

Constructor Summary

AccessConstructor and Description
protected
protected
AbstractIdentityMap(int
is the maximum size to be allocated for the receiver.
size
,
ClassDescriptor descriptor, AbstractSession session, boolean isolated)

Instantiate an new IdentityMap with it's maximum size.

Method Summary

Modifier and TypeMethod and Description
public CacheKey
acquireDeferredLock(Object primaryKey, boolean isCacheCheckComplete)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireDeferredLock.

Acquire a deferred lock on the object.
public CacheKey
acquireLock(Object primaryKey, boolean forMerge, boolean isCacheCheckComplete)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireLock.

Acquire an active lock on the object.
public CacheKey
acquireLockNoWait(Object primaryKey, boolean forMerge)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireLockNoWait.

Acquire an active lock on the object, if not already locked.
public CacheKey
acquireLockWithWait(Object primaryKey, boolean forMerge, int wait)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireLockWithWait.

Acquire an active lock on the object, if not already locked.
public CacheKey
public CacheKey
acquireReadLockOnCacheKeyNoWait(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireReadLockOnCacheKeyNoWait.

Acquire a read lock on the object, if not already locked.
public Object
clone()

Overrides java.lang.Object.clone.

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.clone.

Clone the map and all of the CacheKeys.
public abstract void
collectLocks(HashMap<K, V> threadList)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.collectLocks.

Add all locked CacheKeys to the map grouped by thread.
public boolean
containsKey(Object
is the primary key for the object to search for.
primaryKey
)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.containsKey.

Return true if an CacheKey with the primary key is in the map.
public CacheKey
createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)

Create the correct type of CacheKey for this map.

public abstract Enumeration<E>
elements()

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.elements.

Allow for the cache to be iterated on.
public Object
get(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.get.

Return the object cached in the identity map or null if it could not be found.
public Map<Object, CacheKey>

Returns:

Map of Entity PKs associated to the Entities that were retrieved
getAllCacheKeysFromIdentityMapWithEntityPK
(Object[]
List of Entity PKs to extract from the cache
pkList
,
ClassDescriptor
Descriptor type to be retrieved.
descriptor
,
AbstractSession session)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getAllCacheKeysFromIdentityMapWithEntityPK.

ADVANCED: Using a list of Entity PK this method will attempt to bulk load the entire list from the cache.
public Map<Object, Object>

Returns:

Map of Entity PKs associated to the Entities that were retrieved
getAllFromIdentityMapWithEntityPK
(Object[]
List of Entity PKs to extract from the cache
pkList
,
ClassDescriptor
Descriptor type to be retrieved.
descriptor
,
AbstractSession session)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getAllFromIdentityMapWithEntityPK.

ADVANCED: Using a list of Entity PK this method will attempt to bulk load the entire list from the cache.
public abstract CacheKey
getCacheKey(Object primaryKey, boolean forMerge)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.getCacheKey.

Get the cache key (with object) for the primary key.
public CacheKey
getCacheKeyForLock(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getCacheKeyForLock.

Get the cache key (with object) for the primary key.
protected CacheKey
getCacheKeyWithReadLock(Object primaryKey)

Get the cache key (with object) for the primary key with read lock.

public static Class<? extends IdentityMap>
getDefaultIdentityMapClass()

Returns the class which should be used as an identity map in a descriptor by default.

public ClassDescriptor
getDescriptor()

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getDescriptor.

Return the class that this is the map for.
public Class<?>
public int

Returns:

The maxSize for the IdentityMap (NOTE: some subclasses may use this differently).
getMaxSize
()

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getMaxSize.

public abstract int
getSize()

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.getSize.

Return the number of CacheKeys in the IdentityMap.
public abstract int
getSize(Class<?> myClass, boolean recurse)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.getSize.

Return the number of actual objects of type myClass in the IdentityMap.
public Object
getWrapper(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getWrapper.

Get the wrapper object from the cache key associated with the given primary key, this is used for EJB2.
public Object
getWriteLockValue(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getWriteLockValue.

Get the write lock value from the cache key associated to the primarykey.
public abstract Enumeration<E>
keys()

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.keys.

Allow for the CacheKeys to be iterated on.
public abstract CacheKey
put(Object
is the primary key for the object.
primaryKey
,
Object
is the domain object to cache.
object
,
Object
is the current write lock value of object, if null the version is ignored.
writeLockValue
,
long readTime)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.put.

Store the object in the cache at its primary key.
protected abstract CacheKey
putCacheKeyIfAbsent(CacheKey cacheKey)

Return the CacheKey (with object) matching the searchKey.

public void
release()

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.release.

This method may be called during initialize all identity maps.
public Object
remove(Object primaryKey, Object object)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.remove.

Remove the CacheKey with the primaryKey from the map.
public abstract Object
remove(CacheKey cacheKey)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.remove.

Remove the CacheKey from the map.
public void
setDescriptor(ClassDescriptor descriptor)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.setDescriptor.

Set the descriptor that this is the map for.
protected synchronized void
setMaxSize(int
is the new maximum size.
size
)

Set the maximum size for the receiver.

public void
setWrapper(Object primaryKey, Object wrapper)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.setWrapper.

Update the wrapper object in the CacheKey associated with the given primaryKey, this is used for EJB2.
public void
setWriteLockValue(Object primaryKey, Object writeLockValue)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.setWriteLockValue.

Update the write lock value of the CacheKey associated with the given primaryKey.
public String
toString()

Overrides java.lang.Object.toString.

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.toString.

Returns a string representation of the object.
public void
updateMaxSize(int maxSize)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.updateMaxSize.

This method will be used to update the max cache size, any objects exceeding the max cache size will be remove from the cache.
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

descriptorback to summary
protected transient ClassDescriptor descriptor

PERF: Store the descriptor to allow lastAccessed cache lookup optimization.

isIsolatedback to summary
protected boolean isIsolated

Is this identity map within an IsolatedClientSession

maxSizeback to summary
protected int maxSize

The initial or maximum size of the cache depending upon the concrete implementation.

sessionback to summary
protected AbstractSession session

Session that the map is on

Constructor Detail

AbstractIdentityMapback to summary
protected AbstractIdentityMap()
AbstractIdentityMapback to summary
protected AbstractIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isolated)

Instantiate an new IdentityMap with it's maximum size.

Note

Subclasses may provide different behavior for maxSize.

Parameters
size:int

is the maximum size to be allocated for the receiver.

Method Detail

acquireDeferredLockback to summary
public CacheKey acquireDeferredLock(Object primaryKey, boolean isCacheCheckComplete)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireDeferredLock.

Acquire a deferred lock on the object. This is used while reading if the object has relationships without indirection. This first thread will get an active lock. Other threads will get deferred locks, all threads will wait until all other threads are complete before releasing their locks.

Annotations
@Override
acquireLockback to summary
public CacheKey acquireLock(Object primaryKey, boolean forMerge, boolean isCacheCheckComplete)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireLock.

Acquire an active lock on the object. This is used by reading (when using indirection or no relationships) and by merge.

Annotations
@Override
acquireLockNoWaitback to summary
public CacheKey acquireLockNoWait(Object primaryKey, boolean forMerge)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireLockNoWait.

Acquire an active lock on the object, if not already locked. This is used by merge for missing existing objects.

Annotations
@Override
acquireLockWithWaitback to summary
public CacheKey acquireLockWithWait(Object primaryKey, boolean forMerge, int wait)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireLockWithWait.

Acquire an active lock on the object, if not already locked. This is used by merge for missing existing objects.

Annotations
@Override
acquireReadLockOnCacheKeyback to summary
public CacheKey acquireReadLockOnCacheKey(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireReadLockOnCacheKey.

Acquire a read lock on the object. This is used by UnitOfWork cloning. This will allow multiple users to read the same object but prevent writes to the object while the read lock is held.

Annotations
@Override
acquireReadLockOnCacheKeyNoWaitback to summary
public CacheKey acquireReadLockOnCacheKeyNoWait(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.acquireReadLockOnCacheKeyNoWait.

Acquire a read lock on the object, if not already locked. This is used by UnitOfWork cloning. This will allow multiple users to read the same object but prevent writes to the object while the read lock is held.

Annotations
@Override
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.clone.

Clone the map and all of the CacheKeys. This is used by UnitOfWork commitAndResumeOnFailure to avoid corrupting the cache during a failed commit.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
collectLocksback to summary
public abstract void collectLocks(HashMap<K, V> threadList)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.collectLocks.

Add all locked CacheKeys to the map grouped by thread. Used to print all the locks in the identity map.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.containsKey.

Return true if an CacheKey with the primary key is in the map. User API.

Parameters
primaryKey:Object

is the primary key for the object to search for.

Annotations
@Override
createCacheKeyback to summary
public CacheKey createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)

Create the correct type of CacheKey for this map.

elementsback to summary
public abstract Enumeration<E> elements()

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.elements.

Allow for the cache to be iterated on.

Annotations
@Override
getback to summary
public Object get(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.get.

Return the object cached in the identity map or null if it could not be found. User API.

Annotations
@Override
getAllCacheKeysFromIdentityMapWithEntityPKback to summary
public Map<Object, CacheKey> getAllCacheKeysFromIdentityMapWithEntityPK(Object[] pkList, ClassDescriptor descriptor, AbstractSession session)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getAllCacheKeysFromIdentityMapWithEntityPK.

ADVANCED: Using a list of Entity PK this method will attempt to bulk load the entire list from the cache. In certain circumstances this can have large performance improvements over loading each item individually.

Parameters
pkList:Object[]

List of Entity PKs to extract from the cache

descriptor:ClassDescriptor

Descriptor type to be retrieved.

Returns:Map<Object, CacheKey>

Map of Entity PKs associated to the Entities that were retrieved

Annotations
@Override
getAllFromIdentityMapWithEntityPKback to summary
public Map<Object, Object> getAllFromIdentityMapWithEntityPK(Object[] pkList, ClassDescriptor descriptor, AbstractSession session)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getAllFromIdentityMapWithEntityPK.

ADVANCED: Using a list of Entity PK this method will attempt to bulk load the entire list from the cache. In certain circumstances this can have large performance improvements over loading each item individually.

Parameters
pkList:Object[]

List of Entity PKs to extract from the cache

descriptor:ClassDescriptor

Descriptor type to be retrieved.

Returns:Map<Object, Object>

Map of Entity PKs associated to the Entities that were retrieved

Annotations
@Override
getCacheKeyback to summary
public abstract CacheKey getCacheKey(Object primaryKey, boolean forMerge)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.getCacheKey.

Get the cache key (with object) for the primary key.

Annotations
@Override
getCacheKeyForLockback to summary
public CacheKey getCacheKeyForLock(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getCacheKeyForLock.

Get the cache key (with object) for the primary key.

Annotations
@Override
getCacheKeyWithReadLockback to summary
protected CacheKey getCacheKeyWithReadLock(Object primaryKey)

Get the cache key (with object) for the primary key with read lock.

getDefaultIdentityMapClassback to summary
public static Class<? extends IdentityMap> getDefaultIdentityMapClass()

Returns the class which should be used as an identity map in a descriptor by default.

getDescriptorback to summary
public ClassDescriptor getDescriptor()

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getDescriptor.

Return the class that this is the map for.

Annotations
@Override
getDescriptorClassback to summary
public Class<?> getDescriptorClass()

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getDescriptorClass.

Return the class that this is the map for.

Annotations
@Override
getMaxSizeback to summary
public int getMaxSize()

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getMaxSize.

Returns:int

The maxSize for the IdentityMap (NOTE: some subclasses may use this differently).

Annotations
@Override
getSizeback to summary
public abstract int getSize()

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.getSize.

Return the number of CacheKeys in the IdentityMap. This may contain weak referenced objects that have been garbage collected.

Annotations
@Override
getSizeback to summary
public abstract int getSize(Class<?> myClass, boolean recurse)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.getSize.

Return the number of actual objects of type myClass in the IdentityMap. Recurse = true will include subclasses of myClass in the count.

Annotations
@Override
getWrapperback to summary
public Object getWrapper(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getWrapper.

Get the wrapper object from the cache key associated with the given primary key, this is used for EJB2.

Annotations
@Override
getWriteLockValueback to summary
public Object getWriteLockValue(Object primaryKey)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.getWriteLockValue.

Get the write lock value from the cache key associated to the primarykey. User API.

Annotations
@Override
keysback to summary
public abstract Enumeration<E> keys()

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.keys.

Allow for the CacheKeys to be iterated on.

Annotations
@Override
putback to summary
public abstract CacheKey put(Object primaryKey, Object object, Object writeLockValue, long readTime)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.put.

Store the object in the cache at its primary key. This is used by InsertObjectQuery, typically into the UnitOfWork identity map. Merge and reads do not use put, but acquireLock. Also an advanced (very) user API.

Parameters
primaryKey:Object

is the primary key for the object.

object:Object

is the domain object to cache.

writeLockValue:Object

is the current write lock value of object, if null the version is ignored.

Annotations
@Override
putCacheKeyIfAbsentback to summary
protected abstract CacheKey putCacheKeyIfAbsent(CacheKey cacheKey)

Return the CacheKey (with object) matching the searchKey. If the CacheKey is missing then put the searchKey in the map. The searchKey should have already been locked.

releaseback to summary
public void release()

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.release.

This method may be called during initialize all identity maps. It allows the identity map or interceptor the opportunity to release any resources before being thrown away.

Annotations
@Override
removeback to summary
public Object remove(Object primaryKey, Object object)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.remove.

Remove the CacheKey with the primaryKey from the map. This is used by DeleteObjectQuery and merge. This is also an advanced (very) user API.

Annotations
@Override
removeback to summary
public abstract Object remove(CacheKey cacheKey)

Redeclares org.eclipse.persistence.internal.identitymaps.IdentityMap.remove.

Remove the CacheKey from the map.

Annotations
@Override
setDescriptorback to summary
public void setDescriptor(ClassDescriptor descriptor)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.setDescriptor.

Set the descriptor that this is the map for.

Annotations
@Override
setMaxSizeback to summary
protected synchronized void setMaxSize(int size)

Set the maximum size for the receiver.

Parameters
size:int

is the new maximum size.

setWrapperback to summary
public void setWrapper(Object primaryKey, Object wrapper)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.setWrapper.

Update the wrapper object in the CacheKey associated with the given primaryKey, this is used for EJB2.

Annotations
@Override
setWriteLockValueback to summary
public void setWriteLockValue(Object primaryKey, Object writeLockValue)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.setWriteLockValue.

Update the write lock value of the CacheKey associated with the given primaryKey. This is used by UpdateObjectQuery, and is also an advanced (very) user API.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
updateMaxSizeback to summary
public void updateMaxSize(int maxSize)

Implements org.eclipse.persistence.internal.identitymaps.IdentityMap.updateMaxSize.

This method will be used to update the max cache size, any objects exceeding the max cache size will be remove from the cache. Please note that this does not remove the object from the identityMap, except in the case of the CacheIdentityMap.

Annotations
@Override