Top Description Fields Constructors Methods
org.eclipse.persistence.sessions.interceptors

public abstract Class CacheInterceptor

extends Object
implements IdentityMap
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.internal.identitymaps.IdentityMap, java.lang.Cloneable
Imports
java.util.Collection, .Enumeration, .HashMap, .Map, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.indirection.ValueHolderInterface, org.eclipse.persistence.internal.helper.Helper, org.eclipse.persistence.internal.identitymaps.CacheKey, .IdentityMap, org.eclipse.persistence.internal.sessions.AbstractSession, org.eclipse.persistence.mappings.ForeignReferenceMapping

Purpose: Define a class through which Cache access can be intercepted.

Description: EclipseLink makes extensive use of caching functionality. This class provides the mechanism for intercepting the cache access. Once intercepted applications can allow the process to continue by calling the method on the class attribute targetIdentityMap as described in the API javadocs or redirect the process entirely. * As with IdentityMaps an entire class inheritance hierarchy will share the same interceptor.

To implement a CacheInterceptor users should subclass this class implementing those methods they wish to intercept.

Configuration: Interceptors may be added to a session by using a Session or Descriptor customizer to set the class name of the interceptor on the target ClassDescriptor through the method setCacheInterceptorClass(Class).

Field Summary

Modifier and TypeField and Description
protected AbstractSession
protected IdentityMap
targetIdentityMap

This attribute stores the actual IdentityMap as configured by the user.

Constructor Summary

AccessConstructor and Description
protected
CacheInterceptor(IdentityMap targetIdentityMap, AbstractSession interceptedSession)

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 abstract Object
clone()

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

Overrides java.lang.Object.clone.

Clone the map and all of the CacheKeys.
public Enumeration<CacheKey>

Returns:

Enumeration with clone of the CacheKey Collection
cloneKeys
()

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

Allow for the CacheKey elements to be iterated.
public void
collectLocks(HashMap<K, V> threadList)

Implements 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.
protected abstract CacheKeyInterceptor
public Enumeration<E>
elements()

Implements 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 abstract 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)

Redeclares 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 abstract 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)

Redeclares 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 CacheKey
getCacheKey(Object primaryKey, boolean forMerge)

Implements 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.
public ClassDescriptor
getDescriptor()

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

Return the descriptor 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 int
getSize()

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

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

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

Return the number of actual objects of type myClass in the IdentityMap.
public IdentityMap
getTargetIdenttyMap()

Return the instance of the IdentityMap that this intercpetor is wrapping.

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 Enumeration<CacheKey>

Returns:

Enumeration of CacheKey instances.
keys
()

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

Allow for the CacheKey elements to be iterated.
public Enumeration<CacheKey>

Returns:

Enumeration of CacheKey instances.
keys
(boolean
value of true if read lock on the CacheKey instances should be checked or false otherwise
checkReadLocks
)

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

Allow for the CacheKey elements to be iterated.
public void
lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface<T> valueHolder, ForeignReferenceMapping mapping)

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

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)

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

Store the object in the cache at its primary key.
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 Object
remove(CacheKey cacheKey)

Implements 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.
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

interceptedSessionback to summary
protected AbstractSession interceptedSession
targetIdentityMapback to summary
protected IdentityMap targetIdentityMap

This attribute stores the actual IdentityMap as configured by the user.

Constructor Detail

CacheInterceptorback to summary
protected CacheInterceptor(IdentityMap targetIdentityMap, AbstractSession interceptedSession)

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 abstract Object clone()

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

Overrides java.lang.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.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
cloneKeysback to summary
public Enumeration<CacheKey> cloneKeys()

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

Allow for the CacheKey elements to be iterated. Clone of CacheKey Collection is returned so this iteration should be thread safe.

Returns:Enumeration<CacheKey>

Enumeration with clone of the CacheKey Collection

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

Implements 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
createCacheKeyInterceptorback to summary
protected abstract CacheKeyInterceptor createCacheKeyInterceptor(CacheKey wrappedCacheKey)
elementsback to summary
public Enumeration<E> elements()

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

Allow for the cache to be iterated on. This method is only used during debugging when validateCache() has been called to print out the contents of the cache.

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 abstract Map<Object, CacheKey> getAllCacheKeysFromIdentityMapWithEntityPK(Object[] pkList, ClassDescriptor descriptor, AbstractSession session)

Redeclares 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 abstract Map<Object, Object> getAllFromIdentityMapWithEntityPK(Object[] pkList, ClassDescriptor descriptor, AbstractSession session)

Redeclares 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 CacheKey getCacheKey(Object primaryKey, boolean forMerge)

Implements 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
getDescriptorback to summary
public ClassDescriptor getDescriptor()

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

Return the descriptor 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 int getSize()

Implements 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 int getSize(Class<?> myClass, boolean recurse)

Implements 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
getTargetIdenttyMapback to summary
public IdentityMap getTargetIdenttyMap()

Return the instance of the IdentityMap that this intercpetor is wrapping. Any call that is to be passed on to the underlying EclipseLink cache should be passed to this IdentityMap.

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 Enumeration<CacheKey> keys()

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

Allow for the CacheKey elements to be iterated. CacheKey Collection is reused so this iteration may not be thread safe.

Returns:Enumeration<CacheKey>

Enumeration of CacheKey instances.

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

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

Allow for the CacheKey elements to be iterated. CacheKey Collection is reused so this iteration may not be thread safe.

Parameters
checkReadLocks:boolean

value of true if read lock on the CacheKey instances should be checked or false otherwise

Returns:Enumeration<CacheKey>

Enumeration of CacheKey instances.

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

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

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

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

Implements 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
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 Object remove(CacheKey cacheKey)

Implements 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
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