Search in sources :

Example 1 with ViewResult

use of com.couchbase.client.java.view.ViewResult in project cas by apereo.

the class CouchbaseServiceRegistryDao method load.

@Override
public List<RegisteredService> load() {
    try {
        LOGGER.debug("Loading services");
        final ViewResult allKeys = executeViewQueryForAllServices();
        final List<RegisteredService> services = new LinkedList<>();
        for (final ViewRow row : allKeys) {
            final RawJsonDocument document = row.document(RawJsonDocument.class);
            if (document != null) {
                final String json = document.content();
                LOGGER.debug("Found service: [{}]", json);
                final StringReader stringReader = new StringReader(json);
                services.add(this.registeredServiceJsonSerializer.from(stringReader));
            }
        }
        return services;
    } catch (final RuntimeException e) {
        LOGGER.error(e.getMessage(), e);
        return new LinkedList<>();
    }
}
Also used : StringReader(java.io.StringReader) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument) ViewResult(com.couchbase.client.java.view.ViewResult) LinkedList(java.util.LinkedList) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 2 with ViewResult

use of com.couchbase.client.java.view.ViewResult in project cas by apereo.

the class CouchbaseServiceRegistry method load.

@Override
public List<RegisteredService> load() {
    try {
        final ViewResult allKeys = executeViewQueryForAllServices();
        final List<RegisteredService> services = new ArrayList<>();
        for (final ViewRow row : allKeys) {
            final RawJsonDocument document = row.document(RawJsonDocument.class);
            if (document != null) {
                final String json = document.content();
                LOGGER.debug("Found service: [{}]", json);
                final StringReader stringReader = new StringReader(json);
                final RegisteredService service = this.registeredServiceJsonSerializer.from(stringReader);
                services.add(service);
                publishEvent(new CasRegisteredServiceLoadedEvent(this, service));
            }
        }
        return services;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
Also used : CasRegisteredServiceLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument) ViewResult(com.couchbase.client.java.view.ViewResult) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 3 with ViewResult

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

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

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

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