com.google.appengine.api.datastore.FetchOptions

Here are the examples of the java api class com.google.appengine.api.datastore.FetchOptions taken from open source projects.

1. QueryImpl#fetchOptions()

Project: objectify
Source File: QueryImpl.java
View license
/**
	 * @return a set of fetch options for the current limit, offset, and cursors,
	 *  based on the default fetch options.  There will always be options even if default.
	 */
private FetchOptions fetchOptions() {
    FetchOptions opts = FetchOptions.Builder.withDefaults();
    if (this.startAt != null)
        opts = opts.startCursor(this.startAt);
    if (this.endAt != null)
        opts = opts.endCursor(this.endAt);
    if (this.limit != 0)
        opts = opts.limit(this.limit);
    if (this.offset != 0)
        opts = opts.offset(this.offset);
    if (this.chunk == null)
        opts = opts.chunkSize(DEFAULT_CHUNK_SIZE);
    else
        opts = opts.chunkSize(this.chunk);
    return opts;
}

2. DeviceSubscription#deleteAllContinuously()

View license
/**
   * 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);
    }
}

3. QueryOperations#executeQuery()

View license
private EntityListDto executeQuery(QueryDto queryDto, User user) {
    // check if kindName is not the config kinds
    SecurityChecker.getInstance().checkIfKindNameAccessible(queryDto.getKindName());
    // create Query
    Query q = SecurityChecker.getInstance().createKindQueryWithNamespace(queryDto.getKindName(), user);
    q.setKeysOnly();
    // set filters
    FilterDto cf = queryDto.getFilterDto();
    if (cf != null) {
        q.setFilter(cf.getDatastoreFilter());
    }
    // add sort orders
    if (queryDto.getSortedPropertyName() != null) {
        q.addSort(queryDto.getSortedPropertyName(), queryDto.isSortAscending() ? SortDirection.ASCENDING : SortDirection.DESCENDING);
    }
    // add limit
    FetchOptions fo;
    if (queryDto.getLimit() != null && queryDto.getLimit() > 0) {
        fo = FetchOptions.Builder.withLimit(queryDto.getLimit());
    } else {
        fo = FetchOptions.Builder.withDefaults();
    }
    // execute the query
    List<Entity> results = datastore.prepare(q).asList(fo);
    // get entities from the keys
    List<Key> keyList = new LinkedList<Key>();
    for (Entity e : results) {
        keyList.add(e.getKey());
    }
    Map<String, Entity> resultEntities = CrudOperations.getInstance().getAllEntitiesByKeyList(keyList);
    // convert the Entities to CbDtos
    EntityListDto cdl = new EntityListDto();
    for (Entity keyOnlyEntity : results) {
        Entity e = resultEntities.get(keyOnlyEntity.getKey().getName());
        cdl.getEntries().add(EntityDto.createFromEntity(e));
    }
    return cdl;
}

4. DeviceSubscription#deleteAllContinuously()

View license
/**
   * 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);
    }
}

5. QueryOperations#executeQuery()

View license
private EntityListDto executeQuery(QueryDto queryDto, User user) {
    // check if kindName is not the config kinds
    SecurityChecker.getInstance().checkIfKindNameAccessible(queryDto.getKindName());
    // create Query
    Query q = SecurityChecker.getInstance().createKindQueryWithNamespace(queryDto.getKindName(), user);
    q.setKeysOnly();
    // set filters
    FilterDto cf = queryDto.getFilterDto();
    if (cf != null) {
        q.setFilter(cf.getDatastoreFilter());
    }
    // add sort orders
    if (queryDto.getSortedPropertyName() != null) {
        q.addSort(queryDto.getSortedPropertyName(), queryDto.isSortAscending() ? SortDirection.ASCENDING : SortDirection.DESCENDING);
    }
    // add limit
    FetchOptions fo;
    if (queryDto.getLimit() != null && queryDto.getLimit() > 0) {
        fo = FetchOptions.Builder.withLimit(queryDto.getLimit());
    } else {
        fo = FetchOptions.Builder.withDefaults();
    }
    // execute the query
    List<Entity> results = datastore.prepare(q).asList(fo);
    // get entities from the keys
    List<Key> keyList = new LinkedList<Key>();
    for (Entity e : results) {
        keyList.add(e.getKey());
    }
    Map<String, Entity> resultEntities = CrudOperations.getInstance().getAllEntitiesByKeyList(keyList);
    // convert the Entities to CbDtos
    EntityListDto cdl = new EntityListDto();
    for (Entity keyOnlyEntity : results) {
        Entity e = resultEntities.get(keyOnlyEntity.getKey().getName());
        cdl.getEntries().add(EntityDto.createFromEntity(e));
    }
    return cdl;
}