Package org.apache.openjpa.jdbc.kernel
Class PreparedQueryCacheImpl
java.lang.Object
org.apache.openjpa.jdbc.kernel.PreparedQueryCacheImpl
- All Implemented Interfaces:
PreparedQueryCache,Configurable
An implementation of the cache of
prepared queries.- Since:
- 2.0.0
- Author:
- Pinaki Poddar
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStrong exclusion.static classWeak exclusion.Nested classes/interfaces inherited from interface org.apache.openjpa.kernel.PreparedQueryCache
PreparedQueryCache.Exclusion -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExclusionPattern(String pattern) Adds a pattern for exclusion.booleanCache the given query keyed by its identifier.voidclear()Clears all cached queries.voidInvoked upon completion of bean property configuration for this object.Get the PreparedQuery with the given identifier if it exists. null otherwise.intbooleanAffirm if statistics is gathered.Gets the exclusion patterns.Get a map view of the cached queries indexed by identifier.Gets the simple statistics for executed queries.initialize(String key, Object result) Initialize the cached Prepared Query registered with the given key earlier by the given execution result.booleaninvalidate(String id) Remove the PreparedQuery with the given identifier from this cache.isCachable(String id) Affirms if a PreparedQuery can be cached against the given key.isExcluded(String id) Returns the exclusion status of if the given query key.protected voidlock(boolean readOnly) Note: Care needs to be taken so that a read lock is never held while requesting a write lock.markUncachable(String id, PreparedQueryCache.Exclusion exclusion) Marks the given key as not amenable to caching.register(String id, Query query, FetchConfiguration hints) Register the given query for caching against the given key if it has not already been cached.voidremoveExclusionPattern(String pattern) Removes a pattern for exclusion.voidInvoked prior to setting bean properties.voidsetEnableStatistics(boolean enable) Enable/disable gathering of statistics.voidsetExcludes(String excludes) Sets one or more exclusion regular expression patterns separated by semicolon.voidsetMaxCacheSize(int size) voidInvoked before bean property configuration is begun on this object.protected voidunlock(boolean readOnly)
-
Constructor Details
-
PreparedQueryCacheImpl
public PreparedQueryCacheImpl()
-
-
Method Details
-
register
Description copied from interface:PreparedQueryCacheRegister the given query for caching against the given key if it has not already been cached. If the query can not be cached, then mark it as such to avoid computing for the same key again.- Specified by:
registerin interfacePreparedQueryCache- Returns:
- TRUE the query is registered in the cache by this call null if the query is already registered in the cache FALSE if can not be registered in the cache, either because it is known not to be cacheable from a previous attempt or a hint is given to ignore the cached version.
-
getMapView
Description copied from interface:PreparedQueryCacheGet a map view of the cached queries indexed by identifier.- Specified by:
getMapViewin interfacePreparedQueryCache
-
cache
Cache the given query keyed by its identifier. Does not cache if the identifier matches any exclusion pattern or has been marked as non-cachable. Also register the identifier as not cachable against the matched exclusion pattern.- Specified by:
cachein interfacePreparedQueryCache- Returns:
- true if the given query is cached. false if it can not be cached due to exclusion.
- See Also:
-
#markUncachable(String)PreparedQueryCache.setExcludes(String)PreparedQueryCache.addExclusionPattern(String)
-
initialize
Description copied from interface:PreparedQueryCacheInitialize the cached Prepared Query registered with the given key earlier by the given execution result. If it is not possible to initialize the Prepared Query from the given execution result, then the corresponding key will be marked as invalid for caching.- Specified by:
initializein interfacePreparedQueryCache- Parameters:
key- the key used during registrationresult- an opaque instance carrying the execution result of the original query.- Returns:
- the initialized Prepared Query. If it is not possible to initialize the cached, possibly hollow Prepared Query from the given result, return null.
-
invalidate
Description copied from interface:PreparedQueryCacheRemove the PreparedQuery with the given identifier from this cache.- Specified by:
invalidatein interfacePreparedQueryCache
-
get
Description copied from interface:PreparedQueryCacheGet the PreparedQuery with the given identifier if it exists. null otherwise.- Specified by:
getin interfacePreparedQueryCache
-
isCachable
Description copied from interface:PreparedQueryCacheAffirms if a PreparedQuery can be cached against the given key.- Specified by:
isCachablein interfacePreparedQueryCache- Returns:
- Boolean.FALSE if the given key is explicitly marked before as not be cached or matches any of the exclusion patterns. Boolean.TRUE if the given key currently exists in the cache. Otherwise, return null implying this receiver can not determine whether this key can be cached on not.
-
markUncachable
Description copied from interface:PreparedQueryCacheMarks the given key as not amenable to caching. Explicit marking helps to avoid repeated computational cost of determining whether a query can be cached or not.- Specified by:
markUncachablein interfacePreparedQueryCache- Parameters:
id- is the key to be excludedexclusion- directs whether exclusion is irreversible or not.- Returns:
- The value for the given key if it had been cached before. null otherwise.
-
isExcluded
Description copied from interface:PreparedQueryCacheReturns the exclusion status of if the given query key.- Specified by:
isExcludedin interfacePreparedQueryCache- Returns:
- null implies that the key is not excluded.
-
setExcludes
Description copied from interface:PreparedQueryCacheSets one or more exclusion regular expression patterns separated by semicolon. Any existing cache entry whose key matches any of the given pattern will be marked non-cachable in a reversible manner.- Specified by:
setExcludesin interfacePreparedQueryCache
-
getExcludes
Description copied from interface:PreparedQueryCacheGets the exclusion patterns.- Specified by:
getExcludesin interfacePreparedQueryCache
-
addExclusionPattern
Adds a pattern for exclusion. Any query cached currently whose identifier matches the given pattern will be marked invalidated as a side-effect.- Specified by:
addExclusionPatternin interfacePreparedQueryCache
-
removeExclusionPattern
Removes a pattern for exclusion. Any query identifier marked as not cachable due to the given pattern will now be removed from the list of uncachables as a side-effect.- Specified by:
removeExclusionPatternin interfacePreparedQueryCache- See Also:
-
getStatistics
Description copied from interface:PreparedQueryCacheGets the simple statistics for executed queries. If the statistics gathering is disabled, an empty statistics is returned.- Specified by:
getStatisticsin interfacePreparedQueryCache
-
lock
protected void lock(boolean readOnly) Note: Care needs to be taken so that a read lock is never held while requesting a write lock. This will result in a deadlock.- Parameters:
readOnly- - If true, a read lock will be acquired. Else a write lock will be acquired.
-
unlock
protected void unlock(boolean readOnly) - Parameters:
readOnly- - If true, the read lock will be released. Else a write lock will be released.
-
clear
public void clear()Description copied from interface:PreparedQueryCacheClears all cached queries.- Specified by:
clearin interfacePreparedQueryCache
-
setEnableStatistics
public void setEnableStatistics(boolean enable) Description copied from interface:PreparedQueryCacheEnable/disable gathering of statistics.- Specified by:
setEnableStatisticsin interfacePreparedQueryCache
-
getEnableStatistics
public boolean getEnableStatistics()Description copied from interface:PreparedQueryCacheAffirm if statistics is gathered.- Specified by:
getEnableStatisticsin interfacePreparedQueryCache
-
setMaxCacheSize
public void setMaxCacheSize(int size) -
getCacheSize
public int getCacheSize() -
setConfiguration
Description copied from interface:ConfigurableInvoked prior to setting bean properties.- Specified by:
setConfigurationin interfaceConfigurable
-
startConfiguration
public void startConfiguration()Description copied from interface:ConfigurableInvoked before bean property configuration is begun on this object.- Specified by:
startConfigurationin interfaceConfigurable
-
endConfiguration
public void endConfiguration()Description copied from interface:ConfigurableInvoked upon completion of bean property configuration for this object.- Specified by:
endConfigurationin interfaceConfigurable
-