Search in sources :

Example 6 with ViewRow

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

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

the class StudentGradeService method extractDocuments.

private List<JsonDocument> extractDocuments(ViewResult result) {
    List<JsonDocument> docs = new ArrayList<>();
    for (ViewRow row : result.allRows()) {
        JsonDocument doc = row.document();
        docs.add(doc);
    }
    return docs;
}
Also used : ArrayList(java.util.ArrayList) JsonDocument(com.couchbase.client.java.document.JsonDocument) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 8 with ViewRow

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

Example 9 with ViewRow

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

the class StudentGradeService method sumGradePointsByStudent.

public Map<String, Long> sumGradePointsByStudent() {
    ViewQuery query = ViewQuery.from("studentGrades", "sumGradePointsByStudent").reduce().groupLevel(1);
    ViewResult result = bucket.query(query);
    Map<String, Long> gradePointsByStudent = new HashMap<>();
    for (ViewRow row : result.allRows()) {
        String course = (String) row.key();
        long sum = Long.valueOf(row.value().toString());
        gradePointsByStudent.put(course, sum);
    }
    return gradePointsByStudent;
}
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 10 with ViewRow

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

the class StudentGradeServiceIntegrationTest method printViewResultDocuments.

private void printViewResultDocuments(ViewResult result) {
    for (ViewRow row : result.allRows()) {
        JsonDocument doc = row.document();
        String key = doc.id();
        logger.info(key + "=" + doc.content().toString());
    }
}
Also used : ViewRow(com.couchbase.client.java.view.ViewRow) JsonDocument(com.couchbase.client.java.document.JsonDocument)

Aggregations

ViewRow (com.couchbase.client.java.view.ViewRow)10 ViewResult (com.couchbase.client.java.view.ViewResult)6 ViewQuery (com.couchbase.client.java.view.ViewQuery)4 JsonDocument (com.couchbase.client.java.document.JsonDocument)3 ArrayList (java.util.ArrayList)3 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 LinkedList (java.util.LinkedList)1 CasRegisteredServiceLoadedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent)1 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)1 Ticket (org.apereo.cas.ticket.Ticket)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1