|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The Query interface allows applications to obtain persistent instances
from the data store.
The PersistenceManager
is the factory for Query instances. There
may be many Query instances associated with a PersistenceManager. Multiple
queries might be executed simultaneously by different threads, but the
implementation might choose to execute them serially. In either case, the
implementation must be thread safe.
There are three required elements in a Query: the class of the results, the candidate collection of instances, and the filter.
There are optional elements: parameter declarations, variable declarations, import statements, and an ordering specification.
The query namespace is modeled after methods in Java:
There are two namespaces in queries. Type names have their own namespace that is separate from the namespace for fields, variables and parameters.
The method setClass introduces the name of the candidate class in the type namespace. The method declareImports introduces the names of the imported class or interface types in the type namespace. Imported type names must be unique. When used (e.g. in a parameter declaration, cast expression, etc.) a type name must be the name of the candidate class, the name of a class or interface imported by method declareImports, or denote a class or interface from the same package as the candidate class.
The method setClass introduces the names of the candidate class fields.
The method declareParameters introduces the names of the parameters. A name introduced by declareParameters hides the name of a candidate class field if equal. Parameter names must be unique.
The method declareVariables introduces the names of the variables. A name introduced by declareVariables hides the name of a candidate class field if equal. Variable names must be unique and must not conflict with parameter names.
A hidden field may be accessed using the 'this' qualifier: this.fieldName.
The Query interface provides methods which execute the query based on the parameters given. They return a Collection which the user can iterate to get results. For future extension, the signature of the execute methods specifies that they return an Object which must be cast to Collection by the user.
Any parameters passed to the execute methods are used only for this execution, and are not remembered for future execution.
Method Summary | |
void |
close(java.lang.Object queryResult)
Close a query result and release any resources associated with it. |
void |
closeAll()
Close all query results associated with this Query instance, and release all resources associated with them. |
void |
compile()
Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan. |
void |
declareImports(java.lang.String imports)
Set the import statements to be used to identify the fully qualified name of variables or parameters. |
void |
declareParameters(java.lang.String parameters)
Declare the list of parameters query execution. |
void |
declareVariables(java.lang.String variables)
Declare the unbound variables to be used in the query. |
java.lang.Object |
execute()
Execute the query and return the filtered Collection. |
java.lang.Object |
execute(java.lang.Object p1)
Execute the query and return the filtered Collection. |
java.lang.Object |
execute(java.lang.Object p1,
java.lang.Object p2)
Execute the query and return the filtered Collection. |
java.lang.Object |
execute(java.lang.Object p1,
java.lang.Object p2,
java.lang.Object p3)
Execute the query and return the filtered Collection. |
java.lang.Object |
executeWithArray(java.lang.Object[] parameters)
Execute the query and return the filtered Collection. |
java.lang.Object |
executeWithMap(java.util.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(java.util.Collection pcs)
Set the candidate Collection to query. |
void |
setCandidates(Extent pcs)
Set the candidate Extent to query. |
void |
setClass(java.lang.Class cls)
Set the class of the candidate instances of the query. |
void |
setFilter(java.lang.String filter)
Set the filter for the query. |
void |
setIgnoreCache(boolean ignoreCache)
Set the ignoreCache option. |
void |
setOrdering(java.lang.String ordering)
Set the ordering specification for the result Collection. |
Method Detail |
public void setClass(java.lang.Class cls)
The class specifies the class of the candidates of the query. Elements of the candidate collection that are of the specified class are filtered before being put into the result Collection.
cls
- the Class of the candidate instances.public void setCandidates(Extent pcs)
pcs
- the Candidate Extent.public void setCandidates(java.util.Collection pcs)
pcs
- the Candidate collection.public void setFilter(java.lang.String filter)
AThe filter specification is a String containing a boolean expression that is to be evaluated for each of the instances in the candidate collection. If the filter is not specified, then it defaults to "true", which has the effect of filtering the input Collection only for class type.
An element of the candidate collection is returned in the result if:
The user may denote uniqueness in the filter expression by explicitly declaring an expression (for example, e1 != e2).
Rules for constructing valid expressions follow the Java language, except for these differences:
Identifiers in the expression are considered to be in the name space of the specified class, with the addition of declared imports, parameters and variables. As in the Java language, this is a reserved word which means the element of the collection being evaluated.
Navigation through single-valued fields is specified by the Java language syntax of field_name.field_name....field_name.
A JDO implementation is allowed to reorder the filter expression for optimization purposes.
filter
- the query filter.public void declareImports(java.lang.String imports)
The String parameter to this method follows the syntax of the import statement of the Java language.
imports
- import statements separated by semicolons.public void declareParameters(java.lang.String parameters)
The String parameter to this method follows the syntax for formal parameters in the Java language.
parameters
- the list of parameters separated by commas.public void declareVariables(java.lang.String variables)
variables
- the variables separated by semicolons.public void setOrdering(java.lang.String ordering)
Each ordering declaration is the name of the field on which to order the results followed by one of the following words: "ascending" or "descending".
The field must be declared in the candidate class or must be a navigation expression starting with a field in the candidate class.
Valid field types are primitive types except boolean; wrapper types except Boolean; BigDecimal; BigInteger; String; and Date.
ordering
- the ordering specification.public void setIgnoreCache(boolean ignoreCache)
ignoreCache
- the setting of the ignoreCache option.public boolean getIgnoreCache()
setIgnoreCache(boolean)
public void compile()
public java.lang.Object execute()
executeWithArray(Object[] parameters)
public java.lang.Object execute(java.lang.Object p1)
p1
- the value of the first parameter declared.
executeWithArray(Object[] parameters)
public java.lang.Object execute(java.lang.Object p1, java.lang.Object p2)
p1
- the value of the first parameter declared.p2
- the value of the second parameter declared.
executeWithArray(Object[] parameters)
public java.lang.Object execute(java.lang.Object p1, java.lang.Object p2, java.lang.Object p3)
p1
- the value of the first parameter declared.p2
- the value of the second parameter declared.p3
- the value of the third parameter declared.
executeWithArray(Object[] parameters)
public java.lang.Object executeWithMap(java.util.Map parameters)
parameters
- the Map containing all of the parameters.
executeWithArray(Object[] parameters)
public java.lang.Object executeWithArray(java.lang.Object[] parameters)
The execution of the query obtains the values of the parameters and matches them against the declared parameters in order. The names of the declared parameters are ignored. 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.
parameters
- the Object array with all of the parameters.
public PersistenceManager getPersistenceManager()
If this Query was restored from a serialized form, it has no PersistenceManager, and this method returns null.
public void close(java.lang.Object queryResult)
queryResult
- the result of execute(...) on this Query instance.public void closeAll()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |