org.datanucleus.query.typesafe
Interface TypesafeQuery<T>

All Known Implementing Classes:
JDOTypesafeQuery

public interface TypesafeQuery<T>

Interface for a type-safe query, using a fluent API. Designed to handle JDO query requirements as a whole.


Field Summary
static java.lang.String QUERY_CLASS_PREFIX
           
 
Method Summary
 TypesafeQuery<T> 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.
 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 deletePersistentAll()
          Method to execute the query deleting the affected instances.
 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
<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
 javax.jdo.PersistenceManager getPersistenceManager()
          Accessor for the PersistenceManager for this query
 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... orderExprs)
          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<T> setExtensions(java.util.Map<java.lang.String,java.lang.Object> extensions)
          Set multiple extensions, or use null to clear all extensions.
 TypesafeQuery<T> 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> candidate, 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 equivalent String form of this query (if applicable for the query language).
 Expression variable(java.lang.String name, java.lang.Class type)
          Method to return a variable for this query.
 

Field Detail

QUERY_CLASS_PREFIX

static final java.lang.String QUERY_CLASS_PREFIX
See Also:
Constant Field Values
Method Detail

candidate

PersistableExpression candidate()
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.

Returns:
Expression for the candidate

parameter

Expression parameter(java.lang.String name,
                     java.lang.Class type)
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.

Parameters:
name - Name of the parameter
type - Java type of the parameter
Returns:
Expression for the parameter

stringParameter

StringExpression stringParameter(java.lang.String name)
Method to return a string parameter for the query.

Parameters:
name - Name of the parameter
Returns:
StringExpression for the parameter

characterParameter

CharacterExpression characterParameter(java.lang.String name)
Method to return a character parameter for the query.

Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

longParameter

NumericExpression<java.lang.Long> longParameter(java.lang.String name)
Method to return a numeric parameter for the query.

Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

integerParameter

NumericExpression<java.lang.Integer> integerParameter(java.lang.String name)
Method to return a numeric parameter for the query.

Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

shortParameter

NumericExpression<java.lang.Short> shortParameter(java.lang.String name)
Method to return a numeric parameter for the query.

Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

doubleParameter

NumericExpression<java.lang.Double> doubleParameter(java.lang.String name)
Method to return a numeric parameter for the query.

Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

floatParameter

NumericExpression<java.lang.Float> floatParameter(java.lang.String name)
Method to return a numeric parameter for the query.

Parameters:
name - Name of the parameter
Returns:
NumericExpression for the parameter

dateParameter

DateExpression<java.sql.Date> dateParameter(java.lang.String name)
Method to return a date parameter for the query.

Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

timeParameter

TimeExpression<java.sql.Time> timeParameter(java.lang.String name)
Method to return a time parameter for the query.

Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

datetimeParameter

DateTimeExpression<java.util.Date> datetimeParameter(java.lang.String name)
Method to return a datetime parameter for the query.

Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

collectionParameter

CollectionExpression collectionParameter(java.lang.String name)
Method to return a collection parameter for the query.

Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

mapParameter

MapExpression mapParameter(java.lang.String name)
Method to return a map parameter for the query.

Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

listParameter

ListExpression listParameter(java.lang.String name)
Method to return a list parameter for the query.

Parameters:
name - Name of the parameter
Returns:
Expression for the parameter

variable

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

Parameters:
name - Name of the variable
type - Type of the variable
Returns:
Expression for the variable

getPersistenceManager

javax.jdo.PersistenceManager getPersistenceManager()
Accessor for the PersistenceManager for this query

Returns:
The PersistenceManager

getFetchPlan

javax.jdo.FetchPlan getFetchPlan()
Accessor for the FetchPlan for this query

Returns:
The FetchPlan

setIgnoreCache

TypesafeQuery<T> setIgnoreCache(boolean ignore)
Whether the query should ignore the cache and go straight to the datastore.

Parameters:
ignore - Ignore the cache flag
Returns:
The query

setCandidates

TypesafeQuery<T> setCandidates(java.util.Collection<T> candidates)
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.

