|
||||||||||
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 |
RLIKE
|
static String |
SIZE_EQUALS
|
Constructor Summary | |
---|---|
HibernateCriteriaBuilder(Class targetClass,
org.hibernate.SessionFactory sessionFactory)
|
|
HibernateCriteriaBuilder(Class targetClass,
org.hibernate.SessionFactory sessionFactory,
boolean uniqueResult)
|
Method Summary | |
---|---|
protected void |
addProjectionToList(org.hibernate.criterion.Projection propertyProjection,
String alias)
Adds a projection to the projectList for the given alias |
void |
avg(String propertyName)
Adds a projection that allows the criteria to return the property average value |
void |
avg(String propertyName,
String alias)
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 |
org.hibernate.Criteria |
buildCriteria(groovy.lang.Closure criteriaClosure)
|
void |
cache(boolean shouldCache)
Whether to use the query cache |
void |
count(String propertyName)
Adds a projection that allows the criteria to return the property count |
void |
count(String propertyName,
String alias)
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 |
countDistinct(String propertyName,
String alias)
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(Collection propertyNames,
String alias)
A distinct projection that takes a list |
void |
distinct(String propertyName)
A projection that selects a distince property name |
void |
distinct(String propertyName,
String alias)
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 |
org.hibernate.Criteria |
getInstance()
Returns the criteria instance |
void |
groupProperty(String propertyName)
Adds a projection that allows the criteria's result to be grouped by a property |
void |
groupProperty(String propertyName,
String alias)
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)
|
void |
join(String associationPath)
Use a join query |
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 |
void |
lock(boolean shouldLock)
Whether a pessimisick lock should be obtained |
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 |
max(String propertyName,
String alias)
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 |
void |
min(String propertyName,
String alias)
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 |
property(String propertyName,
String alias)
A projection that selects a property name |
void |
resultTransformer(org.hibernate.transform.ResultTransformer resultTransformer)
Sets the resultTransformer. |
Object |
rlike(String propertyName,
Object propertyValue)
Creates a Criterion with from the specified property name and "rlike" (a regular expression version of "like") expression |
void |
rowCount()
Adds a projection that allows the criteria to return the row count |
void |
rowCount(String alias)
Adds a projection that allows the criteria to return the row count |
void |
select(String associationPath)
Use a select query |
void |
setUniqueResult(boolean uniqueResult)
Set whether a unique result should be returned |
Object |
sizeEq(String propertyName,
int size)
Creates a Criterion that contrains a collection property by size |
Object |
sizeGe(String propertyName,
int size)
Creates a Criterion that contrains a collection property to be greater than or equal to the given size |
Object |
sizeGt(String propertyName,
int size)
Creates a Criterion that contrains a collection property to be greater than the given size |
Object |
sizeLe(String propertyName,
int size)
Creates a Criterion that contrains a collection property to be less than or equal to the given size |
Object |
sizeLt(String propertyName,
int size)
Creates a Criterion that contrains a collection property to be less than to the given size |
Object |
sizeNe(String propertyName,
int size)
Creates a Criterion that contrains a collection property to be not equal to the given size |
Object |
sqlRestriction(String sqlRestriction)
Applies a sql restriction to the results to allow something like: def results = Person.withCriteria { sqlRestriction "char_length( first_name ) <= 4" } |
void |
sum(String propertyName)
Adds a projection that allows the criteria to retrieve the sum of the results of a property |
void |
sum(String propertyName,
String alias)
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 RLIKE
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 org.hibernate.Criteria getInstance()
public void setUniqueResult(boolean uniqueResult)
uniqueResult
- True if a unique result should be returnedpublic void property(String propertyName)
propertyName
- The name of the propertypublic void property(String propertyName, String alias)
propertyName
- The name of the propertyalias
- The alias to useprotected void addProjectionToList(org.hibernate.criterion.Projection propertyProjection, String alias)
propertyProjection
- The projectionalias
- The aliaspublic void distinct(String propertyName)
propertyName
- The property namepublic void distinct(String propertyName, String alias)
propertyName
- The property namealias
- The alias to usepublic void distinct(Collection propertyNames)
propertyNames
- The list of distince property namespublic void distinct(Collection propertyNames, String alias)
propertyNames
- The list of distince property namesalias
- The alias to usepublic void avg(String propertyName)
propertyName
- The name of the propertypublic void avg(String propertyName, String alias)
propertyName
- The name of the propertyalias
- The alias to usepublic void join(String associationPath)
associationPath
- The path of the associationpublic void lock(boolean shouldLock)
shouldLock
- True if it shouldpublic void select(String associationPath)
associationPath
- The path of the associationpublic void cache(boolean shouldCache)
shouldCache
- True if the query should be cachedpublic void count(String propertyName)
propertyName
- The name of the propertypublic void count(String propertyName, String alias)
propertyName
- The name of the propertyalias
- The alias to usepublic void countDistinct(String propertyName)
propertyName
- The name of the propertypublic void countDistinct(String propertyName, String alias)
propertyName
- The name of the propertyalias
- The alias to usepublic void groupProperty(String propertyName)
propertyName
- The name of the propertypublic void groupProperty(String propertyName, String alias)
propertyName
- The name of the propertyalias
- The alias to usepublic void max(String propertyName)
propertyName
- The name of the propertypublic void max(String propertyName, String alias)
propertyName
- The name of the propertyalias
- The alias to usepublic void min(String propertyName)
propertyName
- The name of the propertypublic void min(String propertyName, String alias)
alias
- The alias to usepublic void rowCount()
public void rowCount(String alias)
alias
- The alias to usepublic void sum(String propertyName)
propertyName
- The name of the propertypublic void sum(String propertyName, String alias)
propertyName
- The name of the propertyalias
- The alias to usepublic 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 sqlRestriction(String sqlRestriction)
def results = Person.withCriteria { sqlRestriction "char_length( first_name ) <= 4" }
sqlRestriction
- the sql restriction
public Object like(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The like value
public Object rlike(String propertyName, Object propertyValue)
propertyName
- The property namepropertyValue
- The ilike 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 sizeGt(String propertyName, int size)
propertyName
- The property namesize
- The size to constrain by
public Object sizeGe(String propertyName, int size)
propertyName
- The property namesize
- The size to constrain by
public Object sizeLe(String propertyName, int size)
propertyName
- The property namesize
- The size to constrain by
public Object sizeLt(String propertyName, int size)
propertyName
- The property namesize
- The size to constrain by
public Object sizeNe(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
public org.hibernate.Criteria buildCriteria(groovy.lang.Closure criteriaClosure)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |