Package org.hibernate.criterion
Class Example
- java.lang.Object
-
- org.hibernate.criterion.Example
-
- All Implemented Interfaces:
Serializable,Criterion
public class Example extends 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.- See Also:
Criteria, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExample.AllPropertySelectorProperty selector that includes all propertiesstatic classExample.NotNullOrZeroPropertySelectorProperty selector that includes only properties that are notnulland non-zero (if numeric)static classExample.NotNullPropertySelectorProperty selector that includes only properties that are notnullstatic interfaceExample.PropertySelectorA strategy for choosing property values for inclusion in the query criteria.
-
Constructor Summary
Constructors Modifier Constructor Description protectedExample(Object exampleEntity, Example.PropertySelector selector)Allow subclasses to instantiate as needed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddComponentTypedValues(String path, Object component, CompositeType type, List<TypedValue> list, Criteria criteria, CriteriaQuery criteriaQuery)protected voidaddPropertyTypedValue(Object value, Type type, List<TypedValue> list)protected voidappendComponentCondition(String path, Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuilder buf)protected voidappendPropertyCondition(String propertyName, Object propertyValue, Criteria criteria, CriteriaQuery cq, StringBuilder buf)static Examplecreate(Object exampleEntity)Create a new Example criterion instance, which includes all non-null properties by defaultExampleenableLike()Use the "like" operator for all string-valued properties.ExampleenableLike(MatchMode matchMode)Use the "like" operator for all string-valued propertiesExampleexcludeNone()Include all properties.ExampleexcludeProperty(String name)Exclude a particular property by name.ExampleexcludeZeroes()Exclude zero-valued properties.TypedValue[]getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)Return typed values for all parameters in the rendered SQL fragmentExampleignoreCase()Ignore case for all string-valued propertiesExamplesetEscapeCharacter(Character escapeCharacter)Set escape character for "like" clause if like matching was enabledExamplesetPropertySelector(Example.PropertySelector selector)Set the property selector to use.StringtoSqlString(Criteria criteria, CriteriaQuery criteriaQuery)Render the SQL fragmentStringtoString()
-
-
-
Constructor Detail
-
Example
protected Example(Object exampleEntity, Example.PropertySelector selector)
Allow subclasses to instantiate as needed.- Parameters:
exampleEntity- The example beanselector- The property selector to use
-
-
Method Detail
-
create
public static Example create(Object exampleEntity)
Create a new Example criterion instance, which includes all non-null properties by default- Parameters:
exampleEntity- The example bean to use.- Returns:
- a new instance of Example
-
setEscapeCharacter
public Example setEscapeCharacter(Character escapeCharacter)
Set escape character for "like" clause if like matching was enabled- Parameters:
escapeCharacter- The escape character- Returns:
this, for method chaining- See Also:
enableLike()
-
enableLike
public Example enableLike()
Use the "like" operator for all string-valued properties. This form implicitly usesMatchMode.EXACT- Returns:
this, for method chaining
-
enableLike
public Example enableLike(MatchMode matchMode)
Use the "like" operator for all string-valued properties- Parameters:
matchMode- The match mode to use.- Returns:
this, for method chaining
-
ignoreCase
public Example ignoreCase()
Ignore case for all string-valued properties- Returns:
this, for method chaining
-
setPropertySelector
public Example setPropertySelector(Example.PropertySelector selector)
Set the property selector to use. The property selector operates separate from excluding a property.- Parameters:
selector- The selector to use- Returns:
this, for method chaining- See Also:
excludeProperty(java.lang.String)
-
excludeZeroes
public Example excludeZeroes()
Exclude zero-valued properties. Equivalent to callingsetPropertySelector(org.hibernate.criterion.Example.PropertySelector)passing inExample.NotNullOrZeroPropertySelector.INSTANCE- Returns:
this, for method chaining- See Also:
setPropertySelector(org.hibernate.criterion.Example.PropertySelector)
-
excludeNone
public Example excludeNone()
Include all properties. Equivalent to callingsetPropertySelector(org.hibernate.criterion.Example.PropertySelector)passing inExample.AllPropertySelector.INSTANCE- Returns:
this, for method chaining- See Also:
setPropertySelector(org.hibernate.criterion.Example.PropertySelector)
-
excludeProperty
public Example excludeProperty(String name)
Exclude a particular property by name.- Parameters:
name- The name of the property to exclude- Returns:
this, for method chaining- See Also:
setPropertySelector(org.hibernate.criterion.Example.PropertySelector)
-
toSqlString
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
Description copied from interface:CriterionRender the SQL fragment- Specified by:
toSqlStringin interfaceCriterion- Parameters:
criteria- The local criteriacriteriaQuery- The overal criteria query- Returns:
- The generated SQL fragment
-
getTypedValues
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
Description copied from interface:CriterionReturn typed values for all parameters in the rendered SQL fragment- Specified by:
getTypedValuesin interfaceCriterion- Parameters:
criteria- The local criteriacriteriaQuery- The overal criteria query- Returns:
- The types values (for binding)
-
addPropertyTypedValue
protected void addPropertyTypedValue(Object value, Type type, List<TypedValue> list)
-
addComponentTypedValues
protected void addComponentTypedValues(String path, Object component, CompositeType type, List<TypedValue> list, Criteria criteria, CriteriaQuery criteriaQuery)
-
appendPropertyCondition
protected void appendPropertyCondition(String propertyName, Object propertyValue, Criteria criteria, CriteriaQuery cq, StringBuilder buf)
-
appendComponentCondition
protected void appendComponentCondition(String path, Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuilder buf)
-
-