org.springframework.datastore.query
Class Query

java.lang.Object
  extended by org.springframework.datastore.query.Query
Direct Known Subclasses:
RedisQuery

public abstract class Query
extends Object

Models a query that can be executed against a data store

Since:
1.0

Nested Class Summary
static class Query.AvgProjection
          Computes the average value of a property
static class Query.Between
          Criterion used to restrict the result to be between values (range query)
static class Query.Conjunction
          A Criterion used to combine to criterion in a logical AND
static class Query.CountProjection
          Used to count the results of a query
static class Query.Criterion
          A criterion is used to restrict the results of a query
static class Query.Disjunction
          A Criterion used to combine to criterion in a logical OR
static class Query.Equals
          A criterion that restricts the results based on equality
static class Query.GreaterThan
          Used to restrict a value to be greater than the given value
static class Query.GreaterThanEquals
          Used to restrict a value to be greater than or equal to the given value
static class Query.IdProjection
          A projection used to obtain the identifier of an object
static class Query.In
          Criterion used to restrict the results based on a list of values
static class Query.Junction
           
static class Query.LessThan
          Used to restrict a value to be less than the given value
static class Query.LessThanEquals
          Used to restrict a value to be less than the given value
static class Query.Like
          Criterion used to restrict the results based on a pattern (likeness)
static class Query.MaxProjection
          Computes the max value of a property
static class Query.MinProjection
          Computes the min value of a property
static class Query.Order
          The ordering of results
static class Query.Projection
          A projection
static class Query.ProjectionList
          A list of projections
static class Query.PropertyCriterion
          Criterion that applies to a property
static class Query.PropertyProjection
          A projection that obtains the value of a property of an entity
static class Query.SumProjection
          Computes the sum of a property
 
Field Summary
protected  Query.Junction criteria
           
protected  PersistentEntity entity
           
protected  int max
           
protected  int offset
           
protected  List<Query.Order> orderBy
           
protected  Query.ProjectionList projections
           
 
Constructor Summary
protected Query(Session session, PersistentEntity entity)
           
 
Method Summary
 void add(Query.Criterion criterion)
           
 Query and(Query.Criterion a, Query.Criterion b)
          Creates a conjunction using two specified criterion
 Query between(String property, Object start, Object end)
          Restricts the results by the given property value range
 Query.Junction disjunction()
          Creates a disjunction (OR) query
 Query eq(String property, Object value)
          Restricts the results by the given properties value
protected abstract  List executeQuery(PersistentEntity entity, Query.Junction criteria)
          Subclasses should implement this to provide the concrete implementation of querying
 Query firstResult(int offset)
          Defines the offset (the first result index) of the query
 PersistentEntity getEntity()
           
 List<Query.Order> getOrderBy()
          Gets the Order entries for this query
 Session getSession()
           
 Query gt(String property, Object value)
          Used to restrict a value to be greater than the given value
 Query gte(String property, Object value)
          Used to restrict a value to be greater than or equal to the given value
 Query in(String property, List values)
          Restricts the results by the given property values
 Query like(String property, String expr)
          Restricts the results by the given properties value
 List list()
          Executes the query returning zero or many results as a list
 Query lt(String property, Object value)
          Used to restrict a value to be less than the given value
 Query lte(String property, Object value)
          Used to restrict a value to be less than or equal to the given value
 Query max(int max)
          Defines the maximum number of results to return
 Query maxResults(int max)
          Defines the maximum number of results to return
 Query offset(int offset)
          Defines the offset (the first result index) of the query
 Query or(Query.Criterion a, Query.Criterion b)
          Creates a disjunction using two specified criterion
 Query order(Query.Order order)
          Specifies the order of results
 Query.ProjectionList projections()
           
 void setUniqueResult(boolean uniqueResult)
          Deprecated.  
 Object singleResult()
          Executes the query returning a single result or null
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entity

protected PersistentEntity entity

criteria

protected Query.Junction criteria

projections

protected Query.ProjectionList projections

max

protected int max

offset

protected int offset

orderBy

protected List<Query.Order> orderBy
Constructor Detail

Query

protected Query(Session session,
                PersistentEntity entity)
Method Detail

projections

public Query.ProjectionList projections()

add

public void add(Query.Criterion criterion)

getSession

public Session getSession()

getEntity

public PersistentEntity getEntity()

disjunction

public Query.Junction disjunction()
Creates a disjunction (OR) query

Returns:
The Junction instance

max

public Query max(int max)
Defines the maximum number of results to return

Parameters:
max - The max results
Returns:
This query instance

maxResults

public Query maxResults(int max)
Defines the maximum number of results to return

Parameters:
max - The max results
Returns:
This query instance

offset

public Query offset(int offset)
Defines the offset (the first result index) of the query

Parameters:
offset - The offset
Returns:
This query instance

firstResult

public Query firstResult(int offset)
Defines the offset (the first result index) of the query

Parameters:
offset - The offset
Returns:
This query instance

order

public Query order(Query.Order order)
Specifies the order of results

Parameters:
order - The order object
Returns:
The Query instance

getOrderBy

public List<Query.Order> getOrderBy()
Gets the Order entries for this query

Returns:
The order entries

eq

public Query eq(String property,
                Object value)
Restricts the results by the given properties value

Parameters:
property - The name of the property
value - The value to restrict by
Returns:
This query instance

gt

public Query gt(String property,
                Object value)
Used to restrict a value to be greater than the given value

Parameters:
property - The name of the property
value - The value to restrict by
Returns:
This query instance

gte

public Query gte(String property,
                 Object value)
Used to restrict a value to be greater than or equal to the given value

Parameters:
property - The name of the property
value - The value to restrict by
Returns:
This query instance

lte

public Query lte(String property,
                 Object value)
Used to restrict a value to be less than or equal to the given value

Parameters:
property - The name of the property
value - The value to restrict by
Returns:
This query instance

lt

public Query lt(String property,
                Object value)
Used to restrict a value to be less than the given value

Parameters:
property - The name of the property
value - The value to restrict by
Returns:
This query instance

in

public Query in(String property,
                List values)
Restricts the results by the given property values

Parameters:
property - The name of the property
values - The values to restrict by
Returns:
This query instance

between

public Query between(String property,
                     Object start,
                     Object end)
Restricts the results by the given property value range

Parameters:
property - The name of the property
start - The start of the range
end - The end of the range
Returns:
This query instance

like

public Query like(String property,
                  String expr)
Restricts the results by the given properties value

Parameters:
property - The name of the property
expr - The expression to restrict by
Returns:
This query instance

and

public Query and(Query.Criterion a,
                 Query.Criterion b)
Creates a conjunction using two specified criterion

Parameters:
a - The left hand side
b - The right hand side
Returns:
This query instance

or

public Query or(Query.Criterion a,
                Query.Criterion b)
Creates a disjunction using two specified criterion

Parameters:
a - The left hand side
b - The right hand side
Returns:
This query instance

list

public List list()
Executes the query returning zero or many results as a list

Returns:
The results

singleResult

public Object singleResult()
Executes the query returning a single result or null

Returns:
The result

setUniqueResult

public void setUniqueResult(boolean uniqueResult)
Deprecated. 

Here purely for compatibility

Parameters:
uniqueResult - Whether it is a unique result

executeQuery

protected abstract List executeQuery(PersistentEntity entity,
                                     Query.Junction criteria)
Subclasses should implement this to provide the concrete implementation of querying

Parameters:
entity - The entity
criteria - The criteria
Returns:
The results