Package org.apache.openjpa.kernel
Class ExpressionStoreQuery
java.lang.Object
org.apache.openjpa.kernel.AbstractStoreQuery
org.apache.openjpa.kernel.ExpressionStoreQuery
- All Implemented Interfaces:
Serializable
,QueryOperations
,StoreQuery
- Direct Known Subclasses:
JDBCStoreQuery
Implementation of an expression-based query, which can handle
String-based query expressions such as JPQL and JDOQL.
This implementation is suitable for in-memory operation.
Override the following methods to also support datastore operation:
- Override
AbstractStoreQuery.supportsDataStoreExecution()
to returntrue
. - Override
executeQuery(org.apache.openjpa.kernel.StoreQuery.Executor, org.apache.openjpa.meta.ClassMetaData, org.apache.openjpa.meta.ClassMetaData[], boolean, org.apache.openjpa.kernel.exps.ExpressionFactory[], org.apache.openjpa.kernel.exps.QueryExpressions[], java.lang.Object[], org.apache.openjpa.kernel.StoreQuery.Range)
,executeDelete(org.apache.openjpa.kernel.StoreQuery.Executor, org.apache.openjpa.meta.ClassMetaData, org.apache.openjpa.meta.ClassMetaData[], boolean, org.apache.openjpa.kernel.exps.ExpressionFactory[], org.apache.openjpa.kernel.exps.QueryExpressions[], java.lang.Object[])
, andexecuteUpdate(org.apache.openjpa.kernel.StoreQuery.Executor, org.apache.openjpa.meta.ClassMetaData, org.apache.openjpa.meta.ClassMetaData[], boolean, org.apache.openjpa.kernel.exps.ExpressionFactory[], org.apache.openjpa.kernel.exps.QueryExpressions[], java.lang.Object[])
to execute the query against the data store. Keep in mind that the parameters passed to this method might be in use by several threads in different query instances. Thus components like the expression factory must either be thread safe, or this method must synchronize on them. - Override
getDataStoreActions(org.apache.openjpa.meta.ClassMetaData, org.apache.openjpa.meta.ClassMetaData[], boolean, org.apache.openjpa.kernel.exps.ExpressionFactory[], org.apache.openjpa.kernel.exps.QueryExpressions[], java.lang.Object[], org.apache.openjpa.kernel.StoreQuery.Range)
to return a representation of the actions that will be taken on the data store. For use in visual tools. - Override
getExpressionFactory(org.apache.openjpa.meta.ClassMetaData)
to return a factory for creating expressions in the datastore's language. The factory must be cachable.
- Author:
- Abe White
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Provides support for queries that hold query information in aQueryExpressions
instance.static class
The DataStoreExecutor executes the query against the implementation's overriddenExpressionStoreQuery.DataStoreExecutor.executeQuery(org.apache.openjpa.kernel.StoreQuery, java.lang.Object[], org.apache.openjpa.kernel.StoreQuery.Range)
method.static class
Runs the expression query in memory.Nested classes/interfaces inherited from class org.apache.openjpa.kernel.AbstractStoreQuery
AbstractStoreQuery.AbstractExecutor
Nested classes/interfaces inherited from interface org.apache.openjpa.kernel.StoreQuery
StoreQuery.Executor, StoreQuery.Range
-
Field Summary
Fields inherited from class org.apache.openjpa.kernel.AbstractStoreQuery
ctx
Fields inherited from interface org.apache.openjpa.kernel.QueryOperations
OP_DELETE, OP_SELECT, OP_UPDATE
Fields inherited from interface org.apache.openjpa.kernel.StoreQuery
EMPTY_BOOLEANS, EMPTY_CLASSES, EMPTY_METAS, EMPTY_OBJECTS, EMPTY_ORDERED_PARAMS, EMPTY_PARAMS, EMPTY_STRINGS
-
Constructor Summary
ConstructorDescriptionExpressionStoreQuery
(ExpressionParser parser) Construct a query with a parser for the language. -
Method Summary
Modifier and TypeMethodDescriptionprotected Number
executeDelete
(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params) Execute the given expression against the given candidate extent and delete the instances.protected ResultObjectProvider
executeQuery
(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params, StoreQuery.Range range) Execute the given expression against the given candidate extent.protected Number
executeUpdate
(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params) Execute the given expression against the given candidate extent and updates the instances.Get the current compilation for this query.protected String[]
getDataStoreActions
(ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params, StoreQuery.Range range) Return the commands that will be sent to the datastore in order to execute the query, typically in the database's native language.protected ExpressionFactory
Return anExpressionFactory
to use to create an expression to be executed against an extent.getFilterListener
(String tag) Return the standard filter listener for the given tag, or null.protected ClassMetaData[]
getIndependentExpressionCandidates
(ClassMetaData type, boolean subclasses) Return the assignable types for the given metadata whose expression trees must be compiled independently.Resolver used in parsing.void
Invalidate any internal compilation state.Create a new compilation for this query.newDataStoreExecutor
(ClassMetaData meta, boolean subs) Return an executor for datastore execution of this query.newInMemoryExecutor
(ClassMetaData meta, boolean subs) Return an executor for in-memory execution of this query.void
Populate internal data from compilation.boolean
Allow direct setting of parsed state for facades that do parsing.boolean
True if this query supports in-memory execution, false if it can only run against the datastore.Methods inherited from class org.apache.openjpa.kernel.AbstractStoreQuery
evaluate, getAggregateListener, getContext, newCompilationKey, requiresCandidateType, requiresParameterDeclarations, setContext, supportsAbstractExecutors, supportsDataStoreExecution, supportsParameterDeclarations
-
Field Details
-
_parser
-
_parsed
-
-
Constructor Details
-
ExpressionStoreQuery
Construct a query with a parser for the language.
-
-
Method Details
-
getResolver
Resolver used in parsing. -
setQuery
Allow direct setting of parsed state for facades that do parsing. The facade should call this method twice: once with the query string, and again with the parsed state.- Specified by:
setQuery
in interfaceStoreQuery
- Overrides:
setQuery
in classAbstractStoreQuery
-
getFilterListener
Description copied from interface:StoreQuery
Return the standard filter listener for the given tag, or null.- Specified by:
getFilterListener
in interfaceStoreQuery
- Overrides:
getFilterListener
in classAbstractStoreQuery
-
newCompilation
Description copied from interface:StoreQuery
Create a new compilation for this query. May be null.- Specified by:
newCompilation
in interfaceStoreQuery
- Overrides:
newCompilation
in classAbstractStoreQuery
-
getCompilation
Description copied from interface:StoreQuery
Get the current compilation for this query. If it is null, do not create.- Specified by:
getCompilation
in interfaceStoreQuery
- Overrides:
getCompilation
in classAbstractStoreQuery
-
populateFromCompilation
Description copied from interface:StoreQuery
Populate internal data from compilation.- Specified by:
populateFromCompilation
in interfaceStoreQuery
- Overrides:
populateFromCompilation
in classAbstractStoreQuery
-
invalidateCompilation
public void invalidateCompilation()Description copied from interface:StoreQuery
Invalidate any internal compilation state.- Specified by:
invalidateCompilation
in interfaceStoreQuery
- Overrides:
invalidateCompilation
in classAbstractStoreQuery
-
supportsInMemoryExecution
public boolean supportsInMemoryExecution()Description copied from interface:StoreQuery
True if this query supports in-memory execution, false if it can only run against the datastore.- Specified by:
supportsInMemoryExecution
in interfaceStoreQuery
- Overrides:
supportsInMemoryExecution
in classAbstractStoreQuery
-
newInMemoryExecutor
Description copied from interface:StoreQuery
Return an executor for in-memory execution of this query. Executors must be cachable and thread safe. If this class returns true fromStoreQuery.supportsAbstractExecutors()
, the given metadata will always be for the candidate class of this query, or possibly null if the candidate class is not itself persistence capable (like an interface or abstract base class). Otherwise, the given type will be a mapped class.- Specified by:
newInMemoryExecutor
in interfaceStoreQuery
- Overrides:
newInMemoryExecutor
in classAbstractStoreQuery
subs
- whether to include dependent mapped subclasses in the results; independent subclasses should never be included
-
newDataStoreExecutor
Description copied from interface:StoreQuery
Return an executor for datastore execution of this query. Executors must be cachable and thread safe. If this class returns true fromStoreQuery.supportsAbstractExecutors()
, the given metadata will always be for the candidate class of this query, or possibly null if the candidate class is not itself persistence capable (like an interface or abstract base class). Otherwise, the given type will be a mapped class.- Specified by:
newDataStoreExecutor
in interfaceStoreQuery
- Overrides:
newDataStoreExecutor
in classAbstractStoreQuery
subs
- whether to include dependent mapped subclasses in the results; independent subclasses should never be included
-
executeQuery
protected ResultObjectProvider executeQuery(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params, StoreQuery.Range range) Execute the given expression against the given candidate extent.- Parameters:
ex
- current executorbase
- the base type the query should matchtypes
- the independent candidate typessubclasses
- true if subclasses should be included in the resultsfacts
- the expression factory used to build the query for each base typeparsed
- the parsed query valuesparams
- parameter values, or empty arrayrange
- result range- Returns:
- a provider for matching objects
-
executeDelete
protected Number executeDelete(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params) Execute the given expression against the given candidate extent and delete the instances.- Parameters:
ex
- current executorbase
- the base type the query should matchtypes
- the independent candidate typessubclasses
- true if subclasses should be included in the resultsfacts
- the expression factory used to build the query for each base typeparsed
- the parsed query valuesparams
- parameter values, or empty array- Returns:
- a number indicating the number of instances deleted, or null to execute the delete in memory
-
executeUpdate
protected Number executeUpdate(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params) Execute the given expression against the given candidate extent and updates the instances.- Parameters:
ex
- current executorbase
- the base type the query should matchtypes
- the independent candidate typessubclasses
- true if subclasses should be included in the resultsfacts
- the expression factory used to build the query for each base typeparsed
- the parsed query valuesparams
- parameter values, or empty array- Returns:
- a number indicating the number of instances updated, or null to execute the update in memory.
-
getDataStoreActions
protected String[] getDataStoreActions(ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, Object[] params, StoreQuery.Range range) Return the commands that will be sent to the datastore in order to execute the query, typically in the database's native language.- Parameters:
base
- the base type the query should matchtypes
- the independent candidate typessubclasses
- true if subclasses should be included in the resultsfacts
- the expression factory used to build the query for each base typeparsed
- the parsed query valuesparams
- parameter values, or empty arrayrange
- result range- Returns:
- a textual description of the query to execute
-
getIndependentExpressionCandidates
protected ClassMetaData[] getIndependentExpressionCandidates(ClassMetaData type, boolean subclasses) Return the assignable types for the given metadata whose expression trees must be compiled independently. -
getExpressionFactory
Return anExpressionFactory
to use to create an expression to be executed against an extent. Each factory will be used to compile one filter only. The factory must be cachable.
-