Search in sources :

Example 6 with ViewResult

use of com.couchbase.client.java.view.ViewResult 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 7 with ViewResult

use of com.couchbase.client.java.view.ViewResult 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)

Example 8 with ViewResult

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

the class StudentGradeService method findByGradeLessThan.

public List<JsonDocument> findByGradeLessThan(int upper) {
    ViewQuery query = queryBuilder.findByGradeLessThan(upper);
    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 9 with ViewResult

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

the class StudentGradeService method findByCourses.

public List<JsonDocument> findByCourses(String... courses) {
    ViewQuery query = queryBuilder.findByCourses(courses);
    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 10 with ViewResult

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

the class StudentGradeService method countStudentsByCourse.

public Map<String, Long> countStudentsByCourse() {
    ViewQuery query = ViewQuery.from("studentGrades", "countStudentsByCourse").reduce().groupLevel(1);
    ViewResult result = bucket.query(query);
    Map<String, Long> numStudentsByCourse = new HashMap<>();
    for (ViewRow row : result.allRows()) {
        JsonArray keyArray = (JsonArray) row.key();
        String course = keyArray.getString(0);
        long count = Long.valueOf(row.value().toString());
        numStudentsByCourse.put(course, count);
    }
    return numStudentsByCourse;
}
Also used : JsonArray(com.couchbase.client.java.document.json.JsonArray) 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)

Aggregations

ViewResult (com.couchbase.client.java.view.ViewResult)14 ViewQuery (com.couchbase.client.java.view.ViewQuery)12 ViewRow (com.couchbase.client.java.view.ViewRow)6 HashMap (java.util.HashMap)3 RawJsonDocument (com.couchbase.client.java.document.RawJsonDocument)2 StringReader (java.io.StringReader)2 JsonArray (com.couchbase.client.java.document.json.JsonArray)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 CasRegisteredServiceLoadedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent)1