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
public class QueryImpl extends Object implements Query
Implementation of theQueryinterface.- Author:
 - Abe White
 - See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classQueryImpl.CompilationStruct of compiled query properties.static classQueryImpl.PackingResultObjectProviderResult object provider that packs results before returning them.classQueryImpl.RemoveOnCloseResultListResult 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
Constructors Constructor Description QueryImpl(Broker broker, String language, StoreQuery storeQuery)Construct a query managed by the given broker. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAggregateListener(AggregateListener listener)Register an aggregate listener for the query.voidaddFilterListener(FilterListener listener)Register a filter listener for the query.voidassertNotReadOnly()Assert that the query is not read-only.voidassertNotSerialized()Check that the query has not been serialized, which causes it to lose its association with its Broker.voidassertOpen()Assert that the query's broker is still open.protected voidassertParameters(StoreQuery q, StoreQuery.Executor ex, Object[] params)Checks that the passed parameters match the declarations.protected voidassertParameters(StoreQuery q, StoreQuery.Executor ex, Map params)ClassclassForName(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).voidcloseAll()Close all open query results.voidcloseResources()Close query results that are consuming resources.protected QueryImpl.CompilationcompilationFromCache()Find the cached compilation for the current query, creating one if it does not exist.voidcompile()Compile the query.voiddeclareParameters(String params)Declared parameters, for query languages that use them.protected QueryImpl.RemoveOnCloseResultListdecorateResultList(ResultList<?> res)Optionally decorate the native result.longdeleteAll()Deletes all of the instances that are satisfied by the query.longdeleteAll(Object[] params)Deletes all of the instances that are satisfied by the query.longdeleteAll(Map params)Deletes all of the instances that are satisfied by the query.NumberdeleteInMemory(StoreQuery q, StoreQuery.Executor executor, Object[] params)Helper method to delete the objects found by executing a query on the given executor.Objectexecute()Execute.Objectexecute(Object[] params)Execute with parameter array.Objectexecute(Map params)Execute with parameter map.ClassMetaData[]getAccessPathMetaDatas()Return the classes that affect this query.AggregateListenergetAggregateListener(String tag)Return the filter listener for the given tag, or null.Collection<AggregateListener>getAggregateListeners()The set of aggregate listeners.StringgetAlias()If this query is not a projection but places candidate results into a result class under an alias, return that alias.BrokergetBroker()The broker that generated this query.Collection<?>getCandidateCollection()Return the candidate collection, ornullif an extent was specified instead of a collection.ExtentgetCandidateExtent()Return the candidate extent, ornullif a collection was specified instead of an extent.ClassgetCandidateType()Return the class of the objects that this query will return, ornullif this information is not available / not relevant.ObjectgetCompilation()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.longgetEndRange()Return the 0-based exclusive end index for the returned results, orLong.MAX_VALUEfor no limit.FetchConfigurationgetFetchConfiguration()Return the fetch configuration for this query.FilterListenergetFilterListener(String tag)Return the filter listener for the given tag, or null.Collection<FilterListener>getFilterListeners()The set of filter listeners.booleangetIgnoreChanges()Whether to ignore changes in the current transaction.StringgetLanguage()The query language.intgetOperation()Returns the operation that this query will be expected to perform.OrderedMap<Object,Class<?>>getOrderedParameterTypes()Return a map of parameter name to type for this query.StringgetParameterDeclaration()The parameter declaration.LinkedMapgetParameterTypes()Return a map of parameter name to type for this query.String[]getProjectionAliases()If this query is a projection, return the projection aliases.Class<?>[]getProjectionTypes()If this query is a projection, return the projection types.QuerygetQuery()Return the query for this context.StringgetQueryString()The query string.StringgetResultMappingName()Name of a mapping from the result data to its object representation.ClassgetResultMappingScope()Scope of a mapping from the result data to its object representation.ClassgetResultType()Returns the result class that has been set throughQueryContext.setResultType(java.lang.Class<?>), or null if none.longgetStartRange()Return the 0-based start index for the returned results.StoreContextgetStoreContext()The persistence context for the query.StoreQuerygetStoreQuery()Internal store query.MapgetUpdates()If this query is a bulk update, return a map of theFieldMetaDatas toConstants.booleanhasGrouping()Return true if the query uses grouping.booleanhasSubclasses()Whether query results will include subclasses of the candidate class.static booleanisAccessPathDirty(Broker broker, ClassMetaData[] accessMetas)booleanisAggregate()Return true if the query is an aggregate.booleanisDistinct()Affirms if this query results are distinct instance(s).booleanisParsedQuery()Affirms if this query has originated by parsing a string-based query.booleanisReadOnly()Whether the query has been marked read-only.booleanisUnique()The unique flag.voidlock()Synchronize on the query's internal lock.voidremoveAggregateListener(AggregateListener listener)Remove an aggregate listener from the query.voidremoveFilterListener(FilterListener listener)Remove a filter listener from the query.voidsetCandidateCollection(Collection<?> candidateCollection)Set a collection of candidates.voidsetCandidateExtent(Extent candidateExtent)Set the candidate extent.voidsetCandidateType(Class candidateClass, boolean subs)Set the candidate type.voidsetIgnoreChanges(boolean flag)Whether to ignore changes in the current transaction.booleansetQuery(Object query)The query string or template.voidsetRange(long start, long end)Set the range of results to return.voidsetReadOnly(boolean flag)Whether the query has been marked read-only.voidsetResultMapping(Class<?> scope, String name)Name and scope of a mapping from the result data to its object representation.voidsetResultType(Class cls)Specify the type of object in which the result of evaluating this query.voidsetUnique(boolean unique)Specify that the query will return only 1 result, rather than a collection.voidstartLocking()voidstopLocking()protected ObjecttoResult(StoreQuery q, StoreQuery.Executor ex, ResultObjectProvider rop, StoreQuery.Range range)Return the query result for the given result object provider.StringtoString()voidunlock()Unlock the query's internal lock.longupdateAll()Performs an update of the instances that are satisfied by the query.longupdateAll(Object[] params)Performs an update of the instances that are satisfied by the query.longupdateAll(Map params)Performs an update of the instances that are satisfied by the query.NumberupdateInMemory(StoreQuery q, StoreQuery.Executor executor, Object[] params)Helper method to update the objects found by executing a query on the given executor. 
 - 
 
