Top Description Inners Fields Constructors Methods
org.hibernate.criterion

public Class Example

extends Object
implements Criterion
Class Inheritance
All Implemented Interfaces
org.hibernate.criterion.Criterion, java.io.Serializable
Imports
java.io.Serializable, java.util.ArrayList, .HashSet, .List, .Set, org.hibernate.Criteria, .EntityMode, .HibernateException, org.hibernate.engine.TypedValue, org.hibernate.persister.entity.EntityPersister, org.hibernate.type.CompositeType, .Type, org.hibernate.util.StringHelper

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
org.hibernate.Criteria

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
pack-priv static class
public static interface
Example.PropertySelector

A strategy for choosing property values for inclusion in the query criteria

Field Summary

Modifier and TypeField and Description
private static final Example.PropertySelector
private final Object
private Character
private final Set<E>
private boolean
private boolean
private MatchMode
private static final Example.PropertySelector
private static final Example.PropertySelector
private Example.PropertySelector
private static final Object[]

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected void
addComponentTypedValues(String path, Object component, CompositeType type, List<E> list, Criteria criteria, CriteriaQuery criteriaQuery)

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

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

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

public static Example

Returns:

a new instance of Example
create
(Object entity)

Create a new instance, which includes all non-null properties by default

public Example
enableLike(MatchMode matchMode)

Use the "like" operator for all string-valued properties

public Example
enableLike()

Use the "like" operator for all string-valued properties

public Example
excludeNone()

Don't exclude null or zero-valued properties

public Example
excludeProperty(String name)

Exclude a particular named property

public Example
excludeZeroes()

Exclude zero-valued properties

private EntityMode
getEntityMode(Criteria criteria, CriteriaQuery criteriaQuery)

public TypedValue[]
getTypedValues(Criteria
The local criteria
criteria
,
CriteriaQuery
The overal criteria query
criteriaQuery
)

Implements org.hibernate.criterion.Criterion.getTypedValues.

Return typed values for all parameters in the rendered SQL fragment
public Example
ignoreCase()

Ignore case for all string-valued properties

private boolean
isPropertyIncluded(Object value, String name, Type type)

public Example
setEscapeCharacter(Character escapeCharacter)

Set escape character for "like" clause

public Example
setPropertySelector(Example.PropertySelector selector)

Set the property selector

public String
toSqlString(Criteria
The local criteria
criteria
,
CriteriaQuery
The overal criteria query
criteriaQuery
)

Implements org.hibernate.criterion.Criterion.toSqlString.

Render the SQL fragment
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ALLback to summary
private static final Example.PropertySelector ALL
entityback to summary
private final Object entity
escapeCharacterback to summary
private Character escapeCharacter
excludedPropertiesback to summary
private final Set<E> excludedProperties
isIgnoreCaseEnabledback to summary
private boolean isIgnoreCaseEnabled
isLikeEnabledback to summary
private boolean isLikeEnabled
matchModeback to summary
private MatchMode matchMode
NOT_NULLback to summary
private static final Example.PropertySelector NOT_NULL
NOT_NULL_OR_ZEROback to summary
private static final Example.PropertySelector NOT_NULL_OR_ZERO
selectorback to summary
private Example.PropertySelector selector
TYPED_VALUESback to summary
private static final Object[] TYPED_VALUES

Constructor Detail

Exampleback to summary
protected Example(Object entity, Example.PropertySelector selector)

Method Detail

