com.avaje.ebean
Interface Filter<T>

Type Parameters:
T - the entity bean type

public interface Filter<T>

Provides support for filtering and sorting lists of entities without going back to the database.

That is, it uses local in-memory sorting and filtering of a list of entity beans. It is not used in a Database query or invoke a Database query.

You can optionally specify a sortByClause and if so, the sort will always execute prior to the filter expressions. You can specify any number of filter expressions and they are effectively joined by logical "AND".

The result of the filter method will leave the original list unmodified and return a new List instance.

 
        // get a list of entities (query execution statistics in this case)
 
        List<MetaQueryStatistic> list =
                Ebean.find(MetaQueryStatistic.class).findList();
 
        long nowMinus24Hrs = System.currentTimeMillis() -24*(1000*60*60);
 
        // sort and filter the list returning a filtered list...
 
        List<MetaQueryStatistic> filteredList =
           Ebean.filter(MetaQueryStatistic.class) 
                        .sort("avgTimeMicros desc")
                        .gt("executionCount", 0) 
                        .gt("lastQueryTime", nowMinus24Hrs)
                        .eq("autofetchTuned", true) 
                        .maxRows(10) 
                        .filter(list);
 
 

The propertyNames can traverse the object graph (e.g. customer.name) by using dot notation. If any point during the object graph traversal to get a property value is null then null is returned.

        // examples of property names that 
        // ... will traverse the object graph
        // ... where customer is a property of our bean

        customer.name
        customer.shippingAddress.city
 

 
        // get a list of entities (query execution statistics)
 
        List<Order> orders =
                        Ebean.find(Order.class).findList();
 
 
        // Apply a filter...
 
        List<Order> filteredOrders =
                Ebean.filter(Order.class) 
                        .startsWith("customer.name", "Rob")
                        .eq("customer.shippingAddress.city", "Auckland")
                        .filter(orders);
 
 


Method Summary
 Filter<T> between(String propertyName, Object value1, Object value2)
          Between - property between the two given values.
 Filter<T> contains(String propertyName, String value)
          Contains - property contains the string "value".
 Filter<T> endsWith(String propertyName, String value)
          Ends With.
 Filter<T> eq(String prop, Object value)
          Equal To - property equal to the given value.
 List<T> filter(List<T> sourceList)
          Apply the filter to the list returning a new list of the matching elements in the sorted order.
 Filter<T> ge(String propertyName, Object value)
          Greater Than or Equal to - property greater than or equal to the given value.
 Filter<T> gt(String propertyName, Object value)
          Greater Than - property greater than the given value.
 Filter<T> icontains(String propertyName, String value)
          Case insensitive Contains.
 Filter<T> iendsWith(String propertyName, String value)
          Case insensitive Ends With.
 Filter<T> ieq(String propertyName, String value)
          Case Insensitive Equal To.
 Filter<T> in(String propertyName, Set<?> values)
          In - property has a value contained in the set of values.
 Filter<T> isNotNull(String propertyName)
          Is Not Null - property is not null.
 Filter<T> isNull(String propertyName)
          Is Null - property is null.
 Filter<T> istartsWith(String propertyName, String value)
          Case insensitive Starts With.
 Filter<T> le(String propertyName, Object value)
          Less Than or Equal to - property less than or equal to the given value.
 Filter<T> lt(String propertyName, Object value)
          Less Than - property less than the given value.
 Filter<T> maxRows(int maxRows)
          Specify the maximum number of rows/elements to return.
 Filter<T> ne(String propertyName, Object value)
          Not Equal To - property not equal to the given value.
 Filter<T> sort(String sortByClause)
          Specify a sortByClause.
 Filter<T> startsWith(String propertyName, String value)
          Starts With.
 

Method Detail

sort

Filter<T> sort(String sortByClause)
Specify a sortByClause.

The sort (if specified) will always execute first followed by the filter expressions.

Refer to Ebean.sort(List, String) for more detail.


maxRows

Filter<T> maxRows(int maxRows)
Specify the maximum number of rows/elements to return.


eq

Filter<T> eq(String prop,
             Object value)
Equal To - property equal to the given value.


ne

Filter<T> ne(String propertyName,
             Object value)
Not Equal To - property not equal to the given value.


ieq

Filter<T> ieq(String propertyName,
              String value)
Case Insensitive Equal To.


between

Filter<T> between(String propertyName,
                  Object value1,
                  Object value2)
Between - property between the two given values.


gt

Filter<T> gt(String propertyName,
             Object value)
Greater Than - property greater than the given value.


ge

Filter<T> ge(String propertyName,
             Object value)
Greater Than or Equal to - property greater than or equal to the given value.


lt

Filter<T> lt(String propertyName,
             Object value)
Less Than - property less than the given value.


le

Filter<T> le(String propertyName,
             Object value)
Less Than or Equal to - property less than or equal to the given value.


isNull

Filter<T> isNull(String propertyName)
Is Null - property is null.


isNotNull

Filter<T> isNotNull(String propertyName)
Is Not Null - property is not null.


startsWith

Filter<T> startsWith(String propertyName,
                     String value)
Starts With.


istartsWith

Filter<T> istartsWith(String propertyName,
                      String value)
Case insensitive Starts With.


endsWith

Filter<T> endsWith(String propertyName,
                   String value)
Ends With.


iendsWith

Filter<T> iendsWith(String propertyName,
                    String value)
Case insensitive Ends With.


contains

Filter<T> contains(String propertyName,
                   String value)
Contains - property contains the string "value".


icontains

Filter<T> icontains(String propertyName,
                    String value)
Case insensitive Contains.


in

Filter<T> in(String propertyName,
             Set<?> values)
In - property has a value contained in the set of values.


filter

List<T> filter(List<T> sourceList)
Apply the filter to the list returning a new list of the matching elements in the sorted order.

The sourceList will remain unmodified.

Returns:
Returns a new list with the sorting and filters applied.


Copyright © 2010. All Rights Reserved.