- 
- 
Constructor Detail
- 
QueryImpl
public QueryImpl(Broker broker, String language, StoreQuery storeQuery)
Construct a query managed by the given broker. 
 - 
 
- 
Method Detail
- 
getStoreQuery
public StoreQuery getStoreQuery()
Internal store query. 
- 
getBroker
public Broker getBroker()
Description copied from interface:QueryThe broker that generated this query. 
- 
getQuery
public Query getQuery()
Description copied from interface:QueryContextReturn 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:
 getQueryin interfaceQueryContext
 
- 
getStoreContext
public StoreContext getStoreContext()
Description copied from interface:QueryContextThe persistence context for the query.- Specified by:
 getStoreContextin interfaceQueryContext
 
- 
getLanguage
public String getLanguage()
Description copied from interface:QueryContextThe query language.- Specified by:
 getLanguagein interfaceQueryContext
 
- 
getFetchConfiguration
public FetchConfiguration getFetchConfiguration()
Description copied from interface:QueryContextReturn the fetch configuration for this query.- Specified by:
 getFetchConfigurationin interfaceQueryContext
 
- 
getQueryString
public String getQueryString()
Description copied from interface:QueryContextThe query string.- Specified by:
 getQueryStringin interfaceQueryContext
 
- 
getIgnoreChanges
public boolean getIgnoreChanges()
Description copied from interface:QueryContextWhether to ignore changes in the current transaction.- Specified by:
 getIgnoreChangesin interfaceQueryContext
 
- 
setIgnoreChanges
public void setIgnoreChanges(boolean flag)
Description copied from interface:QueryWhether to ignore changes in the current transaction.- Specified by:
 setIgnoreChangesin interfaceQuery
 
- 
isReadOnly
public boolean isReadOnly()
Description copied from interface:QueryContextWhether the query has been marked read-only.- Specified by:
 isReadOnlyin interfaceQueryContext
 
