Package com.google.appengine.api.datastore

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


    }

    @Test
    public void testEndCursorAndOffset() {
        QueryResultList<Entity> results = executeQuery(withLimit(3));
        Cursor cursor = results.getCursor();    // points to foo4

        results = executeQuery(withEndCursor(cursor).offset(1));
        assertEquals(asList(foo2, foo3), results);
    }
View Full Code Here


    }

    @Test
    public void testEndCursorLessThanOffset() {
        QueryResultList<Entity> results = executeQuery(withLimit(1));
        Cursor cursor = results.getCursor();    // points to foo2

        results = executeQuery(withEndCursor(cursor).offset(3));
        assertTrue(results.isEmpty());
    }
View Full Code Here

    }

    @Test
    public void testEndCursorAndLimit() {
        QueryResultList<Entity> results = executeQuery(withLimit(3));
        Cursor cursor = results.getCursor();    // points to foo4

        results = executeQuery(withEndCursor(cursor).limit(2));
        assertEquals(asList(foo1, foo2), results);

        results = executeQuery(withEndCursor(cursor).limit(5)); // even if limit is past endCursor, endCursor will still apply
View Full Code Here

    }

    @Test
    public void testEndCursorAndOffsetAndLimit() {
        QueryResultList<Entity> results = executeQuery(withLimit(3));
        Cursor cursor = results.getCursor();    // points to foo4

        results = executeQuery(withEndCursor(cursor).offset(1).limit(2));
        assertEquals(asList(foo2, foo3), results);

        results = executeQuery(withEndCursor(cursor).offset(1).limit(5));
View Full Code Here

        int onePage = 5;
        String filterData = "ff";
        Query query = new Query(kindName, rootKey);
        query.setFilter(new FilterPredicate("name", Query.FilterOperator.EQUAL, filterData));
        // fetch first page
        Cursor cursor = checkPage(query, null, null, onePage, onePage, filterData, filterData);
        Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString());
        // fetch next page
        checkPage(query, decodedCursor, null, onePage, onePage, filterData, filterData);
    }
View Full Code Here

    public void testSort() {
        int onePage = 6;
        Query query = new Query(kindName, rootKey);
        query.addSort("name", Query.SortDirection.ASCENDING);
        // fetch first page   aa,aa,aa,aa,aa,aa
        Cursor cursor = checkPage(query, null, null, onePage, onePage, testDat[0], testDat[0]);
        Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString());
        // fetch next page    aa,aa,aa,aa,bb,bb
        checkPage(query, decodedCursor, null, onePage, onePage, testDat[0], testDat[1]);

        // desc
        onePage = total / testDat.length;
View Full Code Here

    @Test
    public void testEndFetch() {
        int onePage = total - 30;
        Query query = new Query(kindName, rootKey);
        // fetch first page
        Cursor cursor = checkPage(query, null, null, onePage, onePage, null, null);
        Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString());
        // fetch next page,   get remaining after 1st page.
        checkPage(query, decodedCursor, null, onePage, total - onePage, null, null);
    }
View Full Code Here

    public void testEndCursor() {
        int limit = total / testDat.length;
        Query query = new Query(kindName, rootKey);
        query.addSort("name", Query.SortDirection.ASCENDING);
        // fetch 1st page
        Cursor cursor = checkPage(query, null, null, limit, limit, testDat[0], testDat[0]);
        Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString());
        // fetch 1st page again since using decodedCursor as end cursor
        checkPage(query, null, decodedCursor, limit, limit, testDat[0], testDat[0]);
    }
View Full Code Here

        query.addSort("name", Query.SortDirection.ASCENDING);
        FetchOptions fetchOption = FetchOptions.Builder.withLimit(limit);
        // fetch 1st page and get cursor1
        QueryResultList<Entity> nextBatch = service.prepare(query)
            .asQueryResultList(fetchOption);
        Cursor cursor1 = Cursor.fromWebSafeString(nextBatch.getCursor().toWebSafeString());
        // fetch 2nd page and get cursor2
        nextBatch = service.prepare(query).asQueryResultList(fetchOption.startCursor(cursor1));
        Cursor cursor2 = Cursor.fromWebSafeString(nextBatch.getCursor().toWebSafeString());
        // cursor1 as start and cursor2 as end and 15 in limit -- -- should return 2nd page.
        checkPage(query, cursor1, cursor2, limit, limit, testDat[1], testDat[1]);
        // cursor1 as start and cursor2 as end and 30 in limit -- should return 2nd page.
        checkPage(query, cursor1, cursor2, 2 * limit, limit, testDat[1], testDat[1]);
        // cursor2 as start and cursor1 as end and 15 in limit -- should not return any.
View Full Code Here

        Query query = new Query(kindName, rootKey);
        query.addSort(Entity.KEY_RESERVED_PROPERTY);
        QueryResultIterator<Entity> iter = service.prepare(query).asQueryResultIterator();
        Entity e1 = iter.next();
        Entity e2 = iter.next();
        Cursor cursor = iter.getCursor();
        //reverse
        query = query.reverse();
        cursor = cursor.reverse();
        iter = service.prepare(query).asQueryResultIterator(FetchOptions.Builder.withStartCursor(cursor));
        Assert.assertEquals(e2, iter.next());
        Assert.assertEquals(e1, iter.next());
    }
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.