Package org.hibernate.criterion
Class Example
- java.lang.Object
-
- org.hibernate.criterion.Example
-
- All Implemented Interfaces:
java.io.Serializable,Criterion
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.- 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(java.lang.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(java.lang.String path, java.lang.Object component, CompositeType type, java.util.List<TypedValue> list, Criteria criteria, CriteriaQuery criteriaQuery)protected voidaddPropertyTypedValue(java.lang.Object value, Type type, java.util.List<TypedValue> list)protected voidappendComponentCondition(java.lang.String path, java.lang.Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, java.lang.StringBuilder buf)protected voidappendPropertyCondition(java.lang.String propertyName, java.lang.Object propertyValue, Criteria criteria, CriteriaQuery cq, java.lang.StringBuilder buf)static Examplecreate(java.lang.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(java.lang.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(java.lang.Character escapeCharacter)Set escape character for "like" clause if like matching was enabledExamplesetPropertySelector(Example.PropertySelector selector)Set the property selector to use.java.lang.StringtoSqlString(Criteria criteria, CriteriaQuery criteriaQuery)Render the SQL fragmentjava.lang.StringtoString()
-
-
-
Constructor Detail
-
Example
protected Example(java.lang.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(java.lang.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(java.lang.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 separately 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(java.lang.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 java.lang.String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
Description copied from interface:CriterionRender the SQL fragment- Specified by:
toSqlStringin interfaceCriterion- Parameters:
criteria- The local criteriacriteriaQuery- The overall 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 overall criteria query- Returns:
- The types values (for binding)
-
addPropertyTypedValue
protected void addPropertyTypedValue(java.lang.Object value, Type type, java.util.List<TypedValue> list)
-
addComponentTypedValues
protected void addComponentTypedValues(java.lang.String path, java.lang.Object component, CompositeType type, java.util.List<TypedValue> list, Criteria criteria, CriteriaQuery criteriaQuery)
-
appendPropertyCondition
protected void appendPropertyCondition(java.lang.String propertyName, java.lang.Object propertyValue, Criteria criteria, CriteriaQuery cq, java.lang.StringBuilder buf)
-
appendComponentCondition
protected void appendComponentCondition(java.lang.String path, java.lang.Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, java.lang.StringBuilder buf)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-