org.datanucleus.jdo.query
Class JDOTypesafeQuery<T>

java.lang.Object
  extended by org.datanucleus.jdo.query.AbstractTypesafeQuery<T>
      extended by org.datanucleus.jdo.query.JDOTypesafeQuery<T>
All Implemented Interfaces:
TypesafeQuery<T>

public class JDOTypesafeQuery<T>
extends AbstractTypesafeQuery<T>
implements TypesafeQuery<T>

Implementation of a typesafe Query for JDO.


Field Summary
protected  java.util.Collection<T> candidates
           
protected  java.util.Map<java.lang.String,java.lang.Object> extensions
          Any extensions
protected  java.util.HashSet<Query> internalQueries
          Internal queries generated by this typesafe query.
protected  java.util.Map<java.lang.String,ExpressionImpl> parameterExprByName
          Map of parameter expression keyed by the name.
protected  java.util.Map<java.lang.String,java.lang.Object> parameterValuesByName
          Map of parameters keyed by their name/expression.
protected  ExpressionImpl rangeLowerExpr
          Range : lower limit expression.
protected  ExpressionImpl rangeUpperExpr
          Range : upper limit expression.
protected  java.util.HashSet<JDOTypesafeSubquery> subqueries
          Set of any subqueries used by this query.
 
Fields inherited from class org.datanucleus.jdo.query.AbstractTypesafeQuery
candidateAlias, candidateCls, filter, grouping, having, om, ordering, pm, result, resultDistinct
 
Fields inherited from interface org.datanucleus.query.typesafe.TypesafeQuery
QUERY_CLASS_PREFIX
 
Constructor Summary
JDOTypesafeQuery(javax.jdo.PersistenceManager pm, java.lang.Class<T> candidateClass)
          Constructor for a typesafe query.
 
Method Summary
 TypesafeQuery addExtension(java.lang.String key, java.lang.Object value)
          Add a vendor-specific extension to this query.
 PersistableExpression candidate()
          Method to return an expression for the candidate of the query.
 CharacterExpression characterParameter(java.lang.String name)
          Method to return a character parameter for the query.
 void close(java.lang.Object result)
          Method to close the specified query result.
 void closeAll()
          Method to close all query results from this query.
 CollectionExpression collectionParameter(java.lang.String name)
          Method to return a collection parameter for the query.
 QueryCompilation compile(MetaDataManager mmgr, ClassLoaderResolver clr)
          Method to compile the typesafe query.
 DateExpression<java.sql.Date> dateParameter(java.lang.String name)
          Method to return a date parameter for the query.
 DateTimeExpression<java.util.Date> datetimeParameter(java.lang.String name)
          Method to return a datetime parameter for the query.
 long delete()
          Extension method to provide bulk delete capabilities (not part of JDO).
 long deletePersistentAll()
          Method to execute the query deleting the affected instances.
protected  void discardCompiled()
          Called when something is set on the query making any compilation invalid.
 NumericExpression<java.lang.Double> doubleParameter(java.lang.String name)
          Method to return a numeric parameter for the query.
 TypesafeQuery<T> excludeSubclasses()
          Method to remove subclasses (of the candidate) from the query
protected  java.lang.Object executeInternalQuery(Query internalQuery)
           
<T> java.util.List<T>
executeList()
          Method to execute the query where there are (potentially) multiple rows and we are returning the candidate type.
 java.util.List<java.lang.Object[]> executeResultList(boolean distinct, Expression... exprs)
          Method to execute the query where there are (potentially) multiple rows and we have a result defined but no result class.
<R> java.util.List<R>
executeResultList(java.lang.Class<R> resultCls, boolean distinct, Expression... exprs)
          Method to execute the query where there are (potentially) multiple rows and we are returning either a result type or the candidate type.
 java.lang.Object[] executeResultUnique(boolean distinct, Expression... exprs)
          Method to execute the query where there is a single row and we have a result defined but no result class.
<R> R
executeResultUnique(java.lang.Class<R> resultCls, boolean distinct, Expression... exprs)
          Method to execute the query where there is a single row and we are returning either a result type or the candidate type.
<T> T
executeUnique()
          Method to execute the query where there is a single row and we are returning the candidate type.
 TypesafeQuery<T> filter(BooleanExpression expr)
          Method to set the filter of the query.
 NumericExpression<java.lang.Float> floatParameter(java.lang.String name)
          Method to return a numeric parameter for the query.
 javax.jdo.FetchPlan getFetchPlan()
          Accessor for the FetchPlan for this query
