Package org.apache.openjpa.datacache
Class AbstractQueryCache
java.lang.Object
org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
org.apache.openjpa.datacache.AbstractQueryCache
- All Implemented Interfaces:
Serializable
,QueryCache
,TypesChangedListener
,Configurable
,Closeable
,EventManager
- Direct Known Subclasses:
ConcurrentQueryCache
public abstract class AbstractQueryCache
extends AbstractConcurrentEventManager
implements QueryCache, Configurable
Abstract
QueryCache
implementation that provides various
statistics, logging, and timeout functionality common across cache
implementations.- Author:
- Patrick Linskey, Abe White
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A default implementation of query statistics for the Query result cache.static enum
-
Field Summary
Modifier and TypeFieldDescriptionprotected OpenJPAConfiguration
The configuration set by the system.protected ConcurrentHashMap<String,
Long> protected Log
The log to use.Fields inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
_listeners
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new types event listener to this cache.void
afterCommit
(RemoteCommitEvent event) This method is part of theRemoteCommitListener
interface.void
clear()
Remove all data from this cache.protected abstract void
Clear the cache.void
close()
Free the resources used by this cache.protected void
close
(boolean clear) int
count()
void
Invoked upon completion of bean property configuration for this object.protected void
Implement this method to fire the given event to the given listener.Return a list of oids for the given query key.getAllEntityTimestamp
(List<String> keyList) Returns a list of timestamps in the form of Long objects which are the last updated time stamps for the given entities in the keylist.boolean
Returns the evictionPolicy for QueryCacheprotected abstract QueryResult
getInternal
(QueryKey qk) Return the list for the given key.getName()
Gets the simple statistics for query results.void
initialize
(DataCacheManager manager) Initialize any resources associated with the givenDataCacheManager
.boolean
isClosed()
protected abstract Collection
keySet()
Return a threadsafe view of the keys in this cache.protected Collection
Individual query results will be registered as types changed listeners.void
Notification that instances of persistent types have changed.boolean
Pin the value stored underqk
into the cache.protected abstract boolean
pinInternal
(QueryKey qk) Pin an object to the cache.put
(QueryKey qk, QueryResult oids) Set the list of OIDs for the given query key.protected abstract QueryResult
putInternal
(QueryKey qk, QueryResult oids) Add the given result to the cache, returning the old result under the given key.Remove the value stored under the given query key.protected void
Remove all results under the given keys from the cache.protected abstract QueryResult
Remove the result under the given key from the cache.boolean
Remove an types event listener from this cache.void
Invoked prior to setting bean properties.void
setEnableStatistics
(boolean enable) void
setEvictPolicy
(String evictPolicy) Sets the eviction policy for the query cachevoid
void
Invoked before bean property configuration is begun on this object.boolean
Unpin the value stored underkey
into the cache.protected abstract boolean
Unpin an object from the cache.protected void
updateEntityTimestamp
(Map<String, Long> timestampMap) Updates the entity timestamp map with the current time in millisecondsMethods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, removeListener, setFailFast
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.openjpa.datacache.QueryCache
writeLock, writeUnlock
-
Field Details
-
conf
The configuration set by the system. -
log
The log to use. -
entityTimestampMap
-
evictPolicy
-
-
Constructor Details
-
AbstractQueryCache
public AbstractQueryCache()
-
-
Method Details
-
setEnableStatistics
public void setEnableStatistics(boolean enable) -
getEnableStatistics
public boolean getEnableStatistics() -
getStatistics
Description copied from interface:QueryCache
Gets the simple statistics for query results. If the statistics gathering is disabled, an empty statistics is returned.- Specified by:
getStatistics
in interfaceQueryCache
-
initialize
Description copied from interface:QueryCache
Initialize any resources associated with the givenDataCacheManager
.- Specified by:
initialize
in interfaceQueryCache
-
onTypesChanged
Description copied from interface:TypesChangedListener
Notification that instances of persistent types have changed.- Specified by:
onTypesChanged
in interfaceTypesChangedListener
-
get
Description copied from interface:QueryCache
Return a list of oids for the given query key. This is an unmodifiable list.- Specified by:
get
in interfaceQueryCache
- Returns:
- The query results matching the given key, or null if none
-
put
Description copied from interface:QueryCache
Set the list of OIDs for the given query key. A reference to the given list will be stored in the query cache, so the list should not be modified after invoking this method.- Specified by:
put
in interfaceQueryCache
- Returns:
- The previously cached value, or
null
if the key was not previously cached. SeeMap.put(K, V)
for more information.
-
remove
Description copied from interface:QueryCache
Remove the value stored under the given query key. This method is typically not invoked directly from outside theQueryCache
class. Instead, the cache should be updated by implementingRemoteCommitListener
, which will result in all queries that may be invalid being dropped.- Specified by:
remove
in interfaceQueryCache
- Returns:
- The previously cached value, or
null
if the key was not previously cached. SeeMap.remove(java.lang.Object)
for more information.
-
pin
Description copied from interface:QueryCache
Pin the value stored underqk
into the cache. This method guarantees thatqk
's value will not be expired if the cache exceeds its capacity. It causes this data to be ignored when determining whether or not the cache is full, effectively increasing the total amount of data stored in the cache. This method does not affect the behavior ofQueryCache.remove(org.apache.openjpa.datacache.QueryKey)
orTypesChangedListener.onTypesChanged(org.apache.openjpa.datacache.TypesChangedEvent)
.- Specified by:
pin
in interfaceQueryCache
- Returns:
true
ifkey
's value was pinned into the cache;false
if the key is not in the cache.
-
unpin
Description copied from interface:QueryCache
Unpin the value stored underkey
into the cache. This method reverses a previous invocation ofQueryCache.pin(org.apache.openjpa.datacache.QueryKey)
. This method does not remove anything from the cache; it merely makeskey
's value a candidate for flushing from the cache.- Specified by:
unpin
in interfaceQueryCache
- Returns:
true
ifkey
's value was unpinned from the cache;false
if the key is not in the cache.
-
clear
public void clear()Description copied from interface:QueryCache
Remove all data from this cache.- Specified by:
clear
in interfaceQueryCache
-
close
public void close()Description copied from interface:QueryCache
Free the resources used by this cache.- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceQueryCache
-
close
protected void close(boolean clear) -
isClosed
public boolean isClosed() -
addTypesChangedListener
Description copied from interface:QueryCache
Add a new types event listener to this cache.- Specified by:
addTypesChangedListener
in interfaceQueryCache
-
removeTypesChangedListener
Description copied from interface:QueryCache
Remove an types event listener from this cache.- Specified by:
removeTypesChangedListener
in interfaceQueryCache
-
afterCommit
This method is part of theRemoteCommitListener
interface. If your cache subclass relies on OpenJPA for clustering support, make it implementRemoteCommitListener
. This method will take care of invalidating entries from remote commits, by delegating toonTypesChanged(org.apache.openjpa.datacache.TypesChangedEvent)
. -
keySet
Return a threadsafe view of the keys in this cache. This collection must be iterable without risk of concurrent modification exceptions. It does not have to implement contains() efficiently or use set semantics. -
getInternal
Return the list for the given key. -
putInternal
Add the given result to the cache, returning the old result under the given key. -
removeInternal
Remove the result under the given key from the cache. -
removeAllInternal
Remove all results under the given keys from the cache. -
clearInternal
protected abstract void clearInternal()Clear the cache. -
pinInternal
Pin an object to the cache. -
unpinInternal
Unpin an object from the cache. -
setConfiguration
Description copied from interface:Configurable
Invoked prior to setting bean properties.- Specified by:
setConfiguration
in interfaceConfigurable
-
startConfiguration
public void startConfiguration()Description copied from interface:Configurable
Invoked before bean property configuration is begun on this object.- Specified by:
startConfiguration
in interfaceConfigurable
-
endConfiguration
public void endConfiguration()Description copied from interface:Configurable
Invoked upon completion of bean property configuration for this object.- Specified by:
endConfiguration
in interfaceConfigurable
-
fireEvent
Description copied from class:AbstractConcurrentEventManager
Implement this method to fire the given event to the given listener.- Specified by:
fireEvent
in classAbstractConcurrentEventManager
-
newListenerCollection
Individual query results will be registered as types changed listeners. We want such query results to be gc'd once the only reference is held by the list of expiration listeners.- Overrides:
newListenerCollection
in classAbstractConcurrentEventManager
-
setEvictPolicy
Sets the eviction policy for the query cache- Parameters:
evictPolicy
- -- String value that specifies the eviction policy
-
getEvictPolicy
Returns the evictionPolicy for QueryCache- Returns:
- -- returns a String value of evictPolicy attribute
-
updateEntityTimestamp
Updates the entity timestamp map with the current time in milliseconds- Parameters:
timestampMap
- -- a map that contains entityname and its last updated timestamp
-
getAllEntityTimestamp
Returns a list of timestamps in the form of Long objects which are the last updated time stamps for the given entities in the keylist.- Parameters:
keyList
- -- List of entity names- Returns:
- -- Returns a list that has the timestamp for the given entities
-
setName
-
getName
-
count
public int count()
-