Java Code Examples for com.google.appengine.api.datastore.PreparedQuery#asIterator()

The following examples show how to use com.google.appengine.api.datastore.PreparedQuery#asIterator() . 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: TestBase.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
private static <T extends TempData> List<T> getAllTempData(Class<T> type, boolean unreadOnly) {
    try {
        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        String kind = getKind(type);
        Query query = new Query(kind);
        if (unreadOnly) {
            query.setFilter(new Query.FilterPredicate(TEMP_DATA_READ_PROPERTY, Query.FilterOperator.EQUAL, false));
        } else {
            query.addSort("timestamp", Query.SortDirection.ASCENDING);
        }
        PreparedQuery pq = ds.prepare(query);
        Iterator<Entity> iter = pq.asIterator();
        List<T> result = new ArrayList<>();
        while (iter.hasNext()) {
            Entity entity = iter.next();
            T data = readTempData(type, entity, ds);
            result.add(data);
        }
        return result;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example 2
Source File: TestBase.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
public static <T extends TempData> T getLastTempData(Class<T> type) {
    try {
        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        String kind = getKind(type);
        PreparedQuery pq = ds.prepare(new Query(kind).addSort("timestamp", Query.SortDirection.DESCENDING));
        Iterator<Entity> iter = pq.asIterator();
        if (iter.hasNext()) {
            Entity entity = iter.next();
            return readTempData(type, entity, ds);
        } else {
            return null;
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example 3
Source File: DatastoreHelperTestBase.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
private void assertIAEWhenAccessingIterator(PreparedQuery preparedQuery) {
    Iterator<Entity> iterator = preparedQuery.asIterator();
    try {
        iterator.hasNext();
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
        // pass
    }
}