org.hibernate.criterion

Class Example

Implemented Interfaces:
Criterion, Serializable

public class Example
extends java.lang.Object
implements Criterion

Support for query by example.
 List results = session.createCriteria(Parent.class)
     .add( Example.create(parent).ignoreCase() )
     .createCriteria("child")
         .add( Example.create( parent.getChild() ) )
     .list();
 
"Examples" may be mixed and matched with "Expressions" in the same Criteria.
Author:
Gavin King
See Also:
Criteria

Nested Class Summary

static interface
Example.PropertySelector
A strategy for choosing property values for inclusion in the query criteria

Constructor Summary

Example(Object entity, Example.PropertySelector selector)

Method Summary

protected void
addComponentTypedValues(String path, Object component, AbstractComponentType type, List list, Criteria criteria, CriteriaQuery criteriaQuery)
protected void
addPropertyTypedValue(Object value, Type type, List list)
protected void
appendComponentCondition(String path, Object component, AbstractComponentType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuffer buf)
protected void
appendPropertyCondition(String propertyName, Object propertyValue, Criteria criteria, CriteriaQuery cq, StringBuffer buf)
static Example
create(Object entity)
Create a new instance, which includes all non-null properties by default
Example
enableLike()
Use the "like" operator for all string-valued properties
Example
enableLike(MatchMode matchMode)
Use the "like" operator for all string-valued properties
Example
excludeNone()
Don't exclude null or zero-valued properties
Example
excludeProperty(String name)
Exclude a particular named property
Example
excludeZeroes()
Exclude zero-valued properties
TypedValue[]
getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
Example
ignoreCase()
Ignore case for all string-valued properties
Example
setEscapeCharacter(Character escapeCharacter)
Set escape character for "like" clause
Example
setPropertySelector(Example.PropertySelector selector)
Set the property selector
String
toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
String
toString()

Constructor Details

Example

protected Example(Object entity,
                  Example.PropertySelector selector)

Method Details

addComponentTypedValues

protected void addComponentTypedValues(String path,
                                       Object component,
                                       AbstractComponentType type,
                                       List list,
                                       Criteria criteria,
                                       CriteriaQuery criteriaQuery)
            throws HibernateException

addPropertyTypedValue

protected void addPropertyTypedValue(Object value,
                                     Type type,
                                     List list)

appendComponentCondition

protected void appendComponentCondition(String path,
                                        Object component,
                                        AbstractComponentType type,
                                        Criteria criteria,
                                        CriteriaQuery criteriaQuery,
                                        StringBuffer buf)
            throws HibernateException

appendPropertyCondition

protected void appendPropertyCondition(String propertyName,
                                       Object propertyValue,
                                       Criteria criteria,
                                       CriteriaQuery cq,
                                       StringBuffer buf)
            throws HibernateException

create

public static Example create(Object entity)
Create a new instance, which includes all non-null properties by default
Parameters:
entity -
Returns:
a new instance of Example

enableLike

public Example enableLike()
Use the "like" operator for all string-valued properties

enableLike

public Example enableLike(MatchMode matchMode)
Use the "like" operator for all string-valued properties

excludeNone

public Example excludeNone()
Don't exclude null or zero-valued properties

excludeProperty

public Example excludeProperty(String name)
Exclude a particular named property

excludeZeroes

public Example excludeZeroes()
Exclude zero-valued properties

getTypedValues

public TypedValue[] getTypedValues(Criteria criteria,
                                   CriteriaQuery criteriaQuery)
            throws HibernateException
Specified by:
getTypedValues in interface Criterion

ignoreCase

public Example ignoreCase()
Ignore case for all string-valued properties

setEscapeCharacter

public Example setEscapeCharacter(Character escapeCharacter)
Set escape character for "like" clause

setPropertySelector

public Example setPropertySelector(Example.PropertySelector selector)
Set the property selector

toSqlString

public String toSqlString(Criteria criteria,
                          CriteriaQuery criteriaQuery)
            throws HibernateException
Specified by:
toSqlString in interface Criterion

toString

public String toString()