org.apache.openjpa.kernel
Class ExpressionStoreQuery

java.lang.Object
  extended by org.apache.openjpa.kernel.AbstractStoreQuery
      extended by org.apache.openjpa.kernel.ExpressionStoreQuery
All Implemented Interfaces:
java.io.Serializable, QueryOperations, StoreQuery

public class ExpressionStoreQuery
extends AbstractStoreQuery

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:

Author:
Abe White
See Also:
Serialized Form

Nested Class Summary
 
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
 
Field Summary
 
Fields inherited from class org.apache.openjpa.kernel.AbstractStoreQuery
ctx
 
Fields inherited from interface org.apache.openjpa.kernel.StoreQuery
EMPTY_BOOLEANS, EMPTY_CLASSES, EMPTY_METAS, EMPTY_OBJECTS, EMPTY_PARAMS, EMPTY_STRINGS
 
Fields inherited from interface org.apache.openjpa.kernel.QueryOperations
OP_DELETE, OP_SELECT, OP_UPDATE
 
Constructor Summary
ExpressionStoreQuery(ExpressionParser parser)
          Construct a query with a parser for the language.
 
Method Summary
protected  java.lang.Number executeDelete(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, java.lang.Object[] params)
          Execute the given expression against the given candidate extent and delete the instances.
protected  org.apache.openjpa.lib.rop.ResultObjectProvider executeQuery(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, java.lang.Object[] params, boolean lrs, long startIdx, long endIdx)
          Execute the given expression against the given candidate extent.
protected  java.lang.Number executeUpdate(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, java.lang.Object[] params)
          Execute the given expression against the given candidate extent and updates the instances.