Parameters:
candidates - The candidates
Returns:
The query

excludeSubclasses

TypesafeQuery<T> excludeSubclasses()
Method to remove subclasses (of the candidate) from the query

Returns:
The query

includeSubclasses

TypesafeQuery<T> includeSubclasses()
Method to include subclasses (of the candidate) to the query

Returns:
The query

filter

TypesafeQuery<T> filter(BooleanExpression expr)
Method to set the filter of the query.

Parameters:
expr - Filter expression
Returns:
The query

groupBy

TypesafeQuery<T> groupBy(Expression... exprs)
Method to set the grouping(s) for the query.

Parameters:
exprs - Grouping expression(s)
Returns:
The query

having

TypesafeQuery<T> having(Expression expr)
Method to set the having clause of the query.

Parameters:
expr - Having expression
Returns:
The query

orderBy

TypesafeQuery<T> orderBy(OrderExpression... orderExprs)
Method to set the ordering of the query.

Parameters:
orderExprs - Ordering expression(s)
Returns:
The query

range

TypesafeQuery<T> range(NumericExpression lowerInclExpr,
                       NumericExpression upperExclExpr)
Method to set the range of any required results, using expressions.

Parameters:
lowerInclExpr - The position of the first result (inclusive)
upperExclExpr - The position of the last result (exclusive)
Returns:
The query

range

TypesafeQuery<T> range(long lowerIncl,
                       long upperExcl)
Method to set the range of any required results, using long values.

Parameters:
lowerIncl - The position of the first result (inclusive)
upperExcl - The position of the last result (exclusive)
Returns:
The query

range

TypesafeQuery<T> range(Expression paramLowerInclExpr,
                       Expression paramUpperExclExpr)
Method to set the range of any required results, using parameters (expressions).

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

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. To obtain the expression for the subquery to link it back to this query, call "result(...)" on the subquery.

Parameters:
candidateAlias - Alias for the candidate
Returns:
The subquery

subquery

<S> TypesafeSubquery<S> subquery(java.lang.Class<S> candidate,
                                 java.lang.String candidateAlias)
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.

Parameters:
candidate - Candidate for the subquery
candidateAlias - Alias for the candidate
Returns:
The subquery

setParameter

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

Parameters:
paramExpr - Parameter expression
value - The value
Returns:
The query

setParameter

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

Parameters:
paramName - Parameter name
value - The value
Returns:
The query

addExtension

TypesafeQuery<T> addExtension(java.lang.String key,
                              java.lang.Object value)
Add a vendor-specific extension to this query. The key and value are not standard. An implementation must ignore keys that are not recognized.

Parameters:
key - the key of the extension
value - the value of the extension
Returns:
The query

setExtensions

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

Parameters:
extensions - the map of extensions
Returns:
The query
See Also:
addExtension(java.lang.String, java.lang.Object)

executeList

<T> java.util.List<T> executeList()
Method to execute the query where there are (potentially) multiple rows and we are returning the candidate type.

Returns:
The results

executeUnique

<T> T executeUnique()
Method to execute the query where there is a single row and we are returning the candidate type.

Returns:
The result

executeResultList

<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.

Parameters:
resultCls - Result class
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The results

executeResultUnique

<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.

Parameters:
resultCls - Result class
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The result

executeResultList

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.

Parameters:
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The results

executeResultUnique

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.

Parameters:
distinct - Whether to provide distinct results
exprs - Result expression(s)
Returns:
The results

deletePersistentAll

long deletePersistentAll()
Method to execute the query deleting the affected instances.

Returns:
The number of objects deleted

close

void close(java.lang.Object result)
Method to close the specified query result.

Parameters:
result - The result

closeAll

void closeAll()
Method to close all query results from this query.


toString

java.lang.String toString()
Method to return the equivalent String form of this query (if applicable for the query language).

Overrides:
toString in class java.lang.Object
Returns:
The single-string form of this query


Copyright © 2011. All Rights Reserved.