Java Code Examples for com.google.appengine.api.datastore.Query#CompositeFilter

The following examples show how to use com.google.appengine.api.datastore.Query#CompositeFilter . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompositeFilter() {
    Query query = new Query(kindName, rootKey);
    Filter filter = Query.CompositeFilterOperator.and(
        Query.FilterOperator.LESS_THAN_OR_EQUAL.of("intData", 40),
        Query.FilterOperator.GREATER_THAN.of("intData", 0));
    query.setFilter(filter);
    query.addSort("intData", Query.SortDirection.DESCENDING);
    List<Entity> es = service.prepare(query).asList(fo);
    assertEquals("check return count", 2, es.size());
    assertEquals("check query filter", filter, query.getFilter());
    assertEquals("check query key only", false, query.isKeysOnly());

    Query.CompositeFilter cf = (Query.CompositeFilter) query.getFilter();
    assertEquals(2, cf.getSubFilters().size());
    assertEquals(Query.CompositeFilterOperator.AND, cf.getOperator());
}
 
Example 2
Source File: FilterDto.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the tree of {@link FilterDto}s to a tree of {@link FilterDto}s.
 */
public Filter getDatastoreFilter() {

  switch (this.operator) {
  case EQ:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.EQUAL, getOperand());
  case LT:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN, getOperand());
  case LE:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN_OR_EQUAL,
        getOperand());
  case GT:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN,
        getOperand());
  case GE:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN_OR_EQUAL,
        getOperand());
  case NE:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.NOT_EQUAL, getOperand());
  case IN:
    LinkedList<Object> l = new LinkedList<Object>(values);
    l.removeFirst();
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.IN, l);
  case AND:
    return new Query.CompositeFilter(CompositeFilterOperator.AND, getSubfilters(subfilters));
  case OR:
    return new Query.CompositeFilter(CompositeFilterOperator.OR, getSubfilters(subfilters));
  }
  return null;
}
 
Example 3
Source File: FilterDto.java    From solutions-mobile-backend-starter-java with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the tree of {@link FilterDto}s to a tree of {@link FilterDto}s.
 */
public Filter getDatastoreFilter() {

  switch (this.operator) {
  case EQ:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.EQUAL, getOperand());
  case LT:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN, getOperand());
  case LE:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN_OR_EQUAL,
        getOperand());
  case GT:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN,
        getOperand());
  case GE:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN_OR_EQUAL,
        getOperand());
  case NE:
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.NOT_EQUAL, getOperand());
  case IN:
    LinkedList<Object> l = new LinkedList<Object>(values);
    l.removeFirst();
    return new Query.FilterPredicate(getPropName(), Query.FilterOperator.IN, l);
  case AND:
    return new Query.CompositeFilter(CompositeFilterOperator.AND, getSubfilters(subfilters));
  case OR:
    return new Query.CompositeFilter(CompositeFilterOperator.OR, getSubfilters(subfilters));
  }
  return null;
}
 
Example 4
Source File: CommentManagerNoSql.java    From solutions-photo-sharing-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Comment> getComments(Photo photo) {
  Query query = new Query(getKind());
  Query.Filter photoIdFilter =
      new Query.FilterPredicate(CommentNoSql.FIELD_NAME_PHOTO_ID,
          FilterOperator.EQUAL, photo.getId());
  List<Filter> filters = Arrays.asList(photoIdFilter, new Query.FilterPredicate(
      CommentNoSql.FIELD_NAME_PHOTO_OWNER_ID, FilterOperator.EQUAL, photo.getOwnerId()));
  Filter filter = new Query.CompositeFilter(CompositeFilterOperator.AND, filters);
  query.setFilter(filter);
  query.addSort(CommentNoSql.FIELD_NAME_TIMESTAMP, SortDirection.DESCENDING);
  FetchOptions options = FetchOptions.Builder.withDefaults();
  return queryEntities(query, options);
}
 
Example 5
Source File: PhotoManagerNoSql.java    From solutions-photo-sharing-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Photo> getSharedPhotos(String userId) {
  Query query = new Query(getKind());
  Query.Filter ownerFilter =
      new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_OWNER_ID, FilterOperator.NOT_EQUAL, userId);
  List<Query.Filter> filterList =
      Arrays.asList(ownerFilter,
          new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_SHARED, FilterOperator.EQUAL, true),
          new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE, FilterOperator.EQUAL, true)
          );
  Filter filter = new Query.CompositeFilter(CompositeFilterOperator.AND, filterList);
  query.setFilter(filter);
  FetchOptions options = FetchOptions.Builder.withDefaults();
  return queryEntities(query, options);
}