- 
setReadOnly
public void setReadOnly(boolean flag)
Description copied from interface:QueryContextWhether the query has been marked read-only.- Specified by:
 setReadOnlyin interfaceQueryContext
 
- 
addFilterListener
public void addFilterListener(FilterListener listener)
Description copied from interface:QueryRegister a filter listener for the query.- Specified by:
 addFilterListenerin interfaceQuery
 
- 
removeFilterListener
public void removeFilterListener(FilterListener listener)
Description copied from interface:QueryRemove a filter listener from the query.- Specified by:
 removeFilterListenerin interfaceQuery
 
- 
getFilterListeners
public Collection<FilterListener> getFilterListeners()
Description copied from interface:QueryContextThe set of filter listeners.- Specified by:
 getFilterListenersin interfaceQueryContext
 
- 
getFilterListener
public FilterListener getFilterListener(String tag)
Description copied from interface:QueryContextReturn the filter listener for the given tag, or null.- Specified by:
 getFilterListenerin interfaceQueryContext
 
- 
addAggregateListener
public void addAggregateListener(AggregateListener listener)
Description copied from interface:QueryRegister an aggregate listener for the query.- Specified by:
 addAggregateListenerin interfaceQuery
 
- 
removeAggregateListener
public void removeAggregateListener(AggregateListener listener)
Description copied from interface:QueryRemove an aggregate listener from the query.- Specified by:
 removeAggregateListenerin interfaceQuery
 
- 
getAggregateListeners
public Collection<AggregateListener> getAggregateListeners()
Description copied from interface:QueryContextThe set of aggregate listeners.- Specified by:
 getAggregateListenersin interfaceQueryContext
 
- 
getAggregateListener
public AggregateListener getAggregateListener(String tag)
Description copied from interface:QueryContextReturn the filter listener for the given tag, or null.- Specified by:
 getAggregateListenerin interfaceQueryContext
 
- 
getCandidateExtent
public Extent getCandidateExtent()
Description copied from interface:QueryReturn the candidate extent, ornullif a collection was specified instead of an extent.- Specified by:
 getCandidateExtentin interfaceQuery
 
- 
setCandidateExtent
public void setCandidateExtent(Extent candidateExtent)
Description copied from interface:QuerySet the candidate extent.- Specified by:
 setCandidateExtentin interfaceQuery
 
- 
getCandidateCollection
public Collection<?> getCandidateCollection()
Description copied from interface:QueryContextReturn the candidate collection, ornullif an extent was specified instead of a collection.- Specified by:
 getCandidateCollectionin interfaceQueryContext
 
- 
setCandidateCollection
public void setCandidateCollection(Collection<?> candidateCollection)
Description copied from interface:QuerySet a collection of candidates.- Specified by:
 setCandidateCollectionin interfaceQuery
 
- 
getCandidateType
public Class getCandidateType()
Description copied from interface:QueryContextReturn the class of the objects that this query will return, ornullif this information is not available / not relevant.- Specified by:
 getCandidateTypein interfaceQueryContext
 
- 
setCandidateType
public void setCandidateType(Class candidateClass, boolean subs)
Description copied from interface:QueryContextSet the candidate type.- Specified by:
 setCandidateTypein interfaceQueryContext
 
- 
hasSubclasses
public boolean hasSubclasses()
Description copied from interface:QueryContextWhether query results will include subclasses of the candidate class.- Specified by:
 hasSubclassesin interfaceQueryContext
 
- 
getResultMappingName
public String getResultMappingName()
Description copied from interface:QueryContextName of a mapping from the result data to its object representation.- Specified by:
 getResultMappingNamein interfaceQueryContext
 
- 
getResultMappingScope
public Class getResultMappingScope()
Description copied from interface:QueryContextScope of a mapping from the result data to its object representation.- Specified by:
 getResultMappingScopein interfaceQueryContext
 
- 
setResultMapping
public void setResultMapping(Class<?> scope, String name)
Description copied from interface:QueryContextName and scope of a mapping from the result data to its object representation.- Specified by:
 setResultMappingin interfaceQueryContext
 
