Class QueryImpl
- java.lang.Object
-
- com.sun.jdo.spi.persistence.support.sqlstore.query.QueryImpl
-
- All Implemented Interfaces:
Query
,Serializable
public class QueryImpl extends Object implements Query
- Version:
- 0.1
- Author:
- Michael Bouschen
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static ResourceBundle
messages
I18N support
-
Constructor Summary
Constructors Constructor Description QueryImpl(PersistenceManager pm)
Create an empty query instance with no elements.QueryImpl(PersistenceManager pm, Class candidateClass)
Create a query instance with the candidate class specified.QueryImpl(PersistenceManager pm, Class candidateClass, String filter)
Create a query instance with the candidate class and filter specified.QueryImpl(PersistenceManager pm, Class candidateClass, Collection candidateCollection)
Create a query instance with the candidate class and candidate collection specified.QueryImpl(PersistenceManager pm, Class candidateClass, Collection candidateCollection, String filter)
Create a query instance with the candidate class, the candidate collection, and filter specified.QueryImpl(PersistenceManager pm, Object compiled)
Create a new Query using elements from another Query.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearPersistenceManager()
This method clears the PersistenceManager and the candidateCollection fields.void
compile()
Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.void
declareImports(String imports)
Bind the import statements to the query instance.void
declareParameters(String parameters)
Bind the parameter statements to the query instance.void
declareVariables(String variables)
Bind the unbound variable statements to the query instance.Object
execute()
Execute the query and return the filtered Collection.Object
execute(Object p1)
Execute the query and return the filtered Collection.Object
execute(Object p1, Object p2)
Execute the query and return the filtered Collection.Object
execute(Object p1, Object p2, Object p3)
Execute the query and return the filtered Collection.Object
executeWithArray(Object[] parameters)
Execute the query and return the filtered Collection.Object
executeWithMap(Map parameters)
Execute the query and return the filtered Collection.boolean
getIgnoreCache()
Get the ignoreCache option setting.PersistenceManager
getPersistenceManager()
Get the PersistenceManager associated with this Query.void
setCandidates(Collection candidateCollection)
Bind the candidate Collection to the query instance.void
setClass(Class candidateClass)
Bind the candidate class to the query instance.void
setFilter(String filter)
Bind the query filter to the query instance.void
setIgnoreCache(boolean ignoreCache)
Set the ignoreCache option.void
setOrdering(String ordering)
Bind the ordering statements to the query instance.void
setPrefetchEnabled(boolean prefetchEnabled)
Sets the prefetchEnabled option.void
setResult(String result)
Set the result of the query.String
toString()
Returns a string representation of the object.
-
-
-
Field Detail
-
messages
protected static final ResourceBundle messages
I18N support
-
-
Constructor Detail
-
QueryImpl
public QueryImpl(PersistenceManager pm)
Create an empty query instance with no elements.
-
QueryImpl
public QueryImpl(PersistenceManager pm, Object compiled)
Create a new Query using elements from another Query. The other Query must have been created by the same JDO implementation. It might be active in a different PersistenceManager or might have been serialized and restored.- Parameters:
compiled
- another Query from the same JDO implementation
-
QueryImpl
public QueryImpl(PersistenceManager pm, Class candidateClass)
Create a query instance with the candidate class specified.- Parameters:
candidateClass
- the Class of the candidate instances.
-
QueryImpl
public QueryImpl(PersistenceManager pm, Class candidateClass, Collection candidateCollection)
Create a query instance with the candidate class and candidate collection specified.- Parameters:
candidateClass
- the Class of the candidate instances.candidateCollection
- the Collection of candidate instances.
-
QueryImpl
public QueryImpl(PersistenceManager pm, Class candidateClass, String filter)
Create a query instance with the candidate class and filter specified.- Parameters:
candidateClass
- the Class of the candidate instances.filter
- the Filter for candidate instances.
-
QueryImpl
public QueryImpl(PersistenceManager pm, Class candidateClass, Collection candidateCollection, String filter)
Create a query instance with the candidate class, the candidate collection, and filter specified.- Parameters:
candidateClass
- the Class of the candidate instances.candidateCollection
- the Collection of candidate instances.filter
- the Filter for candidate instances
-
-
Method Detail
-
setClass
public void setClass(Class candidateClass)
Bind the candidate class to the query instance. The class is used to scope the names in the query filter. All of the candidate instances will be of this class or subclass.
-
setCandidates
public void setCandidates(Collection candidateCollection)
Bind the candidate Collection to the query instance.- Specified by:
setCandidates
in interfaceQuery
- Parameters:
candidateCollection
- the Candidate collection.
-
setFilter
public void setFilter(String filter)
Bind the query filter to the query instance. The query filter is a Java boolean expression, which tells whether instances in the candidate collection are to be returned in the result.
-
declareImports
public void declareImports(String imports)
Bind the import statements to the query instance. All imports must be declared in the same method call, and the imports must be separated by semicolons. The syntax is the same as in the Java language import statement. Parameters and unbound variables might come from a different class from the candidate class, and the names might need to be declared in an import statement to eliminate ambiguity.- Specified by:
declareImports
in interfaceQuery
- Parameters:
imports
- import statements separated by semicolons.
-
declareParameters
public void declareParameters(String parameters)
Bind the parameter statements to the query instance. This method defines the parameter types and names which will be used by a subsequent execute method. The parameter declaration is a String containing one or more query parameter declarations separated with commas. It follows the syntax for formal parameters in the Java language. Each parameter named in the parameter declaration must be bound to a value when the query is executed.- Specified by:
declareParameters
in interfaceQuery
- Parameters:
parameters
- the list of parameters separated by commas.
-
declareVariables
public void declareVariables(String variables)
Bind the unbound variable statements to the query instance. This method defines the types and names of variables that will be used in the filter but not provided as values by the execute method. Variables might be used in the filter, and these variables must be declared with their type. The unbound variable declaration is a String containing one or more unbound variable declarations separated with semicolons. It follows the syntax for local variables in the Java language.- Specified by:
declareVariables
in interfaceQuery
- Parameters:
variables
- the variables separated by semicolons.
-
setOrdering
public void setOrdering(String ordering)
Bind the ordering statements to the query instance. The ordering specification includes a list of expressions with the ascending/descending indicator.- Specified by:
setOrdering
in interfaceQuery
- Parameters:
ordering
- the ordering declarations separated by comma.
-
setResult
public void setResult(String result)
Set the result of the query.The query result is an optional keyword distinct followed by a Java expression, which tells what values are to be returned by the JDO query. If the result is not specified, then it defaults to "distinct this", which has the effect of returning the elements of the candidates that match the filter.
-
setIgnoreCache
public void setIgnoreCache(boolean ignoreCache)
Set the ignoreCache option. The ignoreCache option setting specifies whether the query should execute entirely in the back end, instead of in the cache.- Specified by:
setIgnoreCache
in interfaceQuery
- Parameters:
ignoreCache
- the setting of the ignoreCache option.
-
getIgnoreCache
public boolean getIgnoreCache()
Get the ignoreCache option setting.- Specified by:
getIgnoreCache
in interfaceQuery
- Returns:
- the ignoreCache option setting.
- See Also:
setIgnoreCache(boolean)
-
setPrefetchEnabled
public void setPrefetchEnabled(boolean prefetchEnabled)
Sets the prefetchEnabled option. The prefetchEnabled option specifies whether prefetch of relationship fields should be enabled for this query. The prefetch is enabled by default if such fields are part of DFG. A user needs to explicitely disable prefetch for any particular query if the related instances will not be used in this transaction.- Specified by:
setPrefetchEnabled
in interfaceQuery
- Parameters:
prefetchEnabled
- the setting of the prefetchEnabled option.
-
compile
public void compile()
Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.
-
execute
public Object execute()
Execute the query and return the filtered Collection.- Specified by:
execute
in interfaceQuery
- Returns:
- the filtered Collection.
- See Also:
(Object[] parameters)
-
execute
public Object execute(Object p1)
Execute the query and return the filtered Collection.- Specified by:
execute
in interfaceQuery
- Parameters:
p1
- the value of the first parameter declared.- Returns:
- the filtered Collection.
- See Also:
(Object[] parameters)
-
execute
public Object execute(Object p1, Object p2)
Execute the query and return the filtered Collection.- Specified by:
execute
in interfaceQuery
- Parameters:
p1
- the value of the first parameter declared.p2
- the value of the second parameter declared.- Returns:
- the filtered Collection.
- See Also:
(Object[] parameters)
-
execute
public Object execute(Object p1, Object p2, Object p3)
Execute the query and return the filtered Collection.- Specified by:
execute
in interfaceQuery
- Parameters:
p1
- the value of the first parameter declared.p2
- the value of the second parameter declared.p3
- the value of the third parameter declared.- Returns:
- the filtered Collection.
- See Also:
(Object[] parameters)
-
executeWithMap
public Object executeWithMap(Map parameters)
Execute the query and return the filtered Collection.- Specified by:
executeWithMap
in interfaceQuery
- Parameters:
parameters
- the Map containing all of the parameters.- Returns:
- the filtered Collection.
- See Also:
(Object[] parameters)
-
executeWithArray
public Object executeWithArray(Object[] parameters)
Execute the query and return the filtered Collection.The execution of the query obtains the values of the parameters and matches them against the declared parameters in order. The type of the declared parameters must match the type of the passed parameters, except that the passed parameters might need to be unwrapped to get their primitive values.
The filter, import, declared parameters, declared variables, and ordering statements are verified for consistency.
Each element in the candidate Collection is examined to see that it is assignment compatible to the Class of the query. It is then evaluated by the boolean expression of the filter. The element passes the filter if there exist unique values for all variables for which the filter expression evaluates to true.
- Specified by:
executeWithArray
in interfaceQuery
- Parameters:
parameters
- the Object array with all of the parameters.- Returns:
- the filtered Collection.
-
getPersistenceManager
public PersistenceManager getPersistenceManager()
Get the PersistenceManager associated with this Query.If this Query has no PersistenceManager return null.
- Specified by:
getPersistenceManager
in interfaceQuery
- Returns:
- the PersistenceManager associated with this Query.
-
clearPersistenceManager
public void clearPersistenceManager()
This method clears the PersistenceManager and the candidateCollection fields. Then this query instance cannot be executed anymore, but it might be used to create a new equivalent query instance by passing this query instance to PersistenceManager newQuery method taking a compiled query.This method effectively disconnects the PersistenceManager allowing it to be garbage collected.
-
-