Class CacheKey
- java.lang.Object
-
- org.eclipse.persistence.internal.helper.ConcurrencyManager
-
- org.eclipse.persistence.internal.identitymaps.CacheKey
-
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
CacheKeyInterceptor
,LinkedCacheKey
,WeakCacheKey
public class CacheKey extends ConcurrencyManager implements Cloneable
Purpose: Container class for storing objects in an IdentityMap.
Responsibilities:
- Hold key and object.
- Maintain and update the current writeLockValue.
- Since:
- TOPLink/Java 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
CACHE_KEY_INVALID
static int
CHECK_INVALIDATION_POLICY
The following constants are used for the invalidationState variablelong
CREATION_THREAD_HASHCODE
long
CREATION_THREAD_ID
String
CREATION_THREAD_NAME
protected int
invalidationState
Invalidation State can be used to indicate whether this cache key is considered validprotected boolean
isIsolated
Set to true if this CacheKey comes from an IsolatedClientSession, or DatabaseSessionImpl.protected boolean
isWrapper
Stores if this CacheKey instance is a wrapper for the underlying CacheKey.protected Object
key
The key holds the vector of primary key values for the object.protected long
lastUpdatedQueryId
This attribute is the system time in milli seconds that the object was last refreshed onprotected IdentityMap
mapOwner
static int
MAX_WAIT_TRIES
protected Object
object
protected AbstractRecord
protectedForeignKeys
Stores retrieved FK values for relationships that are not stored in the Entityprotected long
readTime
The read time stores the millisecond value of the last time the object help by this cache key was confirmed as up to date.protected Record
record
This is used for Document Preservation to cache the record that this object was built fromprotected Object
transactionId
The ID of the database transaction that last wrote the object.protected Object
wrapper
The cached wrapper for the object, used in EJB.protected Object
writeLockValue
The writeLock value is being held as an object so that it might contain a number or timestamp.-
Fields inherited from class org.eclipse.persistence.internal.helper.ConcurrencyManager
activeThread, DEFERRED_LOCK_MANAGERS, depth, lockedByMergeManager, numberOfReaders, numberOfWritersWaiting, shouldTrackStack, stack
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CacheKey()
Internal: Only used by subclasses that may want to wrap the cache key.CacheKey(Object primaryKey)
CacheKey(Object primaryKey, Object object, Object lockValue)
CacheKey(Object primaryKey, Object object, Object lockValue, long readTime, boolean isIsolated)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acquire()
Acquire the lock on the cache key object.void
acquire(boolean forMerge)
Acquire the lock on the cache key object.void
acquireDeferredLock()
Acquire the deferred lock.boolean
acquireIfUnownedNoWait()
Acquire the lock on the cache key object.void
acquireLock(ObjectBuildingQuery query)
boolean
acquireNoWait()
Acquire the lock on the cache key object.boolean
acquireNoWait(boolean forMerge)
Acquire the lock on the cache key object.void
acquireReadLock()
Acquire the read lock on the cache key object.boolean
acquireReadLockNoWait()
Acquire the read lock on the cache key object.boolean
acquireWithWait(boolean forMerge, int wait)
Acquire the lock on the cache key object.void
checkDeferredLock()
Check the deferred lock on the cache key object.void
checkReadLock()
Check the read lock on the cache key object.Object
clone()
INTERNAL: Clones itself.boolean
equals(Object object)
Determine if the receiver is equal to anObject.boolean
equals(CacheKey key)
Determine if the receiver is equal to key.Thread
getActiveThread()
Return the active thread.int
getInvalidationState()
INTERNAL: Return the value of the invalidationState Variable The return value will be a constant CHECK_INVALIDATION_POLICY - The Invalidation policy is must be checked for this cache key's sate CACHE_KEY_INVALID - This cache key has been labeled invalid.Object
getKey()
long
getLastUpdatedQueryId()
INTERNAL: This method returns the system time in millis seconds at which this object was last refreshed CR #4365 CR #2698903 ...Object
getObject()
IdentityMap
getOwningMap()
AbstractRecord
getProtectedForeignKeys()
INTERNAL: Return the FK cachelong
getReadTime()
INTERNAL: Return the current value of the Read Time variableRecord
getRecord()
Object
getTransactionId()
CacheKey
getWrappedCacheKey()
If a Wrapper subclasses this CacheKey this method will be used to unwrap the cache key.Object
getWrapper()
Object
getWriteLockValue()
int
hashCode()
Overrides hashCode() in Object to use the primaryKey's hashCode for storage in data structures.boolean
hasProtectedForeignKeys()
Returns true if the protectedForeignKeys record is non-null and non-empty, false otherwise.boolean
isIsolated()
Returns true if this CacheKey is from an IsolatedClientSessionboolean
isWrapper()
Returns true if this Instance of CacheKey is a wrapper and should be unwrapped before passing to IdentityMap APIs.void
release()
Release the lock on the cache key object.void
releaseDeferredLock()
Release the deferred lockvoid
releaseReadLock()
Release the read lock on the cache key object.Object
removeFromOwningMap()
Removes this cacheKey from the owning mapvoid
setInvalidationState(int invalidationState)
INTERNAL: Set the value of the invalidationState Variable The possible values are from an enumeration of constants CHECK_INVALIDATION_POLICY - The invalidation policy is must be checked for this cache key's sate CACHE_KEY_INVALID - This cache key has been labelled invalid.void
setIsolated(boolean isIsolated)
void
setIsWrapper(boolean isWrapper)
void
setKey(Object key)
void
setLastUpdatedQueryId(long id)
INTERNAL: This method sets the system time in millis seconds at which this object was last refreshed CR #4365 CR #2698903 ...void
setObject(Object object)
void
setOwningMap(IdentityMap map)
void
setProtectedForeignKeys(AbstractRecord protectedForeignKeys)
void
setReadTime(long readTime)
INTERNAL: Set the read time of this cache keyvoid
setRecord(Record newRecord)
void
setTransactionId(Object transactionId)
void
setWrapper(Object wrapper)
void
setWriteLockValue(Object writeLockValue)
String
toString()
Print the nested depth.void
updateAccess()
Notifies that cache key that it has been accessed.Object
waitForObject()
-
Methods inherited from class org.eclipse.persistence.internal.helper.ConcurrencyManager
acquireIfUnownedNoWait, addReadLockToReadLockManager, clearJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse, enrichStringBuildingExplainWhyThreadIsStuckInIsBuildObjectOnThreadComplete, getConcurrencyManagerCreationDate, getConcurrencyManagerId, getDeferredLockManager, getDeferredLockManagers, getDepth, getNumberOfReaders, getNumberOfWritersWaiting, getReadLockManager, getReadLockManagerEnsureResultIsNotNull, getReadLockManagers, getStack, getThreadsToWaitOnAcquire, getThreadsToWaitOnAcquireMethodName, getThreadsToWaitOnAcquireReadLock, getThreadsToWaitOnAcquireReadLockMethodName, getThreadsWaitingToReleaseDeferredLocks, getThreadsWaitingToReleaseDeferredLocksJustification, getTotalNumberOfKeysAcquiredForReading, getTotalNumberOfKeysReleasedForReading, getTotalNumberOfKeysReleasedForReadingBlewUpExceptionDueToCacheKeyHavingReachedCounterZero, initializeDeferredLockManagers, isAcquired, isBuildObjectOnThreadComplete, isLockedByMergeManager, isNested, putDeferredLock, putThreadAsWaitingToAcquireLockForReading, putThreadAsWaitingToAcquireLockForWriting, releaseAllLocksAcquiredByThread, removeDeferredLockManager, removeReadLockFromReadLockManager, removeReadLockManagerIfEmpty, removeThreadNoLongerWaitingToAcquireLockForReading, removeThreadNoLongerWaitingToAcquireLockForWriting, setActiveThread, setDepth, setIsLockedByMergeManager, setJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse, setNumberOfReaders, setNumberOfWritersWaiting, setShouldTrackStack, setStack, shouldTrackStack, transitionToDeferredLock
-
-
-
-
Field Detail
-
CREATION_THREAD_ID
public final long CREATION_THREAD_ID
-
CREATION_THREAD_NAME
public final String CREATION_THREAD_NAME
-
CREATION_THREAD_HASHCODE
public final long CREATION_THREAD_HASHCODE
-
key
protected Object key
The key holds the vector of primary key values for the object.
-
object
protected Object object
-
mapOwner
protected IdentityMap mapOwner
-
writeLockValue
protected Object writeLockValue
The writeLock value is being held as an object so that it might contain a number or timestamp.
-
wrapper
protected Object wrapper
The cached wrapper for the object, used in EJB.
-
record
protected Record record
This is used for Document Preservation to cache the record that this object was built from
-
lastUpdatedQueryId
protected long lastUpdatedQueryId
This attribute is the system time in milli seconds that the object was last refreshed on
-
invalidationState
protected int invalidationState
Invalidation State can be used to indicate whether this cache key is considered valid
-
CHECK_INVALIDATION_POLICY
public static final int CHECK_INVALIDATION_POLICY
The following constants are used for the invalidationState variable- See Also:
- Constant Field Values
-
CACHE_KEY_INVALID
public static final int CACHE_KEY_INVALID
- See Also:
- Constant Field Values
-
MAX_WAIT_TRIES
public static final int MAX_WAIT_TRIES
- See Also:
- Constant Field Values
-
readTime
protected long readTime
The read time stores the millisecond value of the last time the object help by this cache key was confirmed as up to date.
-
isWrapper
protected boolean isWrapper
Stores if this CacheKey instance is a wrapper for the underlying CacheKey. CacheKey wrappers may be used with cache interceptors.
-
protectedForeignKeys
protected AbstractRecord protectedForeignKeys
Stores retrieved FK values for relationships that are not stored in the Entity
-
isIsolated
protected boolean isIsolated
Set to true if this CacheKey comes from an IsolatedClientSession, or DatabaseSessionImpl.
-
transactionId
protected Object transactionId
The ID of the database transaction that last wrote the object. This is used for database change notification.
-
-
Constructor Detail
-
CacheKey
protected CacheKey()
Internal: Only used by subclasses that may want to wrap the cache key. Could be replaced by switching to an interface.
-
CacheKey
public CacheKey(Object primaryKey)
-
-
Method Detail
-
acquire
public void acquire()
Acquire the lock on the cache key object.- Overrides:
acquire
in classConcurrencyManager
-
acquire
public void acquire(boolean forMerge)
Acquire the lock on the cache key object. For the merge process called with true from the merge process, if true then the refresh will not refresh the object- Overrides:
acquire
in classConcurrencyManager
-
acquireNoWait
public boolean acquireNoWait()
Acquire the lock on the cache key object. But only if the object has no lock on it Added for CR 2317- Overrides:
acquireNoWait
in classConcurrencyManager
-
acquireIfUnownedNoWait
public boolean acquireIfUnownedNoWait()
Acquire the lock on the cache key object. Only acquire a lock if the cache key's active thread is not set. Added for Bug 5840635
-
acquireNoWait
public boolean acquireNoWait(boolean forMerge)
Acquire the lock on the cache key object. But only if the object has no lock on it Added for CR 2317 called with true from the merge process, if true then the refresh will not refresh the object- Overrides:
acquireNoWait
in classConcurrencyManager
-
acquireWithWait
public boolean acquireWithWait(boolean forMerge, int wait)
Acquire the lock on the cache key object. But only if the object has no lock on it Added for CR 2317 called with true from the merge process, if true then the refresh will not refresh the object- Overrides:
acquireWithWait
in classConcurrencyManager
-
acquireDeferredLock
public void acquireDeferredLock()
Acquire the deferred lock.- Overrides:
acquireDeferredLock
in classConcurrencyManager
-
acquireLock
public void acquireLock(ObjectBuildingQuery query)
-
checkReadLock
public void checkReadLock()
Check the read lock on the cache key object. This can be called to ensure the cache key has a valid built object. It does not hold a lock, so the object could be refreshed afterwards.- Overrides:
checkReadLock
in classConcurrencyManager
-
checkDeferredLock
public void checkDeferredLock()
Check the deferred lock on the cache key object. This can be called to ensure the cache key has a valid built object. It does not hold a lock, so the object could be refreshed afterwards.- Overrides:
checkDeferredLock
in classConcurrencyManager
-
acquireReadLock
public void acquireReadLock()
Acquire the read lock on the cache key object.- Overrides:
acquireReadLock
in classConcurrencyManager
-
acquireReadLockNoWait
public boolean acquireReadLockNoWait()
Acquire the read lock on the cache key object. Return true if acquired.- Overrides:
acquireReadLockNoWait
in classConcurrencyManager
-
equals
public boolean equals(Object object)
Determine if the receiver is equal to anObject. If anObject is a CacheKey, do further comparison, otherwise, return false.- Overrides:
equals
in classObject
- See Also:
equals(CacheKey)
-
equals
public boolean equals(CacheKey key)
Determine if the receiver is equal to key. Use an index compare, because it is much faster than enumerations.
-
getLastUpdatedQueryId
public long getLastUpdatedQueryId()
INTERNAL: This method returns the system time in millis seconds at which this object was last refreshed CR #4365 CR #2698903 ... instead of using millis we will now use id's instead. Method renamed appropriately.
-
getKey
public Object getKey()
-
getActiveThread
public Thread getActiveThread()
Return the active thread.- Overrides:
getActiveThread
in classConcurrencyManager
-
getObject
public Object getObject()
-
getOwningMap
public IdentityMap getOwningMap()
-
getReadTime
public long getReadTime()
INTERNAL: Return the current value of the Read Time variable
-
getRecord
public Record getRecord()
-
getWrapper
public Object getWrapper()
-
getWrappedCacheKey
public CacheKey getWrappedCacheKey()
If a Wrapper subclasses this CacheKey this method will be used to unwrap the cache key.- Returns:
-
getWriteLockValue
public Object getWriteLockValue()
-
hashCode
public int hashCode()
Overrides hashCode() in Object to use the primaryKey's hashCode for storage in data structures.
-
hasProtectedForeignKeys
public boolean hasProtectedForeignKeys()
Returns true if the protectedForeignKeys record is non-null and non-empty, false otherwise.
-
isIsolated
public boolean isIsolated()
Returns true if this CacheKey is from an IsolatedClientSession
-
isWrapper
public boolean isWrapper()
Returns true if this Instance of CacheKey is a wrapper and should be unwrapped before passing to IdentityMap APIs. Wrapped CacheKeys may be used in the Cache Interceptors.
-
getProtectedForeignKeys
public AbstractRecord getProtectedForeignKeys()
INTERNAL: Return the FK cache
-
getInvalidationState
public int getInvalidationState()
INTERNAL: Return the value of the invalidationState Variable The return value will be a constant CHECK_INVALIDATION_POLICY - The Invalidation policy is must be checked for this cache key's sate CACHE_KEY_INVALID - This cache key has been labeled invalid.
-
release
public void release()
Release the lock on the cache key object.- Overrides:
release
in classConcurrencyManager
-
releaseDeferredLock
public void releaseDeferredLock()
Release the deferred lock- Overrides:
releaseDeferredLock
in classConcurrencyManager
-
releaseReadLock
public void releaseReadLock()
Release the read lock on the cache key object.- Overrides:
releaseReadLock
in classConcurrencyManager
-
removeFromOwningMap
public Object removeFromOwningMap()
Removes this cacheKey from the owning map
-
setInvalidationState
public void setInvalidationState(int invalidationState)
INTERNAL: Set the value of the invalidationState Variable The possible values are from an enumeration of constants CHECK_INVALIDATION_POLICY - The invalidation policy is must be checked for this cache key's sate CACHE_KEY_INVALID - This cache key has been labelled invalid.
-
setLastUpdatedQueryId
public void setLastUpdatedQueryId(long id)
INTERNAL: This method sets the system time in millis seconds at which this object was last refreshed CR #4365 CR #2698903 ... instead of using millis we will now use ids instead. Method renamed appropriately.
-
setKey
public void setKey(Object key)
-
setObject
public void setObject(Object object)
-
setOwningMap
public void setOwningMap(IdentityMap map)
-
setProtectedForeignKeys
public void setProtectedForeignKeys(AbstractRecord protectedForeignKeys)
-
setReadTime
public void setReadTime(long readTime)
INTERNAL: Set the read time of this cache key
-
setRecord
public void setRecord(Record newRecord)
-
setWrapper
public void setWrapper(Object wrapper)
-
setWriteLockValue
public void setWriteLockValue(Object writeLockValue)
-
toString
public String toString()
Description copied from class:ConcurrencyManager
Print the nested depth.- Overrides:
toString
in classConcurrencyManager
-
updateAccess
public void updateAccess()
Notifies that cache key that it has been accessed. Allows the LRU sub-cache to be maintained.
-
setIsolated
public void setIsolated(boolean isIsolated)
-
setIsWrapper
public void setIsWrapper(boolean isWrapper)
-
getTransactionId
public Object getTransactionId()
-
setTransactionId
public void setTransactionId(Object transactionId)
-
waitForObject
public Object waitForObject()
-
-