org.datanucleus.jdo
Class JDOQuery

java.lang.Object
  extended by org.datanucleus.jdo.JDOQuery
All Implemented Interfaces:
java.io.Serializable, javax.jdo.Query

public class JDOQuery
extends java.lang.Object
implements javax.jdo.Query

Wrapper for JDO Query class. Stores the PM the query is executed against, the internal query, and the query language. The language is stored since it is referenced by the JDO API and so we don't have to embody knowledge of which internal query type is for which language (could be moved to the internal query).

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface javax.jdo.Query
JDOQL, SQL
 
Constructor Summary
JDOQuery(javax.jdo.PersistenceManager pm, Query query, java.lang.String language)
          Constructor for a query used by JDO.
 
Method Summary
 void addExtension(java.lang.String key, java.lang.Object value)
          Method to add an extension to the query.
 void addSubquery(javax.jdo.Query sub, java.lang.String variableDecl, java.lang.String candidateExpr)
          Add a subquery to this query.
 void addSubquery(javax.jdo.Query sub, java.lang.String variableDecl, java.lang.String candidateExpr, java.util.Map parameters)
          Add a subquery to this query.
 void addSubquery(javax.jdo.Query sub, java.lang.String variableDecl, java.lang.String candidateExpr, java.lang.String... parameters)
          Add a subquery to this query.
 void addSubquery(javax.jdo.Query sub, java.lang.String variableDecl, java.lang.String candidateExpr, java.lang.String parameter)
          Add a subquery to this query.
 void cancel(java.lang.Thread thr)
          Method to cancel the executing query for the supplied thread.
 void cancelAll()
          Method to cancel any executing queries.
 void close(java.lang.Object queryResult)
          Close the query result.
 void closeAll()
          Close all query results for this query.
 void compile()
          Compile the query.
 void declareImports(java.lang.String imports)
          Declare any imports for the query.
 void declareParameters(java.lang.String parameters)
          Declare any parameters for the query.
 void declareVariables(java.lang.String variables)
          Declare any variables for the query.
 long deletePersistentAll()
          Execute the query deleting all instances found.
 long deletePersistentAll(java.util.Map parameters)
          Execute the query deleting all instances found.
 long deletePersistentAll(java.lang.Object... parameters)
          Execute the query deleting all instances found.
 java.lang.Object execute()
          Execute the query.
 java.lang.Object execute(java.lang.Object p1)
          Execute the query.
 java.lang.Object execute(java.lang.Object p1, java.lang.Object p2)
          Execute the query.
 java.lang.Object execute(java.lang.Object p1, java.lang.Object p2, java.lang.Object p3)
          Execute the query.
 java.lang.Object executeWithArray(java.lang.Object... parameterValues)
          Execute the query.
 java.lang.Object executeWithMap(java.util.Map parameters)
          Execute the query.
 java.lang.Integer getDatastoreReadTimeoutMillis()
          Accessor for the datastore read timeout.
 java.lang.Integer getDatastoreWriteTimeoutMillis()
          Accessor for the datastore write timeout.
 javax.jdo.FetchPlan getFetchPlan()
          Accessor for the fetch plan to use.
 boolean getIgnoreCache()
          Accessor for the ignore cache setting
 Query getInternalQuery()
          Accessor for the internal query.
 java.lang.String getLanguage()
          Accessor for the query language.
 javax.jdo.PersistenceManager getPersistenceManager()
          Accessor for the PersistenceManager.
 java.lang.Boolean getSerializeRead()
          Accessor for whether to serialise any read objects in this query.
 boolean isUnmodifiable()
          Accessor for whether the query is modifiable.
 void setCandidates(java.util.Collection pcs)
          Set the candidates for the query.
 void setCandidates(javax.jdo.Extent extent)
          Set the candidates for the query.
 void setClass(java.lang.Class candidateClass)
          Set the candidate class for the query.
 void setDatastoreReadTimeoutMillis(java.lang.Integer timeout)
          Set the datastore read timeout.
 void setDatastoreWriteTimeoutMillis(java.lang.Integer timeout)
          Set the datastore write timeout.
 void setExtensions(java.util.Map extensions)
          Set the extensions for the query.
 void setFilter(java.lang.String filter)
          Set the filter for the query.
 void setGrouping(java.lang.String grouping)
          Set the grouping for the query.
 void setIgnoreCache(boolean ignoreCache)
          Set the ignore cache setting for the query.
 void setOrdering(java.lang.String ordering)
          Set the ordering for the query.
 void setRange(long fromIncl, long toExcl)
          Set the range for the query.
 void setRange(java.lang.String range)
          Set the range for the query.
 void setResult(java.lang.String result)
          Set the result for the query.
 void setResultClass(java.lang.Class result_cls)
          Set the result class for the query.
 void setSerializeRead(java.lang.Boolean serialize)
          Mutator for whether to serialise any read objects.
 void setUnique(boolean unique)
          Set whether to expect a unique result.
 void setUnmodifiable()
          Set the query to be unmodifiable.
 java.lang.String toString()
          Convenience method to return the query in string form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JDOQuery

