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

The following examples show how to use com.google.appengine.api.datastore.Query#Filter . 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: FilterDto.java    From solutions-mobile-backend-starter-java with Apache License 2.0 5 votes vote down vote up
private List<Filter> getSubfilters(List<FilterDto> values) {
  List<Filter> subfilters = new LinkedList<Query.Filter>();
  for (FilterDto cb : values) {
    subfilters.add(cb.getDatastoreFilter());
  }
  return subfilters;
}
 
Example 2
Source File: ListTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testStrFilter() {
    Query q = new Query(kindName);
    q.setAncestor(rootKey);
    Query.Filter filter = Query.CompositeFilterOperator.and(
        new FilterPredicate("stringData", Query.FilterOperator.LESS_THAN, "qqq"),
        new FilterPredicate("stringData", Query.FilterOperator.GREATER_THAN, "mmm"));
    q.setFilter(filter);
    q.addSort("stringData", Query.SortDirection.ASCENDING);
    assertEquals(2, service.prepare(q).countEntities(fo));
    List<Entity> elist = service.prepare(q).asList(fo);
    assertEquals(Arrays.asList("abc", "xyz", "mno"), elist.get(0).getProperty("stringData"));
    assertEquals(Arrays.asList("ppp", "iii", "ddd"), elist.get(1).getProperty("stringData"));
}
 
Example 3
Source File: ListTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
/**
 * Google issueId:1458158
 */
@Test
public void testIntFilter() {
    Query q = new Query(kindName);
    Query.Filter filter = Query.CompositeFilterOperator.and(
        new FilterPredicate("intData1", Query.FilterOperator.LESS_THAN, 20),
        new FilterPredicate("intData1", Query.FilterOperator.GREATER_THAN, 1),
        new FilterPredicate("intData1", Query.FilterOperator.EQUAL, null));
    q.setFilter(filter);
    q.addSort("intData1", Query.SortDirection.ASCENDING);
    q.setAncestor(rootKey);
    assertEquals(1, service.prepare(q).countEntities(fo));
    List<Entity> elist = service.prepare(q).asList(fo);
    assertEquals(Arrays.asList(1L, 10L, null), elist.get(0).getProperty("intData1"));
}
 
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> getActivePhotos() {
  Query query = new Query(getKind());
  Query.Filter filter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE,
      FilterOperator.EQUAL, true);
  query.addSort(PhotoNoSql.FIELD_NAME_UPLOAD_TIME, SortDirection.DESCENDING);
  query.setFilter(filter);
  FetchOptions options = FetchOptions.Builder.withDefaults();
  return queryEntities(query, options);
}
 
Example 6
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> getOwnedPhotos(String userId) {
  Query query = new Query(getKind());
  query.setAncestor(userManager.createDemoUserKey(userId));
  Query.Filter filter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE,
      FilterOperator.EQUAL, true);
  query.setFilter(filter);
  FetchOptions options = FetchOptions.Builder.withDefaults();
  return queryEntities(query, options);
}
 
Example 7
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);
}
 
Example 8
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> getDeactivedPhotos() {
  Query query = new Query(getKind());
  Query.Filter filter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE,
      FilterOperator.EQUAL, false);
  query.setFilter(filter);
  FetchOptions options = FetchOptions.Builder.withDefaults();
  return queryEntities(query, options);
}
 
Example 9
Source File: QueryTestBase.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
private Query createQuery(Query.Filter filter) {
    return createQuery().setFilter(filter);
}
 
Example 10
Source File: QueryTestBase.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
private Query createQuery(Query.Filter filter, Key parent) {
    return createQuery().setAncestor(parent).setFilter(filter);
}
 
Example 11
Source File: QueryTestBase.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
protected Set<Entity> whenFilteringWith(Query.Filter filter) {
    Query query = createQuery(filter);
    List<Entity> results = service.prepare(query).asList(withDefaults());
    return new HashSet<Entity>(results);
}
 
Example 12
Source File: QueryTestBase.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
protected Set<Entity> whenFilteringWith(Query.Filter filter, Key parent) {
    Query query = createQuery(filter, parent);
    List<Entity> results = service.prepare(query).asList(withDefaults());
    return new HashSet<Entity>(results);
}