Top Description Inners Fields Constructors Methods
org.eclipse.persistence.internal.identitymaps

public Class HardCacheWeakIdentityMap

extends WeakIdentityMap
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.internal.identitymaps.SoftCacheWeakIdentityMap
Imports
org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.internal.helper.linkedlist.ExposedNodeLinkedList, .LinkedNode, org.eclipse.persistence.internal.sessions.AbstractSession

Purpose: A HardCacheWeakIdentityMap is identical to the weak identity map, however the weak reference can be a performance problem for some types of apps because it can cause too much garbage collection of objects read causing them to be re-read and re-built (this defeats the purpose of the cache). The hard weak cache solves this by also holding a fixed number of objects in memory to improve caching.
This class makes use of an exposed node linked list to maintain the objects by storing the link nodes in the cache key.

Responsibilities:

Since
TOPLink/Java 1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
HardCacheWeakIdentityMap.ReferenceCacheKey

Inner class to define the specialized weak cache key.

Field Summary

Modifier and TypeField and Description
protected ExposedNodeLinkedList
referenceCache

A subset of cache entries have hard references maintained in this list to reduce garbage collection frequency

Inherited from org.eclipse.persistence.internal.identitymaps.WeakIdentityMap:
cleanupCountcleanupSize

Constructor Summary

AccessConstructor and Description
public
HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated)

Method Summary

Modifier and TypeMethod and Description
public Object
buildReference(Object
is the domain object to cache.
object
)

Allows subclass to create a SoftReference to the object.

public CacheKey
createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)

Overrides org.eclipse.persistence.internal.identitymaps.WeakIdentityMap.createCacheKey.

Use a ReferenceCacheKey that also stores the linked list node to manage the LRU sub-cache of references.
public ExposedNodeLinkedList
getReferenceCache()

Return the linked reference cache.

public boolean
hasReference(Object
the object for hard or the reference for soft.
reference
)

Checks if the object is null, or reference's object is null.

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)

Overrides org.eclipse.persistence.internal.identitymaps.FullIdentityMap.put.

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

Store the object in the cache at its primary key, and add to sub-cache list.
public Object
public synchronized void
Inherited from org.eclipse.persistence.internal.identitymaps.WeakIdentityMap:
checkCleanupcleanupDeadCacheKeysputCacheKeyIfAbsent

Field Detail

referenceCacheback to summary
protected ExposedNodeLinkedList referenceCache

A subset of cache entries have hard references maintained in this list to reduce garbage collection frequency

Constructor Detail

HardCacheWeakIdentityMapback to summary
public HardCacheWeakIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isIsolated)

Method Detail

buildReferenceback to summary
public Object buildReference(Object object)

Allows subclass to create a SoftReference to the object.

Parameters
object:Object

is the domain object to cache.

createCacheKeyback to summary
public CacheKey createCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime)

Overrides org.eclipse.persistence.internal.identitymaps.WeakIdentityMap.createCacheKey.

Use a ReferenceCacheKey that also stores the linked list node to manage the LRU sub-cache of references.

Annotations
@Override
getReferenceCacheback to summary
public ExposedNodeLinkedList getReferenceCache()

Return the linked reference cache.

hasReferenceback to summary
public boolean hasReference(Object reference)

Checks if the object is null, or reference's object is null.

Parameters
reference:Object

the object for hard or the reference for soft.

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

Overrides org.eclipse.persistence.internal.identitymaps.FullIdentityMap.put.

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

Store the object in the cache at its primary key, and add to sub-cache list.

Parameters
primaryKey:Object

Doc from org.eclipse.persistence.internal.identitymaps.FullIdentityMap.put.

is the primary key for the object.

object:Object

Doc from org.eclipse.persistence.internal.identitymaps.FullIdentityMap.put.

is the domain object to cache.

writeLockValue:Object

Doc from org.eclipse.persistence.internal.identitymaps.FullIdentityMap.put.

is the current write lock value of object, if null the version is ignored.

Annotations
@Override
removeback to summary
public Object remove(CacheKey cacheKey)

Overrides org.eclipse.persistence.internal.identitymaps.FullIdentityMap.remove.

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

Remove the cache key from the map and the sub-cache list.

Returns:Object

Doc from org.eclipse.persistence.internal.identitymaps.FullIdentityMap.remove.

the object held within the CacheKey or null if no object cached for given cacheKey.

Annotations
@Override
updateMaxSizeback to summary
public synchronized void updateMaxSize(int maxSize)

Overrides org.eclipse.persistence.internal.identitymaps.AbstractIdentityMap.updateMaxSize.

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

This method will be used to update the max cache size.

Annotations
@Override
org.eclipse.persistence.internal.identitymaps back to summary

public Class HardCacheWeakIdentityMap.ReferenceCacheKey

extends WeakCacheKey
Class Inheritance

Inner class to define the specialized weak cache key. Keeps track of the linked list node to allow quick repositioning.

Field Summary

Modifier and TypeField and Description
protected LinkedNode
Inherited from org.eclipse.persistence.internal.identitymaps.WeakCacheKey:
reference

Constructor Summary

AccessConstructor and Description
public
ReferenceCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime, boolean isIsolated)

Method Summary

Modifier and TypeMethod and Description
public ExposedNodeLinkedList
public LinkedNode
public void
public void
updateAccess()

Overrides org.eclipse.persistence.internal.identitymaps.CacheKey.updateAccess.

Notifies that cache key that it has been accessed.
Inherited from org.eclipse.persistence.internal.identitymaps.WeakCacheKey:
getObjectsetObject

Field Detail

referenceNodeback to summary
protected LinkedNode referenceNode

Constructor Detail

ReferenceCacheKeyback to summary
public ReferenceCacheKey(Object primaryKey, Object object, Object writeLockValue, long readTime, boolean isIsolated)

Method Detail

getReferenceCacheback to summary
public ExposedNodeLinkedList getReferenceCache()
getReferenceCacheNodeback to summary
public LinkedNode getReferenceCacheNode()
setReferenceCacheNodeback to summary
public void setReferenceCacheNode(LinkedNode referenceNode)
updateAccessback to summary
public void updateAccess()

Overrides org.eclipse.persistence.internal.identitymaps.CacheKey.updateAccess.

Notifies that cache key that it has been accessed. Allows the LRU sub-cache to be maintained, the cache node must be moved to the front of the list.

Annotations
@Override