protected  Query getInternalQuery()
          Convenience method to generate an internal DataNucleus Query and apply the generic compilation to it.
 javax.jdo.PersistenceManager getPersistenceManager()
          Accessor for the PersistenceManager for this query
static java.lang.String getQueryClassNameForClassName(java.lang.String name)
          Method to return the (simple) name of the query class for a specified class name.
 TypesafeQuery<T> groupBy(Expression... exprs)
          Method to set the grouping(s) for the query.
 TypesafeQuery<T> having(Expression expr)
          Method to set the having clause of the query.
 TypesafeQuery<T> includeSubclasses()
          Method to include subclasses (of the candidate) to the query
 NumericExpression<java.lang.Integer> integerParameter(java.lang.String name)
          Method to return a numeric parameter for the query.
 ListExpression listParameter(java.lang.String name)
          Method to return a list parameter for the query.
 NumericExpression<java.lang.Long> longParameter(java.lang.String name)
          Method to return a numeric parameter for the query.
 MapExpression mapParameter(java.lang.String name)
          Method to return a map parameter for the query.
 TypesafeQuery<T> orderBy(OrderExpression... exprs)
          Method to set the ordering of the query.
 Expression parameter(java.lang.String name, java.lang.Class type)
          Method to return a parameter for the query.
 TypesafeQuery<T> range(Expression paramLowerInclExpr, Expression paramUpperExclExpr)
          Method to set the range of any required results, using parameters (expressions).
 TypesafeQuery<T> range(long lowerIncl, long upperExcl)
          Method to set the range of any required results, using long values.
 TypesafeQuery<T> range(NumericExpression lowerInclExpr, NumericExpression upperExclExpr)
          Method to set the range of any required results, using expressions.
 TypesafeQuery<T> setCandidates(java.util.Collection<T> candidates)
          Method to set the candidates to use over which we are querying.
 TypesafeQuery setExtensions(java.util.Map<java.lang.String,java.lang.Object> extensions)
          Set multiple extensions, or use null to clear all extensions.
 TypesafeQuery setIgnoreCache(boolean ignore)
          Whether the query should ignore the cache and go straight to the datastore.
 TypesafeQuery<T> setParameter(Expression paramExpr, java.lang.Object value)
          Method to set a parameter value for use when executing the query.
 TypesafeQuery<T> setParameter(java.lang.String paramName, java.lang.Object value)
          Method to set a parameter value for use when executing the query.
 NumericExpression<java.lang.Short> shortParameter(java.lang.String name)
          Method to return a numeric parameter for the query.
 StringExpression stringParameter(java.lang.String name)
          Method to return a string parameter for the query.
<S> TypesafeSubquery<S>
subquery(java.lang.Class<S> candidateClass, java.lang.String candidateAlias)
          Method to return a subquery for use in this query.
 TypesafeSubquery<T> subquery(java.lang.String candidateAlias)
          Method to return a subquery for use in this query using the same candidate class as this query.
 TimeExpression<java.sql.Time> timeParameter(java.lang.String name)
          Method to return a time parameter for the query.
 java.lang.String toString()
          Method to return the single-string form of this JDOQL query.
 long update()
          Extension method to provide bulk update capabilities (not part of JDO).
 Expression variable(java.lang.String name, java.lang.Class type)
          Method to return a variable for this query.
 
Methods inherited from class org.datanucleus.jdo.query.AbstractTypesafeQuery
getCompilation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

candidates

protected java.util.Collection<T> candidates

rangeLowerExpr

protected ExpressionImpl rangeLowerExpr
Range : lower limit expression.


rangeUpperExpr

protected ExpressionImpl rangeUpperExpr
Range : upper limit expression.


extensions

protected java.util.Map<java.lang.String,java.lang.Object> extensions
Any extensions


parameterExprByName

protected java.util.Map<java.lang.String,ExpressionImpl> parameterExprByName
Map of parameter expression keyed by the name.


parameterValuesByName

protected java.util.Map<java.lang.String,java.lang.Object> parameterValuesByName
Map of parameters keyed by their name/expression.


subqueries

protected transient java.util.HashSet<JDOTypesafeSubquery> subqueries
Set of any subqueries used by this query.


internalQueries

protected transient java.util.HashSet<Query> internalQueries
Internal queries generated by this typesafe query. Managed so that they can be closed.

Constructor Detail

JDOTypesafeQuery

public JDOTypesafeQuery(javax.jdo.PersistenceManager pm,
                        java.lang.Class<T> candidateClass)
Constructor for a typesafe query.

Parameters:
pm - Persistence Manager
candidateClass - The candidate class
Method Detail

