grails.gorm
Class CriteriaBuilder

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by grails.gorm.CriteriaBuilder
All Implemented Interfaces:
GroovyObject

public class CriteriaBuilder
extends GroovyObjectSupport

Criteria builder implementation that operates against Spring datastore abstraction


Field Summary
static String AND
           
static String ID_EQUALS
           
static String IS_EMPTY
           
static String IS_NOT_EMPTY
           
static String IS_NOT_NULL
           
static String IS_NULL
           
static String NOT
           
static String OR
           
static String ORDER_ASCENDING
           
static String ORDER_DESCENDING
           
 
Constructor Summary
CriteriaBuilder(Class targetClass, Datastore datastore)
           
CriteriaBuilder(Class targetClass, Datastore datastore, Query query)
           
 
Method Summary
 Query.ProjectionList avg(String name)
          Computes the average value of a property
 Query.Criterion between(String propertyName, Object start, Object finish)
          Restricts the results by the given property value range (inclusive)
 void build(Closure criteria)
           
 Query.ProjectionList count()
          Count the number of records returned
 Query.Criterion eq(String propertyName, Object propertyValue)
          Creates an "equals" Criterion based on the specified property name and value.
 Query.Criterion gt(String property, Object value)
          Used to restrict a value to be greater than or equal to the given value
 Query.Criterion gte(String property, Object value)
          Used to restrict a value to be greater than or equal to the given value
 Query.ProjectionList id()
           
 Query.Criterion in(String propertyName, Collection values)
          Creates an "in" Criterion based on the specified property name and list of values.
 Query.Criterion in(String propertyName, Object[] values)
          Creates an "in" Criterion based on the specified property name and list of values.
 Query.Criterion inList(String propertyName, Collection values)
          Creates an "in" Criterion based on the specified property name and list of values.
 Query.Criterion inList(String propertyName, Object[] values)
          Creates an "in" Criterion based on the specified property name and list of values.
 Object invokeMethod(String name, Object obj)
           
 Query.Criterion like(String propertyName, Object propertyValue)
          Creates an "equals" Criterion based on the specified property name and value.
 Query.Criterion lt(String property, Object value)
          Used to restrict a value to be less than or equal to the given value
 Query.Criterion lte(String property, Object value)
          Used to restrict a value to be less than or equal to the given value
 Query.ProjectionList max(String name)
          Computes the max value of a property
 Query.ProjectionList min(String name)
          Computes the min value of a property
 Object order(String propertyName)
          Orders by the specified property name (defaults to ascending)
 Object order(String propertyName, String direction)
          Orders by the specified property name and direction
 Query.ProjectionList property(String name)
          A projection that obtains the value of a property of an entity
 Query.ProjectionList rowCount()
          Count the number of records returned
 Query.ProjectionList sum(String name)
          Computes the sum of a property
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, getProperty, setMetaClass, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORDER_DESCENDING

public static final String ORDER_DESCENDING
See Also:
Constant Field Values

ORDER_ASCENDING

public static final String ORDER_ASCENDING
See Also:
Constant Field Values

AND

public static final String AND
See Also:
Constant Field Values

NOT

public static final String NOT
See Also:
Constant Field Values

OR

public static final String OR
See Also:
Constant Field Values

IS_NULL

public static final String IS_NULL
See Also:
Constant Field Values

IS_NOT_NULL

public static final String IS_NOT_NULL
See Also:
Constant Field Values

ID_EQUALS

public static final String ID_EQUALS
See Also:
Constant Field Values

IS_EMPTY

public static final String IS_EMPTY
See Also:
Constant Field Values

IS_NOT_EMPTY

public static final String IS_NOT_EMPTY
See Also:
Constant Field Values
Constructor Detail

CriteriaBuilder

public CriteriaBuilder(Class targetClass,
                       Datastore datastore)

CriteriaBuilder

public CriteriaBuilder(Class targetClass,
                       Datastore datastore,
                       Query query)
Method Detail

id

public Query.ProjectionList id()

count

public Query.ProjectionList count()
Count the number of records returned

Returns:
The project list

rowCount

public Query.ProjectionList rowCount()
Count the number of records returned

Returns:
The project list

property

public Query.ProjectionList property(String name)
A projection that obtains the value of a property of an entity

Parameters:
name - The name of the property
Returns:
The projection list

sum

public Query.ProjectionList sum(String name)
Computes the sum of a property

Parameters:
name - The name of the property
Returns:
The projection list

min

public Query.ProjectionList min(String name)
Computes the min value of a property

Parameters:
name - The name of the property
Returns:
The projection list

max

public Query.ProjectionList max(String name)
Computes the max value of a property

Parameters:
name - The name of the property
Returns:
The PropertyProjection instance

avg

public Query.ProjectionList avg(String name)
Computes the average value of a property

Parameters:
name - The name of the property
Returns:
The PropertyProjection instance

invokeMethod

public Object invokeMethod(String name,
                           Object obj)
Specified by:
invokeMethod in interface GroovyObject
Overrides:
invokeMethod in class GroovyObjectSupport

eq

public Query.Criterion eq(String propertyName,
                          Object propertyValue)
Creates an "equals" Criterion based on the specified property name and value.

Parameters:
propertyName - The property name
propertyValue - The property value
Returns:
A Criterion instance

between

public Query.Criterion between(String propertyName,
                               Object start,
                               Object finish)
Restricts the results by the given property value range (inclusive)

Parameters:
propertyName - The property name
start - The start of the range
finish - The end of the range
Returns:
A Criterion instance

gte

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

Parameters:
property - The property
value - The value
Returns:
The Criterion instance

gt

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

Parameters:
property - The property
value - The value
Returns:
The Criterion instance

lte

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

Parameters:
property - The property
value - The value
Returns:
The Criterion instance

lt

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

Parameters:
property - The property
value - The value
Returns:
The Criterion instance

like

public Query.Criterion like(String propertyName,
                            Object propertyValue)
Creates an "equals" Criterion based on the specified property name and value.

Parameters:
propertyName - The property name
propertyValue - The property value
Returns:
A Criterion instance

in

public Query.Criterion in(String propertyName,
                          Collection values)
Creates an "in" Criterion based on the specified property name and list of values.

Parameters:
propertyName - The property name
values - The values
Returns:
A Criterion instance

inList

public Query.Criterion inList(String propertyName,
                              Collection values)
Creates an "in" Criterion based on the specified property name and list of values.

Parameters:
propertyName - The property name
values - The values
Returns:
A Criterion instance

inList

public Query.Criterion inList(String propertyName,
                              Object[] values)
Creates an "in" Criterion based on the specified property name and list of values.

Parameters:
propertyName - The property name
values - The values
Returns:
A Criterion instance

in

public Query.Criterion in(String propertyName,
                          Object[] values)
Creates an "in" Criterion based on the specified property name and list of values.

Parameters:
propertyName - The property name
values - The values
Returns:
A Criterion instance

order

public Object order(String propertyName)
Orders by the specified property name (defaults to ascending)

Parameters:
propertyName - The property name to order by
Returns:
A Order instance

order

public Object order(String propertyName,
                    String direction)
Orders by the specified property name and direction

Parameters:
propertyName - The property name to order by
direction - Either "asc" for ascending or "desc" for descending
Returns:
A Order instance

build

public void build(Closure criteria)