com.google.appengine.api.datastore.QueryResultIterable Java Examples

The following examples show how to use com.google.appengine.api.datastore.QueryResultIterable. 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: DeviceSubscription.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes all device subscription entities continuously using task push queue.
 *
 * @param time Threshold time before which entities created will be deleted. If time is null,
 *             current time is used and set as Threshold time.
 * @param cursor Query cursor indicates last query result set position
 */
protected void deleteAllContinuously(Date time, String cursor) {
  if (time == null) {
    time = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
  }

  Query.FilterPredicate timeFilter = new Query.FilterPredicate(PROPERTY_TIMESTAMP,
      FilterOperator.LESS_THAN_OR_EQUAL, time);
  QueryResultIterable<Entity> entities;
  List<Key> keys = new ArrayList<Key> ();
  List<String> subIds = new ArrayList<String> ();
  Query queryAll;

  queryAll = new Query(DeviceSubscription.SUBSCRIPTION_KIND).setFilter(timeFilter);
  FetchOptions options = FetchOptions.Builder.withLimit(BATCH_DELETE_SIZE);
  if (!StringUtility.isNullOrEmpty(cursor)) {
    options.startCursor(Cursor.fromWebSafeString(cursor));
  }

  entities = this.datastoreService.prepare(queryAll).asQueryResultIterable(options);
  if (entities != null && entities.iterator() != null) {
    for (Entity entity : entities) {
      keys.add(entity.getKey());
      String[] ids = new Gson().fromJson((String) entity.getProperty(PROPERTY_SUBSCRIPTION_IDS),
          String[].class);
      subIds.addAll(Arrays.asList(ids));
    }
  }

  if (keys.size() > 0) {
    deleteInBatch(keys);
    enqueueDeleteDeviceSubscription(time, entities.iterator().getCursor().toWebSafeString());
  }
  if (subIds.size() > 0) {
    deletePsiSubscriptions(subIds);
  }
}
 
Example #2
Source File: DeviceSubscription.java    From solutions-mobile-backend-starter-java with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes all device subscription entities continuously using task push queue.
 *
 * @param time Threshold time before which entities created will be deleted. If time is null,
 *             current time is used and set as Threshold time.
 * @param cursor Query cursor indicates last query result set position
 */
protected void deleteAllContinuously(Date time, String cursor) {
  if (time == null) {
    time = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
  }

  Query.FilterPredicate timeFilter = new Query.FilterPredicate(PROPERTY_TIMESTAMP,
      FilterOperator.LESS_THAN_OR_EQUAL, time);
  QueryResultIterable<Entity> entities;
  List<Key> keys = new ArrayList<Key> ();
  List<String> subIds = new ArrayList<String> ();
  Query queryAll;

  queryAll = new Query(DeviceSubscription.SUBSCRIPTION_KIND).setFilter(timeFilter);
  FetchOptions options = FetchOptions.Builder.withLimit(BATCH_DELETE_SIZE);
  if (!StringUtility.isNullOrEmpty(cursor)) {
    options.startCursor(Cursor.fromWebSafeString(cursor));
  }

  entities = this.datastoreService.prepare(queryAll).asQueryResultIterable(options);
  if (entities != null && entities.iterator() != null) {
    for (Entity entity : entities) {
      keys.add(entity.getKey());
      String[] ids = new Gson().fromJson((String) entity.getProperty(PROPERTY_SUBSCRIPTION_IDS),
          String[].class);
      subIds.addAll(Arrays.asList(ids));
    }
  }

  if (keys.size() > 0) {
    deleteInBatch(keys);
    enqueueDeleteDeviceSubscription(time, entities.iterator().getCursor().toWebSafeString());
  }
  if (subIds.size() > 0) {
    deletePsiSubscriptions(subIds);
  }
}
 
Example #3
Source File: PreparedQueryTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsQueryResultIterable() throws Exception {
    QueryResultIterable<Entity> iterable = preparedQuery.asQueryResultIterable();
    assertNotNull(iterable);
    assertNotNull(iterable.iterator());
    assertTrue(iterable.iterator().hasNext());
    assertEquals(john, iterable.iterator().next());
}
 
Example #4
Source File: PreparedQueryTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsQueryResultIterableWithOptions() throws Exception {
    QueryResultIterable<Entity> iterable = preparedQuery.asQueryResultIterable(withDefaults());
    assertNotNull(iterable);
    assertNotNull(iterable.iterator());
    assertTrue(iterable.iterator().hasNext());
    assertEquals(john, iterable.iterator().next());
}
 
Example #5
Source File: QueryFetchOptionsTest.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
private QueryResultIterable<Entity> executeQueryForIterable(FetchOptions fetchOptions) {
    Query query = new Query("Foo").addSort("bar");
    return service.prepare(query).asQueryResultIterable(fetchOptions);
}