Sunteți pe pagina 1din 2

javax.jdo.

Query - JDO interface


javax.jdo
Interface Query
Superinterfaces:
Serializable
The Query interface allows applications to obtain persistent instances, values, and
aggregate data 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, ordering and grouping specifications, result and result class, the
range of results, and flags indicating whether the query result is unique and
whether the query can be modified.

The query namespace is modeled after methods in Java:

setClass corresponds to the class definition


declareParameters corresponds to formal parameters of a method
declareVariables corresponds to local variables of a method
setFilter and setOrdering correspond to the method body
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 of the
same name. 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.

The result of the query by default is a list of result class instances, but might
be specified via setResult. The class of the result by default is the candidate
class, but might be specified via setResultClass.

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 single instance or a List of result class instances
which the user can iterate to get results. The signature of the execute methods
specifies that they return an Object which must be cast to the appropriate result
by the user.

Any parameters passed to the execute methods are used only for this execution, and
are not remembered for future execution.

S-ar putea să vă placă și