Package org.apache.openjpa.datacache
Class AbstractDataCache
- java.lang.Object
- 
- org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
- 
- org.apache.openjpa.datacache.AbstractDataCache
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- DataCache,- Configurable,- Clearable,- Closeable,- EventManager
 - Direct Known Subclasses:
- ConcurrentDataCache
 
 public abstract class AbstractDataCache extends AbstractConcurrentEventManager implements DataCache, Configurable AbstractDataCacheimplementation that provides various statistics, logging, and timeout functionality common across cache implementations.- Author:
- Patrick Linskey, Abe White
- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected boolean_evictOnBulkUpdateprotected java.util.Set<java.lang.String>_excludedTypesprotected java.util.Set<java.lang.String>_includedTypesprotected CacheStatisticsSPI_statsprotected OpenJPAConfigurationconfThe configuration set by the system.protected LoglogThe log to use.- 
Fields inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager_listeners
 - 
Fields inherited from interface org.apache.openjpa.datacache.DataCacheNAME_DEFAULT
 
- 
 - 
Constructor SummaryConstructors Constructor Description AbstractDataCache()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddExpirationListener(ExpirationListener listen)Add a new expiration event listener to this cache.voidafterCommit(RemoteCommitEvent event)This method is part of theRemoteCommitListenerinterface.voidclear()Remove all data from this cache.protected abstract voidclearInternal()Clear the cache.voidclose()Free the resources used by this cache.protected voidclose(boolean clear)voidcommit(java.util.Collection<DataCachePCData> additions, java.util.Collection<DataCachePCData> newUpdates, java.util.Collection<DataCachePCData> existingUpdates, java.util.Collection<java.lang.Object> deletes)Perform a batch update of the cache.booleancontains(java.lang.Object key)Returnstrueif this cache contains data corresponding tooid; otherwise returnsfalse.java.util.BitSetcontainsAll(java.util.Collection<java.lang.Object> keys)Returns the indexes of the oids in this cache.voidendConfiguration()Invoked upon completion of bean property configuration for this object.protected voidfireEvent(java.lang.Object event, java.lang.Object listener)Implement this method to fire the given event to the given listener.DataCachePCDataget(java.lang.Object key)Return the cached object for the given oid.java.util.Map<java.lang.Object,DataCachePCData>getAll(java.util.List<java.lang.Object> keys)Returns the objects for the given key List.voidgetEnableStatistics()java.lang.StringgetEvictionSchedule()booleangetEvictOnBulkUpdate()Returns whether the the cache needs to be updated when bulk updates as executed.java.util.Set<java.lang.String>getExcludedTypes()protected abstract DataCachePCDatagetInternal(java.lang.Object oid)Return the object for the given oid.java.lang.StringgetName()Returns a string name that can be used by end-user-visible code to identify this cache.DataCachegetPartition(java.lang.String name, boolean create)Gets the named partition.java.util.Set<java.lang.String>getPartitionNames()Gets the name of the known partitions.CacheStatisticsgetStatistics()Returns number of read/write request and cache hit ratio data.java.util.Set<java.lang.String>getTypes()voidinitialize(DataCacheManager manager)Initialize any resources associated with the givenDataCacheManager.booleanisClosed()booleanisPartitioned()Affirms if this cache maintains partitions.protected voidkeyRemoved(java.lang.Object key, boolean expired)Invoke when a key is removed from this cache.booleanpin(java.lang.Object key)Pin the value stored underoidinto the cache.voidpinAll(java.lang.Class<?> cls, boolean subs)Pin all oids for the given type.java.util.BitSetpinAll(java.util.Collection<java.lang.Object> keys)Pin all oids to the cache.protected abstract booleanpinInternal(java.lang.Object oid)Pin an object to the cache.DataCachePCDataput(DataCachePCData data)Set the cached value for the given instance.protected voidputAllInternal(java.util.Collection<DataCachePCData> pcs)Add all of the given objects to the cache.protected abstract DataCachePCDataputInternal(java.lang.Object oid, DataCachePCData pc)Add the given object to the cache, returning the old object under the given oid.protected booleanrecacheUpdates()Returntrueif updates to data already in the cache (either incommit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)or theupdate(org.apache.openjpa.datacache.DataCachePCData)) should be put back into the cache.DataCachePCDataremove(java.lang.Object key)Remove the value stored under the given oid.voidremoveAll(java.lang.Class<?> cls, boolean subClasses)Remove the objects of the given class from the cache.java.util.BitSetremoveAll(java.util.Collection<java.lang.Object> keys)Remove the values stored under the given oids.protected abstract voidremoveAllInternal(java.lang.Class<?> cls, boolean subclasses)Evict objects in cache by class.protected voidremoveAllInternal(java.util.Collection<java.lang.Object> oids)Remove all objects under the given oids from the cache.protected voidremoveAllTypeNamesInternal(java.util.Collection<java.lang.String> classNames)Remove all objects of the given class names from the cache.booleanremoveExpirationListener(ExpirationListener listen)Remove an expiration event listener from this cache.protected abstract DataCachePCDataremoveInternal(java.lang.Object oid)Remove the object under the given oid from the cache.DataCacheselectCache(OpenJPAStateManager sm)voidsetConfiguration(Configuration conf)Invoked prior to setting bean properties.voidsetEnableStatistics(boolean enable)voidsetEvictionSchedule(java.lang.String s)voidsetEvictOnBulkUpdate(boolean b)voidsetExcludedTypes(java.lang.String types)voidsetExcludedTypes(java.util.Set<java.lang.String> types)voidsetName(java.lang.String name)Sets a string name to be used to identify this cache to end-user needs.voidsetTypes(java.lang.String types)voidsetTypes(java.util.Set<java.lang.String> types)voidstartConfiguration()Invoked before bean property configuration is begun on this object.java.lang.StringtoString()booleanunpin(java.lang.Object key)Unpin the value stored underoidfrom the cache.voidunpinAll(java.lang.Class<?> cls, boolean subs)Unpin all oids associaed with the given type from the cache.java.util.BitSetunpinAll(java.util.Collection<java.lang.Object> keys)Unpin all oids from the cache.protected abstract booleanunpinInternal(java.lang.Object oid)Unpin an object from the cache.voidupdate(DataCachePCData data)Update the cached value for the given instance.- 
Methods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManageraddListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, newListenerCollection, removeListener, setFailFast
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.apache.openjpa.datacache.DataCachewriteLock, writeUnlock
 
