Class IdentityMapManager
- java.lang.Object
-
- org.eclipse.persistence.internal.identitymaps.IdentityMapManager
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class IdentityMapManager extends java.lang.Object implements java.io.Serializable, java.lang.CloneablePurpose: Maintain identity maps for domain classes mapped with EclipseLink.
Responsibilities:
- Build new identity maps lazily using info from the descriptor
- Insert objects into appropriate identity map
- Get object from appropriate identity map using object or primary key with class
- Get and Set write lock values for cached objects
- Since:
- TOPLink/Java 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<CacheIndex,IdentityMap>cacheIndexesA map of indexes on the cache.protected ConcurrencyManagercacheMutexEnsure mutual exclusion depending on the cache isolation.protected java.util.Map<java.lang.Class,IdentityMap>identityMapsA table of identity maps with the key being the domain Class.protected booleanisCacheAccessPreCheckRequiredPERF: Used to avoid readLock and profiler checks to improve performance.protected IdentityMaplastAccessedIdentityMapPERF: Optimize the object retrieval from the identity map.protected static java.lang.StringMONITOR_PREFIXprotected java.util.Map<java.lang.Object,IdentityMap>queryResultsA table of identity maps with the key being the queryprotected java.util.Map<java.lang.Class,java.util.Set>queryResultsInvalidationsByClassA map of class to list of queries that need to be invalidated when that class changes.protected AbstractSessionsessionA reference to the session owning this manager.protected WriteLockManagerwriteLockManagerUsed to store the write lock manager used for merging.
-
Constructor Summary
Constructors Modifier Constructor Description protectedIdentityMapManager()IdentityMapManager(AbstractSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheKeyacquireDeferredLock(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor, boolean isCacheCheckComplete)Provides access for setting a deferred lock on an object in the IdentityMap.CacheKeyacquireLock(java.lang.Object primaryKey, java.lang.Class domainClass, boolean forMerge, ClassDescriptor descriptor, boolean isCacheCheckComplete)Provides access for setting a concurrency lock on an object in the IdentityMap.CacheKeyacquireLockNoWait(java.lang.Object primaryKey, java.lang.Class domainClass, boolean forMerge, ClassDescriptor descriptor)Provides access for setting a concurrency lock on an object in the IdentityMap.CacheKeyacquireLockWithWait(java.lang.Object primaryKey, java.lang.Class domainClass, boolean forMerge, ClassDescriptor descriptor, int wait)Provides access for setting a concurrency lock on an object in the IdentityMap.voidacquireReadLock()Provides access for setting a concurrency lock on an IdentityMap.CacheKeyacquireReadLockOnCacheKey(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor)INTERNAL: Find the cachekey for the provided primary key and place a readlock on it.CacheKeyacquireReadLockOnCacheKeyNoWait(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor)INTERNAL: Find the cachekey for the provided primary key and place a readlock on it.booleanacquireWriteLock()Lock the entire cache if the cache isolation requires.protected IdentityMapbuildNewIdentityMap(java.lang.Class identityMapClass, int size, ClassDescriptor descriptor, boolean isIsolated)INTERNAL: Return a new empty identity map of the class type.IdentityMapbuildNewIdentityMap(ClassDescriptor descriptor)INTERNAL: (Public to allow testing to access) Return a new empty identity map to cache instances of the class.protected java.lang.ObjectcheckForInheritance(java.lang.Object domainObject, java.lang.Class superClass, ClassDescriptor descriptor)This method is used to resolve the inheritance issues arisen when conforming from the identity map 1.voidcheckIsCacheAccessPreCheckRequired()PERF: Used to micro optimize cache access.voidclearCacheIndexes()Clear all index caches.voidclearLastAccessedIdentityMap()INTERNAL: Clear the the lastAccessedIdentityMap and the lastAccessedIdentityMapClassvoidclearQueryCache()Clear all the query caches.voidclearQueryCache(ReadQuery query)Remove the cache key related to a query.java.lang.Objectclone()INTERNAL: Clones itself, used for uow commit and resume on failure.booleancontainsKey(java.lang.Object key, java.lang.Class theClass, ClassDescriptor descriptor)Return true if an CacheKey with the primary key is in the map.java.util.Map<java.lang.Object,CacheKey>getAllCacheKeysFromIdentityMapWithEntityPK(java.lang.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.java.util.VectorgetAllFromIdentityMap(Expression selectionCriteria, java.lang.Class theClass, Record translationRow, int valueHolderPolicy, boolean shouldReturnInvalidatedObjects)Query the cache in-memory.java.util.Map<java.lang.Object,java.lang.Object>getAllFromIdentityMapWithEntityPK(java.lang.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.CacheKeygetCacheKeyByIndex(CacheIndex index, CacheId indexValues, boolean shouldCheckExpiry, ClassDescriptor descriptor)Return the cache key for the cache index or null if not found.CacheKeygetCacheKeyForObject(java.lang.Object primaryKey, java.lang.Class theClass, ClassDescriptor descriptor, boolean forMerge)Retrieve the cache key for the given identity information.CacheKeygetCacheKeyForObjectForLock(java.lang.Object primaryKey, java.lang.Class theClass, ClassDescriptor descriptor)Retrieve the cache key for the given identity information.ConcurrencyManagergetCacheMutex()Return the cache mutex.java.util.VectorgetClassesRegistered()This method is used to get a list of those classes with IdentityMaps in the Session.java.lang.ObjectgetFromIdentityMap(java.lang.Object object)Get the object from the identity map which has the same identity information as the given object.java.lang.ObjectgetFromIdentityMap(java.lang.Object key, java.lang.Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor)Get the object from the identity map which has the given primary key and class.java.lang.ObjectgetFromIdentityMap(java.lang.Object key, java.lang.Class theClass, ClassDescriptor descriptor)Get the object from the identity map which has the given primary key and class.java.lang.ObjectgetFromIdentityMap(Expression selectionCriteria, java.lang.Class theClass, Record translationRow, int valueHolderPolicy, boolean conforming, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor)java.lang.ObjectgetFromIdentityMapWithDeferredLock(java.lang.Object key, java.lang.Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor)Get the object from the cache with the given primary key and class.IdentityMapgetIdentityMap(ClassDescriptor descriptor)INTERNAL: Return the identity map for the class, if missing create a new one.IdentityMapgetIdentityMap(ClassDescriptor descriptor, boolean returnNullIfNoMap)INTERNAL: Return the identity map for the class.java.util.IteratorgetIdentityMapClasses()Return an iterator of the classes in the identity map.protected java.util.Map<java.lang.Class,IdentityMap>getIdentityMaps()java.lang.ObjectgetQueryResult(ReadQuery query, java.util.List parameters, boolean shouldCheckExpiry)Get the cached results associated with a query.protected AbstractSessiongetSession()java.lang.ObjectgetWrapper(java.lang.Object primaryKey, java.lang.Class theClass)Get the wrapper object from the cache key associated with the given primary key, this is used for EJB.WriteLockManagergetWriteLockManager()Returns the single write Lock manager for this sessionjava.lang.ObjectgetWriteLockValue(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor)Retrieve the write lock value of the cache key associated with the given primary key,voidinitializeIdentityMap(java.lang.Class theClass)Reset the identity map for only the instances of the class.voidinitializeIdentityMaps()voidinvalidateObjects(Expression selectionCriteria, java.lang.Class theClass, Record translationRow, boolean shouldInvalidateOnException)Invalidate objects meeting selectionCriteria.voidinvalidateQueryCache(java.lang.Class classThatChanged)Invalidate/remove any results for the class from the query cache.voidprintIdentityMap(java.lang.Class businessClass)Used to print all the objects in the identity map of the passed in class.voidprintIdentityMaps()Used to print all the objects in every identity map in this session.voidprintLocks()Used to print all the Locks in every identity map in this session.voidprintLocks(java.lang.Class theClass)Used to print all the Locks in the specified identity map in this session.voidputCacheKeyByIndex(CacheIndex index, CacheId indexValues, CacheKey cacheKey, ClassDescriptor descriptor)Index the cache key by the index values.CacheKeyputInIdentityMap(java.lang.Object domainObject, java.lang.Object keys, java.lang.Object writeLockValue, long readTime, ClassDescriptor descriptor)Register the object with the identity map.voidputQueryResult(ReadQuery query, java.util.List parameters, java.lang.Object results)Set the results for a query.protected voidreleaseReadLock()Read-release the local-map and the entire cache.voidreleaseWriteLock()Lock the entire cache if the cache isolation requires.java.lang.ObjectremoveFromIdentityMap(java.lang.Object key, java.lang.Class domainClass, ClassDescriptor descriptor, java.lang.Object objectToRemove)Remove the object from the object cache.protected voidsetCacheMutex(ConcurrencyManager cacheMutex)Set the cache mutex.voidsetIdentityMaps(java.util.concurrent.ConcurrentMap identityMaps)protected voidsetSession(AbstractSession session)voidsetWrapper(java.lang.Object primaryKey, java.lang.Class theClass, java.lang.Object wrapper)Update the wrapper object the cache key associated with the given primary key, this is used for EJB.voidsetWriteLockValue(java.lang.Object primaryKey, java.lang.Class theClass, java.lang.Object writeLockValue)Update the write lock value of the cache key associated with the given primary key,
-
-
-
Field Detail
-
MONITOR_PREFIX
protected static final java.lang.String MONITOR_PREFIX
- See Also:
- Constant Field Values
-
identityMaps
protected java.util.Map<java.lang.Class,IdentityMap> identityMaps
A table of identity maps with the key being the domain Class.
-
queryResults
protected java.util.Map<java.lang.Object,IdentityMap> queryResults
A table of identity maps with the key being the query
-
queryResultsInvalidationsByClass
protected java.util.Map<java.lang.Class,java.util.Set> queryResultsInvalidationsByClass
A map of class to list of queries that need to be invalidated when that class changes.
-
cacheIndexes
protected java.util.Map<CacheIndex,IdentityMap> cacheIndexes
A map of indexes on the cache.
-
session
protected AbstractSession session
A reference to the session owning this manager.
-
cacheMutex
protected transient ConcurrencyManager cacheMutex
Ensure mutual exclusion depending on the cache isolation.
-
lastAccessedIdentityMap
protected IdentityMap lastAccessedIdentityMap
PERF: Optimize the object retrieval from the identity map.
-
writeLockManager
protected transient WriteLockManager writeLockManager
Used to store the write lock manager used for merging.
-
isCacheAccessPreCheckRequired
protected boolean isCacheAccessPreCheckRequired
PERF: Used to avoid readLock and profiler checks to improve performance.
-
-
Constructor Detail
-
IdentityMapManager
protected IdentityMapManager()
-
IdentityMapManager
public IdentityMapManager(AbstractSession session)
-
-
Method Detail
-
acquireDeferredLock
public CacheKey acquireDeferredLock(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor, boolean isCacheCheckComplete)
Provides access for setting a deferred lock on an object in the IdentityMap.
-
acquireLock
public CacheKey acquireLock(java.lang.Object primaryKey, java.lang.Class domainClass, boolean forMerge, ClassDescriptor descriptor, boolean isCacheCheckComplete)
Provides access for setting a concurrency lock on an object in the IdentityMap. called with true from the merge process, if true then the refresh will not refresh the object.
-
acquireLockNoWait
public CacheKey acquireLockNoWait(java.lang.Object primaryKey, java.lang.Class domainClass, boolean forMerge, ClassDescriptor descriptor)
Provides access for setting a concurrency lock on an object in the IdentityMap. called with true from the merge process, if true then the refresh will not refresh the object.
-
acquireLockWithWait
public CacheKey acquireLockWithWait(java.lang.Object primaryKey, java.lang.Class domainClass, boolean forMerge, ClassDescriptor descriptor, int wait)
Provides access for setting a concurrency lock on an object in the IdentityMap. called with true from the merge process, if true then the refresh will not refresh the object.
-
checkIsCacheAccessPreCheckRequired
public void checkIsCacheAccessPreCheckRequired()
PERF: Used to micro optimize cache access. Avoid the readLock and profile checks if not required.
-
acquireReadLock
public void acquireReadLock()
Provides access for setting a concurrency lock on an IdentityMap.
-
acquireReadLockOnCacheKey
public CacheKey acquireReadLockOnCacheKey(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor)
INTERNAL: Find the cachekey for the provided primary key and place a readlock on it. This will allow multiple users to read the same object but prevent writes to the object while the read lock is held.
-
acquireReadLockOnCacheKeyNoWait
public CacheKey acquireReadLockOnCacheKeyNoWait(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor)
INTERNAL: Find the cachekey for the provided primary key and place a readlock on it. This will allow multiple users to read the same object but prevent writes to the object while the read lock is held. If no readlock can be acquired then do not wait but return null.
-
acquireWriteLock
public boolean acquireWriteLock()
Lock the entire cache if the cache isolation requires. By default concurrent reads and writes are allowed. By write, unit of work merge is meant.
-
buildNewIdentityMap
public IdentityMap buildNewIdentityMap(ClassDescriptor descriptor)
INTERNAL: (Public to allow testing to access) Return a new empty identity map to cache instances of the class.
-
buildNewIdentityMap
protected IdentityMap buildNewIdentityMap(java.lang.Class identityMapClass, int size, ClassDescriptor descriptor, boolean isIsolated) throws DescriptorException
INTERNAL: Return a new empty identity map of the class type.- Throws:
DescriptorException
-
clearLastAccessedIdentityMap
public void clearLastAccessedIdentityMap()
INTERNAL: Clear the the lastAccessedIdentityMap and the lastAccessedIdentityMapClass
-
clone
public java.lang.Object clone()
INTERNAL: Clones itself, used for uow commit and resume on failure.- Overrides:
clonein classjava.lang.Object
-
clearQueryCache
public void clearQueryCache()
Clear all the query caches.
-
clearCacheIndexes
public void clearCacheIndexes()
Clear all index caches.
-
clearQueryCache
public void clearQueryCache(ReadQuery query)
Remove the cache key related to a query. Note this method is not synchronized and care should be taken to ensure there are no other threads accessing the cache key. This is used to clean up cached clones of queries.
-
invalidateQueryCache
public void invalidateQueryCache(java.lang.Class classThatChanged)
Invalidate/remove any results for the class from the query cache. This is used to invalidate the query cache on any change.
-
containsKey
public boolean containsKey(java.lang.Object key, java.lang.Class theClass, ClassDescriptor descriptor)Return true if an CacheKey with the primary key is in the map. User API.- Parameters:
key- is the primary key for the object to search for.
-
getAllFromIdentityMap
public java.util.Vector getAllFromIdentityMap(Expression selectionCriteria, java.lang.Class theClass, Record translationRow, int valueHolderPolicy, boolean shouldReturnInvalidatedObjects)
Query the cache in-memory.
-
getAllFromIdentityMapWithEntityPK
public java.util.Map<java.lang.Object,java.lang.Object> getAllFromIdentityMapWithEntityPK(java.lang.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- List of Entity PKs to extract from the cacheClassDescriptor- Descriptor type to be retrieved.- Returns:
- Map of Entity PKs associated to the Entities that were retrieved
- Throws:
QueryException
-
getAllCacheKeysFromIdentityMapWithEntityPK
public java.util.Map<java.lang.Object,CacheKey> getAllCacheKeysFromIdentityMapWithEntityPK(java.lang.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- List of Entity PKs to extract from the cacheClassDescriptor- Descriptor type to be retrieved.- Returns:
- Map of Entity PKs associated to the Entities that were retrieved
- Throws:
QueryException
-
invalidateObjects
public void invalidateObjects(Expression selectionCriteria, java.lang.Class theClass, Record translationRow, boolean shouldInvalidateOnException)
Invalidate objects meeting selectionCriteria.
-
getCacheKeyForObjectForLock
public CacheKey getCacheKeyForObjectForLock(java.lang.Object primaryKey, java.lang.Class theClass, ClassDescriptor descriptor)
Retrieve the cache key for the given identity information.
-
getCacheKeyForObject
public CacheKey getCacheKeyForObject(java.lang.Object primaryKey, java.lang.Class theClass, ClassDescriptor descriptor, boolean forMerge)
Retrieve the cache key for the given identity information.
-
getCacheMutex
public ConcurrencyManager getCacheMutex()
Return the cache mutex. This allows for the entire cache to be locked. This is done for transaction isolations on merges, although never locked by default.
-
getClassesRegistered
public java.util.Vector getClassesRegistered()
This method is used to get a list of those classes with IdentityMaps in the Session.
-
getFromIdentityMap
public java.lang.Object getFromIdentityMap(java.lang.Object object)
Get the object from the identity map which has the same identity information as the given object.
-
getFromIdentityMap
public java.lang.Object getFromIdentityMap(java.lang.Object key, java.lang.Class theClass, ClassDescriptor descriptor)Get the object from the identity map which has the given primary key and class.
-
getFromIdentityMap
public java.lang.Object getFromIdentityMap(java.lang.Object key, java.lang.Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor)Get the object from the identity map which has the given primary key and class. Only return the object if it has not been invalidated.
-
getFromIdentityMap
public java.lang.Object getFromIdentityMap(Expression selectionCriteria, java.lang.Class theClass, Record translationRow, int valueHolderPolicy, boolean conforming, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor)
-
getFromIdentityMapWithDeferredLock
public java.lang.Object getFromIdentityMapWithDeferredLock(java.lang.Object key, java.lang.Class theClass, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor)Get the object from the cache with the given primary key and class. Do not return the object if it was invalidated.
-
getIdentityMap
public IdentityMap getIdentityMap(ClassDescriptor descriptor)
INTERNAL: Return the identity map for the class, if missing create a new one.
-
getIdentityMap
public IdentityMap getIdentityMap(ClassDescriptor descriptor, boolean returnNullIfNoMap)
INTERNAL: Return the identity map for the class.- Parameters:
returnNullIfNoMap- if true return null if no map, otherwise create one.
-
getIdentityMaps
protected java.util.Map<java.lang.Class,IdentityMap> getIdentityMaps()
-
getIdentityMapClasses
public java.util.Iterator getIdentityMapClasses()
Return an iterator of the classes in the identity map.
-
getQueryResult
public java.lang.Object getQueryResult(ReadQuery query, java.util.List parameters, boolean shouldCheckExpiry)
Get the cached results associated with a query. Results are cached by the values of the parameters to the query so different parameters will have different cached results.
-
getCacheKeyByIndex
public CacheKey getCacheKeyByIndex(CacheIndex index, CacheId indexValues, boolean shouldCheckExpiry, ClassDescriptor descriptor)
Return the cache key for the cache index or null if not found.
-
putCacheKeyByIndex
public void putCacheKeyByIndex(CacheIndex index, CacheId indexValues, CacheKey cacheKey, ClassDescriptor descriptor)
Index the cache key by the index values.
-
getSession
protected AbstractSession getSession()
-
getWrapper
public java.lang.Object getWrapper(java.lang.Object primaryKey, java.lang.Class theClass)Get the wrapper object from the cache key associated with the given primary key, this is used for EJB.
-
getWriteLockManager
public WriteLockManager getWriteLockManager()
Returns the single write Lock manager for this session
-
getWriteLockValue
public java.lang.Object getWriteLockValue(java.lang.Object primaryKey, java.lang.Class domainClass, ClassDescriptor descriptor)Retrieve the write lock value of the cache key associated with the given primary key,
-
initializeIdentityMap
public void initializeIdentityMap(java.lang.Class theClass) throws EclipseLinkExceptionReset the identity map for only the instances of the class. For inheritance the user must make sure that they only use the root class.- Throws:
EclipseLinkException
-
initializeIdentityMaps
public void initializeIdentityMaps()
-
printIdentityMap
public void printIdentityMap(java.lang.Class businessClass)
Used to print all the objects in the identity map of the passed in class. The output of this method will be logged to this session's SessionLog at SEVERE level.
-
printIdentityMaps
public void printIdentityMaps()
Used to print all the objects in every identity map in this session. The output of this method will be logged to this session's SessionLog at SEVERE level.
-
printLocks
public void printLocks()
Used to print all the Locks in every identity map in this session. The output of this method will be logged to this session's SessionLog at FINEST level.
-
printLocks
public void printLocks(java.lang.Class theClass)
Used to print all the Locks in the specified identity map in this session. The output of this method will be logged to this session's SessionLog at FINEST level.
-
putInIdentityMap
public CacheKey putInIdentityMap(java.lang.Object domainObject, java.lang.Object keys, java.lang.Object writeLockValue, long readTime, ClassDescriptor descriptor)
Register the object with the identity map. The object must always be registered with its version number if optimistic locking is used. The readTime may also be included in the cache key as it is constructed
-
putQueryResult
public void putQueryResult(ReadQuery query, java.util.List parameters, java.lang.Object results)
Set the results for a query. Query results are cached based on the parameter values provided to the query different parameter values access different caches.
-
releaseReadLock
protected void releaseReadLock()
Read-release the local-map and the entire cache.
-
releaseWriteLock
public void releaseWriteLock()
Lock the entire cache if the cache isolation requires. By default concurrent reads and writes are allowed. By write, unit of work merge is meant.
-
removeFromIdentityMap
public java.lang.Object removeFromIdentityMap(java.lang.Object key, java.lang.Class domainClass, ClassDescriptor descriptor, java.lang.Object objectToRemove)Remove the object from the object cache.
-
setCacheMutex
protected void setCacheMutex(ConcurrencyManager cacheMutex)
Set the cache mutex. This allows for the entire cache to be locked. This is done for transaction isolations on merges, although never locked by default.
-
setIdentityMaps
public void setIdentityMaps(java.util.concurrent.ConcurrentMap identityMaps)
-
setSession
protected void setSession(AbstractSession session)
-
setWrapper
public void setWrapper(java.lang.Object primaryKey, java.lang.Class theClass, java.lang.Object wrapper)Update the wrapper object the cache key associated with the given primary key, this is used for EJB.
-
setWriteLockValue
public void setWriteLockValue(java.lang.Object primaryKey, java.lang.Class theClass, java.lang.Object writeLockValue)Update the write lock value of the cache key associated with the given primary key,
-
checkForInheritance
protected java.lang.Object checkForInheritance(java.lang.Object domainObject, java.lang.Class superClass, ClassDescriptor descriptor)This method is used to resolve the inheritance issues arisen when conforming from the identity map 1. Avoid reading the unintended subclass during in-memory query(e.g. when querying on large project, do not want to check small project, both are inherited from the project, and stored in the same identity map). 2. EJB container-generated classes broke the inheritance hierarchy. Need to use associated descriptor to track the relationship. CR4005-2612426, King-Sept-18-2002
-
-