Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.Cursor


                "In case of asQueryResultList(), you cannot specify sortInMemory().");
        }
        addFilterIfPolyModel();
        List<M> modelList = null;
        boolean hasNext = false;
        Cursor cursor = null;
        if (fetchOptions.getLimit() == null) {
            QueryResultList<Entity> entityList = asQueryResultEntityList();
            modelList = new ArrayList<M>(entityList.size());
            for (Entity e : entityList) {
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                M model = mm.entityToModel(e);
                mm.postGet(model);
                modelList.add(model);
            }
            cursor = entityList.getCursor();
        } else {
            int limit = fetchOptions.getLimit();
            fetchOptions.limit(limit + 1);
            modelList = new ArrayList<M>();
            QueryResultIterator<Entity> ite = asQueryResultEntityIterator();
            while (true) {
                hasNext = ite.hasNext();
                if (!hasNext || modelList.size() == limit) {
                    cursor = ite.getCursor();
                    break;
                }
                Entity e = ite.next();
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                M model = mm.entityToModel(e);
                mm.postGet(model);
                modelList.add(model);
            }
        }
        String cursorWebSafeString =
            cursor == null ? null : cursor.toWebSafeString();
        return new S3QueryResultList<M>(
            modelList,
            cursorWebSafeString,
            getEncodedFilters(),
            getEncodedSorts(),
View Full Code Here


    @Test
    public void startCursor() throws Exception {
        ds.put(new Entity("Hoge"));
        MyQuery query = new MyQuery(ds, "Hoge");
        QueryResultList<Entity> list = query.limit(1).asQueryResultEntityList();
        Cursor cursor = list.getCursor();
        query = new MyQuery(ds, "Hoge");
        assertThat(query.startCursor(cursor), is(sameInstance(query)));
        assertThat(query.fetchOptions.getStartCursor(), is(cursor));
    }
View Full Code Here

    @Test
    public void endCursor() throws Exception {
        ds.put(new Entity("Hoge"));
        MyQuery query = new MyQuery(ds, "Hoge");
        QueryResultList<Entity> list = query.limit(1).asQueryResultEntityList();
        Cursor cursor = list.getCursor();
        query = new MyQuery(ds, "Hoge");
        assertThat(query.endCursor(cursor), is(sameInstance(query)));
        assertThat(query.fetchOptions.getEndCursor(), is(cursor));
    }
View Full Code Here

    @Test
    public void encodedStartCursor() throws Exception {
        ds.put(new Entity("Hoge"));
        MyQuery query = new MyQuery(ds, "Hoge");
        QueryResultList<Entity> list = query.limit(1).asQueryResultEntityList();
        Cursor cursor = list.getCursor();
        String encodedCursor = cursor.toWebSafeString();
        query = new MyQuery(ds, "Hoge");
        assertThat(
            query.encodedStartCursor(encodedCursor),
            is(sameInstance(query)));
        assertThat(query.fetchOptions.getStartCursor(), is(cursor));
View Full Code Here

    @Test
    public void encodedEndCursor() throws Exception {
        ds.put(new Entity("Hoge"));
        MyQuery query = new MyQuery(ds, "Hoge");
        QueryResultList<Entity> list = query.limit(1).asQueryResultEntityList();
        Cursor cursor = list.getCursor();
        String encodedCursor = cursor.toWebSafeString();
        query = new MyQuery(ds, "Hoge");
        assertThat(
            query.encodedEndCursor(encodedCursor),
            is(sameInstance(query)));
        assertThat(query.fetchOptions.getEndCursor(), is(cursor));
View Full Code Here

                "In case of asQueryResultList(), you cannot specify sortInMemory().");
        }
        applyPolyModelFilter();
        List<M> modelList = null;
        boolean hasNext = false;
        Cursor cursor = null;
        if (fetchOptions.getLimit() == null) {
            QueryResultList<Entity> entityList = asQueryResultEntityList();
            modelList = new ArrayList<M>(entityList.size());
            for (Entity e : entityList) {
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                M model = mm.entityToModel(e);
                mm.postGet(model);
                modelList.add(model);
            }
            cursor = entityList.getCursor();
        } else {
            int limit = fetchOptions.getLimit();
            fetchOptions.limit(limit + 1);
            modelList = new ArrayList<M>();
            QueryResultIterator<Entity> ite = asQueryResultEntityIterator();
            while (true) {
                hasNext = ite.hasNext();
                if (!hasNext || modelList.size() == limit) {
                    cursor = ite.getCursor();
                    break;
                }
                Entity e = ite.next();
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                M model = mm.entityToModel(e);
                mm.postGet(model);
                modelList.add(model);
            }
        }
        String cursorWebSafeString =
            cursor == null ? null : cursor.toWebSafeString();
        return new S3QueryResultList<M>(
            modelList,
            cursorWebSafeString,
            getEncodedFilter(),
            getEncodedSorts(),
View Full Code Here

        EntityQuery q = new EntityQuery(ds, "Hoge");
        QueryResultList<Entity> qrList =
            q
                .filter("myString", FilterOperator.EQUAL, "aaa")
                .asQueryResultList();
        Cursor cursor = qrList.getCursor();
        S3QueryResultList<Entity> list =
            new S3QueryResultList<Entity>(
                qrList,
                cursor.toWebSafeString(),
                q.getEncodedFilter(),
                q.getEncodedSorts(),
                true);
        assertThat(list.getEncodedCursor(), is(cursor.toWebSafeString()));
        assertThat(list.getEncodedFilter(), is(q.getEncodedFilter()));
        assertThat(list.getEncodedSorts(), is(q.getEncodedSorts()));
        assertThat(list.hasNext(), is(true));
    }
View Full Code Here

                "In case of asQueryResultList(), you cannot specify sortInMemory().");
        }
        addFilterIfPolyModel();
        List<M> modelList = null;
        boolean hasNext = false;
        Cursor cursor = null;
        if (fetchOptions.getLimit() == null) {
            QueryResultList<Entity> entityList = asQueryResultEntityList();
            modelList = new ArrayList<M>(entityList.size());
            for (Entity e : entityList) {
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                modelList.add(mm.entityToModel(e));
            }
            cursor = entityList.getCursor();
        } else {
            int limit = fetchOptions.getLimit();
            fetchOptions.limit(limit + 1);
            modelList = new ArrayList<M>();
            QueryResultIterator<Entity> ite = asQueryResultEntityIterator();
            while (true) {
                hasNext = ite.hasNext();
                if (!hasNext || modelList.size() == limit) {
                    cursor = ite.getCursor();
                    break;
                }
                Entity e = ite.next();
                ModelMeta<M> mm = DatastoreUtil.getModelMeta(modelMeta, e);
                modelList.add(mm.entityToModel(e));
            }
        }
        return new S3QueryResultList<M>(
            modelList,
            cursor.toWebSafeString(),
            getEncodedFilters(),
            getEncodedSorts(),
            hasNext);
    }
View Full Code Here

  }

  private Object fulfillEntityQuery(
      PreparedQuery preparedQuery, FetchOptions opts, Function<Entity, Object> resultTransformer,
      DatastoreService ds, ManagedConnection mconn) {
    Cursor endCursor = null;
    Iterable<Entity> entityIterable;
    if (opts != null) {
      if (opts.getLimit() != null) {
        QueryResultList<Entity> entities = preparedQuery.asQueryResultList(opts);
        endCursor = entities.getCursor();
View Full Code Here

        // We know that offset won't be null because opts is not null.
        opts.limit(intExclNo - offset);
      }
    }
    Cursor cursor = getCursor();
    // If we have a cursor, add it to the fetch options
    if (cursor != null) {
      if (opts == null) {
        opts = withCursor(cursor);
      } else {
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.Cursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.