candidate

public PersistableExpression candidate()
Description copied from interface: TypesafeQuery
Method to return an expression for the candidate of the query. Cast the returned expression to the candidate "Q" type to be able to call methods on it. This calls the method "Q{type}.candidate(null)" The preference is to use the "Q{type}.candidate()" method for real type-safe handling.

Specified by:
candidate in interface TypesafeQuery<T>
Returns:
Expression for the candidate

parameter

public Expression parameter(java.lang.String name,
                            java.lang.Class type)
Description copied from interface: TypesafeQuery
Method to return a parameter for the query. Cast the returned parameter to the right type to be able to call methods on it. The preference is to use the "xxxParameter(String)" methods for real type-safe handling.

Specified by:
parameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
type - Java type of the parameter
Returns:
Expression for the parameter

stringParameter

public StringExpression stringParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a string parameter for the query.

Specified by:
stringParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
StringExpression for the parameter

characterParameter

public CharacterExpression characterParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a character parameter for the query.

Specified by:
characterParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

longParameter

public NumericExpression<java.lang.Long> longParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a numeric parameter for the query.

Specified by:
longParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

integerParameter

public NumericExpression<java.lang.Integer> integerParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a numeric parameter for the query.

Specified by:
integerParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

shortParameter

public NumericExpression<java.lang.Short> shortParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a numeric parameter for the query.

Specified by:
shortParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

doubleParameter

public NumericExpression<java.lang.Double> doubleParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a numeric parameter for the query.

Specified by:
doubleParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

floatParameter

public NumericExpression<java.lang.Float> floatParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a numeric parameter for the query.

Specified by:
floatParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

dateParameter

public DateExpression<java.sql.Date> dateParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a date parameter for the query.

Specified by:
dateParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

timeParameter

public TimeExpression<java.sql.Time> timeParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a time parameter for the query.

Specified by:
timeParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

datetimeParameter

public DateTimeExpression<java.util.Date> datetimeParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a datetime parameter for the query.

Specified by:
datetimeParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

collectionParameter

public CollectionExpression collectionParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a collection parameter for the query.

Specified by:
collectionParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

mapParameter

public MapExpression mapParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a map parameter for the query.

Specified by:
mapParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

listParameter

public ListExpression listParameter(java.lang.String name)
Description copied from interface: TypesafeQuery
Method to return a list parameter for the query.

Specified by:
listParameter in interface TypesafeQuery<T>
Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

variable

public Expression variable(java.lang.String name,
                           java.lang.Class type)
Description copied from interface: TypesafeQuery
Method to return a variable for this query. Cast the returned variable to the right type to be able to call methods on it.

Specified by:
variable in interface TypesafeQuery<T>
Parameters:
name - Name of the variable
type - Type of the variable
Returns:
Expression for the variable

excludeSubclasses

public TypesafeQuery<T> excludeSubclasses()
Description copied from interface: TypesafeQuery
Method to remove subclasses (of the candidate) from the query

Specified by:
excludeSubclasses in interface TypesafeQuery<T>
Returns:
The query

includeSubclasses

public TypesafeQuery<T> includeSubclasses()
Description copied from interface: TypesafeQuery
Method to include subclasses (of the candidate) to the query

Specified by:
includeSubclasses in interface TypesafeQuery<T>
Returns:
The query

filter

public TypesafeQuery<T> filter(BooleanExpression expr)
Description copied from interface: TypesafeQuery
Method to set the filter of the query.

Specified by:
filter in interface TypesafeQuery<T>
Parameters:
expr - Filter expression
Returns:
The query

groupBy

public TypesafeQuery<T> groupBy(Expression... exprs)
Description copied from interface: TypesafeQuery
Method to set the grouping(s) for the query.

Specified by:
groupBy in interface TypesafeQuery<T>
Parameters:
exprs - Grouping expression(s)
Returns:
The query

having

public TypesafeQuery<T> having(Expression expr)
Description copied from interface: TypesafeQuery
Method to set the having clause of the query.

Specified by:
having in interface TypesafeQuery<T>
Parameters:
expr - Having expression
Returns:
The query

orderBy

public TypesafeQuery<T> orderBy(OrderExpression... exprs)
Description copied from interface: TypesafeQuery
Method to set the ordering of the query.

Specified by:
orderBy in interface TypesafeQuery<T>
Parameters:
exprs - Ordering expression(s)
Returns:
The query

range

public TypesafeQuery<T> range(long lowerIncl,
                              long upperExcl)