public JDOQuery(javax.jdo.PersistenceManager pm,
                Query query,
                java.lang.String language)
Constructor for a query used by JDO.

Parameters:
pm - PersistenceManager
query - Underlying query
language - Query language
Method Detail

close

public void close(java.lang.Object queryResult)
Close the query result.

Specified by:
close in interface javax.jdo.Query
Parameters:
queryResult - Query result

closeAll

public void closeAll()
Close all query results for this query.

Specified by:
closeAll in interface javax.jdo.Query

compile

public void compile()
Compile the query.

Specified by:
compile in interface javax.jdo.Query

declareImports

public void declareImports(java.lang.String imports)
Declare any imports for the query.

Specified by:
declareImports in interface javax.jdo.Query
Parameters:
imports - The imports

declareParameters

public void declareParameters(java.lang.String parameters)
Declare any parameters for the query.

Specified by:
declareParameters in interface javax.jdo.Query
Parameters:
parameters - The parameters

declareVariables

public void declareVariables(java.lang.String variables)
Declare any variables for the query.

Specified by:
declareVariables in interface javax.jdo.Query
Parameters:
variables - The variables

deletePersistentAll

public long deletePersistentAll()
Execute the query deleting all instances found.

Specified by:
deletePersistentAll in interface javax.jdo.Query
Returns:
Number of deleted instances

deletePersistentAll

public long deletePersistentAll(java.lang.Object... parameters)
Execute the query deleting all instances found.

Specified by:
deletePersistentAll in interface javax.jdo.Query
Parameters:
parameters - Parameters to use when executing
Returns:
Number of deleted instances

deletePersistentAll

public long deletePersistentAll(java.util.Map parameters)
Execute the query deleting all instances found.

Specified by:
deletePersistentAll in interface javax.jdo.Query
Parameters:
parameters - Parameters to use when executing
Returns:
Number of deleted instances

execute

public java.lang.Object execute()
Execute the query.

Specified by:
execute in interface javax.jdo.Query
Returns:
The results

execute

public java.lang.Object execute(java.lang.Object p1)
Execute the query.

Specified by:
execute in interface javax.jdo.Query
Parameters:
p1 - First param value
Returns:
The results

execute

public java.lang.Object execute(java.lang.Object p1,
                                java.lang.Object p2)
Execute the query.

Specified by:
execute in interface javax.jdo.Query
Parameters:
p1 - First param value
p2 - Second param value
Returns:
The results

execute

public java.lang.Object execute(java.lang.Object p1,
                                java.lang.Object p2,
                                java.lang.Object p3)
Execute the query.

Specified by:
execute in interface javax.jdo.Query
Parameters:
p1 - First param value
p2 - Second param value
p3 - Third param value
Returns:
The results

executeWithArray

public java.lang.Object executeWithArray(java.lang.Object... parameterValues)
Execute the query.

Specified by:
executeWithArray in interface javax.jdo.Query
Parameters:
parameterValues - Param values
Returns:
The results

executeWithMap

public java.lang.Object executeWithMap(java.util.Map parameters)
Execute the query.

Specified by:
executeWithMap in interface javax.jdo.Query
Parameters:
parameters - Param values
Returns:
The results

cancelAll

public void cancelAll()
Method to cancel any executing queries.