addComponentTypedValuesback to summary
protected void addComponentTypedValues(String path, Object component, CompositeType type, List<E> list, Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException
addPropertyTypedValueback to summary
protected void addPropertyTypedValue(Object value, Type type, List<E> list)
appendComponentConditionback to summary
protected void appendComponentCondition(String path, Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuffer buf) throws HibernateException
appendPropertyConditionback to summary
protected void appendPropertyCondition(String propertyName, Object propertyValue, Criteria criteria, CriteriaQuery cq, StringBuffer buf) throws HibernateException
createback to summary
public static Example create(Object entity)

Create a new instance, which includes all non-null properties by default

Returns:Example

a new instance of Example

enableLikeback to summary
public Example enableLike(MatchMode matchMode)

Use the "like" operator for all string-valued properties

enableLikeback to summary
public Example enableLike()

Use the "like" operator for all string-valued properties

excludeNoneback to summary
public Example excludeNone()

Don't exclude null or zero-valued properties

excludePropertyback to summary
public Example excludeProperty(String name)

Exclude a particular named property

excludeZeroesback to summary
public Example excludeZeroes()

Exclude zero-valued properties

getEntityModeback to summary
private EntityMode getEntityMode(Criteria criteria, CriteriaQuery criteriaQuery)
getTypedValuesback to summary
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException

Implements org.hibernate.criterion.Criterion.getTypedValues.

Doc from org.hibernate.criterion.Criterion.getTypedValues.

Return typed values for all parameters in the rendered SQL fragment

Parameters
criteria:Criteria

The local criteria

criteriaQuery:CriteriaQuery

The overal criteria query

Returns:TypedValue[]

The types values (for binding)

Exceptions
HibernateException:
Problem determining types.
ignoreCaseback to summary
public Example ignoreCase()

Ignore case for all string-valued properties

isPropertyIncludedback to summary
private boolean isPropertyIncluded(Object value, String name, Type type)
setEscapeCharacterback to summary
public Example setEscapeCharacter(Character escapeCharacter)

Set escape character for "like" clause

setPropertySelectorback to summary
public Example setPropertySelector(Example.PropertySelector selector)

Set the property selector

toSqlStringback to summary
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException

Implements org.hibernate.criterion.Criterion.toSqlString.

Doc from org.hibernate.criterion.Criterion.toSqlString.

Render the SQL fragment

Parameters
criteria:Criteria

The local criteria

criteriaQuery:CriteriaQuery

The overal criteria query

Returns:String

The generated SQL fragment

Exceptions
HibernateException:
Problem during rendering.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

org.hibernate.criterion back to summary

pack-priv final Class Example.AllPropertySelector

extends Object
implements PropertySelector
Class Inheritance
All Implemented Interfaces
org.hibernate.criterion.Example.PropertySelector, java.io.Serializable

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AllPropertySelectorback to summary
pack-priv AllPropertySelector()

Method Detail

includeback to summary
public boolean include(Object object, String propertyName, Type type)

Implements org.hibernate.criterion.Example.PropertySelector.include.

readResolveback to summary
private Object readResolve()
org.hibernate.criterion back to summary

pack-priv final Class Example.NotNullOrZeroPropertySelector

extends Object
implements PropertySelector
Class Inheritance
  • java.lang.Object
  • org.hibernate.criterion.Example.NotNullOrZeroPropertySelector
All Implemented Interfaces
org.hibernate.criterion.Example.PropertySelector, java.io.Serializable

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NotNullOrZeroPropertySelectorback to summary
pack-priv NotNullOrZeroPropertySelector()

Method Detail

includeback to summary
public boolean include(Object object, String propertyName, Type type)

Implements org.hibernate.criterion.Example.PropertySelector.include.

readResolveback to summary
private Object readResolve()
org.hibernate.criterion back to summary

pack-priv final Class Example.NotNullPropertySelector

extends Object
implements PropertySelector
Class Inheritance
All Implemented Interfaces
org.hibernate.criterion.Example.PropertySelector, java.io.Serializable

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NotNullPropertySelectorback to summary
pack-priv NotNullPropertySelector()

Method Detail

includeback to summary
public boolean include(Object object, String propertyName, Type type)

Implements org.hibernate.criterion.Example.PropertySelector.include.

readResolveback to summary
private Object readResolve()
org.hibernate.criterion back to summary

public Interface Example.PropertySelector

extends Serializable
Known Direct Implementers
org.hibernate.criterion.Example.AllPropertySelector, org.hibernate.criterion.Example.NotNullPropertySelector, org.hibernate.criterion.Example.NotNullOrZeroPropertySelector

A strategy for choosing property values for inclusion in the query criteria

Method Summary

Modifier and TypeMethod and Description
public boolean
include(Object propertyValue, String propertyName, Type type)

Method Detail

includeback to summary
public boolean include(Object propertyValue, String propertyName, Type type)