Package com.couchace.core.api.query

Examples of com.couchace.core.api.query.CouchPageNavigation


    public void pagePreviousByIdTest() {

        // Skip to last (page 4)
        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byId").limit(3).build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
        while (pageNavigation.hasNextPage()) {
            er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryNextPage()).execute();
            pageNavigation = er.getCouchPageNavigation();
        }
        assertEquals(er.getSize(), 1);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[9]);
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertFalse(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?startkey=9&startkey_docid=Pet:9&skip=1&descending=false");
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byId?startkey=10&startkey_docid=Pet:10&skip=1&descending=true");

        // Previous (page 3)

        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryPreviousPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[6]);
        assertEquals(foundPets.get(1), pets[7]);
        assertEquals(foundPets.get(2), pets[8]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?startkey=10&startkey_docid=Pet:10&skip=1&descending=true");
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byId?startkey=7&startkey_docid=Pet:7&skip=1&descending=true");
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byId?startkey=9&startkey_docid=Pet:9&skip=1&descending=false");

        // Previous (page 2)
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryPreviousPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[3]);
        assertEquals(foundPets.get(1), pets[4]);
        assertEquals(foundPets.get(2), pets[5]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertTrue(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?startkey=7&startkey_docid=Pet:7&skip=1&descending=true");
        assertEquals(pageNavigation.getPreviousPage(), "_design/pet/_view/byId?startkey=4&startkey_docid=Pet:4&skip=1&descending=true");
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byId?startkey=6&startkey_docid=Pet:6&skip=1&descending=false");

        // Previous (page 1)
        er = couchDatabase.get().entity(PetEntity.class, pageNavigation.queryPreviousPage()).execute();
        assertEquals(er.getSize(), 3);
        foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[0]);
        assertEquals(foundPets.get(1), pets[1]);
        assertEquals(foundPets.get(2), pets[2]);
        pageNavigation = er.getCouchPageNavigation();
        assertNotNull(pageNavigation);
        assertFalse(pageNavigation.hasPreviousPage());
        assertTrue(pageNavigation.hasNextPage());
        assertTrue(pageNavigation.hasRequestedPage());
        assertEquals(pageNavigation.getRequestedPage(), "_design/pet/_view/byId?startkey=4&startkey_docid=Pet:4&skip=1&descending=true");
        assertNull(pageNavigation.getPreviousPage());
        assertEquals(pageNavigation.getNextPage(), "_design/pet/_view/byId?startkey=3&startkey_docid=Pet:3&skip=1&descending=false");
    }
View Full Code Here


                // Parse entity documents
                List<EntityDocument<T>> entityDocuments = jsonStrategy.readEntityDocuments(
                        couch.get(),
                        entityMeta,
                        httpResponse.getStringContent());
                CouchPageNavigation couchPageNavigation;
                if (request.getViewQuery() != null) {
                    couchPageNavigation = buildPageNavigationForViewQuery(httpResponse.getUri(), entityDocuments, request.getViewQuery());
                } else if (request.getPageQuery() != null) {
                    couchPageNavigation = buildPageNavigationForPageQuery(httpResponse.getUri(), entityDocuments, request.getPageQuery());
                } else {
View Full Code Here

                        CouchPageNavigation.empty(),
                        documentList);

            } else {
                List<TextDocument> documentList = jsonStrategy.readTextDocuments(httpResponse.getStringContent());
                CouchPageNavigation couchPageNavigation;
                if (request.getViewQuery() != null) {
                    couchPageNavigation = buildPageNavigationForViewQuery(httpResponse.getUri(), documentList, request.getViewQuery());
                } else if (request.getPageQuery() != null) {
                    couchPageNavigation = buildPageNavigationForPageQuery(httpResponse.getUri(), documentList, request.getPageQuery());
                } else {
View Full Code Here

            documentList.remove(pageQuery.getPageSize());
            CouchDocument pageEndEntity = documentList.get(documentList.size() - 1);
            forwardPageUri = httpClient.pageUri(requestedPageUri, pageEndEntity, pageQuery.isReverse()).toString();
        }

        CouchPageNavigation pageNavigation;
        if (pageQuery.isReverse()) {
            Collections.reverse(documentList);
            pageNavigation = new CouchPageNavigation(pageQuery.getPageSize(), pageQuery.getRequestedPage(), forwardPageUri, backPageUri, pageQuery.isIncludeDocs());
        } else {
            pageNavigation = new CouchPageNavigation(pageQuery.getPageSize(), pageQuery.getRequestedPage(), backPageUri, forwardPageUri, pageQuery.isIncludeDocs());
        }

        return pageNavigation;
    }
View Full Code Here

        String requestedPage = requestedPageUri.toString();
        int designIndex = requestedPage.indexOf("_design");
        if (designIndex > 0) {
            requestedPage = requestedPage.substring(designIndex);
        }
        return new CouchPageNavigation(viewQuery.getLimit(), requestedPage, null, nextPage, viewQuery.isIncludeDocs());
    }
View Full Code Here

                // Parse entity documents
                List<EntityDocument<T>> entityDocuments = jsonStrategy.readEntityDocuments(
                    couch.get(),
                        entityMeta,
                    couchHttpResponse.getStringContent());
                CouchPageNavigation couchPageNavigation;
                if (request.getViewQuery() != null) {
                    couchPageNavigation = buildPageNavigationForViewQuery(couchHttpResponse.getUri(), entityDocuments, request.getViewQuery());
                } else if (request.getPageQuery() != null) {
                    couchPageNavigation = buildPageNavigationForPageQuery(couchHttpResponse.getUri(), entityDocuments, request.getPageQuery());
                } else {
View Full Code Here

                        CouchPageNavigation.empty(),
                        documentList);

            } else {
                List<TextDocument> documentList = jsonStrategy.readTextDocuments(couchHttpResponse.getStringContent());
                CouchPageNavigation couchPageNavigation;
                if (request.getViewQuery() != null) {
                    couchPageNavigation = buildPageNavigationForViewQuery(couchHttpResponse.getUri(), documentList, request.getViewQuery());
                } else if (request.getPageQuery() != null) {
                    couchPageNavigation = buildPageNavigationForPageQuery(couchHttpResponse.getUri(), documentList, request.getPageQuery());
                } else {
View Full Code Here

            documentList.remove(pageQuery.getPageSize());
            CouchDocument pageEndEntity = documentList.get(documentList.size() - 1);
            forwardPageUri = httpClient.pageUri(requestedPageUri, pageEndEntity, pageQuery.isReverse()).toString();
        }

        CouchPageNavigation pageNavigation;
        if (pageQuery.isReverse()) {
            Collections.reverse(documentList);
            pageNavigation = new CouchPageNavigation(pageQuery.getPageSize(), pageQuery.getRequestedPage(), forwardPageUri, backPageUri, pageQuery.isIncludeDocs());
        } else {
            pageNavigation = new CouchPageNavigation(pageQuery.getPageSize(), pageQuery.getRequestedPage(), backPageUri, forwardPageUri, pageQuery.isIncludeDocs());
        }

        return pageNavigation;
    }
View Full Code Here

        String requestedPage = requestedPageUri.toString();
        int designIndex = requestedPage.indexOf("_design");
        if (designIndex > 0) {
            requestedPage = requestedPage.substring(designIndex);
        }
        return new CouchPageNavigation(viewQuery.getLimit(), requestedPage, null, nextPage, viewQuery.isIncludeDocs());
    }
View Full Code Here

TOP

Related Classes of com.couchace.core.api.query.CouchPageNavigation

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.