public class Example extends Object implements Criterion
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.
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)
exampleEntity
- The example beanselector
- The property selector to usepublic static Example create(Object exampleEntity)
exampleEntity
- The example bean to use.public Example setEscapeCharacter(Character escapeCharacter)
escapeCharacter
- The escape characterthis
, for method chainingenableLike()
public Example enableLike()
MatchMode.EXACT
this
, for method chainingpublic Example enableLike(MatchMode matchMode)
matchMode
- The match mode to use.this
, for method chainingpublic Example ignoreCase()
this
, for method chainingpublic Example setPropertySelector(Example.PropertySelector selector)
selector
- The selector to usethis
, for method chainingexcludeProperty(java.lang.String)
public Example excludeZeroes()
setPropertySelector(org.hibernate.criterion.Example.PropertySelector)
passing in Example.NotNullOrZeroPropertySelector.INSTANCE
this
, for method chainingsetPropertySelector(org.hibernate.criterion.Example.PropertySelector)
public Example excludeNone()
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)
name
- The name of the property to excludethis
, for method chainingsetPropertySelector(org.hibernate.criterion.Example.PropertySelector)
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
Criterion
toSqlString
in interface Criterion
criteria
- The local criteriacriteriaQuery
- The overall criteria querypublic TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
Criterion
getTypedValues
in interface Criterion
criteria
- The local criteriacriteriaQuery
- The overall 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-2021 Red Hat, Inc. All Rights Reserved.