public abstract class IdentityMap extends Object implements Serializable, Cloneable
Purpose: Caches objects, and allows their retrieval by their primary key.
Responsibilities:
CacheKey
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected int |
maxSize
The innitial or maximum size of the cache depending upon the concrete implementation
|
protected CacheKey |
searchKey
Used to optimize get through avoiding recreation of the cache key each time.
|
Constructor and Description |
---|
IdentityMap(int size)
Instantiate an new IdentityMap with it's maximum size.
|
Modifier and Type | Method and Description |
---|---|
CacheKey |
acquireDeferredLock(Vector primaryKey)
Acquire the deferred lock
|
CacheKey |
acquireLock(Vector primaryKey,
boolean forMerge)
Set an exclusive lock on an object in the IdentityMap.
|
CacheKey |
acquireLockNoWait(Vector primaryKey,
boolean forMerge)
Set an exclusive lock on an object in the IdentityMap.
|
CacheKey |
acquireReadLockOnCacheKey(Vector primaryKey)
INTERNAL:
Find the cachekey for the provided primary key and place a readlock on it.
|
CacheKey |
acquireReadLockOnCacheKeyNoWait(Vector primaryKey)
INTERNAL:
Find the cachekey for the provided primary key and place a readlock on it.
|
Object |
clone()
INTERNAL:
Clones itself.
|
abstract void |
collectLocks(HashMap threadList)
INTERNAL:
Used to print all the Locks in every identity map in this session.
|
boolean |
containsKey(Vector primaryKey)
Return true if an object is indexed in the recevier at the primary key <aVector>
|
CacheKey |
createCacheKey(Vector primaryKey,
Object object,
Object writeLockValue) |
CacheKey |
createCacheKey(Vector primaryKey,
Object object,
Object writeLockValue,
long readTime) |
abstract Enumeration |
elements()
Allow for the cache to be iterated on.
|
Object |
get(Vector primaryKey)
Return the object cached in the identity map or null if it could not be found.
|
protected abstract CacheKey |
getCacheKey(CacheKey cacheKey)
Return the cache key (with object) matching the cache key wrapper of the primary key.
|
protected CacheKey |
getCacheKey(Vector primaryKey)
Get the cache key (with object) for the primary key.
|
protected CacheKey |
getCacheKeyWithReadLock(Vector primaryKey)
Get the cache key (with object) for the primary key with read lock.
|
static Class |
getDefaultIdentityMapClass()
INTERNAL:
Returns the class which should be used as an identity map.
|
int |
getMaxSize() |
protected CacheKey |
getSearchKey() |
abstract int |
getSize()
Return the number of objects in the receiver.
|
abstract int |
getSize(Class myClass,
boolean recurse)
Return the number of actual objects of type myClass in the IdentityMap.
|
Object |
getWrapper(Vector primaryKey)
Get the wrapper object from the cache key associated with the given primary key,
this is used for EJB.
|
Object |
getWriteLockValue(Vector primaryKey)
Get the write lock value from the cache key associated to the primarykey
|
void |
initialize(int size)
Initialize the newly allocated instance of this class.
|
abstract Enumeration |
keys()
Allow for the cache keys to be iterated on.
|
protected abstract void |
put(CacheKey cacheKey)
Store the object in the cache with the cache key.
|
abstract CacheKey |
put(Vector primaryKey,
Object object,
Object writeLockValue,
long readTime)
Store the object in the cache at its primary key.
|
abstract Object |
remove(CacheKey cacheKey)
Remove the cache key from the cache.
|
Object |
remove(Vector primaryKey)
Remove the primary key from the cache.
|
protected void |
setMaxSize(int size)
Set the maximum size for the recevier.
|
protected void |
setSearchKey(CacheKey searchKey) |
void |
setWrapper(Vector primaryKey,
Object wrapper)
Update the wrapper object the cache key associated with the given primary key,
this is used for EJB.
|
void |
setWriteLockValue(Vector primaryKey,
Object writeLockValue)
Update the write lock value of the cache key associated with the given primary key,
|
String |
toString() |
void |
updateCacheKey(CacheKey cacheKey)
This is used to notify the identity map of a locked keys modification to allow updating of weak refs.
|
void |
updateMaxSize(int maxSize)
INTERNAL:
This method will be used to update the max cache size, any objects exceeding the max cache size will
be remove from the cache.
|
protected int maxSize
protected CacheKey searchKey
public IdentityMap(int size)
NOTE: Subclasses may provide different behaviour for maxSize.
anInteger
- is the maximum size to be allocated for the recevier.public CacheKey acquireDeferredLock(Vector primaryKey)
public CacheKey acquireLock(Vector primaryKey, boolean forMerge)
public abstract void collectLocks(HashMap threadList)
public CacheKey acquireLockNoWait(Vector primaryKey, boolean forMerge)
public CacheKey acquireReadLockOnCacheKey(Vector primaryKey)
public CacheKey acquireReadLockOnCacheKeyNoWait(Vector primaryKey)
public boolean containsKey(Vector primaryKey)
aVector
- is the primary key for the object to search for.public CacheKey createCacheKey(Vector primaryKey, Object object, Object writeLockValue)
public CacheKey createCacheKey(Vector primaryKey, Object object, Object writeLockValue, long readTime)
public abstract Enumeration elements()
public Object get(Vector primaryKey)
protected CacheKey getCacheKey(Vector primaryKey)
protected abstract CacheKey getCacheKey(CacheKey cacheKey)
protected CacheKey getCacheKeyWithReadLock(Vector primaryKey)
public static Class getDefaultIdentityMapClass()
public int getMaxSize()
protected CacheKey getSearchKey()
public abstract int getSize()
public abstract int getSize(Class myClass, boolean recurse)
public Object getWrapper(Vector primaryKey)
public Object getWriteLockValue(Vector primaryKey)
public void initialize(int size)
anInteger
- is the maximum size to be allocated for the recevier.public abstract Enumeration keys()
public abstract CacheKey put(Vector primaryKey, Object object, Object writeLockValue, long readTime)
primaryKey
- is the primary key for the object.object
- is the domain object to cache.writeLockValue
- is the current write lock value of object, if null the version is ignored.readTime
- the read time of the object to be stored in the cacheprotected abstract void put(CacheKey cacheKey)
protected void setMaxSize(int size)
anInteger
- is the new maximum size.public void updateMaxSize(int maxSize)
protected void setSearchKey(CacheKey searchKey)
public void setWrapper(Vector primaryKey, Object wrapper)
public void setWriteLockValue(Vector primaryKey, Object writeLockValue)
public void updateCacheKey(CacheKey cacheKey)
Copyright © 2023. All rights reserved.