Package org.apache.openjpa.kernel
Class QueryImpl
java.lang.Object
org.apache.openjpa.kernel.QueryImpl
- All Implemented Interfaces:
Serializable
,Query
,QueryContext
,QueryFlushModes
,QueryOperations
- Direct Known Subclasses:
DistributedQueryImpl
Implementation of the
Query
interface.- Author:
- Abe White
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Struct of compiled query properties.static class
Result object provider that packs results before returning them.class
Result list that removes itself from the query's open result list when it is closed. -
Field Summary
Fields inherited from interface org.apache.openjpa.kernel.QueryFlushModes
FLUSH_FALSE, FLUSH_TRUE, FLUSH_WITH_CONNECTION
Fields inherited from interface org.apache.openjpa.kernel.QueryOperations
OP_DELETE, OP_SELECT, OP_UPDATE
-
Constructor Summary
ConstructorDescriptionQueryImpl
(Broker broker, String language, StoreQuery storeQuery) Construct a query managed by the given broker. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAggregateListener
(AggregateListener listener) Register an aggregate listener for the query.void
addFilterListener
(FilterListener listener) Register a filter listener for the query.void
Assert that the query is not read-only.void
Check that the query has not been serialized, which causes it to lose its association with its Broker.void
Assert that the query's broker is still open.protected void
assertParameters
(StoreQuery q, StoreQuery.Executor ex, Object[] params) Checks that the passed parameters match the declarations.protected void
assertParameters
(StoreQuery q, StoreQuery.Executor ex, Map params) classForName
(String name, String[] imports) Helper method to instantiate the class with the given name, taking into account the query's candidate package, automatic imports, and the given imports (if any).void
closeAll()
Close all open query results.void
Close query results that are consuming resources.protected QueryImpl.Compilation
Find the cached compilation for the current query, creating one if it does not exist.void
compile()
Compile the query.void
declareParameters
(String params) Declared parameters, for query languages that use them.protected QueryImpl.RemoveOnCloseResultList
decorateResultList
(ResultList<?> res) Optionally decorate the native result.long
Deletes all of the instances that are satisfied by the query.long
Deletes all of the instances that are satisfied by the query.long
Deletes all of the instances that are satisfied by the query.deleteInMemory
(StoreQuery q, StoreQuery.Executor executor, Object[] params) Helper method to delete the objects found by executing a query on the given executor.execute()
Execute.Execute with parameter array.Execute with parameter map.Return the classes that affect this query.Return the filter listener for the given tag, or null.The set of aggregate listeners.getAlias()
If this query is not a projection but places candidate results into a result class under an alias, return that alias.The broker that generated this query.Collection<?>
Return the candidate collection, ornull
if an extent was specified instead of a collection.Return the candidate extent, ornull
if a collection was specified instead of an extent.Return the class of the objects that this query will return, ornull
if this information is not available / not relevant.Return the query's compilation state.String[]
getDataStoreActions
(Map params) Returns a description of the commands that will be sent to the datastore in order to execute this query.long
Return the 0-based exclusive end index for the returned results, orLong.MAX_VALUE
for no limit.Return the fetch configuration for this query.getFilterListener
(String tag) Return the filter listener for the given tag, or null.The set of filter listeners.boolean
Whether to ignore changes in the current transaction.The query language.int
Returns the operation that this query will be expected to perform.OrderedMap<Object,
Class<?>> Return a map of parameter name to type for this query.The parameter declaration.Return a map of parameter name to type for this query.String[]
If this query is a projection, return the projection aliases.Class<?>[]
If this query is a projection, return the projection types.getQuery()
Return the query for this context.The query string.Name of a mapping from the result data to its object representation.Scope of a mapping from the result data to its object representation.Returns the result class that has been set throughQueryContext.setResultType(java.lang.Class<?>)
, or null if none.long
Return the 0-based start index for the returned results.The persistence context for the query.Internal store query.If this query is a bulk update, return a map of theFieldMetaData
s toConstant
s.boolean
Return true if the query uses grouping.boolean
Whether query results will include subclasses of the candidate class.static boolean
isAccessPathDirty
(Broker broker, ClassMetaData[] accessMetas) boolean
Return true if the query is an aggregate.boolean
Affirms if this query results are distinct instance(s).boolean
Affirms if this query has originated by parsing a string-based query.boolean
Whether the query has been marked read-only.boolean
isUnique()
The unique flag.void
lock()
Synchronize on the query's internal lock.void
removeAggregateListener
(AggregateListener listener) Remove an aggregate listener from the query.void
removeFilterListener
(FilterListener listener) Remove a filter listener from the query.void
setCandidateCollection
(Collection<?> candidateCollection) Set a collection of candidates.void
setCandidateExtent
(Extent candidateExtent) Set the candidate extent.void
setCandidateType
(Class candidateClass, boolean subs) Set the candidate type.void
setIgnoreChanges
(boolean flag) Whether to ignore changes in the current transaction.boolean
The query string or template.void
setRange
(long start, long end) Set the range of results to return.void
setReadOnly
(boolean flag) Whether the query has been marked read-only.void
setResultMapping
(Class<?> scope, String name) Name and scope of a mapping from the result data to its object representation.void
setResultType
(Class cls) Specify the type of object in which the result of evaluating this query.void
setUnique
(boolean unique) Specify that the query will return only 1 result, rather than a collection.void
void
protected Object
toResult
(StoreQuery q, StoreQuery.Executor ex, ResultObjectProvider rop, StoreQuery.Range range) Return the query result for the given result object provider.toString()
void
unlock()
Unlock the query's internal lock.long
Performs an update of the instances that are satisfied by the query.long
Performs an update of the instances that are satisfied by the query.long
Performs an update of the instances that are satisfied by the query.updateInMemory
(StoreQuery q, StoreQuery.Executor executor, Object[] params) Helper method to update the objects found by executing a query on the given executor.
-
Constructor Details
-
QueryImpl
Construct a query managed by the given broker.
-
-
Method Details
-
getStoreQuery
Internal store query. -
getBroker
Description copied from interface:Query
The broker that generated this query. -
getQuery
Description copied from interface:QueryContext
Return the query for this context. Note that the query will be unavailable in remote contexts, and this method may throw an exception to that effect.- Specified by:
getQuery
in interfaceQueryContext
-
getStoreContext
Description copied from interface:QueryContext
The persistence context for the query.- Specified by:
getStoreContext
in interfaceQueryContext
-
getLanguage
Description copied from interface:QueryContext
The query language.- Specified by:
getLanguage
in interfaceQueryContext
-
getFetchConfiguration
Description copied from interface:QueryContext
Return the fetch configuration for this query.- Specified by:
getFetchConfiguration
in interfaceQueryContext
-
getQueryString
Description copied from interface:QueryContext
The query string.- Specified by:
getQueryString
in interfaceQueryContext
-
getIgnoreChanges
public boolean getIgnoreChanges()Description copied from interface:QueryContext
Whether to ignore changes in the current transaction.- Specified by:
getIgnoreChanges
in interfaceQueryContext
-
setIgnoreChanges
public void setIgnoreChanges(boolean flag) Description copied from interface:Query
Whether to ignore changes in the current transaction.- Specified by:
setIgnoreChanges
in interfaceQuery
-
isReadOnly
public boolean isReadOnly()Description copied from interface:QueryContext
Whether the query has been marked read-only.- Specified by:
isReadOnly
in interfaceQueryContext
-
setReadOnly
public void setReadOnly(boolean flag) Description copied from interface:QueryContext
Whether the query has been marked read-only.- Specified by:
setReadOnly
in interfaceQueryContext
-
addFilterListener
Description copied from interface:Query
Register a filter listener for the query.- Specified by:
addFilterListener
in interfaceQuery
-
removeFilterListener
Description copied from interface:Query
Remove a filter listener from the query.- Specified by:
removeFilterListener
in interfaceQuery
-
getFilterListeners
Description copied from interface:QueryContext
The set of filter listeners.- Specified by:
getFilterListeners
in interfaceQueryContext
-
getFilterListener
Description copied from interface:QueryContext
Return the filter listener for the given tag, or null.- Specified by:
getFilterListener
in interfaceQueryContext
-
addAggregateListener
Description copied from interface:Query
Register an aggregate listener for the query.- Specified by:
addAggregateListener
in interfaceQuery
-
removeAggregateListener
Description copied from interface:Query
Remove an aggregate listener from the query.- Specified by:
removeAggregateListener
in interfaceQuery
-
getAggregateListeners
Description copied from interface:QueryContext
The set of aggregate listeners.- Specified by:
getAggregateListeners
in interfaceQueryContext
-
getAggregateListener
Description copied from interface:QueryContext
Return the filter listener for the given tag, or null.- Specified by:
getAggregateListener
in interfaceQueryContext
-
getCandidateExtent
Description copied from interface:Query
Return the candidate extent, ornull
if a collection was specified instead of an extent.- Specified by:
getCandidateExtent
in interfaceQuery
-
setCandidateExtent
Description copied from interface:Query
Set the candidate extent.- Specified by:
setCandidateExtent
in interfaceQuery
-
getCandidateCollection
Description copied from interface:QueryContext
Return the candidate collection, ornull
if an extent was specified instead of a collection.- Specified by:
getCandidateCollection
in interfaceQueryContext
-
setCandidateCollection
Description copied from interface:Query
Set a collection of candidates.- Specified by:
setCandidateCollection
in interfaceQuery
-
getCandidateType
Description copied from interface:QueryContext
Return the class of the objects that this query will return, ornull
if this information is not available / not relevant.- Specified by:
getCandidateType
in interfaceQueryContext
-
setCandidateType
Description copied from interface:QueryContext
Set the candidate type.- Specified by:
setCandidateType
in interfaceQueryContext
-
hasSubclasses
public boolean hasSubclasses()Description copied from interface:QueryContext
Whether query results will include subclasses of the candidate class.- Specified by:
hasSubclasses
in interfaceQueryContext
-
getResultMappingName
Description copied from interface:QueryContext
Name of a mapping from the result data to its object representation.- Specified by:
getResultMappingName
in interfaceQueryContext
-
getResultMappingScope
Description copied from interface:QueryContext
Scope of a mapping from the result data to its object representation.- Specified by:
getResultMappingScope
in interfaceQueryContext
-
setResultMapping
Description copied from interface:QueryContext
Name and scope of a mapping from the result data to its object representation.- Specified by:
setResultMapping
in interfaceQueryContext
-
isUnique
public boolean isUnique()Description copied from interface:QueryContext
The unique flag.- Specified by:
isUnique
in interfaceQueryContext
-
isParsedQuery
public boolean isParsedQuery()Affirms if this query has originated by parsing a string-based query. -
setUnique
public void setUnique(boolean unique) Description copied from interface:QueryContext
Specify that the query will return only 1 result, rather than a collection. The execute method will return null if the query result size is 0.- Specified by:
setUnique
in interfaceQueryContext
-
getResultType
Description copied from interface:QueryContext
Returns the result class that has been set throughQueryContext.setResultType(java.lang.Class<?>)
, or null if none.- Specified by:
getResultType
in interfaceQueryContext
-
setResultType
Description copied from interface:QueryContext
Specify the type of object in which the result of evaluating this query.- Specified by:
setResultType
in interfaceQueryContext
-
getStartRange
public long getStartRange()Description copied from interface:QueryContext
Return the 0-based start index for the returned results.- Specified by:
getStartRange
in interfaceQueryContext
-
getEndRange
public long getEndRange()Description copied from interface:QueryContext
Return the 0-based exclusive end index for the returned results, orLong.MAX_VALUE
for no limit.- Specified by:
getEndRange
in interfaceQueryContext
-
setRange
public void setRange(long start, long end) Description copied from interface:QueryContext
Set the range of results to return.- Specified by:
setRange
in interfaceQueryContext
- Parameters:
start
- 0-based inclusive start indexend
- 0-based exclusive end index, orLong.MAX_VALUE
for no limit
-
getParameterDeclaration
Description copied from interface:QueryContext
The parameter declaration.- Specified by:
getParameterDeclaration
in interfaceQueryContext
-
declareParameters
Description copied from interface:QueryContext
Declared parameters, for query languages that use them.- Specified by:
declareParameters
in interfaceQueryContext
-
compile
public void compile()Description copied from interface:Query
Compile the query. -
getCompilation
Description copied from interface:QueryContext
Return the query's compilation state.- Specified by:
getCompilation
in interfaceQueryContext
-
compilationFromCache
Find the cached compilation for the current query, creating one if it does not exist. -
execute
Description copied from interface:Query
Execute. -
execute
Description copied from interface:Query
Execute with parameter array. -
execute
Description copied from interface:Query
Execute with parameter map. -
deleteAll
public long deleteAll()Description copied from interface:Query
Deletes all of the instances that are satisfied by the query. -
deleteAll
Description copied from interface:Query
Deletes all of the instances that are satisfied by the query. -
deleteAll
Description copied from interface:Query
Deletes all of the instances that are satisfied by the query. -
updateAll
public long updateAll()Description copied from interface:Query
Performs an update of the instances that are satisfied by the query. -
updateAll
Description copied from interface:Query
Performs an update of the instances that are satisfied by the query. -
updateAll
Description copied from interface:Query
Performs an update of the instances that are satisfied by the query. -
deleteInMemory
Description copied from interface:QueryContext
Helper method to delete the objects found by executing a query on the given executor.- Specified by:
deleteInMemory
in interfaceQueryContext
-
updateInMemory
Description copied from interface:QueryContext
Helper method to update the objects found by executing a query on the given executor.- Specified by:
updateInMemory
in interfaceQueryContext
-
toResult
protected Object toResult(StoreQuery q, StoreQuery.Executor ex, ResultObjectProvider rop, StoreQuery.Range range) throws Exception Return the query result for the given result object provider.- Throws:
Exception
-
decorateResultList
Optionally decorate the native result. -
isAccessPathDirty
-
closeAll
public void closeAll()Description copied from interface:Query
Close all open query results. -
closeResources
public void closeResources()Description copied from interface:Query
Close query results that are consuming resources. Allow results that are not consuming resources to remain open so that they continue to function normally.- Specified by:
closeResources
in interfaceQuery
-
getDataStoreActions
Description copied from interface:Query
Returns a description of the commands that will be sent to the datastore in order to execute this query. This will typically be in the native query language of the database (e.g., SQL).- Specified by:
getDataStoreActions
in interfaceQuery
- Parameters:
params
- the named parameter map for the query invocation
-
setQuery
Description copied from interface:Query
The query string or template. -
getAlias
Description copied from interface:QueryContext
If this query is not a projection but places candidate results into a result class under an alias, return that alias.- Specified by:
getAlias
in interfaceQueryContext
-
getProjectionAliases
Description copied from interface:QueryContext
If this query is a projection, return the projection aliases.- Specified by:
getProjectionAliases
in interfaceQueryContext
-
getProjectionTypes
Description copied from interface:QueryContext
If this query is a projection, return the projection types.- Specified by:
getProjectionTypes
in interfaceQueryContext
-
getOperation
public int getOperation()Description copied from interface:QueryContext
Returns the operation that this query will be expected to perform.- Specified by:
getOperation
in interfaceQueryContext
- See Also:
-
isAggregate
public boolean isAggregate()Description copied from interface:QueryContext
Return true if the query is an aggregate.- Specified by:
isAggregate
in interfaceQueryContext
-
isDistinct
public boolean isDistinct()Description copied from interface:QueryContext
Affirms if this query results are distinct instance(s).- Specified by:
isDistinct
in interfaceQueryContext
-
hasGrouping
public boolean hasGrouping()Description copied from interface:QueryContext
Return true if the query uses grouping.- Specified by:
hasGrouping
in interfaceQueryContext
-
getAccessPathMetaDatas
Description copied from interface:QueryContext
Return the classes that affect this query.- Specified by:
getAccessPathMetaDatas
in interfaceQueryContext
-
getOrderedParameterTypes
Description copied from interface:QueryContext
Return a map of parameter name to type for this query. The returned map will iterate in the order that the parameters were declared or, if they're implicit, used.- Specified by:
getOrderedParameterTypes
in interfaceQueryContext
-
getParameterTypes
Description copied from interface:QueryContext
Return a map of parameter name to type for this query. The returned map will iterate in the order that the parameters were declared or, if they're implicit, used.- Specified by:
getParameterTypes
in interfaceQueryContext
-
getUpdates
Description copied from interface:QueryContext
If this query is a bulk update, return a map of theFieldMetaData
s toConstant
s.- Specified by:
getUpdates
in interfaceQueryContext
-
lock
public void lock()Description copied from interface:QueryContext
Synchronize on the query's internal lock.- Specified by:
lock
in interfaceQueryContext
-
unlock
public void unlock()Description copied from interface:QueryContext
Unlock the query's internal lock.- Specified by:
unlock
in interfaceQueryContext
-
startLocking
public void startLocking() -
stopLocking
public void stopLocking() -
classForName
Description copied from interface:QueryContext
Helper method to instantiate the class with the given name, taking into account the query's candidate package, automatic imports, and the given imports (if any). Returns null if the type cannot be found.- Specified by:
classForName
in interfaceQueryContext
-
assertOpen
public void assertOpen()Description copied from interface:Query
Assert that the query's broker is still open.- Specified by:
assertOpen
in interfaceQuery
-
assertNotReadOnly
public void assertNotReadOnly()Description copied from interface:Query
Assert that the query is not read-only.- Specified by:
assertNotReadOnly
in interfaceQuery
-
assertNotSerialized
public void assertNotSerialized()Description copied from interface:Query
Check that the query has not been serialized, which causes it to lose its association with its Broker.- Specified by:
assertNotSerialized
in interfaceQuery
-
assertParameters
Checks that the passed parameters match the declarations. -
assertParameters
-
toString
-