|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovy.lang.GroovyObjectSupport grails.orm.HibernateCriteriaBuilder
public class HibernateCriteriaBuilder
Wraps the Hibernate Criteria API in a builder. The builder can be retrieved through the "createCriteria()" dynamic static method of Grails domain classes (Example in Groovy):
def c = Account.createCriteria() def results = c { projections { groupProperty("branch") } like("holderFirstName", "Fred%") and { between("balance", 500, 1000) eq("branch", "London") } maxResults(10) order("holderLastName", "desc") }
The builder can also be instantiated standalone with a SessionFactory and persistent Class instance:
new HibernateCriteriaBuilder(clazz, sessionFactory).list { eq("firstName", "Fred") }
Field Summary | |
---|---|
static String |
AND
|
static String |
BETWEEN
|
static String |
EQUALS
|
static String |
EQUALS_PROPERTY
|
static String |
GREATER_THAN
|
static String |
GREATER_THAN_OR_EQUAL
|
static String |
GREATER_THAN_OR_EQUAL_PROPERTY
|
static String |
GREATER_THAN_PROPERTY
|
static String |
ID_EQUALS
|
static String |
ILIKE
|
static String |
IN
|
static String |
IS_EMPTY
|
static String |
IS_NOT_EMPTY
|
static String |
IS_NOT_NULL
|
static String |
IS_NULL
|
static String |
LESS_THAN
|
static String |
LESS_THAN_OR_EQUAL
|
static String |
LESS_THAN_OR_EQUAL_PROPERTY
|
static String |
LESS_THAN_PROPERTY
|
static String |
LIKE
|
static String |
NOT
|
static String |
NOT_EQUAL
|
static String |
NOT_EQUAL_PROPERTY
|
static String |
OR
|
static String |
ORDER_ASCENDING
|
static String |
ORDER_DESCENDING
|
static String |
SIZE_EQUALS
|
Constructor Summary | |
---|---|
HibernateCriteriaBuilder(Class targetClass,
org.hibernate.SessionFactory sessionFactory)
|
|
HibernateCriteriaBuilder(Class targetClass,
org.hibernate.SessionFactory sessionFactory,
boolean uniqueResult)
|
Method Summary | |
---|---|
void |
avg(String propertyName)
Adds a projection that allows the criteria to return the property average value |
Object |
between(String propertyName,
Object lo,
Object hi)
Creates a "between" Criterion based on the property name and specified lo and hi values |
void |
count(String propertyName)
Adds a projection that allows the criteria to return the property count |
void |
countDistinct(String propertyName)
Adds a projection that allows the criteria to return the distinct property count |
void |
distinct(Collection propertyNames)
A distinct projection that takes a list |
void |
distinct(String propertyName)
A projection that selects a distince property name |
Object |
eq(String propertyName,
Object propertyValue)
Creates an "equals" Criterion based on the specified property name and value |
Object |
eqProperty(String propertyName,
String otherPropertyName)
Creates a Criterion that compares to class properties for equality |
void |
fetchMode(String associationPath,
org.hibernate.FetchMode fetchMode)
Sets the fetch mode of an associated path |
Object |
ge(String propertyName,
Object propertyValue)
Creates a "greater than or equal to" Criterion based on the specified property name and value |
Object |
geProperty(String propertyName,
String otherPropertyName)
Creates a Criterion that tests if the first property is greater than or equal to the second property |
void |
groupProperty(String propertyName)
Adds a projection that allows the criteria's result to be grouped by a property |
Object |
gt(String propertyName,
Object propertyValue)
Creates a "greater than" Criterion based on the specified property name and value |
Object |
gtProperty(String propertyName,
String otherPropertyName)
Creates a Criterion that tests if the first property is greater than the second property |
Object |
ilike(String propertyName,
Object propertyValue)
Creates a Criterion with from the specified property name and "ilike" (a case sensitive version of "like") expression |
Object |
in(String propertyName,
Collection values)
Applys a "in" contrain on the specified property |
Object |
in(String propertyName,
Object[] values)
Applys a "in" contrain on the specified property |
Object |
inList(String propertyName,
Collection values)
Delegates to in as in is a Groovy keyword |
Object |
inList(String propertyName,
Object[] values)
Delegates to in as in is a Groovy keyword |
Object |
invokeMethod(String name,
Object obj)
|
Object |
le(String propertyName,
Object propertyValue)
Creates a "less than or equal to" Criterion based on the specified property name and value |
Object |
leProperty(String propertyName,
String otherPropertyName)
Creates a Criterion that tests if the first property is less than or equal to the second property |
Object |
like(String propertyName,
Object propertyValue)
Creates a Criterion with from the specified property name and "like" expression |
Object |
lt(String propertyName,
Object propertyValue)
Creates a "less than" Criterion based on the specified property name and value |
Object |
ltProperty(String propertyName,
String otherPropertyName)
Creates a Criterion that tests if the first property is less than the second property |
void |
max(String propertyName)
Adds a projection that allows the criteria to retrieve a maximum property value |
void |
min(String propertyName)
Adds a projection that allows the criteria to retrieve a minimum property value |
Object |
ne(String propertyName,
Object propertyValue)
Creates a "not equal" Criterion based on the specified property name and value |
Object |
neProperty(String propertyName,
String otherPropertyName)
Creates a Criterion that compares to class properties for ! |
Object |
notEqual(String propertyName,
Object propertyValue)
|
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 |
void |
property(String propertyName)
A projection that selects a property name |
void |
resultTransformer(org.hibernate.transform.ResultTransformer resultTransformer)
Sets the resultTransformer. |
void |
rowCount()
Adds a projection that allows the criteria to return the row count |
void |
setUniqueResult(boolean uniqueResult)
|
Object |
sizeEq(String propertyName,
int size)
Creates a Criterion that contrains a collection property by size |
void |
sum(String propertyName)
Adds a projection that allows the criteria to retrieve the sum of the results 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 |
---|
public static final String AND
public static final String IS_NULL
public static final String IS_NOT_NULL
public static final String NOT
public static final String OR
public static final String ID_EQUALS
public static final String IS_EMPTY
public static final String IS_NOT_EMPTY
public static final String BETWEEN
public static final String EQUALS
public static final String EQUALS_PROPERTY
public static final String GREATER_THAN
public static final String GREATER_THAN_PROPERTY
public static final String GREATER_THAN_OR_EQUAL
public static final String GREATER_THAN_OR_EQUAL_PROPERTY
public static final String ILIKE
public static final String IN
public static final String LESS_THAN
public static final String LESS_THAN_PROPERTY
public static final String LESS_THAN_OR_EQUAL
public static final String LESS_THAN_OR_EQUAL_PROPERTY
public static final String LIKE
public static final String NOT_EQUAL
public static final String NOT_EQUAL_PROPERTY
public static final String SIZE_EQUALS
public static final String ORDER_DESCENDING
public static final String ORDER_ASCENDING
Constructor Detail |
---|
public HibernateCriteriaBuilder(Class targetClass, org.hibernate.SessionFactory sessionFactory)
public HibernateCriteriaBuilder(Class targetClass, org.hibernate.SessionFactory sessionFactory, boolean uniqueResult)
Method Detail |
---|
public void setUniqueResult(boolean uniqueResult)
public void property(String propertyName)
propertyName
- The name of the propertypublic void distinct(String propertyName)
propertyName
- The property namepublic void distinct(Collection propertyNames)
propertyNames
- The list of distince property namespublic void avg(String propertyName)
propertyName
- The name of the propertypublic void count(String propertyName)
propertyName
- The name of the propertypublic void countDistinct(String propertyName)
propertyName
- The name of the propertypublic void groupProperty(String propertyName)
propertyName
- The name of the propertypublic void max(String propertyName)
propertyName
- The name of the propertypublic void min(String propertyName)
propertyName
- The name of the propertypublic void rowCount()
public void sum(String propertyName)
propertyName
- The name of the propertypublic void fetchMode(String associationPath, org.hibernate.FetchMode fetchMode)
associationPath
- The name of the associated pathfetchMode
- The fetch mode to setpublic void resultTransformer(org.hibernate.transform.ResultTransformer resultTransformer)
resultTransformer
- The result transformer to use.public Object eqProperty(String propertyName, String otherPropertyName)
propertyName
- The first property nameotherPropertyName
- The second property name
public Object neProperty(String propertyName, String otherPropertyName)
propertyName
- The first property nameotherPropertyName
- The second property name
public Object gtProperty(String propertyName, String otherPropertyName)
propertyName
- The first property nameotherPropertyName
- The second property name
public Object geProperty(String propertyName, String otherPropertyName)
propertyName
- The first property nameotherPropertyName
- The second property name
public Object ltProperty(String propertyName, String otherPropertyName)
propertyName
- The first property nameotherPropertyName
- The second property name
public Object leProperty(String propertyName, String otherPropertyName)
propertyName
- The first property nameotherPropertyName
- The second property name
public Object gt(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The property value
public Object ge(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The property value
public Object lt(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The property value
public Object le(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The property value
public Object eq(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The property value
public Object like(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The like value
public Object ilike(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The ilike value
public Object in(String propertyName, Collection values)
propertyName
- The property namevalues
- A collection of values
public Object inList(String propertyName, Collection values)
public Object inList(String propertyName, Object[] values)
public Object in(String propertyName, Object[] values)
propertyName
- The property namevalues
- A collection of values
public Object order(String propertyName)
propertyName
- The property name to order by
public Object order(String propertyName, String direction)
propertyName
- The property name to order bydirection
- Either "asc" for ascending or "desc" for descending
public Object sizeEq(String propertyName, int size)
propertyName
- The property namesize
- The size to constrain by
public Object ne(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The property value
public Object notEqual(String propertyName, Object propertyValue)
public Object between(String propertyName, Object lo, Object hi)
propertyName
- The property namelo
- The low valuehi
- The high value
public Object invokeMethod(String name, Object obj)
invokeMethod
in interface groovy.lang.GroovyObject
invokeMethod
in class groovy.lang.GroovyObjectSupport
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |