Adelin
Adelin

Reputation: 18961

How to use the composite filter of app-engine data store queries?

I have the this function:

@Override
  public List<Expense> getExpensesBetween(Date firstDate, Date secondDate) {

    Query query = new Query(expenseEntityKind);

    query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, secondDate);

    query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, firstDate);

    Iterable<Entity> entities = service.prepare(query).asIterable();

    return getReturnedExpenses(entities);
  }

I want to return all the expenses between two date i.e greater than or equal 2012-05-01 AND less than or equal 2012-06-01. I took a look at the documentations of Google app-engine. It says that we must use Composite Filters. Google documentations: " However, if you want to set more than one filter on a query, you must use CompositeFilter. You must have at least two filters to use CompositeFilter. However, this documentations seems to be old and i didn't find any function called setFilter();. Any suggestion how to create a composite filter ? I use App-engine sdk 1.6.6. Thanks in advance.

Upvotes: 0

Views: 1796

Answers (2)

Bikram
Bikram

Reputation: 98

The following is taken from https://cloud.google.com/appengine/docs/java/datastore/queries which might be helpful here

Filter heightMinFilter =
  new FilterPredicate("height",
                      FilterOperator.GREATER_THAN_OR_EQUAL,
                      minHeight);

Filter heightMaxFilter =
  new FilterPredicate("height",
                      FilterOperator.LESS_THAN_OR_EQUAL,
                      maxHeight);

//Use CompositeFilter to combine multiple filters
Filter heightRangeFilter =
  CompositeFilterOperator.and(heightMinFilter, heightMaxFilter);

Upvotes: 1

bebo
bebo

Reputation: 114

The documentation you are looking is for the newest version (1.7.0). That features have been just introduced. Here an example of how to use CompositeFilter (1.7.0 also).

Upvotes: 0

Related Questions