org.apache.openjpa.kernel
public interface PreparedQueryCache extends Configurable
prepared queries
.
To cache a PreparedQuery is two-stage process. In the first stage,
register(String, Query, FetchConfiguration)
register}
an identification key and a compiled Query Q to create a
hollow PreparedQuery instance P in the cache. In the second stage, after Q
executes, initialize(String, Object)
initialize} the hollow
Prepared Query P from the result of execution such as the target
database query PQ and its parameters. After initialization, P can
be used with re-parameterization for subsequent execution of the original
Query Q.
The target database query PQ associated to a cached prepared query P
may depend upon query execution context such as fetch plan or
lock group. This cache, by design, does not monitor the context or
automatically invalidate an entry P when the original query Q is executed
with context parameters that affect the target query PQ.
The user must notify this receiver to invalidate a cached entry P when
execution context changes in a way that will modify the resultant database
language query PQ.
One of the built-in mechanism (available in JPA facade) is to set query hints
to either invalidate the query entirely or ignore the cached version for the
current execution.QueryHints.HINT_IGNORE_PREPARED_QUERY
,
This cache allows customization of whether a query can be cached or not
via either explicit marking of certain keys as non-cachable (which is
irreversible or strong) or addition/removal of exclusion patterns
(which is reversible or weak).
,
#markUncachable(String)
,
addExclusionPattern(String)
,
setExcludes(String)
,
removeExclusionPattern(String)
Modifier and Type | Interface and Description |
---|---|
static interface |
PreparedQueryCache.Exclusion
A structure to describe the strength and reason for excluding a query from the cache.
|
Modifier and Type | Method and Description |
---|---|
void |
addExclusionPattern(java.lang.String pattern)
Adds the given pattern to the list of excluded patterns.
|
boolean |
cache(PreparedQuery q)
Cache the given PreparedQuery.
|
void |
clear()
Clears all cached queries.
|
PreparedQuery |
get(java.lang.String id)
Get the PreparedQuery with the given identifier if it exists.
|
boolean |
getEnableStatistics()
Affirm if statistics is gathered.
|
java.util.List<PreparedQueryCache.Exclusion> |
getExcludes()
Gets the exclusion patterns.
|
java.util.Map<java.lang.String,java.lang.String> |
getMapView()
Get a map view of the cached queries indexed by identifier.
|
QueryStatistics<java.lang.String> |
getStatistics()
Gets the simple statistics for executed queries.
|
PreparedQuery |
initialize(java.lang.String key,
java.lang.Object executionResult)
Initialize the cached Prepared Query registered with the given
key earlier by the given execution result.
|
boolean |
invalidate(java.lang.String id)
Remove the PreparedQuery with the given identifier from this cache.
|
java.lang.Boolean |
isCachable(java.lang.String id)
Affirms if a PreparedQuery can be cached against the given key.
|
PreparedQueryCache.Exclusion |
isExcluded(java.lang.String id)
Returns the exclusion status of if the given query key.
|
PreparedQuery |
markUncachable(java.lang.String id,
PreparedQueryCache.Exclusion exclusion)
Marks the given key as not amenable to caching.
|
java.lang.Boolean |
register(java.lang.String key,
Query query,
FetchConfiguration hints)
Register the given query for caching against the given key if it has not
already been cached.
|
void |
removeExclusionPattern(java.lang.String pattern)
Removes the given pattern from the list of excluded patterns.
|
void |
setEnableStatistics(boolean enable)
Enable/disable gathering of statistics.
|
void |
setExcludes(java.lang.String excludes)
Sets one or more exclusion regular expression patterns separated by
semicolon.
|
endConfiguration, setConfiguration, startConfiguration
java.lang.Boolean register(java.lang.String key, Query query, FetchConfiguration hints)
PreparedQuery initialize(java.lang.String key, java.lang.Object executionResult)
key
- the key used during registrationexecutionResult
- an opaque instance carrying the execution result
of the original query.java.util.Map<java.lang.String,java.lang.String> getMapView()
boolean cache(PreparedQuery q)
#markUncachable(String)
,
setExcludes(String)
,
addExclusionPattern(String)
boolean invalidate(java.lang.String id)
PreparedQuery get(java.lang.String id)
java.lang.Boolean isCachable(java.lang.String id)
PreparedQuery markUncachable(java.lang.String id, PreparedQueryCache.Exclusion exclusion)
id
- is the key to be excludedexclusion
- directs whether exclusion is irreversible or not.PreparedQueryCache.Exclusion isExcluded(java.lang.String id)
java.util.List<PreparedQueryCache.Exclusion> getExcludes()
void setExcludes(java.lang.String excludes)
void addExclusionPattern(java.lang.String pattern)
void removeExclusionPattern(java.lang.String pattern)
markUncachable(String, Exclusion)
void clear()
void setEnableStatistics(boolean enable)
boolean getEnableStatistics()
QueryStatistics<java.lang.String> getStatistics()