Specified by:
cancelAll in interface javax.jdo.Query
Throws:
javax.jdo.JDOUnsupportedOptionException - if the datastore doesn't support cancellation of queries

cancel

public void cancel(java.lang.Thread thr)
Method to cancel the executing query for the supplied thread.

Specified by:
cancel in interface javax.jdo.Query
Throws:
javax.jdo.JDOUnsupportedOptionException - if the datastore doesn't support cancellation of queries

setCandidates

public void setCandidates(javax.jdo.Extent extent)
Set the candidates for the query.

Specified by:
setCandidates in interface javax.jdo.Query
Parameters:
extent - Extent defining the candidates

setCandidates

public void setCandidates(java.util.Collection pcs)
Set the candidates for the query.

Specified by:
setCandidates in interface javax.jdo.Query
Parameters:
pcs - PC candidates

setClass

public void setClass(java.lang.Class candidateClass)
Set the candidate class for the query.

Specified by:
setClass in interface javax.jdo.Query
Parameters:
candidateClass - Candidate class

addExtension

public void addExtension(java.lang.String key,
                         java.lang.Object value)
Method to add an extension to the query.

Specified by:
addExtension in interface javax.jdo.Query
Parameters:
key - Key for the extension
value - Value for the extension

setExtensions

public void setExtensions(java.util.Map extensions)
Set the extensions for the query.

Specified by:
setExtensions in interface javax.jdo.Query
Parameters:
extensions - The extensions

getFetchPlan

public javax.jdo.FetchPlan getFetchPlan()
Accessor for the fetch plan to use.

Specified by:
getFetchPlan in interface javax.jdo.Query
Returns:
The fetch plan

setFilter

public void setFilter(java.lang.String filter)
Set the filter for the query.

Specified by:
setFilter in interface javax.jdo.Query
Parameters:
filter - The query filter

setGrouping

public void setGrouping(java.lang.String grouping)
Set the grouping for the query.

Specified by:
setGrouping in interface javax.jdo.Query
Parameters:
grouping - The grouping

getIgnoreCache

public boolean getIgnoreCache()
Accessor for the ignore cache setting

Specified by:
getIgnoreCache in interface javax.jdo.Query
Returns:
Ignore cache

setIgnoreCache

public void setIgnoreCache(boolean ignoreCache)
Set the ignore cache setting for the query.

Specified by:
setIgnoreCache in interface javax.jdo.Query
Parameters:
ignoreCache - The ignore cache setting

setOrdering

public void setOrdering(java.lang.String ordering)
Set the ordering for the query.

Specified by:
setOrdering in interface javax.jdo.Query
Parameters:
ordering - The ordering

getPersistenceManager

public javax.jdo.PersistenceManager getPersistenceManager()
Accessor for the PersistenceManager.

Specified by:
getPersistenceManager in interface javax.jdo.Query
Returns:
PM

setRange

public void setRange(java.lang.String range)
Set the range for the query.

Specified by:
setRange in interface javax.jdo.Query
Parameters:
range - The range specification

setRange

public void setRange(long fromIncl,
                     long toExcl)
Set the range for the query.

Specified by:
setRange in interface javax.jdo.Query
Parameters:
fromIncl - From range inclusive
toExcl - To range exclusive

setResult

public void setResult(java.lang.String result)
Set the result for the query.

Specified by:
setResult in interface javax.jdo.Query
Parameters:
result - Result clause

setResultClass

public void setResultClass(java.lang.Class result_cls)
Set the result class for the query.

Specified by:
setResultClass in interface javax.jdo.Query
Parameters:
result_cls - Result class

setDatastoreReadTimeoutMillis

public void setDatastoreReadTimeoutMillis(java.lang.Integer timeout)
Set the datastore read timeout.

Specified by:
setDatastoreReadTimeoutMillis in interface javax.jdo.Query
Parameters:
timeout - Timeout interval (millisecs)

getDatastoreReadTimeoutMillis

public java.lang.Integer getDatastoreReadTimeoutMillis()
Accessor for the datastore read timeout.

Specified by:
getDatastoreReadTimeoutMillis in interface javax.jdo.Query
Returns:
Timeout (if defined)

