Package org.datanucleus.api.jdo
Class JDOQuery<T>
java.lang.Object
org.datanucleus.api.jdo.JDOQuery<T>
- Type Parameters:
T
- Candidate class for this query
- All Implemented Interfaces:
Serializable
,AutoCloseable
,javax.jdo.Query<T>
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
(package private) JDOFetchPlan
JDO Fetch Plan.static final String
static final String
(package private) String
Query language.(package private) Map
Map of parameters keyed by their name.(package private) Object[]
Positional parameter values.(package private) javax.jdo.PersistenceManager
PersistenceManager for the query.static final String
(package private) org.datanucleus.store.query.Query
<T> Underlying query that will be executed.private static final long
static final String
Fields inherited from interface javax.jdo.Query
JDOQL, SQL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExtension
(String key, Object value) Method to add an extension to the query.void
addSubquery
(javax.jdo.Query sub, String variableDecl, String candidateExpr) Add a subquery to this query.void
addSubquery
(javax.jdo.Query sub, String variableDecl, String candidateExpr, String parameter) Add a subquery to this query.void
addSubquery
(javax.jdo.Query sub, String variableDecl, String candidateExpr, String... parameters) Add a subquery to this query.void
addSubquery
(javax.jdo.Query sub, String variableDecl, String candidateExpr, Map parameters) Add a subquery to this query.protected void
Method to assert if this Query is open.void
Method to cancel the executing query for the supplied thread.void
Method to cancel any executing queries.void
close()
void
Close the query result.void
closeAll()
Close all query results for this query.void
compile()
Compile the query.javax.jdo.Query
<T> datastoreReadTimeoutMillis
(Integer interval) javax.jdo.Query
<T> datastoreWriteTimeoutMillis
(Integer interval) void
declareImports
(String imports) Declare any imports for the query.void
declareParameters
(String parameters) Declare any parameters for the query.void
declareVariables
(String variables) Declare any variables for the query.long
Execute the query deleting all instances found.long
deletePersistentAll
(Object... parameters) Execute the query deleting all instances found.long
deletePersistentAll
(Map parameters) Execute the query deleting all instances found.protected long
execute()
Execute the query.Execute the query.Execute the query.Execute the query.protected Object
<R> List
<R> executeResultList
(Class<R> resultCls) <R> R
executeResultUnique
(Class<R> resultCls) executeWithArray
(Object... parameterValues) Execute the query.executeWithMap
(Map parameters) Execute the query.javax.jdo.Query
<T> javax.jdo.Query
<T> extensions
(Map values) javax.jdo.Query
<T> Accessor for the datastore read timeout.Accessor for the datastore write timeout.javax.jdo.FetchPlan
Accessor for the fetch plan to use.boolean
Accessor for the ignore cache settingorg.datanucleus.store.query.Query
<T> Accessor for the internal query.Accessor for the query language.Accessor for the native query invoked by this query (if known at this time and supported by the store plugin).javax.jdo.PersistenceManager
Accessor for the PersistenceManager.Accessor for whether to serialise any read objects in this query.javax.jdo.Query
<T> javax.jdo.Query
<T> ignoreCache
(boolean flag) javax.jdo.Query
<T> boolean
isClosed()
Accessor for whether this Query is closed.boolean
Accessor for whether the query is modifiable.javax.jdo.Query
<T> javax.jdo.Query
<T> parameters
(String parameters) javax.jdo.Query
<T> range
(long fromIncl, long toExcl) javax.jdo.Query
<T> javax.jdo.Query
<T> javax.jdo.Query
<T> saveAsNamedQuery
(String name) Save this query as a named query with the specified name.javax.jdo.Query
<T> serializeRead
(Boolean serialize) void
setCandidates
(Collection<T> pcs) Set the candidates for the query.void
setCandidates
(javax.jdo.Extent<T> extent) Set the candidates for the query.void
Set the candidate class for the query.void
setDatastoreReadTimeoutMillis
(Integer timeout) Set the datastore read timeout.void
setDatastoreWriteTimeoutMillis
(Integer timeout) Set the datastore write timeout.void
setExtensions
(Map extensions) Set the extensions for the query.void
Set the filter for the query.void
setGrouping
(String grouping) Set the grouping for the query.void
setIgnoreCache
(boolean ignoreCache) Set the ignore cache setting for the query.javax.jdo.Query
<T> setNamedParameters
(Map<String, ?> paramMap) void
setOrdering
(String ordering) Set the ordering for the query.javax.jdo.Query
<T> setParameters
(Object... paramValues) void
setRange
(long fromIncl, long toExcl) Set the range for the query.void
Set the range for the query.void
Set the result for the query.void
setResultClass
(Class result_cls) Set the result class for the query.void
setSerializeRead
(Boolean serialize) Mutator for whether to serialise any read objects.void
setUnique
(boolean unique) Set whether to expect a unique result.void
Set the query to be unmodifiable.javax.jdo.Query
<T> javax.jdo.Query
<T> javax.jdo.Query
<T> javax.jdo.Query
<T> toString()
Convenience method to return the query in string form.javax.jdo.Query
<T> javax.jdo.Query
<T>
-
Field Details
-
PROPERTY_CLOSEABLE_QUERY
- See Also:
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
JDOQL_QUERY_LANGUAGE
- See Also:
-
JPQL_QUERY_LANGUAGE
- See Also:
-
SQL_QUERY_LANGUAGE
- See Also:
-
pm
transient javax.jdo.PersistenceManager pmPersistenceManager for the query. -
query
org.datanucleus.store.query.Query<T> queryUnderlying query that will be executed. -
closed
private boolean closed -
language
String languageQuery language. -
fetchPlan
JDOFetchPlan fetchPlanJDO Fetch Plan. -
parameterValueByName
Map parameterValueByNameMap of parameters keyed by their name. -
parameterValues
Object[] parameterValuesPositional parameter values.
-
-
Constructor Details
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacejavax.jdo.Query<T>
-
isClosed
public boolean isClosed()Accessor for whether this Query is closed.- Returns:
- Whether this Query is closed.
-
close
Close the query result.- Specified by:
close
in interfacejavax.jdo.Query<T>
- Parameters:
queryResult
- Query result
-
closeAll
public void closeAll()Close all query results for this query.- Specified by:
closeAll
in interfacejavax.jdo.Query<T>
-
compile
public void compile()Compile the query.- Specified by:
compile
in interfacejavax.jdo.Query<T>
-
declareImports
Declare any imports for the query.- Specified by:
declareImports
in interfacejavax.jdo.Query<T>
- Parameters:
imports
- The imports
-
declareParameters
Declare any parameters for the query.- Specified by:
declareParameters
in interfacejavax.jdo.Query<T>
- Parameters:
parameters
- The parameters
-
declareVariables
Declare any variables for the query.- Specified by:
declareVariables
in interfacejavax.jdo.Query<T>
- Parameters:
variables
- The variables
-
imports
- Specified by:
imports
in interfacejavax.jdo.Query<T>
-
parameters
- Specified by:
parameters
in interfacejavax.jdo.Query<T>
-
variables
- Specified by:
variables
in interfacejavax.jdo.Query<T>
-
setParameters
- Specified by:
setParameters
in interfacejavax.jdo.Query<T>
-
setNamedParameters
- Specified by:
setNamedParameters
in interfacejavax.jdo.Query<T>
-
execute
Execute the query.- Specified by:
execute
in interfacejavax.jdo.Query<T>
- Returns:
- The results
-
execute
Execute the query.- Specified by:
execute
in interfacejavax.jdo.Query<T>
- Parameters:
p1
- First param value- Returns:
- The results
-
execute
Execute the query.- Specified by:
execute
in interfacejavax.jdo.Query<T>
- Parameters:
p1
- First param valuep2
- Second param value- Returns:
- The results
-
execute
Execute the query.- Specified by:
execute
in interfacejavax.jdo.Query<T>
- Parameters:
p1
- First param valuep2
- Second param valuep3
- Third param value- Returns:
- The results
-
executeWithArray
Execute the query.- Specified by:
executeWithArray
in interfacejavax.jdo.Query<T>
- Parameters:
parameterValues
- Param values- Returns:
- The results
-
executeWithMap
Execute the query.- Specified by:
executeWithMap
in interfacejavax.jdo.Query<T>
- Parameters:
parameters
- Param values- Returns:
- The results
-
executeList
- Specified by:
executeList
in interfacejavax.jdo.Query<T>
-
executeUnique
- Specified by:
executeUnique
in interfacejavax.jdo.Query<T>
-
executeResultList
- Specified by:
executeResultList
in interfacejavax.jdo.Query<T>
-
executeResultUnique
- Specified by:
executeResultUnique
in interfacejavax.jdo.Query<T>
-
executeResultList
- Specified by:
executeResultList
in interfacejavax.jdo.Query<T>
-
executeResultUnique
- Specified by:
executeResultUnique
in interfacejavax.jdo.Query<T>
-
executeInternal
-
deletePersistentAll
public long deletePersistentAll()Execute the query deleting all instances found.- Specified by:
deletePersistentAll
in interfacejavax.jdo.Query<T>
- Returns:
- Number of deleted instances
-
deletePersistentAll
Execute the query deleting all instances found.- Specified by:
deletePersistentAll
in interfacejavax.jdo.Query<T>
- Parameters:
parameters
- Parameters to use when executing- Returns:
- Number of deleted instances
-
deletePersistentAll
Execute the query deleting all instances found.- Specified by:
deletePersistentAll
in interfacejavax.jdo.Query<T>
- Parameters:
parameters
- Parameters to use when executing- Returns:
- Number of deleted instances
-
deletePersistentInternal
protected long deletePersistentInternal() -
cancelAll
public void cancelAll()Method to cancel any executing queries.- Specified by:
cancelAll
in interfacejavax.jdo.Query<T>
- Throws:
javax.jdo.JDOUnsupportedOptionException
- if the datastore doesn't support cancellation of queries
-
cancel
Method to cancel the executing query for the supplied thread.- Specified by:
cancel
in interfacejavax.jdo.Query<T>
- Throws:
javax.jdo.JDOUnsupportedOptionException
- if the datastore doesn't support cancellation of queries
-
setCandidates
Set the candidates for the query.- Specified by:
setCandidates
in interfacejavax.jdo.Query<T>
- Parameters:
extent
- Extent defining the candidates
-
setCandidates
Set the candidates for the query.- Specified by:
setCandidates
in interfacejavax.jdo.Query<T>
- Parameters:
pcs
- PC candidates
-
setClass
Set the candidate class for the query.- Specified by:
setClass
in interfacejavax.jdo.Query<T>
- Parameters:
candidateClass
- Candidate class
-
addExtension
Method to add an extension to the query.- Specified by:
addExtension
in interfacejavax.jdo.Query<T>
- Parameters:
key
- Key for the extensionvalue
- Value for the extension
-
setExtensions
Set the extensions for the query.- Specified by:
setExtensions
in interfacejavax.jdo.Query<T>
- Parameters:
extensions
- The extensions
-
extension
- Specified by:
extension
in interfacejavax.jdo.Query<T>
-
extensions
- Specified by:
extensions
in interfacejavax.jdo.Query<T>
-
getFetchPlan
public javax.jdo.FetchPlan getFetchPlan()Accessor for the fetch plan to use.- Specified by:
getFetchPlan
in interfacejavax.jdo.Query<T>
- Returns:
- The fetch plan
-
filter
- Specified by:
filter
in interfacejavax.jdo.Query<T>
-
setFilter
Set the filter for the query.- Specified by:
setFilter
in interfacejavax.jdo.Query<T>
- Parameters:
filter
- The query filter
-
groupBy
- Specified by:
groupBy
in interfacejavax.jdo.Query<T>
-
setGrouping
Set the grouping for the query.- Specified by:
setGrouping
in interfacejavax.jdo.Query<T>
- Parameters:
grouping
- The grouping
-
getIgnoreCache
public boolean getIgnoreCache()Accessor for the ignore cache setting- Specified by:
getIgnoreCache
in interfacejavax.jdo.Query<T>
- Returns:
- Ignore cache
-
setIgnoreCache
public void setIgnoreCache(boolean ignoreCache) Set the ignore cache setting for the query.- Specified by:
setIgnoreCache
in interfacejavax.jdo.Query<T>
- Parameters:
ignoreCache
- The ignore cache setting
-
ignoreCache
- Specified by:
ignoreCache
in interfacejavax.jdo.Query<T>
-
orderBy
- Specified by:
orderBy
in interfacejavax.jdo.Query<T>
-
setOrdering
Set the ordering for the query.- Specified by:
setOrdering
in interfacejavax.jdo.Query<T>
- Parameters:
ordering
- The ordering
-
getPersistenceManager
public javax.jdo.PersistenceManager getPersistenceManager()Accessor for the PersistenceManager.- Specified by:
getPersistenceManager
in interfacejavax.jdo.Query<T>
- Returns:
- PM
-
range
- Specified by:
range
in interfacejavax.jdo.Query<T>
-
range
- Specified by:
range
in interfacejavax.jdo.Query<T>
-
setRange
Set the range for the query.- Specified by:
setRange
in interfacejavax.jdo.Query<T>
- Parameters:
range
- The range specification
-
setRange
public void setRange(long fromIncl, long toExcl) Set the range for the query.- Specified by:
setRange
in interfacejavax.jdo.Query<T>
- Parameters:
fromIncl
- From range inclusivetoExcl
- To range exclusive
-
result
- Specified by:
result
in interfacejavax.jdo.Query<T>
-
setResult
Set the result for the query.- Specified by:
setResult
in interfacejavax.jdo.Query<T>
- Parameters:
result
- Result clause
-
setResultClass
Set the result class for the query.- Specified by:
setResultClass
in interfacejavax.jdo.Query<T>
- Parameters:
result_cls
- Result class
-
setDatastoreReadTimeoutMillis
Set the datastore read timeout.- Specified by:
setDatastoreReadTimeoutMillis
in interfacejavax.jdo.Query<T>
- Parameters:
timeout
- Timeout interval (millisecs)
-
getDatastoreReadTimeoutMillis
Accessor for the datastore read timeout.- Specified by:
getDatastoreReadTimeoutMillis
in interfacejavax.jdo.Query<T>
- Returns:
- Timeout (if defined)
-
setDatastoreWriteTimeoutMillis
Set the datastore write timeout.- Specified by:
setDatastoreWriteTimeoutMillis
in interfacejavax.jdo.Query<T>
- Parameters:
timeout
- Timeout interval (millisecs)
-
getDatastoreWriteTimeoutMillis
Accessor for the datastore write timeout.- Specified by:
getDatastoreWriteTimeoutMillis
in interfacejavax.jdo.Query<T>
- Returns:
- Timeout (if defined)
-
datastoreReadTimeoutMillis
- Specified by:
datastoreReadTimeoutMillis
in interfacejavax.jdo.Query<T>
-
datastoreWriteTimeoutMillis
- Specified by:
datastoreWriteTimeoutMillis
in interfacejavax.jdo.Query<T>
-
setUnique
public void setUnique(boolean unique) Set whether to expect a unique result.- Specified by:
setUnique
in interfacejavax.jdo.Query<T>
- Parameters:
unique
- Whether results are unique
-
isUnmodifiable
public boolean isUnmodifiable()Accessor for whether the query is modifiable.- Specified by:
isUnmodifiable
in interfacejavax.jdo.Query<T>
- Returns:
- Whether it is modifiable
-
setUnmodifiable
public void setUnmodifiable()Set the query to be unmodifiable.- Specified by:
setUnmodifiable
in interfacejavax.jdo.Query<T>
-
unmodifiable
- Specified by:
unmodifiable
in interfacejavax.jdo.Query<T>
-
addSubquery
Add a subquery to this query.- Specified by:
addSubquery
in interfacejavax.jdo.Query<T>
- Parameters:
sub
- the subquery to add to this QueryvariableDecl
- the name of the variable in the outer query to bind the results of the subquerycandidateExpr
- the candidate collection of the subquery as an expression using terms of the outer query
-
addSubquery
public void addSubquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, 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 interfacejavax.jdo.Query<T>
- Parameters:
sub
- the subquery to add to this QueryvariableDecl
- the name of the variable to be used in this QuerycandidateExpr
- the candidate collection to apply to the subqueryparameter
- the expression from the outer query to bind the parameter in the subquery
-
addSubquery
public void addSubquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, 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 interfacejavax.jdo.Query<T>
- Parameters:
sub
- the subquery to add to this QueryvariableDecl
- the name of the variable to be used in this QuerycandidateExpr
- the candidate collection to apply to the subqueryparameters
- the expressions from the outer query to bind the parameter in the subquery
-
addSubquery
public void addSubquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, 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 interfacejavax.jdo.Query<T>
- Parameters:
sub
- the subquery to add to this QueryvariableDecl
- the name of the variable to be used in this QuerycandidateExpr
- the candidate collection to apply to the subqueryparameters
- the expressions from the outer query to bind the parameter in the subquery
-
subquery
- Specified by:
subquery
in interfacejavax.jdo.Query<T>
-
subquery
public javax.jdo.Query<T> subquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, String parameter) - Specified by:
subquery
in interfacejavax.jdo.Query<T>
-
subquery
public javax.jdo.Query<T> subquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, String... parameters) - Specified by:
subquery
in interfacejavax.jdo.Query<T>
-
subquery
public javax.jdo.Query<T> subquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, Map parameters) - Specified by:
subquery
in interfacejavax.jdo.Query<T>
-
getSerializeRead
Accessor for whether to serialise any read objects in this query.- Specified by:
getSerializeRead
in interfacejavax.jdo.Query<T>
- Returns:
- The setting for whether to serialise any read objects
-
setSerializeRead
Mutator for whether to serialise any read objects.- Specified by:
setSerializeRead
in interfacejavax.jdo.Query<T>
- Parameters:
serialize
- Whether to serialise any read objects in this query.
-
serializeRead
- Specified by:
serializeRead
in interfacejavax.jdo.Query<T>
-
getInternalQuery
Accessor for the internal query.- Returns:
- Internal query
-
getLanguage
Accessor for the query language.- Returns:
- Query language
-
saveAsNamedQuery
Save this query as a named query with the specified name.- Specified by:
saveAsNamedQuery
in interfacejavax.jdo.Query<T>
- Parameters:
name
- The name to refer to it under- Returns:
- This query
-
toString
Convenience method to return the query in string form. -
getNativeQuery
Accessor for the native query invoked by this query (if known at this time and supported by the store plugin).- Returns:
- The native query (e.g for RDBMS this is the SQL).
-
assertIsOpen
protected void assertIsOpen()Method to assert if this Query is open.- Throws:
javax.jdo.JDOFatalUserException
- if the Query is closed.
-