- 
 
- 
- 
- 
Field Detail- 
_statsprotected CacheStatisticsSPI _stats 
 - 
confprotected OpenJPAConfiguration conf The configuration set by the system.
 - 
logprotected Log log The log to use.
 - 
_includedTypesprotected java.util.Set<java.lang.String> _includedTypes 
 - 
_excludedTypesprotected java.util.Set<java.lang.String> _excludedTypes 
 - 
_evictOnBulkUpdateprotected boolean _evictOnBulkUpdate 
 
- 
 - 
Method Detail- 
getNamepublic java.lang.String getName() Description copied from interface:DataCacheReturns a string name that can be used by end-user-visible code to identify this cache.
 - 
setNamepublic void setName(java.lang.String name) Description copied from interface:DataCacheSets a string name to be used to identify this cache to end-user needs.
 - 
setEnableStatisticspublic void setEnableStatistics(boolean enable) 
 - 
getEnableStatisticspublic void getEnableStatistics() 
 - 
getEvictionSchedulepublic java.lang.String getEvictionSchedule() 
 - 
setEvictionSchedulepublic void setEvictionSchedule(java.lang.String s) 
 - 
initializepublic void initialize(DataCacheManager manager) Description copied from interface:DataCacheInitialize any resources associated with the givenDataCacheManager.- Specified by:
- initializein interface- DataCache
 
 - 
