Package com.couchace.core.api.query

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


    }

    @Test(dependsOnMethods = {"putTest", "postTest"})
    public void getCitiesViewTest() {

        CouchViewQuery viewQuery = CouchViewQuery.builder("city", "cityName").build();
        GetDocumentResponse response = couchDatabase.get()
            .document(viewQuery)
            .execute();

        // Verify basics of response.
View Full Code Here


        assertEquals(putResponse.getDocumentId(), documentThreeId);
        assertNotNull(putResponse.getDocumentRevision());
        String initialVersionThree = putResponse.getDocumentRevision();

        // Perform a count, ensure we have three.
        CouchViewQuery couchViewQuery = CouchViewQuery
            .builder("entity", "countEntityType")
            .key("person")
            .includeDocs(false)
            .build();
        GetDocumentResponse countResponse = couchDatabase
                .get()
                .document(couchViewQuery)
                .execute();
        assertTrue(countResponse.isOk(), countResponse.getErrorReason());
        assertEquals(countResponse.getFirstContentAsLong(), new Long(3));

        // GET one by id
        GetEntityResponse<PersonEntity> getResponse = couchDatabase
            .get()
            .entity(PersonEntity.class, documentOneId)
            .execute();
        assertEquals(getResponse.getHttpStatus(), CouchHttpStatus.OK);
        assertEquals(getResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
        EntityDocument<PersonEntity> entityDocument = getResponse.getFirstDocument();
        assertEquals(entityDocument.getDocumentId(), documentOneId);
        assertEquals(entityDocument.getDocumentRevision(), initialVersionOne);
        assertEquals(entityDocument.getEntityType(), "person");
        assertEquals(entityDocument.getEntity(), personEntityOne);
        assertNotNull(entityDocument.getDocumentRevision());
        assertNotNull(entityDocument.getEntity().getVersion());
        assertEquals(entityDocument.getDocumentRevision(), entityDocument.getEntity().getVersion());
        // Validate that the 3rd-party objects were injected.
        PersonEntity personEntity = entityDocument.getEntity();
        assertSame(personEntity.getLogger(), logger);
        assertSame(personEntity.getEventBus(), eventBus);

        // GET two by id
        getResponse = couchDatabase.get().entity(PersonEntity.class, documentTwoId).execute();
        assertEquals(getResponse.getHttpStatus(), CouchHttpStatus.OK);
        assertEquals(getResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
        entityDocument = getResponse.getFirstDocument();
        assertEquals(entityDocument.getDocumentId(), documentTwoId);
        assertEquals(entityDocument.getDocumentRevision(), initialVersionTwo);
        assertEquals(entityDocument.getEntityType(), "person");
        assertEquals(entityDocument.getEntity(), personEntityTwo);

        // GET as a Document
        GetDocumentResponse stringEntityResponse = couchDatabase.get().document(documentTwoId).execute();
        assertEquals(stringEntityResponse.getHttpStatus(), CouchHttpStatus.OK);
        assertEquals(stringEntityResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
        TextDocument stringEntityDoc = stringEntityResponse.getFirstDocument();
        assertEquals(stringEntityDoc.getDocumentId(), documentTwoId);
        assertEquals(stringEntityDoc.getDocumentRevision(), initialVersionTwo);

        // GET one by key
        CouchViewQuery viewQuery = CouchViewQuery.builder("person", "byName").limit(10).key("Farmer Fish").build();
        getResponse = couchDatabase.get().entity(PersonEntity.class, viewQuery).execute();
        assertEquals(getResponse.getHttpStatus(), CouchHttpStatus.OK);
        assertEquals(getResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
        assertEquals(getResponse.getSize(), 1);
        assertEquals(getResponse.getEntityClass(), PersonEntity.class);
View Full Code Here

    private int nextId = 7000;

    public void actionEntityTest() {

        // Perform an initial count, should be zero
        CouchViewQuery couchViewQuery = CouchViewQuery
            .builder("entity", "countEntityType")
            .key("Action")
            .includeDocs(false)
            .build();
        long initialActionCount = couchDatabase
View Full Code Here

    @Test
    public void vehicleEntityTest() throws IOException {

        // Perform an initial count, should be zero
        CouchViewQuery couchViewQuery = CouchViewQuery
            .builder("entity", "countEntityType")
            .key("Vehicle")
            .includeDocs(false)
            .build();
        long initialVehicleCount = couchDatabase
View Full Code Here

                HttpQueryParam queryParam = new HttpQueryParam("rev", request.getDocumentRevision());
                queryParameters = Collections.singletonList(queryParam);
            }
        } else if (request.getViewQuery() != null) {
            // View query
            CouchViewQuery viewQuery = request.getViewQuery();
            path = UriUtil.buildPath(
                databaseName,
                "_design",
                viewQuery.getDesignName(),
                "_view",
                viewQuery.getViewName());

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

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

    return super.getByDocumentId(apiRequestId);
  }

  public QueryResult<ApiRequest> getByClient(ApiClient apiClient, int limit) {

    CouchViewQuery viewQuery = CouchViewQuery.builder(getDesignName(), "byClient")
        .limit(limit)
        .key(apiClient.getApiClientId())
        .build();

    return new QueryResult<>(ApiRequest.class, database, viewQuery);
View Full Code Here

                HttpQueryParam queryParam = new HttpQueryParam("rev", request.getDocumentRevision());
                queryParameters = Collections.singletonList(queryParam);
            }
        } else if (request.getViewQuery() != null) {
            // View query
            CouchViewQuery viewQuery = request.getViewQuery();
            path = UriUtil.buildPath(
                databaseName,
                "_design",
                viewQuery.getDesignName(),
                "_view",
                viewQuery.getViewName());

            queryParameters.add(new HttpQueryParam("include_docs", String.valueOf(viewQuery.isIncludeDocs())));
            if (viewQuery.hasKey()) {
                queryParameters.add(new HttpQueryParam("key", viewQuery.getKeyJson()));
            }
            if (viewQuery.hasStartKey()) {
                queryParameters.add(new HttpQueryParam("startkey", viewQuery.getStartKeyJson()));
            }
            if (viewQuery.hasEndKey()) {
                queryParameters.add(new HttpQueryParam("endkey", viewQuery.getEndKeyJson()));
            }
            if (viewQuery.getLimit() > 0) {
                queryParameters.add(new HttpQueryParam("limit", String.valueOf(viewQuery.getLimit() + 1)));
            }
            if (viewQuery.isDescending()) {
                queryParameters.add(new HttpQueryParam("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.