com.avaje.ebean
Interface ExampleExpression

All Superinterfaces:
Expression, Serializable

public interface ExampleExpression
extends Expression

    

Query by Example expression.

Pass in an example entity and for each non-null scalar properties an expression is added.

By Default this case sensitive, will ignore numeric zero values and will use a Like for string values (you must put in your own wildcards).

To get control over the options you can create an ExampleExpression and set those options such as case insensitive etc.

 
  // 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()
                // pass the bean into the where() clause
                .exampleLike(example)
                // you can add other expressions to the same query
                .gt("id", 2)
                .findList();
  
 
Similarly you can create an ExampleExpression
 Customer example = new Customer();
 example.setName("Rob%"); 
 example.setNotes("%something%");
 
  // create a ExampleExpression with more control 
 ExampleExpression qbe = new ExampleExpression(example, true, LikeType.EQUAL_TO)
                .includeZeros();
                
 List<Customer> list = 
                Ebean.find(Customer.class)
                .where()
                .add(qbe)
                .findList();
 

Author:
Rob Bygrave

Method Summary
 ExampleExpression caseInsensitive()
          Set case insensitive to true.
 ExampleExpression includeZeros()
          By calling this method zero value properties are going to be included in the expression.
 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.
 

Method Detail

includeZeros

ExampleExpression includeZeros()
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.


caseInsensitive

ExampleExpression caseInsensitive()
Set case insensitive to true.


useStartsWith

ExampleExpression useStartsWith()
Use startsWith expression for string properties.


useContains

ExampleExpression useContains()
Use contains expression for string properties.


useEndsWith

ExampleExpression useEndsWith()
Use endsWith expression for string properties.


useEqualTo

ExampleExpression useEqualTo()
Use equal to expression for string properties.



Copyright © 2010. All Rights Reserved.