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

public Interface IdentityMap

extends Cloneable
Known Direct Implementers
org.eclipse.persistence.sessions.interceptors.CacheInterceptor, org.eclipse.persistence.internal.identitymaps.AbstractIdentityMap
Imports
java.util.Enumeration, .HashMap, .Map, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.QueryException, org.eclipse.persistence.indirection.ValueHolderInterface, org.eclipse.persistence.internal.sessions.AbstractSession, org.eclipse.persistence.mappings.ForeignReferenceMapping

Purpose: Provides the interface for IdentityMap interaction.

Responsibilities: Provides access to all of the public interface for the EclipseLink IdentityMaps. This interface can be used if implementing custom identity maps that are radically different than the stock IdentityMaps otherwise simply extending the appropriate IdentityMap implementation is the best approach.

Since
EclipseLink 1.0M7
See Also
CacheKey

Method Summary

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

Acquire a deferred lock on the object.

public CacheKey
acquireLock(Object primaryKey, boolean forMerge, boolean isCacheCheckComplete)

Acquire an active lock on the object.

public CacheKey
acquireLockNoWait(Object primaryKey, boolean forMerge)

Acquire an active lock on the object, if not already locked.

public CacheKey
acquireLockWithWait(Object primaryKey, boolean forMerge, int wait)

Acquire an active lock on the object, if not already locked.

public CacheKey
acquireReadLockOnCacheKey(Object primaryKey)

Acquire a read lock on the object.

public CacheKey
acquireReadLockOnCacheKeyNoWait(Object primaryKey)

Acquire a read lock on the object, if not already locked.

public Object
clone()

Clone the map and all of the CacheKeys.

public Enumeration<CacheKey>

Returns:

clone of the CacheKeys enumeration
cloneKeys
()

Allow for the CacheKeys to be iterated on using copy of keys enumeration.

public void
collectLocks(HashMap<K, V> threadList)

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
)

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

public Enumeration<E>
elements()

Allow for the cache to be iterated on.

public Object
get(Object primaryKey)

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)

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)

ADVANCED: Using a list of Entity PK this method will attempt to bulk load the entire list from the cache.

public CacheKey
getCacheKey(Object primaryKey, boolean forMerge)

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

public CacheKey
getCacheKeyForLock(Object primaryKey)

Get the cache key (with object) for the primary key in order to acquire a lock.

public ClassDescriptor
getDescriptor()

Return the descriptor that this is the map for.

public Class<?>
getDescriptorClass()

Return the class that this is the map for.

public int

Returns:

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

public int
getSize()

Return the number of CacheKeys in the IdentityMap.

public int
getSize(Class<?> myClass, boolean recurse)

Return the number of actual objects of type myClass in the IdentityMap.

public Object
getWrapper(Object primaryKey)

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

public Object
getWriteLockValue(Object primaryKey)

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

public Enumeration<CacheKey>
keys()

Allow for the CacheKeys to be iterated on.

public Enumeration<CacheKey>
keys(boolean
- true if readLocks should be checked, false otherwise.
checkReadLocks
)

Allow for the CacheKeys to be iterated on.

public void
lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface<T> valueHolder, ForeignReferenceMapping mapping)

Notify the cache that a lazy relationship has been triggered in the object and the cache may need to be updated

public 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)

Store the object in the cache at its primary key.

public void
release()

This method may be called during initialize all identity maps.

public Object
remove(Object primaryKey, Object object)

Remove the CacheKey with the primaryKey from the map.

public Object
remove(CacheKey cacheKey)

Remove the CacheKey from the map.

public void
setDescriptor(ClassDescriptor descriptor)

Set the descriptor that this is the map for.

public void
setWrapper(Object primaryKey, Object wrapper)

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

public void
setWriteLockValue(Object primaryKey, Object writeLockValue)

Update the write lock value of the CacheKey associated with the given primaryKey.

public String
public void
updateMaxSize(int maxSize)

This method will be used to update the max cache size, any objects exceeding the max cache size will be remove from the cache.

Method Detail

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

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.

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

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

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

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

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

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

acquireReadLockOnCacheKeyback to summary
public CacheKey acquireReadLockOnCacheKey(Object primaryKey)

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.

acquireReadLockOnCacheKeyNoWaitback to summary
public CacheKey acquireReadLockOnCacheKeyNoWait(Object primaryKey)

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.

cloneback to summary
public Object clone()

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

cloneKeysback to summary
public Enumeration<CacheKey> cloneKeys()

Allow for the CacheKeys to be iterated on using copy of keys enumeration. This is thread safe access to keys.

Returns:Enumeration<CacheKey>

clone of the CacheKeys enumeration

collectLocksback to summary
public void collectLocks(HashMap<K, V> threadList)

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

containsKeyback to summary
public boolean containsKey(Object primaryKey)

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.

elementsback to summary
public Enumeration<E> elements()

Allow for the cache to be iterated on.

getback to summary
public Object get(Object primaryKey)

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

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

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

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

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

getCacheKeyback to summary
public CacheKey getCacheKey(Object primaryKey, boolean forMerge)

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

getCacheKeyForLockback to summary
public CacheKey getCacheKeyForLock(Object primaryKey)

Get the cache key (with object) for the primary key in order to acquire a lock.

getDescriptorback to summary
public ClassDescriptor getDescriptor()

Return the descriptor that this is the map for.

getDescriptorClassback to summary
public Class<?> getDescriptorClass()

Return the class that this is the map for.

getMaxSizeback to summary
public int getMaxSize()
Returns:int

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

getSizeback to summary
public int getSize()

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

getSizeback to summary
public int getSize(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.

getWrapperback to summary
public Object getWrapper(Object primaryKey)

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

getWriteLockValueback to summary
public Object getWriteLockValue(Object primaryKey)

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

keysback to summary
public Enumeration<CacheKey> keys()

Allow for the CacheKeys to be iterated on. Read locks should be checked

keysback to summary
public Enumeration<CacheKey> keys(boolean checkReadLocks)

Allow for the CacheKeys to be iterated on.

Parameters
checkReadLocks:boolean

- true if readLocks should be checked, false otherwise.

lazyRelationshipLoadedback to summary
public void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface<T> valueHolder, ForeignReferenceMapping mapping)

Notify the cache that a lazy relationship has been triggered in the object and the cache may need to be updated

putback to summary
public CacheKey put(Object primaryKey, Object object, Object writeLockValue, long readTime)

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.

releaseback to summary
public void 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.

removeback to summary
public Object remove(Object primaryKey, Object object)

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

removeback to summary
public Object remove(CacheKey cacheKey)

Remove the CacheKey from the map.

setDescriptorback to summary
public void setDescriptor(ClassDescriptor descriptor)

Set the descriptor that this is the map for.

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

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

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

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.

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

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.