commitpublic void commit(java.util.Collection<DataCachePCData> additions, java.util.Collection<DataCachePCData> newUpdates, java.util.Collection<DataCachePCData> existingUpdates, java.util.Collection<java.lang.Object> deletes) Description copied from interface:DataCachePerform a batch update of the cache. Add allDataCachePCDataobjects inadditionsand innewUpdates, make the appropriate modifications to all DataCachePCDatas inexistingUpdates, and delete all OIDs indeletes. All changes made to cached data must be made via this method. It is this method that is responsible for performing any side-effects that should happen on meaningful cache changes. Implementations should bear in mind that thedeletescollection may contain oids that are also in theadditionsmap. This is possible because it is valid for a user to delete an object with a particular oid and then add that object in the same batch.- Specified by:
- commitin interface- DataCache
- Parameters:
- additions- A collection of- DataCachePCDataobjects. These represent data that have been newly created, and thus must be added to the cache.
- newUpdates- A collection of- DataCachePCDataobjects. These represent data that have been modified but were not originally in the cache, and thus must be added to the cache.
- existingUpdates- A collection of- DataCachePCDataobjects. These represent data that have been modified and were originally loaded from the cache. It is up to the cache implementation to decide if these values must be re-enlisted in the cache. Some caches may return live data from- DataCache.get(java.lang.Object)invocations, in which case these values need not be re-enlisted.
- deletes- A collection of object IDs that have been deleted and must therefore be dropped from the cache.
 
 - 
containspublic boolean contains(java.lang.Object key) Description copied from interface:DataCacheReturnstrueif this cache contains data corresponding tooid; otherwise returnsfalse.
 - 
containsAllpublic java.util.BitSet containsAll(java.util.Collection<java.lang.Object> keys) Description copied from interface:DataCacheReturns the indexes of the oids in this cache.- Specified by:
- containsAllin interface- DataCache
 
 - 
getpublic DataCachePCData get(java.lang.Object key) Description copied from interface:DataCacheReturn the cached object for the given oid. Modifying the returned object may or may not change the cached value; theDataCache.update(org.apache.openjpa.datacache.DataCachePCData)method should be used to re-cache any changed objects.
 - 
getAllpublic java.util.Map<java.lang.Object,DataCachePCData> getAll(java.util.List<java.lang.Object> keys) Returns the objects for the given key List.
 - 
putpublic DataCachePCData put(DataCachePCData data) Description copied from interface:DataCacheSet the cached value for the given instance. This does not result in an update of other caches. Rather, it should only be used for loading clean data into the cache. Meaningful changes to the state of the cache should be made via theDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method.
 - 
updatepublic void update(DataCachePCData data) Description copied from interface:DataCacheUpdate the cached value for the given instance. This does not result in an update of other caches. Rather, it should only be used for loading clean data into the cache. Meaningful changes to the state of the cache should be made via theDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method. A cache implementation may or may not return a live object fromDataCache.get(java.lang.Object)invocations. If an object retrieved from aDataCache.get(java.lang.Object)operation needs to be updated, this method can be invoked instead of invokingDataCache.put(org.apache.openjpa.datacache.DataCachePCData). The DataCache implementation can then make optimizations based on how itsDataCache.get(java.lang.Object)method works.
 - 
removepublic DataCachePCData remove(java.lang.Object key) Description copied from interface:DataCacheRemove the value stored under the given oid. This does not result in an update of other caches. Rather, it should only be used for removing data in the cache. Meaningful changes to the state of the cache should be made via theDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method.
 - 
removeAllpublic java.util.BitSet removeAll(java.util.Collection<java.lang.Object> keys) Description copied from interface:DataCacheRemove the values stored under the given oids.- Specified by:
- removeAllin interface- DataCache
- Returns:
- the indexes of the removed oids
- See Also:
- DataCache.remove(java.lang.Object)
 
 - 
