Package org.apache.openjpa.datacache
Class DelegatingQueryCache
- java.lang.Object
-
- org.apache.openjpa.datacache.DelegatingQueryCache
-
- All Implemented Interfaces:
QueryCache
,TypesChangedListener
,Closeable
public class DelegatingQueryCache extends java.lang.Object implements QueryCache
Delegating query cache that can also perform exception translation for use in facades. This cache allows its delegate to be null, in which case it returns default values or all methods.- Since:
- 0.4.0
- Author:
- Abe White
-
-
Constructor Summary
Constructors Constructor Description DelegatingQueryCache(QueryCache cache)
Constructor.DelegatingQueryCache(QueryCache cache, RuntimeExceptionTranslator trans)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTypesChangedListener(TypesChangedListener listen)
Add a new types event listener to this cache.void
clear()
Remove all data from this cache.void
close()
Free the resources used by this cache.boolean
equals(java.lang.Object other)
QueryResult
get(QueryKey qk)
Return a list of oids for the given query key.QueryCache
getDelegate()
Return the direct delegate.QueryCache
getInnermostDelegate()
Return the native delegate.QueryStatistics<QueryKey>
getStatistics()
Gets the simple statistics for query results.int
hashCode()
void
initialize(DataCacheManager mgr)
Initialize any resources associated with the givenDataCacheManager
.void
onTypesChanged(TypesChangedEvent e)
Notification that instances of persistent types have changed.boolean
pin(QueryKey qk)
Pin the value stored underqk
into the cache.QueryResult
put(QueryKey qk, QueryResult oids)
Set the list of OIDs for the given query key.QueryResult
remove(QueryKey qk)
Remove the value stored under the given query key.boolean
removeTypesChangedListener(TypesChangedListener listen)
Remove an types event listener from this cache.protected java.lang.RuntimeException
translate(java.lang.RuntimeException re)
Translate the OpenJPA exception.boolean
unpin(QueryKey qk)
Unpin the value stored underkey
into the cache.void
writeLock()
Obtain a write lock on the cache.void
writeUnlock()
Release the write lock on the cache.
-
-
-
Constructor Detail
-
DelegatingQueryCache
public DelegatingQueryCache(QueryCache cache)
Constructor. Supply delegate.
-
DelegatingQueryCache
public DelegatingQueryCache(QueryCache cache, RuntimeExceptionTranslator trans)
-
-
Method Detail
-
getDelegate
public QueryCache getDelegate()
Return the direct delegate.
-
getInnermostDelegate
public QueryCache getInnermostDelegate()
Return the native delegate.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
translate
protected java.lang.RuntimeException translate(java.lang.RuntimeException re)
Translate the OpenJPA exception.
-
initialize
public void initialize(DataCacheManager mgr)
Description copied from interface:QueryCache
Initialize any resources associated with the givenDataCacheManager
.- Specified by:
initialize
in interfaceQueryCache
-
onTypesChanged
public void onTypesChanged(TypesChangedEvent e)
Description copied from interface:TypesChangedListener
Notification that instances of persistent types have changed.- Specified by:
onTypesChanged
in interfaceTypesChangedListener
-
get
public QueryResult get(QueryKey qk)
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
public QueryResult put(QueryKey qk, QueryResult oids)
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
public QueryResult remove(QueryKey qk)
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.
-
clear
public void clear()
Description copied from interface:QueryCache
Remove all data from this cache.- Specified by:
clear
in interfaceQueryCache
-
pin
public boolean pin(QueryKey qk)
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
public boolean unpin(QueryKey qk)
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.
-
writeLock
public void writeLock()
Description copied from interface:QueryCache
Obtain a write lock on the cache.- Specified by:
writeLock
in interfaceQueryCache
-
writeUnlock
public void writeUnlock()
Description copied from interface:QueryCache
Release the write lock on the cache.- Specified by:
writeUnlock
in interfaceQueryCache
-
addTypesChangedListener
public void addTypesChangedListener(TypesChangedListener listen)
Description copied from interface:QueryCache
Add a new types event listener to this cache.- Specified by:
addTypesChangedListener
in interfaceQueryCache
-
removeTypesChangedListener
public boolean removeTypesChangedListener(TypesChangedListener listen)
Description copied from interface:QueryCache
Remove an types event listener from this cache.- Specified by:
removeTypesChangedListener
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
-
getStatistics
public QueryStatistics<QueryKey> 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
-
-