Package com.couchace.core.api.query

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


            if (request.getDocumentRevision() != null) {
                queryBuilder.add("rev", request.getDocumentRevision());
            }
        } else if (request.getViewQuery() != null) {
            // View query
            CouchViewQuery viewQuery = request.getViewQuery();
            path = UriUtil.buildPath(
                    databaseName,
                    "_design",
                    viewQuery.getDesignName(),
                    "_view",
                    viewQuery.getViewName());

            queryBuilder.add("include_docs", String.valueOf(viewQuery.isIncludeDocs()));
            if (viewQuery.hasKey()) {
                queryBuilder.add("key", viewQuery.getKeyJson());
            }
            if (viewQuery.hasStartKey()) {
                queryBuilder.add("startkey", viewQuery.getStartKeyJson());
            }
            if (viewQuery.hasEndKey()) {
                queryBuilder.add("endkey", viewQuery.getEndKeyJson());
            }
            if (viewQuery.getLimit() > 0) {
                queryBuilder.add("limit", String.valueOf(viewQuery.getLimit() + 1));
            }
            if (viewQuery.isDescending()) {
                queryBuilder.add("descending", String.valueOf(viewQuery.isDescending()));
            }

        } else if (request.getPageQuery() != null) {
            // Page query
            CouchPageQuery pageQuery = request.getPageQuery();
View Full Code Here


            assertNotNull(doc.getDocumentId());
            assertNotNull(doc.getDocumentRevision());
        }

        // Get count using all view
        CouchViewQuery viewQuery = CouchViewQuery.builder("simple", "all").build();
        documentResponse = database
                .get()
                .document(viewQuery)
                .execute();
        assertTrue(documentResponse.isOk(), documentResponse.getErrorReason());
View Full Code Here

    @Test()
    public void byIdTest() {

        // First page
        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byId").limit(3).key(2).build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 1);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[1]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
View Full Code Here

    }

    @Test()
    public void byTypePageTest() {

        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byType").limit(2).key("DOG").build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 2);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[2]);
        assertEquals(foundPets.get(1), pets[3]);
View Full Code Here

    }

    @Test()
    public void byTypeStartEndPageTest() {

        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byType").limit(3).start("CAT").end("DOG").build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 3);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[0]);
        assertEquals(foundPets.get(1), pets[1]);
View Full Code Here

    @Test()
    public void byTypeAndIdTest() {

//    http://127.0.0.1:5984/couch-test/_design/pet/_view/byTypeAndId?key=[%22CAT%22,%202]
        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byTypeAndId").limit(3).key("CAT", 2).build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 1);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[1]);
        CouchPageNavigation pageNavigation = er.getCouchPageNavigation();
View Full Code Here

    @Test()
    public void pageNextByIdTest() {

        // First page
        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byId").limit(3).build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 3);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[0]);
        assertEquals(foundPets.get(1), pets[1]);
View Full Code Here

    @Test()
    public void pageNextByCreatedAtTest() {

        // First page
        CouchViewQuery viewQuery = CouchViewQuery.builder("pet", "byCreatedAt").limit(3).build();
        GetEntityResponse<PetEntity> er = couchDatabase.get().entity(PetEntity.class, viewQuery).execute();
        assertEquals(er.getSize(), 3);
        List<PetEntity> foundPets = er.getEntityList();
        assertEquals(foundPets.get(0), pets[0]);
        assertEquals(foundPets.get(1), pets[1]);
View Full Code Here

    @Test()
    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();
View Full Code Here

            if (request.getDocumentRevision() != null) {
                queryBuilder.add("rev", request.getDocumentRevision());
            }
        } else if (request.getViewQuery() != null) {
            // View query
            CouchViewQuery viewQuery = request.getViewQuery();
            path = UriUtil.buildPath(
                    databaseName,
                    "_design",
                    viewQuery.getDesignName(),
                    "_view",
                    viewQuery.getViewName());

            queryBuilder.add("include_docs", String.valueOf(viewQuery.isIncludeDocs()));
            if (viewQuery.hasKey()) {
                queryBuilder.add("key", viewQuery.getKeyJson());
            }
            if (viewQuery.hasStartKey()) {
                queryBuilder.add("startkey", viewQuery.getStartKeyJson());
            }
            if (viewQuery.hasEndKey()) {
                queryBuilder.add("endkey", viewQuery.getEndKeyJson());
            }
            if (viewQuery.getLimit() > 0) {
                queryBuilder.add("limit", String.valueOf(viewQuery.getLimit() + 1));
            }
            if (viewQuery.isDescending()) {
                queryBuilder.add("descending", String.valueOf(viewQuery.isDescending()));
            }

        } else if (request.getPageQuery() != null) {
            // Page query
            CouchPageQuery pageQuery = request.getPageQuery();
View Full Code Here

TOP

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

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.