Search in sources :

Example 1 with RawJsonDocument

use of com.couchbase.client.java.document.RawJsonDocument in project cas by apereo.

the class CouchbaseServiceRegistryDao method findServiceById.

@Override
public RegisteredService findServiceById(final long id) {
    try {
        LOGGER.debug("Lookup for service [{}]", id);
        final RawJsonDocument document = this.couchbase.bucket().get(String.valueOf(id), RawJsonDocument.class);
        if (document != null) {
            final String json = document.content();
            final StringReader stringReader = new StringReader(json);
            return this.registeredServiceJsonSerializer.from(stringReader);
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : StringReader(java.io.StringReader) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument)

Example 2 with RawJsonDocument

use of com.couchbase.client.java.document.RawJsonDocument 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 3 with RawJsonDocument

use of com.couchbase.client.java.document.RawJsonDocument in project YCSB by brianfrankcooper.

the class BackoffSelectStrategy method readKv.

/**
   * Performs the {@link #read(String, String, Set, HashMap)} operation via Key/Value ("get").
   *
   * @param docId the document ID
   * @param fields the fields to be loaded
   * @param result the result map where the doc needs to be converted into
   * @return The result of the operation.
   */
private Status readKv(final String docId, final Set<String> fields, final HashMap<String, ByteIterator> result) throws Exception {
    RawJsonDocument loaded = bucket.get(docId, RawJsonDocument.class);
    if (loaded == null) {
        return Status.NOT_FOUND;
    }
    decode(loaded.content(), fields, result);
    return Status.OK;
}
Also used : RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument)

Aggregations

RawJsonDocument (com.couchbase.client.java.document.RawJsonDocument)3 StringReader (java.io.StringReader)2 ViewResult (com.couchbase.client.java.view.ViewResult)1 ViewRow (com.couchbase.client.java.view.ViewRow)1 LinkedList (java.util.LinkedList)1