protected  java.lang.String[] getDataStoreActions(StoreQuery.Executor ex, ClassMetaData base, ClassMetaData[] types, boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] parsed, java.lang.Object[] params, long startIdx, long endIdx)
          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 getExpressionFactory(ClassMetaData type)
          Return an ExpressionFactory to use to create an expression to be executed against an extent.
 FilterListener getFilterListener(java.lang.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 getResolver()
          Resolver used in parsing.
 void invalidateCompilation()
          Invalidate any internal compilation state.
 java.lang.Object newCompilation()
          Create a new compilation for this query.
 StoreQuery.Executor newDataStoreExecutor(ClassMetaData meta, boolean subs)
          Return an executor for datastore execution of this query.
 StoreQuery.Executor newInMemoryExecutor(ClassMetaData meta, boolean subs)
          Return an executor for in-memory execution of this query.
 void populateFromCompilation(java.lang.Object comp)
          Populate internal data from compilation.
 boolean setQuery(java.lang.Object query)
          Allow direct setting of parsed state for facades that do parsing.
 boolean supportsInMemoryExecution()
          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
getAggregateListener, getContext, newCompilationKey, requiresCandidateType, requiresParameterDeclarations, setContext, supportsAbstractExecutors, supportsDataStoreExecution, supportsParameterDeclarations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionStoreQuery

public ExpressionStoreQuery(ExpressionParser parser)
Construct a query with a parser for the language.

Method Detail

getResolver

public Resolver getResolver()
Resolver used in parsing.


setQuery

public boolean setQuery(java.lang.Object query)
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 interface StoreQuery
Overrides:
setQuery in class AbstractStoreQuery

getFilterListener

public FilterListener getFilterListener(java.lang.String tag)
Description copied from interface: StoreQuery
Return the standard filter listener for the given tag, or null.

Specified by:
getFilterListener in interface StoreQuery
Overrides:
getFilterListener in class AbstractStoreQuery

newCompilation

public java.lang.Object newCompilation()
Description copied from interface: StoreQuery
Create a new compilation for this query. May be null.

Specified by:
newCompilation in interface StoreQuery
Overrides:
newCompilation in class AbstractStoreQuery

populateFromCompilation

public void populateFromCompilation(java.lang.Object comp)
Description copied from interface: StoreQuery
Populate internal data from compilation.

Specified by:
populateFromCompilation in interface StoreQuery
Overrides:
populateFromCompilation in class AbstractStoreQuery

invalidateCompilation

public void invalidateCompilation()
Description copied from interface: StoreQuery
Invalidate any internal compilation state.

Specified by:
invalidateCompilation in interface StoreQuery
Overrides:
invalidateCompilation in class AbstractStoreQuery

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 interface StoreQuery
Overrides:
supportsInMemoryExecution in class AbstractStoreQuery

newInMemoryExecutor

public StoreQuery.Executor newInMemoryExecutor(ClassMetaData meta,
                                               boolean subs)
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 from StoreQuery.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 interface StoreQuery
Overrides:
newInMemoryExecutor in class AbstractStoreQuery
subs - whether to include dependent mapped subclasses in the results; independent subclasses should never be included

newDataStoreExecutor

public StoreQuery.Executor newDataStoreExecutor(ClassMetaData meta,
                                                boolean subs)
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 from StoreQuery.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 interface StoreQuery
Overrides:
newDataStoreExecutor in class AbstractStoreQuery
subs - whether to include dependent mapped subclasses in the results; independent subclasses should never be included

executeQuery

protected org.apache.openjpa.lib.rop.ResultObjectProvider executeQuery(StoreQuery.Executor ex,
                                                                       ClassMetaData base,
                                                                       ClassMetaData[] types,
                                                                       boolean subclasses,
                                                                       ExpressionFactory[] facts,
                                                                       QueryExpressions[] parsed,
                                                                       java.lang.Object[] params,
                                                                       boolean lrs,
                                                                       long startIdx,
                                                                       long endIdx)
Execute the given expression against the given candidate extent.

Parameters:
ex - current executor
base - the base type the query should match
types - the independent candidate types
subclasses - true if subclasses should be included in the results
facts - the expression factory used to build the query for each base type
parsed - the parsed query values
params - parameter values, or empty array
lrs - whether the result will be handled as a potentially large result set, or will be consumed greedily
startIdx - 0-based inclusive index for first result to return from result object provider
endIdx - 0-based exclusive index for last result to return from result object provider, or Long.MAX_VALUE for no max
Returns:
a provider for matching objects

executeDelete

protected java.lang.Number executeDelete(StoreQuery.Executor ex,
                                         ClassMetaData base,
                                         ClassMetaData[] types,
                                         boolean subclasses,
                                         ExpressionFactory[] facts,
                                         QueryExpressions[] parsed,
                                         java.lang.Object[] params)
Execute the given expression against the given candidate extent and delete the instances.

Parameters:
ex - current executor
base - the base type the query should match
types - the independent candidate types
subclasses - true if subclasses should be included in the results
facts - the expression factory used to build the query for each base type
parsed - the parsed query values
params - parameter values, or empty array
Returns:
a number indicating the number of instances deleted, or null to execute the delete in memory

executeUpdate

protected java.lang.Number executeUpdate(StoreQuery.Executor ex,
                                         ClassMetaData base,
                                         ClassMetaData[] types,
                                         boolean subclasses,
                                         ExpressionFactory[] facts,
                                         QueryExpressions[] parsed,
                                         java.lang.Object[] params)
Execute the given expression against the given candidate extent and updates the instances.

Parameters:
ex - current executor
base - the base type the query should match
types - the independent candidate types
subclasses - true if subclasses should be included in the results
facts - the expression factory used to build the query for each base type
parsed - the parsed query values
params - parameter values, or empty array
Returns:
a number indicating the number of instances updated, or null to execute the update in memory.

getDataStoreActions

protected java.lang.String[] getDataStoreActions(StoreQuery.Executor ex,
                                                 ClassMetaData base,
                                                 ClassMetaData[] types,
                                                 boolean subclasses,
                                                 ExpressionFactory[] facts,
                                                 QueryExpressions[] parsed,
                                                 java.lang.Object[] params,
                                                 long startIdx,
                                                 long endIdx)
Return the commands that will be sent to the datastore in order to execute the query, typically in the database's native language.

Parameters:
ex - current executor
base - the base type the query should match
types - the independent candidate types
subclasses - true if subclasses should be included in the results
facts - the expression factory used to build the query for each base type
parsed - the parsed query values
params - parameter values, or empty array
startIdx - 0-based inclusive index for first result to return from result object provider
endIdx - 0-based exclusive index for last result to return from result object provider, or Long.MAX_VALUE for no max
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

protected ExpressionFactory getExpressionFactory(ClassMetaData type)
Return an ExpressionFactory 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.



Copyright © 2006 Apache Software Foundation. All Rights Reserved.