- 
isUnique
public boolean isUnique()
Description copied from interface:QueryContextThe unique flag.- Specified by:
 isUniquein 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:QueryContextSpecify 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:
 setUniquein interfaceQueryContext
 
- 
getResultType
public Class getResultType()
Description copied from interface:QueryContextReturns the result class that has been set throughQueryContext.setResultType(java.lang.Class<?>), or null if none.- Specified by:
 getResultTypein interfaceQueryContext
 
- 
setResultType
public void setResultType(Class cls)
Description copied from interface:QueryContextSpecify the type of object in which the result of evaluating this query.- Specified by:
 setResultTypein interfaceQueryContext
 
- 
getStartRange
public long getStartRange()
Description copied from interface:QueryContextReturn the 0-based start index for the returned results.- Specified by:
 getStartRangein interfaceQueryContext
 
- 
getEndRange
public long getEndRange()
Description copied from interface:QueryContextReturn the 0-based exclusive end index for the returned results, orLong.MAX_VALUEfor no limit.- Specified by:
 getEndRangein interfaceQueryContext
 
- 
setRange
public void setRange(long start, long end)Description copied from interface:QueryContextSet the range of results to return.- Specified by:
 setRangein interfaceQueryContext- Parameters:
 start- 0-based inclusive start indexend- 0-based exclusive end index, orLong.MAX_VALUEfor no limit
 
- 
getParameterDeclaration
public String getParameterDeclaration()
Description copied from interface:QueryContextThe parameter declaration.- Specified by:
 getParameterDeclarationin interfaceQueryContext
 
- 
declareParameters
public void declareParameters(String params)
Description copied from interface:QueryContextDeclared parameters, for query languages that use them.- Specified by:
 declareParametersin interfaceQueryContext
 
- 
compile
public void compile()
Description copied from interface:QueryCompile the query. 
- 
getCompilation
public Object getCompilation()
Description copied from interface:QueryContextReturn the query's compilation state.- Specified by:
 getCompilationin interfaceQueryContext
 
- 
compilationFromCache
protected QueryImpl.Compilation compilationFromCache()
Find the cached compilation for the current query, creating one if it does not exist. 
- 
execute
public Object execute(Object[] params)
Description copied from interface:QueryExecute with parameter array. 
- 
execute
public Object execute(Map params)
Description copied from interface:QueryExecute with parameter map. 
- 
deleteAll
public long deleteAll()
Description copied from interface:QueryDeletes all of the instances that are satisfied by the query. 
- 
deleteAll
public long deleteAll(Object[] params)
Description copied from interface:QueryDeletes all of the instances that are satisfied by the query. 
- 
deleteAll
public long deleteAll(Map params)
Description copied from interface:QueryDeletes all of the instances that are satisfied by the query. 
- 
updateAll
public long updateAll()
Description copied from interface:QueryPerforms an update of the instances that are satisfied by the query. 
- 
updateAll
public long updateAll(Object[] params)
Description copied from interface:QueryPerforms an update of the instances that are satisfied by the query. 
- 
updateAll
public long updateAll(Map params)
Description copied from interface:QueryPerforms an update of the instances that are satisfied by the query. 
- 
deleteInMemory
public Number deleteInMemory(StoreQuery q, StoreQuery.Executor executor, Object[] params)
Description copied from interface:QueryContextHelper method to delete the objects found by executing a query on the given executor.- Specified by:
 deleteInMemoryin interfaceQueryContext
 
- 
updateInMemory
public Number updateInMemory(StoreQuery q, StoreQuery.Executor executor, Object[] params)
Description copied from interface:QueryContextHelper method to update the objects found by executing a query on the given executor.- Specified by:
 updateInMemoryin 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
protected QueryImpl.RemoveOnCloseResultList decorateResultList(ResultList<?> res)
Optionally decorate the native result. 
- 
isAccessPathDirty
public static boolean isAccessPathDirty(Broker broker, ClassMetaData[] accessMetas)
 
