public class QueryImpl
extends java.lang.Object
implements javax.jdo.Query
Query
).Constructor and Description |
---|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm)
Create an empty query instance with no elements.
|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm,
java.lang.Class cls)
Create a new Query specifying the Class of the candidate instances.
|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm,
java.lang.Class cls,
java.util.Collection cln)
Create a query instance with the candidate class and
candidate collection specified.
|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm,
java.lang.Class cls,
java.util.Collection cln,
java.lang.String filter)
Create a new Query with the Class of the candidate instances,
candidate Collection, and filter.
|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm,
java.lang.Class cls,
java.lang.String filter)
Create a new Query with the Class of the candidate instances and Filter.
|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm,
javax.jdo.Extent cln)
Create a new Query with the candidate Extent; the class
is taken from the Extent.
|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm,
javax.jdo.Extent cln,
java.lang.String filter)
Create a new Query with the
candidate Extent and filter; the class
is taken from the Extent.
|
QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm,
java.lang.Object compiled)
Create a new Query using elements from another Query.
|
Modifier and Type | Method and Description |
---|---|
void |
addExtension(java.lang.String key,
java.lang.Object value)
Add a vendor-specific extension to this query.
|
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.
|
long |
deletePersistentAll()
Deletes all the instances of the candidate class that pass the
filter.
|
long |
deletePersistentAll(java.util.Map parameters)
Deletes all the instances of the candidate class that pass the
filter.
|
long |
deletePersistentAll(java.lang.Object[] parameters)
Deletes all the instances of the candidate class that pass the
filter.
|
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.
|
javax.jdo.FetchPlan |
getFetchPlan()
Returns the
FetchPlan used by this
Query . |
boolean |
getIgnoreCache()
Get the ignoreCache option setting.
|
javax.jdo.PersistenceManager |
getPersistenceManager()
Get the PersistenceManager associated with this Query.
|
boolean |
isUnmodifiable()
The unmodifiable flag, when set, disallows further
modification of the query, except for specifying the range,
result class, and ignoreCache option.
|
void |
setCandidates(java.util.Collection pcs)
Set the candidate Collection to query.
|
void |
setCandidates(javax.jdo.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 |
setExtensions(java.util.Map extensions)
Set multiple extensions, or use null to clear all extensions.
|
void |
setFilter(java.lang.String filter)
Set the filter for the query.
|
void |
setGrouping(java.lang.String group)
Set the grouping expressions, optionally including a "having"
clause.
|
void |
setIgnoreCache(boolean ignoreCache)
Set the ignoreCache option.
|
void |
setOrdering(java.lang.String ordering)
Set the ordering specification for the result Collection.
|
void |
setRange(long fromIncl,
long toExcl)
Set the range of results to return.
|
void |
setRange(java.lang.String fromInclToExcl)
Set the range of results to return.
|
void |
setResult(java.lang.String data)
Specifies what type of data this query should return.
|
void |
setResultClass(java.lang.Class cls)
Specify the type of object in which to return each element of
the result of invoking
execute() or one of its siblings. |
void |
setUnique(boolean unique)
Specify that only the first result of the query should be
returned, rather than a collection.
|
void |
setUnmodifiable()
The unmodifiable flag, when set, disallows further
modification of the query, except for specifying the range,
result class, and ignoreCache option.
|
public QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm)
public QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm, java.lang.Object compiled)
All of the settings of the other Query are copied to this Query, except for the candidate Collection or Extent.
compiled
- another Query from the same JDO implementationpublic QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm, java.lang.Class cls)
cls
- the Class of the candidate instancespublic QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm, javax.jdo.Extent cln)
cln
- the Extent of candidate instancespublic QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm, java.lang.Class cls, java.util.Collection cln)
cls
- the Class of the candidate instances.cln
- the Collection of candidate instances.public QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm, java.lang.Class cls, java.lang.String filter)
cls
- the Class of resultsfilter
- the filter for candidate instancespublic QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm, java.lang.Class cls, java.util.Collection cln, java.lang.String filter)
cls
- the Class of candidate instancescln
- the Collection of candidate instancesfilter
- the filter for candidate instancespublic QueryImpl(org.apache.jdo.pm.PersistenceManagerInternal pm, javax.jdo.Extent cln, java.lang.String filter)
cln
- the Extent of candidate instancesfilter
- the filter for candidate instancespublic 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.
setClass
in interface javax.jdo.Query
cls
- the Class of the candidate instances.public void setCandidates(javax.jdo.Extent pcs)
setCandidates
in interface javax.jdo.Query
pcs
- the Candidate Extent.public void setCandidates(java.util.Collection pcs)
setCandidates
in interface javax.jdo.Query
pcs
- the Candidate collection.public void setFilter(java.lang.String filter)
setFilter
in interface javax.jdo.Query
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.
declareImports
in interface javax.jdo.Query
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.
declareParameters
in interface javax.jdo.Query
parameters
- the list of parameters separated by commas.public void declareVariables(java.lang.String variables)
declareVariables
in interface javax.jdo.Query
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.
setOrdering
in interface javax.jdo.Query
ordering
- the ordering specification.public void setIgnoreCache(boolean ignoreCache)
setIgnoreCache
in interface javax.jdo.Query
ignoreCache
- the setting of the ignoreCache option.public boolean getIgnoreCache()
getIgnoreCache
in interface javax.jdo.Query
setIgnoreCache(boolean)
public void compile()
compile
in interface javax.jdo.Query
public java.lang.Object execute()
execute
in interface javax.jdo.Query
executeWithArray(Object[] parameters)
public java.lang.Object execute(java.lang.Object p1)
execute
in interface javax.jdo.Query
p1
- the value of the first parameter declared.executeWithArray(Object[] parameters)
public java.lang.Object execute(java.lang.Object p1, java.lang.Object p2)
execute
in interface javax.jdo.Query
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)
execute
in interface javax.jdo.Query
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)
executeWithMap
in interface javax.jdo.Query
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 consisten1cy.
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.
executeWithArray
in interface javax.jdo.Query
parameters
- the Object array with all of the parameters.public javax.jdo.PersistenceManager getPersistenceManager()
If this Query was restored from a serialized form, it has no PersistenceManager, and this method returns null.
getPersistenceManager
in interface javax.jdo.Query
public void close(java.lang.Object queryResult)
close
in interface javax.jdo.Query
queryResult
- the result of execute(...) on this Query instance.public void closeAll()
closeAll
in interface javax.jdo.Query
public void setGrouping(java.lang.String group)
setGrouping
in interface javax.jdo.Query
group
- a comma-delimited list of expressions, optionally
followed by the "having" keyword and a boolean expressionpublic void setUnique(boolean unique)
setUnique
in interface javax.jdo.Query
unique
- if true, only one element is returnedpublic void setResult(java.lang.String data)
null
, this query returns
instances of the query's candidate class. If set, this query
will return expressions, including field values (projections) and
aggregate function results.setResult
in interface javax.jdo.Query
data
- a comma-delimited list of expressions
(fields, functions on fields, or aggregate functions)
to return from this querypublic void setResultClass(java.lang.Class cls)
execute()
or one of its siblings.
If the result is not set or set to null, the result class defaults
to the candidate class of the query. If the result consists of one
expression, the result class defaults to the type of that expression.
If the result consists of more than one expression, the result class
defaults to Object[].
The result class may be specified to be one of the java.lang classes
Character, Boolean, Byte, Short, Integer, Long, Float, Double, String,
or Object[]; or one of the java.math classes BigInteger or BigDecimal;
or the java.util class Date; or one of the java.sql classes Date,
Time, or Timestamp; or a user-defined class.
If there are multiple result expressions, the result class must be able to hold all elements of the result specification or a JDOUserException is thrown.
If there is only one result expression, the result class must be assignable from the type of the result expression or must be able to hold all elements of the result specification. A single value must be able to be coerced into the specified result class (treating wrapper classes as equivalent to their unwrapped primitive types) or by matching. If the result class does not satisfy these conditions, a JDOUserException is thrown.
A constructor of a result class specified in the setResult method will be used if the results specification matches the parameters of the constructor by position and type. If more than one constructor satisfies the requirements, the JDO implementation chooses one of them. If no constructor satisfies the results requirements, or if the result class is specified via the setResultClass method, the following requirements apply:
set
or put
methods or fields.
set
or if neither of the above applies,a public method must be found
with the signature void put(Object, Object)
.
During processing of the results,
the first argument is the name of the result expression and
the second argument is the value from the query result.
set
setResultClass
in interface javax.jdo.Query
cls
- the result classpublic void setRange(long fromIncl, long toExcl)
setRange
in interface javax.jdo.Query
fromIncl
- 0-based inclusive start indextoExcl
- 0-based exclusive end index, or
Long.MAX_VALUE
for no limit.public void setRange(java.lang.String fromInclToExcl)
setRange("50, 70");
or
setRange(":from, :to");
or
setRange("50, :to");
.
The execution of the query is
modified to return only a subset of results. If the filter would
normally return 100 instances, and fromIncl is set to 50, and
toExcl is set to 70, then the first 50 results that would have
been returned are skipped, the next 20 results are returned and the
remaining 30 results are ignored. An implementation should execute
the query such that the range algorithm is done at the data store.setRange
in interface javax.jdo.Query
fromInclToExcl
- comma-separated fromIncl and toExcl valuessetRange(long, long)
public void addExtension(java.lang.String key, java.lang.Object value)
addExtension
in interface javax.jdo.Query
key
- the key of the extensionvalue
- the value of the extensionpublic void setExtensions(java.util.Map extensions)
setExtensions
in interface javax.jdo.Query
extensions
- the map of extensionsaddExtension(java.lang.String, java.lang.Object)
public javax.jdo.FetchPlan getFetchPlan()
FetchPlan
used by this
Query
. Modifications of the returned fetch plan will not
cause this query's owning PersistenceManager
's
FetchPlan
to be modified.getFetchPlan
in interface javax.jdo.Query
public long deletePersistentAll(java.lang.Object[] parameters)
deletePersistentAll
in interface javax.jdo.Query
parameters
- for the querydeletePersistentAll()
public long deletePersistentAll(java.util.Map parameters)
deletePersistentAll
in interface javax.jdo.Query
parameters
- for the querydeletePersistentAll()
public long deletePersistentAll()
Dirty instances of affected classes in the cache are first
flushed to the datastore. Instances in the cache or brought into
the cache as a result of executing one of the
deletePersistentAll
methods undergo life cycle changes as if deletePersistent
were called on them.
Specifically, if the class of deleted instances implements the delete callback interface, the corresponding callback methods are called on the deleted instances. Similarly, if there are lifecycle listeners registered for delete events on affected classes, the listener is called for each appropriate deleted instance.
Before returning control to the application, instances of affected classes in the cache are refreshed to reflect whether they were deleted from the datastore.
deletePersistentAll
in interface javax.jdo.Query
public void setUnmodifiable()
setUnmodifiable
in interface javax.jdo.Query
public boolean isUnmodifiable()
isUnmodifiable
in interface javax.jdo.Query
Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.