Description copied from interface: TypesafeQuery
Method to set the range of any required results, using long values.

Specified by:
range in interface TypesafeQuery<T>
Parameters:
lowerIncl - The position of the first result (inclusive)
upperExcl - The position of the last result (exclusive)
Returns:
The query

range

public TypesafeQuery<T> range(NumericExpression lowerInclExpr,
                              NumericExpression upperExclExpr)
Description copied from interface: TypesafeQuery
Method to set the range of any required results, using expressions.

Specified by:
range in interface TypesafeQuery<T>
Parameters:
lowerInclExpr - The position of the first result (inclusive)
upperExclExpr - The position of the last result (exclusive)
Returns:
The query

range

public TypesafeQuery<T> range(Expression paramLowerInclExpr,
                              Expression paramUpperExclExpr)
Description copied from interface: TypesafeQuery
Method to set the range of any required results, using parameters (expressions).

Specified by:
range in interface TypesafeQuery<T>
Parameters:
paramLowerInclExpr - Expression for a parameter defining the position of the first result (inclusive)
paramUpperExclExpr - Expression for a parameter defining the position of the last result (exclusive)
Returns:
The query

subquery

public <S> TypesafeSubquery<S> subquery(java.lang.Class<S> candidateClass,
                                        java.lang.String candidateAlias)
Description copied from interface: TypesafeQuery
Method to return a subquery for use in this query. To obtain the expression for the subquery to link it back to this query, call "result(...)" on the subquery.

Specified by:
subquery in interface TypesafeQuery<T>
Parameters:
candidateClass - Candidate for the subquery
candidateAlias - Alias for the candidate
Returns:
The subquery

subquery

public TypesafeSubquery<T> subquery(java.lang.String candidateAlias)
Description copied from interface: TypesafeQuery
Method to return a subquery for use in this query using the same candidate class as this query. To obtain the expression for the subquery to link it back to this query, call "result(...)" on the subquery.

Specified by:
subquery in interface TypesafeQuery<T>
Parameters:
candidateAlias - Alias for the candidate
Returns:
The subquery

setParameter

public TypesafeQuery<T> setParameter(Expression paramExpr,
                                     java.lang.Object value)
Description copied from interface: TypesafeQuery
Method to set a parameter value for use when executing the query.

Specified by:
setParameter in interface TypesafeQuery<T>
Parameters:
paramExpr - Parameter expression
value - The value
Returns:
The query

setParameter

public TypesafeQuery<T> setParameter(java.lang.String paramName,
                                     java.lang.Object value)
Description copied from interface: TypesafeQuery
Method to set a parameter value for use when executing the query.

Specified by:
setParameter in interface TypesafeQuery<T>
Parameters:
paramName - Parameter name
value - The value
Returns:
The query

setCandidates

public TypesafeQuery<T> setCandidates(java.util.Collection<T> candidates)
Description copied from interface: TypesafeQuery
Method to set the candidates to use over which we are querying. If no candidates are set then the query is performed on the datastore.

Specified by:
setCandidates in interface TypesafeQuery<T>
Parameters:
candidates - The candidates
Returns:
The query

executeList

public <T> java.util.List<T> executeList()
Description copied from interface: TypesafeQuery
Method to execute the query where there are (potentially) multiple rows and we are returning the candidate type.

Specified by:
executeList in interface TypesafeQuery<T>
Returns:
The results

executeUnique

public <T> T executeUnique()
Description copied from interface: TypesafeQuery
Method to execute the query where there is a single row and we are returning the candidate type.

Specified by:
executeUnique in interface TypesafeQuery<T>
Returns:
The result

executeResultList

public java.util.List<java.lang.Object[]> executeResultList(boolean distinct,
                                                            Expression... exprs)
Description copied from interface: TypesafeQuery
Method to execute the query where there are (potentially) multiple rows and we have a result defined but no result class.

Specified by:
executeResultList in interface TypesafeQuery<T>
Parameters:
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The results

executeResultList

public <R> java.util.List<R> executeResultList(java.lang.Class<R> resultCls,
                                               boolean distinct,
                                               Expression... exprs)
Description copied from interface: TypesafeQuery
Method to execute the query where there are (potentially) multiple rows and we are returning either a result type or the candidate type.

Specified by:
executeResultList in interface TypesafeQuery<T>
Parameters:
resultCls - Result class
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The results

executeResultUnique

public java.lang.Object[] executeResultUnique(boolean distinct,
                                              Expression... exprs)
Description copied from interface: TypesafeQuery
Method to execute the query where there is a single row and we have a result defined but no result class.