- 
closeAll
public void closeAll()
Description copied from interface:QueryClose all open query results. 
- 
closeResources
public void closeResources()
Description copied from interface:QueryClose 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:
 closeResourcesin interfaceQuery
 
- 
getDataStoreActions
public String[] getDataStoreActions(Map params)
Description copied from interface:QueryReturns 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:
 getDataStoreActionsin interfaceQuery- Parameters:
 params- the named parameter map for the query invocation
 
- 
setQuery
public boolean setQuery(Object query)
Description copied from interface:QueryThe query string or template. 
- 
getAlias
public String getAlias()
Description copied from interface:QueryContextIf this query is not a projection but places candidate results into a result class under an alias, return that alias.- Specified by:
 getAliasin interfaceQueryContext
 
- 
getProjectionAliases
public String[] getProjectionAliases()
Description copied from interface:QueryContextIf this query is a projection, return the projection aliases.- Specified by:
 getProjectionAliasesin interfaceQueryContext
 
- 
getProjectionTypes
public Class<?>[] getProjectionTypes()
Description copied from interface:QueryContextIf this query is a projection, return the projection types.- Specified by:
 getProjectionTypesin interfaceQueryContext
 
- 
getOperation
public int getOperation()
Description copied from interface:QueryContextReturns the operation that this query will be expected to perform.- Specified by:
 getOperationin interfaceQueryContext- See Also:
 QueryOperations
 
- 
isAggregate
public boolean isAggregate()
Description copied from interface:QueryContextReturn true if the query is an aggregate.- Specified by:
 isAggregatein interfaceQueryContext
 
- 
isDistinct
public boolean isDistinct()
Description copied from interface:QueryContextAffirms if this query results are distinct instance(s).- Specified by:
 isDistinctin interfaceQueryContext
 
- 
hasGrouping
public boolean hasGrouping()
Description copied from interface:QueryContextReturn true if the query uses grouping.- Specified by:
 hasGroupingin interfaceQueryContext
 
- 
getAccessPathMetaDatas
public ClassMetaData[] getAccessPathMetaDatas()
Description copied from interface:QueryContextReturn the classes that affect this query.- Specified by:
 getAccessPathMetaDatasin interfaceQueryContext
 
- 
getOrderedParameterTypes
public OrderedMap<Object,Class<?>> getOrderedParameterTypes()
Description copied from interface:QueryContextReturn 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:
 getOrderedParameterTypesin interfaceQueryContext
 
- 
getParameterTypes
public LinkedMap getParameterTypes()
Description copied from interface:QueryContextReturn 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:
 getParameterTypesin interfaceQueryContext
 
- 
getUpdates
public Map getUpdates()
Description copied from interface:QueryContextIf this query is a bulk update, return a map of theFieldMetaDatas toConstants.- Specified by:
 getUpdatesin interfaceQueryContext
 
- 
lock
public void lock()
Description copied from interface:QueryContextSynchronize on the query's internal lock.- Specified by:
 lockin interfaceQueryContext
 
- 
unlock
public void unlock()
Description copied from interface:QueryContextUnlock the query's internal lock.- Specified by:
 unlockin interfaceQueryContext
 
- 
startLocking
public void startLocking()
 
- 
stopLocking
public void stopLocking()
 
- 
classForName
public Class classForName(String name, String[] imports)
Description copied from interface:QueryContextHelper 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:
 classForNamein interfaceQueryContext
 
- 
assertOpen
public void assertOpen()
Description copied from interface:QueryAssert that the query's broker is still open.- Specified by:
 assertOpenin interfaceQuery
 
- 
assertNotReadOnly
public void assertNotReadOnly()
Description copied from interface:QueryAssert that the query is not read-only.- Specified by:
 assertNotReadOnlyin interfaceQuery
 
- 
assertNotSerialized
public void assertNotSerialized()
Description copied from interface:QueryCheck that the query has not been serialized, which causes it to lose its association with its Broker.- Specified by:
 assertNotSerializedin interfaceQuery
 
- 
assertParameters
protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, Object[] params)
Checks that the passed parameters match the declarations. 
- 
assertParameters
protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, Map params)
 
 - 
 
 -