removeAllpublic void removeAll(java.lang.Class<?> cls, boolean subClasses)Remove the objects of the given class from the cache.
 - 
pinpublic boolean pin(java.lang.Object key) Description copied from interface:DataCachePin the value stored underoidinto the cache. This method guarantees thatoid's value will not be dropped by the caching algorithm. This method does not affect the behavior ofDataCache.remove(java.lang.Object).
 - 
pinAllpublic java.util.BitSet pinAll(java.util.Collection<java.lang.Object> keys) Description copied from interface:DataCachePin all oids to the cache.- Specified by:
- pinAllin interface- DataCache
- Returns:
- the indexes of the pinned oids
- See Also:
- DataCache.pin(java.lang.Object)
 
 - 
pinAllpublic void pinAll(java.lang.Class<?> cls, boolean subs)Description copied from interface:DataCachePin all oids for the given type.
 - 
unpinpublic boolean unpin(java.lang.Object key) Description copied from interface:DataCacheUnpin the value stored underoidfrom the cache. This method reverses a previous invocation ofDataCache.pin(java.lang.Object). This method does not remove anything from the cache; it merely makesoid's value a candidate for flushing from the cache.
 - 
unpinAllpublic java.util.BitSet unpinAll(java.util.Collection<java.lang.Object> keys) Description copied from interface:DataCacheUnpin all oids from the cache.- Specified by:
- unpinAllin interface- DataCache
- Returns:
- the indexes of the unpinned oids
- See Also:
- DataCache.unpin(java.lang.Object)
 
 - 
unpinAllpublic void unpinAll(java.lang.Class<?> cls, boolean subs)Description copied from interface:DataCacheUnpin all oids associaed with the given type from the cache.
 - 
clearpublic void clear() Description copied from interface:DataCacheRemove all data from this cache. This does not result in an update of other caches. Rather, it should only be used for clearing the cache. Meaningful changes to the state of the cache should be made via theDataCache.commit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)method.
 - 
closepublic void close() Description copied from interface:DataCacheFree the resources used by this cache.
 - 
closeprotected void close(boolean clear) 
 - 
isClosedpublic boolean isClosed() 
 - 
addExpirationListenerpublic void addExpirationListener(ExpirationListener listen) Description copied from interface:DataCacheAdd a new expiration event listener to this cache.- Specified by:
- addExpirationListenerin interface- DataCache
 
 - 
removeExpirationListenerpublic boolean removeExpirationListener(ExpirationListener listen) Description copied from interface:DataCacheRemove an expiration event listener from this cache.- Specified by:
- removeExpirationListenerin interface- DataCache
 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
afterCommitpublic void afterCommit(RemoteCommitEvent event) This method is part of theRemoteCommitListenerinterface. If your cache subclass relies on OpenJPA for clustering support, make it implementRemoteCommitListener. This method will take care of invalidating entries from remote commits.
 - 
keyRemovedprotected void keyRemoved(java.lang.Object key, boolean expired)Invoke when a key is removed from this cache. Propagates the expiration event on to all expiration listeners registered with this class.
 - 
recacheUpdatesprotected boolean recacheUpdates() Returntrueif updates to data already in the cache (either incommit(java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<org.apache.openjpa.datacache.DataCachePCData>, java.util.Collection<java.lang.Object>)or theupdate(org.apache.openjpa.datacache.DataCachePCData)) should be put back into the cache. Returns false by default.
 - 
getInternalprotected abstract DataCachePCData getInternal(java.lang.Object oid) Return the object for the given oid.
 - 
putInternalprotected abstract DataCachePCData putInternal(java.lang.Object oid, DataCachePCData pc) Add the given object to the cache, returning the old object under the given oid.
 - 
putAllInternalprotected void putAllInternal(java.util.Collection<DataCachePCData> pcs) Add all of the given objects to the cache.
 - 
