Search in sources :

Example 1 with ViewQuery

use of com.couchbase.client.java.view.ViewQuery in project ff4j by ff4j.

the class EventRepositoryCouchbase method queryView.

public void queryView(Bucket bucket, String design, String view) {
    ViewQuery queryAllFeatures = ViewQuery.from(design, view);
    ViewResult queryResult = bucket.query(queryAllFeatures);
    List<ViewRow> rows = queryResult.allRows();
    for (ViewRow viewRow : rows) {
        System.out.println("Result view:" + viewRow.id() + ":" + viewRow.value());
    }
}
Also used : ViewQuery(com.couchbase.client.java.view.ViewQuery) ViewResult(com.couchbase.client.java.view.ViewResult) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 2 with ViewQuery

use of com.couchbase.client.java.view.ViewQuery in project tutorials by eugenp.

the class StudentGradeService method findTopGradesByCourse.

public List<JsonDocument> findTopGradesByCourse(String course, int limit) {
    ViewQuery query = queryBuilder.findTopGradesByCourse(course, limit);
    ViewResult result = bucket.query(query);
    return extractDocuments(result);
}
Also used : ViewQuery(com.couchbase.client.java.view.ViewQuery) ViewResult(com.couchbase.client.java.view.ViewResult)

Example 3 with ViewQuery

use of com.couchbase.client.java.view.ViewQuery in project tutorials by eugenp.

the class StudentGradeService method findByGradeInRange.

public List<JsonDocument> findByGradeInRange(int lower, int upper, boolean inclusiveEnd) {
    ViewQuery query = queryBuilder.findByGradeInRange(lower, upper, inclusiveEnd);
    ViewResult result = bucket.query(query);
    return extractDocuments(result);
}
Also used : ViewQuery(com.couchbase.client.java.view.ViewQuery) ViewResult(com.couchbase.client.java.view.ViewResult)

Example 4 with ViewQuery

use of com.couchbase.client.java.view.ViewQuery in project tutorials by eugenp.

the class StudentGradeService method sumCreditHoursByStudent.

public Map<String, Long> sumCreditHoursByStudent() {
    ViewQuery query = ViewQuery.from("studentGrades", "sumHoursByStudent").reduce().groupLevel(1);
    ViewResult result = bucket.query(query);
    Map<String, Long> creditHoursByStudent = new HashMap<>();
    for (ViewRow row : result.allRows()) {
        String course = (String) row.key();
        long sum = Long.valueOf(row.value().toString());
        creditHoursByStudent.put(course, sum);
    }
    return creditHoursByStudent;
}
Also used : HashMap(java.util.HashMap) ViewQuery(com.couchbase.client.java.view.ViewQuery) ViewResult(com.couchbase.client.java.view.ViewResult) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 5 with ViewQuery

use of com.couchbase.client.java.view.ViewQuery in project tutorials by eugenp.

the class StudentGradeService method findByCourse.

public List<JsonDocument> findByCourse(String course) {
    ViewQuery query = queryBuilder.findByCourse(course);
    ViewResult result = bucket.query(query);
    return extractDocuments(result);
}
Also used : ViewQuery(com.couchbase.client.java.view.ViewQuery) ViewResult(com.couchbase.client.java.view.ViewResult)

Aggregations

ViewQuery (com.couchbase.client.java.view.ViewQuery)12 ViewResult (com.couchbase.client.java.view.ViewResult)12 ViewRow (com.couchbase.client.java.view.ViewRow)4 HashMap (java.util.HashMap)3 JsonArray (com.couchbase.client.java.document.json.JsonArray)1