Class DefaultExampleExpression
- java.lang.Object
-
- io.ebeaninternal.server.expression.DefaultExampleExpression
-
- All Implemented Interfaces:
ExampleExpression
,Expression
,SpiExpression
public class DefaultExampleExpression extends Object implements SpiExpression, ExampleExpression
A "Query By Example" type of expression.Pass in an example entity and for each non-null scalar properties an expression is added.
// create an example bean and set the properties // with the query parameters you want Customer example = new Customer(); example.setName("Rob%"); example.setNotes("%something%"); List<Customer> list = Ebean.find(Customer.class) .where() .exampleLike(example) .findList();
-
-
Field Summary
-
Fields inherited from interface io.ebeaninternal.api.SpiExpression
SQL_FALSE, SQL_TRUE
-
-
Constructor Summary
Constructors Constructor Description DefaultExampleExpression(EntityBean entity, boolean caseInsensitive, LikeType likeType)
Construct the query by example expression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBindValues(SpiExpressionRequest request)
Adds bind values to the request.void
addSql(SpiExpressionRequest request)
Generates and adds the sql to the request.ExampleExpression
caseInsensitive()
Set case insensitive to true.void
containsMany(BeanDescriptor<?> desc, ManyWhereJoins whereManyJoins)
Process "Many" properties populating ManyWhereJoins.SpiExpression
copyForPlanKey()
Return a copy of the expression for use in the query plan key.Object
getIdEqualTo(String idName)
Return the bind Id value if this is a "equal to" expression for the id property.ExampleExpression
includeZeros()
By calling this method zero value properties are going to be included in the expression.boolean
isSameByBind(SpiExpression other)
Return true if the expression is the same with respect to bind values.boolean
naturalKey(NaturalKeyQueryData<?> data)
Check for match to a natural key query returning false if it doesn't match.String
nestedPath(BeanDescriptor<?> desc)
Return the nested path for this expression.void
prepareExpression(BeanQueryRequest<?> request)
Prepare the expression.int
queryBindHash()
Return a hash for the actual bind values used.void
queryPlanHash(StringBuilder builder)
Return a hash for AutoTune query identification.void
simplify()
Simplify nested expressions if possible.ExampleExpression
useContains()
Use contains expression for string properties.ExampleExpression
useEndsWith()
Use endsWith expression for string properties.ExampleExpression
useEqualTo()
Use equal to expression for string properties.ExampleExpression
useStartsWith()
Use startsWith expression for string properties.void
validate(SpiExpressionValidation validation)
Validate all the properties/paths associated with this expression.void
writeDocQuery(DocQueryContext context)
Write the expression as an elastic search expression.
-
-
-
Constructor Detail
-
DefaultExampleExpression
public DefaultExampleExpression(EntityBean entity, boolean caseInsensitive, LikeType likeType)
Construct the query by example expression.- Parameters:
entity
- the example entity with non null property valuescaseInsensitive
- if true use case insensitive expressionslikeType
- the type of Like wild card used
-
-
Method Detail
-
naturalKey
public boolean naturalKey(NaturalKeyQueryData<?> data)
Description copied from interface:SpiExpression
Check for match to a natural key query returning false if it doesn't match.- Specified by:
naturalKey
in interfaceSpiExpression
-
simplify
public void simplify()
Description copied from interface:SpiExpression
Simplify nested expressions if possible.- Specified by:
simplify
in interfaceSpiExpression
-
writeDocQuery
public void writeDocQuery(DocQueryContext context) throws IOException
Description copied from interface:SpiExpression
Write the expression as an elastic search expression.- Specified by:
writeDocQuery
in interfaceSpiExpression
- Throws:
IOException
-
getIdEqualTo
public Object getIdEqualTo(String idName)
Description copied from interface:SpiExpression
Return the bind Id value if this is a "equal to" expression for the id property.- Specified by:
getIdEqualTo
in interfaceSpiExpression
-
copyForPlanKey
public SpiExpression copyForPlanKey()
Description copied from interface:SpiExpression
Return a copy of the expression for use in the query plan key.- Specified by:
copyForPlanKey
in interfaceSpiExpression
-
nestedPath
public String nestedPath(BeanDescriptor<?> desc)
Description copied from interface:SpiExpression
Return the nested path for this expression.- Specified by:
nestedPath
in interfaceSpiExpression
-
containsMany
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins whereManyJoins)
Description copied from interface:SpiExpression
Process "Many" properties populating ManyWhereJoins.Predicates on Many properties require an extra independent join clause.
- Specified by:
containsMany
in interfaceSpiExpression
-
prepareExpression
public void prepareExpression(BeanQueryRequest<?> request)
Description copied from interface:SpiExpression
Prepare the expression. For example, compile sub-query expressions etc.- Specified by:
prepareExpression
in interfaceSpiExpression
-
includeZeros
public ExampleExpression includeZeros()
Description copied from interface:ExampleExpression
By calling this method zero value properties are going to be included in the expression.By default numeric zero values are excluded as they can result from primitive int and long types.
- Specified by:
includeZeros
in interfaceExampleExpression
-
caseInsensitive
public ExampleExpression caseInsensitive()
Description copied from interface:ExampleExpression
Set case insensitive to true.- Specified by:
caseInsensitive
in interfaceExampleExpression
-
useStartsWith
public ExampleExpression useStartsWith()
Description copied from interface:ExampleExpression
Use startsWith expression for string properties.- Specified by:
useStartsWith
in interfaceExampleExpression
-
useContains
public ExampleExpression useContains()
Description copied from interface:ExampleExpression
Use contains expression for string properties.- Specified by:
useContains
in interfaceExampleExpression
-
useEndsWith
public ExampleExpression useEndsWith()
Description copied from interface:ExampleExpression
Use endsWith expression for string properties.- Specified by:
useEndsWith
in interfaceExampleExpression
-
useEqualTo
public ExampleExpression useEqualTo()
Description copied from interface:ExampleExpression
Use equal to expression for string properties.- Specified by:
useEqualTo
in interfaceExampleExpression
-
validate
public void validate(SpiExpressionValidation validation)
Description copied from interface:SpiExpression
Validate all the properties/paths associated with this expression.- Specified by:
validate
in interfaceSpiExpression
-
addBindValues
public void addBindValues(SpiExpressionRequest request)
Adds bind values to the request.- Specified by:
addBindValues
in interfaceSpiExpression
- Parameters:
request
- the associated request.
-
addSql
public void addSql(SpiExpressionRequest request)
Generates and adds the sql to the request.- Specified by:
addSql
in interfaceSpiExpression
- Parameters:
request
- the associated request.
-
queryPlanHash
public void queryPlanHash(StringBuilder builder)
Return a hash for AutoTune query identification.- Specified by:
queryPlanHash
in interfaceSpiExpression
-
queryBindHash
public int queryBindHash()
Return a hash for the actual bind values used.- Specified by:
queryBindHash
in interfaceSpiExpression
-
isSameByBind
public boolean isSameByBind(SpiExpression other)
Description copied from interface:SpiExpression
Return true if the expression is the same with respect to bind values.- Specified by:
isSameByBind
in interfaceSpiExpression
-
-