public class Example extends Object implements Criterion
Support for query by example.
<pre> List results = session.createCriteria(Parent.class) .add( Example.create(parent).ignoreCase() ) .createCriteria("child") .add( Example.create( parent.getChild() ) ) .list(); </pre>
"Examples" may be mixed and matched with "Expressions" in the same Criteria.
Criteria
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
Example.AllPropertySelector
Property selector that includes all properties
|
static class |
Example.NotNullOrZeroPropertySelector
Property selector that includes only properties that are not
null and non-zero (if numeric) |
static class |
Example.NotNullPropertySelector
Property selector that includes only properties that are not
null |
static interface |
Example.PropertySelector
A strategy for choosing property values for inclusion in the query criteria.
|
Modifier | Constructor and Description |
---|---|
protected |
Example(Object exampleEntity,
Example.PropertySelector selector)
Allow subclasses to instantiate as needed.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addComponentTypedValues(String path,
Object component,
CompositeType type,
List<TypedValue> list,
Criteria criteria,
CriteriaQuery criteriaQuery) |
protected void |
addPropertyTypedValue(Object value,
Type type,
List<TypedValue> list) |
protected void |
appendComponentCondition(String path,
Object component,
CompositeType type,
Criteria criteria,
CriteriaQuery criteriaQuery,
StringBuilder buf) |
protected void |
appendPropertyCondition(String propertyName,
Object propertyValue,
Criteria criteria,
CriteriaQuery cq,
StringBuilder buf) |
static Example |
create(Object exampleEntity)
Create a new Example criterion 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()
Include all properties.
|
Example |
excludeProperty(String name)
Exclude a particular property by name.
|
Example |
excludeZeroes()
Exclude zero-valued properties.
|
TypedValue[] |
getTypedValues(Criteria criteria,
CriteriaQuery criteriaQuery)
Return typed values for all parameters in the rendered SQL fragment
|
Example |
ignoreCase()
Ignore case for all string-valued properties
|
Example |
setEscapeCharacter(Character escapeCharacter)
Set escape character for "like" clause if like matching was enabled
|
Example |
setPropertySelector(Example.PropertySelector selector)
Set the property selector to use.
|
String |
toSqlString(Criteria criteria,
CriteriaQuery criteriaQuery)
Render the SQL fragment
|
String |
toString() |
protected Example(Object exampleEntity, Example.PropertySelector selector)
Allow subclasses to instantiate as needed.
exampleEntity
- The example beanselector
- The property selector to usepublic static Example create(Object exampleEntity)
Create a new Example criterion instance, which includes all non-null properties by default
exampleEntity
- The example bean to use.public Example setEscapeCharacter(Character escapeCharacter)
Set escape character for "like" clause if like matching was enabled
escapeCharacter
- The escape characterthis
, for method chainingenableLike()
public Example enableLike()
Use the "like" operator for all string-valued properties. This form implicitly uses MatchMode.EXACT
this
, for method chainingpublic Example enableLike(MatchMode matchMode)
Use the "like" operator for all string-valued properties
matchMode
- The match mode to use.this
, for method chainingpublic Example ignoreCase()
Ignore case for all string-valued properties
this
, for method chainingpublic Example setPropertySelector(Example.PropertySelector selector)
Set the property selector to use.
The property selector operates separate from excluding a property.
selector
- The selector to usethis
, for method chainingexcludeProperty(java.lang.String)
public Example excludeZeroes()
Exclude zero-valued properties.
Equivalent to calling setPropertySelector(org.hibernate.criterion.Example.PropertySelector)
passing in Example.NotNullOrZeroPropertySelector.INSTANCE
this
, for method chainingsetPropertySelector(org.hibernate.criterion.Example.PropertySelector)
public Example excludeNone()
Include all properties.
Equivalent to calling setPropertySelector(org.hibernate.criterion.Example.PropertySelector)
passing in Example.AllPropertySelector.INSTANCE
this
, for method chainingsetPropertySelector(org.hibernate.criterion.Example.PropertySelector)
public Example excludeProperty(String name)
Exclude a particular property by name.
name
- The name of the property to excludethis
, for method chainingsetPropertySelector(org.hibernate.criterion.Example.PropertySelector)
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
Criterion
Render the SQL fragment
toSqlString
in interface Criterion
criteria
- The local criteriacriteriaQuery
- The overal criteria querypublic TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
Criterion
Return typed values for all parameters in the rendered SQL fragment
getTypedValues
in interface Criterion
criteria
- The local criteriacriteriaQuery
- The overal criteria queryprotected void addPropertyTypedValue(Object value, Type type, List<TypedValue> list)
protected void addComponentTypedValues(String path, Object component, CompositeType type, List<TypedValue> list, Criteria criteria, CriteriaQuery criteriaQuery)
protected void appendPropertyCondition(String propertyName, Object propertyValue, Criteria criteria, CriteriaQuery cq, StringBuilder buf)
protected void appendComponentCondition(String path, Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuilder buf)
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.