removeInternalprotected abstract DataCachePCData removeInternal(java.lang.Object oid) Remove the object under the given oid from the cache.
 - 
removeAllInternalprotected abstract void removeAllInternal(java.lang.Class<?> cls, boolean subclasses)Evict objects in cache by class.
 - 
removeAllInternalprotected void removeAllInternal(java.util.Collection<java.lang.Object> oids) Remove all objects under the given oids from the cache.
 - 
removeAllTypeNamesInternalprotected void removeAllTypeNamesInternal(java.util.Collection<java.lang.String> classNames) Remove all objects of the given class names from the cache.
 - 
clearInternalprotected abstract void clearInternal() Clear the cache.
 - 
pinInternalprotected abstract boolean pinInternal(java.lang.Object oid) Pin an object to the cache.
 - 
unpinInternalprotected abstract boolean unpinInternal(java.lang.Object oid) Unpin an object from the cache.
 - 
getPartitionpublic DataCache getPartition(java.lang.String name, boolean create) Description copied from interface:DataCacheGets the named partition. Note that a partition itself is another cache.- Specified by:
- getPartitionin interface- DataCache
- Parameters:
- name- name of the given partition.
- create- if true optionally create a new partition.
- Returns:
- a partition of the given name. Or null, if either no such partition exists or can not be created.
 
 - 
getPartitionNamespublic java.util.Set<java.lang.String> getPartitionNames() Description copied from interface:DataCacheGets the name of the known partitions.- Specified by:
- getPartitionNamesin interface- DataCache
- Returns:
- empty set if no partition exists.
 
 - 
isPartitionedpublic boolean isPartitioned() Description copied from interface:DataCacheAffirms if this cache maintains partitions.- Specified by:
- isPartitionedin interface- DataCache
 
 - 
getStatisticspublic CacheStatistics getStatistics() Description copied from interface:DataCacheReturns number of read/write request and cache hit ratio data.- Specified by:
- getStatisticsin interface- DataCache
 
 - 
setConfigurationpublic void setConfiguration(Configuration conf) Description copied from interface:ConfigurableInvoked prior to setting bean properties.- Specified by:
- setConfigurationin interface- Configurable
 
 - 
startConfigurationpublic void startConfiguration() Description copied from interface:ConfigurableInvoked before bean property configuration is begun on this object.- Specified by:
- startConfigurationin interface- Configurable
 
 - 
endConfigurationpublic void endConfiguration() Description copied from interface:ConfigurableInvoked upon completion of bean property configuration for this object.- Specified by:
- endConfigurationin interface- Configurable
 
 - 
fireEventprotected void fireEvent(java.lang.Object event, java.lang.Object listener)Description copied from class:AbstractConcurrentEventManagerImplement this method to fire the given event to the given listener.- Specified by:
- fireEventin class- AbstractConcurrentEventManager
 
 - 
getTypespublic java.util.Set<java.lang.String> getTypes() 
 - 
getExcludedTypespublic java.util.Set<java.lang.String> getExcludedTypes() 
 - 
setTypespublic void setTypes(java.util.Set<java.lang.String> types) 
 - 
setTypespublic void setTypes(java.lang.String types) 
 - 
setExcludedTypespublic void setExcludedTypes(java.util.Set<java.lang.String> types) 
 - 
setExcludedTypespublic void setExcludedTypes(java.lang.String types) 
 - 
selectCachepublic DataCache selectCache(OpenJPAStateManager sm) 
 - 
getEvictOnBulkUpdatepublic boolean getEvictOnBulkUpdate() Description copied from interface:DataCacheReturns whether the the cache needs to be updated when bulk updates as executed. Defaults to true.- Specified by:
- getEvictOnBulkUpdatein interface- DataCache
 
 - 
setEvictOnBulkUpdatepublic void setEvictOnBulkUpdate(boolean b) 
 
- 
 
-