Specified by:
executeResultUnique in interface TypesafeQuery<T>
Parameters:
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The results

executeResultUnique

public <R> R executeResultUnique(java.lang.Class<R> resultCls,
                                 boolean distinct,
                                 Expression... exprs)
Description copied from interface: TypesafeQuery
Method to execute the query where there is a single row and we are returning either a result type or the candidate type.

Specified by:
executeResultUnique in interface TypesafeQuery<T>
Parameters:
resultCls - Result class
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The result

getInternalQuery

protected Query getInternalQuery()
Convenience method to generate an internal DataNucleus Query and apply the generic compilation to it.

Returns:
The internal DataNucleus query

executeInternalQuery

protected java.lang.Object executeInternalQuery(Query internalQuery)

deletePersistentAll

public long deletePersistentAll()
Description copied from interface: TypesafeQuery
Method to execute the query deleting the affected instances.

Specified by:
deletePersistentAll in interface TypesafeQuery<T>
Returns:
The number of objects deleted

update

public long update()
Extension method to provide bulk update capabilities (not part of JDO).

Returns:
Number of instances that were updated

delete

public long delete()
Extension method to provide bulk delete capabilities (not part of JDO). This differs from deletePersistentAll() in that it doesn't cascade to related objects (unless the datastore does that automatically), and that it doesn't attempt to update cached objects state to reflect the deletion.

Returns:
Number of instances that were deleted

getFetchPlan

public javax.jdo.FetchPlan getFetchPlan()
Description copied from interface: TypesafeQuery
Accessor for the FetchPlan for this query

Specified by:
getFetchPlan in interface TypesafeQuery<T>
Returns:
The FetchPlan

getPersistenceManager

public javax.jdo.PersistenceManager getPersistenceManager()
Description copied from interface: TypesafeQuery
Accessor for the PersistenceManager for this query

Specified by:
getPersistenceManager in interface TypesafeQuery<T>
Returns:
The PersistenceManager

setIgnoreCache

public TypesafeQuery setIgnoreCache(boolean ignore)
Description copied from interface: TypesafeQuery
Whether the query should ignore the cache and go straight to the datastore.

Specified by:
setIgnoreCache in interface TypesafeQuery<T>
Parameters:
ignore - Ignore the cache flag
Returns:
The query

addExtension

public TypesafeQuery addExtension(java.lang.String key,
                                  java.lang.Object value)
Description copied from interface: TypesafeQuery
Add a vendor-specific extension to this query. The key and value are not standard. An implementation must ignore keys that are not recognized.

Specified by:
addExtension in interface TypesafeQuery<T>
Parameters:
key - the key of the extension
value - the value of the extension
Returns:
The query

setExtensions

public TypesafeQuery setExtensions(java.util.Map<java.lang.String,java.lang.Object> extensions)
Description copied from interface: TypesafeQuery
Set multiple extensions, or use null to clear all extensions. Map keys and values are not standard.

Specified by:
setExtensions in interface TypesafeQuery<T>
Parameters:
extensions - the map of extensions
Returns:
The query
See Also:
TypesafeQuery.addExtension(java.lang.String, java.lang.Object)

close

public void close(java.lang.Object result)
Description copied from interface: TypesafeQuery
Method to close the specified query result.

Specified by:
close in interface TypesafeQuery<T>
Parameters:
result - The result

closeAll

public void closeAll()
Description copied from interface: TypesafeQuery
Method to close all query results from this query.

Specified by:
closeAll in interface TypesafeQuery<T>

compile

public QueryCompilation compile(MetaDataManager mmgr,
                                ClassLoaderResolver clr)
Method to compile the typesafe query.

Overrides:
compile in class AbstractTypesafeQuery<T>
Parameters:
mmgr - Metadata manager
clr - ClassLoader resolver
Returns:
The generic compilation

toString

public java.lang.String toString()
Method to return the single-string form of this JDOQL query.

Specified by:
toString in interface TypesafeQuery<T>
Overrides:
toString in class java.lang.Object
Returns:
Single-string form of the query

discardCompiled

protected void discardCompiled()
Called when something is set on the query making any compilation invalid.

Overrides:
discardCompiled in class AbstractTypesafeQuery<T>

getQueryClassNameForClassName

public static java.lang.String getQueryClassNameForClassName(java.lang.String name)
Method to return the (simple) name of the query class for a specified class name. Currently just returns "Q{className}"

Parameters:
name - Simple name of the class (without package)
Returns:
Simple name of the query class


Copyright © 2011. All Rights Reserved.