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
Modifier and TypeClassDescriptionstatic class
Strong exclusion.static class
Weak exclusion.Nested classes/interfaces inherited from interface org.apache.openjpa.kernel.PreparedQueryCache
PreparedQueryCache.Exclusion
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addExclusionPattern
(String pattern) Adds a pattern for exclusion.boolean
Cache the given query keyed by its identifier.void
clear()
Clears all cached queries.void
Invoked upon completion of bean property configuration for this object.Get the PreparedQuery with the given identifier if it exists. null otherwise.int
boolean
Affirm 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.boolean
invalidate
(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 void
lock
(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.void
removeExclusionPattern
(String pattern) Removes a pattern for exclusion.void
Invoked prior to setting bean properties.void
setEnableStatistics
(boolean enable) Enable/disable gathering of statistics.void
setExcludes
(String excludes) Sets one or more exclusion regular expression patterns separated by semicolon.void
setMaxCacheSize
(int size) void
Invoked before bean property configuration is begun on this object.protected void
unlock
(boolean readOnly)
-
Constructor Details
-
PreparedQueryCacheImpl
public PreparedQueryCacheImpl()
-
-
Method Details
-
register
Description copied from interface:PreparedQueryCache
Register 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:
register
in 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:PreparedQueryCache
Get a map view of the cached queries indexed by identifier.- Specified by:
getMapView
in 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:
cache
in 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:PreparedQueryCache
Initialize 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:
initialize
in 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:PreparedQueryCache
Remove the PreparedQuery with the given identifier from this cache.- Specified by:
invalidate
in interfacePreparedQueryCache
-
get
Description copied from interface:PreparedQueryCache
Get the PreparedQuery with the given identifier if it exists. null otherwise.- Specified by:
get
in interfacePreparedQueryCache
-
isCachable
Description copied from interface:PreparedQueryCache
Affirms if a PreparedQuery can be cached against the given key.- Specified by:
isCachable
in 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:PreparedQueryCache
Marks 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:
markUncachable
in 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:PreparedQueryCache
Returns the exclusion status of if the given query key.- Specified by:
isExcluded
in interfacePreparedQueryCache
- Returns:
- null implies that the key is not excluded.
-
setExcludes
Description copied from interface:PreparedQueryCache
Sets 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:
setExcludes
in interfacePreparedQueryCache
-
getExcludes
Description copied from interface:PreparedQueryCache
Gets the exclusion patterns.- Specified by:
getExcludes
in 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:
addExclusionPattern
in 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:
removeExclusionPattern
in interfacePreparedQueryCache
- See Also:
-
getStatistics
Description copied from interface:PreparedQueryCache
Gets the simple statistics for executed queries. If the statistics gathering is disabled, an empty statistics is returned.- Specified by:
getStatistics
in 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:PreparedQueryCache
Clears all cached queries.- Specified by:
clear
in interfacePreparedQueryCache
-
setEnableStatistics
public void setEnableStatistics(boolean enable) Description copied from interface:PreparedQueryCache
Enable/disable gathering of statistics.- Specified by:
setEnableStatistics
in interfacePreparedQueryCache
-
getEnableStatistics
public boolean getEnableStatistics()Description copied from interface:PreparedQueryCache
Affirm if statistics is gathered.- Specified by:
getEnableStatistics
in interfacePreparedQueryCache
-
setMaxCacheSize
public void setMaxCacheSize(int size) -
getCacheSize
public int getCacheSize() -
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
-