setDatastoreWriteTimeoutMillis

public void setDatastoreWriteTimeoutMillis(java.lang.Integer timeout)
Set the datastore write timeout.

Specified by:
setDatastoreWriteTimeoutMillis in interface javax.jdo.Query
Parameters:
timeout - Timeout interval (millisecs)

getDatastoreWriteTimeoutMillis

public java.lang.Integer getDatastoreWriteTimeoutMillis()
Accessor for the datastore write timeout.

Specified by:
getDatastoreWriteTimeoutMillis in interface javax.jdo.Query
Returns:
Timeout (if defined)

setUnique

public void setUnique(boolean unique)
Set whether to expect a unique result.

Specified by:
setUnique in interface javax.jdo.Query
Parameters:
unique - Whether results are unique

isUnmodifiable

public boolean isUnmodifiable()
Accessor for whether the query is modifiable.

Specified by:
isUnmodifiable in interface javax.jdo.Query
Returns:
Whether it is modifiable

setUnmodifiable

public void setUnmodifiable()
Set the query to be unmodifiable.

Specified by:
setUnmodifiable in interface javax.jdo.Query

addSubquery

public void addSubquery(javax.jdo.Query sub,
                        java.lang.String variableDecl,
                        java.lang.String candidateExpr)
Add a subquery to this query.

Specified by:
addSubquery in interface javax.jdo.Query
Parameters:
sub - the subquery to add to this Query
variableDecl - the name of the variable in the outer query to bind the results of the subquery
candidateExpr - the candidate collection of the subquery as an expression using terms of the outer query

addSubquery

public void addSubquery(javax.jdo.Query sub,
                        java.lang.String variableDecl,
                        java.lang.String candidateExpr,
                        java.lang.String parameter)
Add a subquery to this query. The String version of the method binds the named expression to the parameter implictly or explicitly declared in the subquery.

Specified by:
addSubquery in interface javax.jdo.Query
Parameters:
sub - the subquery to add to this Query
variableDecl - the name of the variable to be used in this Query
candidateExpr - the candidate collection to apply to the subquery
parameter - the expression from the outer query to bind the parameter in the subquery

addSubquery

public void addSubquery(javax.jdo.Query sub,
                        java.lang.String variableDecl,
                        java.lang.String candidateExpr,
                        java.lang.String... parameters)
Add a subquery to this query. The String version of the method binds the named expression to the parameter implictly or explicitly declared in the subquery.

Specified by:
addSubquery in interface javax.jdo.Query
Parameters:
sub - the subquery to add to this Query
variableDecl - the name of the variable to be used in this Query
candidateExpr - the candidate collection to apply to the subquery
parameters - the expressions from the outer query to bind the parameter in the subquery

addSubquery

public void addSubquery(javax.jdo.Query sub,
                        java.lang.String variableDecl,
                        java.lang.String candidateExpr,
                        java.util.Map parameters)
Add a subquery to this query. The String version of the method binds the named expression to the parameter implictly or explicitly declared in the subquery.

Specified by:
addSubquery in interface javax.jdo.Query
Parameters:
sub - the subquery to add to this Query
variableDecl - the name of the variable to be used in this Query
candidateExpr - the candidate collection to apply to the subquery
parameters - the expressions from the outer query to bind the parameter in the subquery

getSerializeRead

public java.lang.Boolean getSerializeRead()
Accessor for whether to serialise any read objects in this query.

Specified by:
getSerializeRead in interface javax.jdo.Query
Returns:
The setting for whether to serialise any read objects

setSerializeRead

public void setSerializeRead(java.lang.Boolean serialize)
Mutator for whether to serialise any read objects.

Specified by:
setSerializeRead in interface javax.jdo.Query
Parameters:
serialize - Whether to serialise any read objects in this query.

getInternalQuery

public Query getInternalQuery()
Accessor for the internal query.

Returns:
Internal query

getLanguage

public java.lang.String getLanguage()
Accessor for the query language.

Returns:
Query language

toString

public java.lang.String toString()
Convenience method to return the query in string form.

Overrides:
toString in class java.lang.Object
Returns:
Stringifier method


Copyright © 2011. All Rights Reserved.