use of com.couchbase.client.java.document.JsonDocument in project sling by apache.
the class CouchbaseNoSqlAdapter method get.
@Override
public NoSqlData get(String path) {
Bucket bucket = couchbaseClient.getBucket();
String cacheKey = CouchbaseKey.build(path, cacheKeyPrefix);
JsonDocument doc = bucket.get(cacheKey);
if (doc == null) {
return null;
} else {
JsonObject data = doc.content().getObject(PN_DATA);
if (data == null) {
return null;
} else {
return new NoSqlData(path, data.toMap(), MultiValueMode.LISTS);
}
}
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class AbstractCrudService method readBulk.
@Override
public List<T> readBulk(Iterable<String> ids) {
final AsyncBucket asyncBucket = bucket.async();
Observable<JsonDocument> asyncOperation = Observable.from(ids).flatMap(new Func1<String, Observable<JsonDocument>>() {
public Observable<JsonDocument> call(String key) {
return asyncBucket.get(key);
}
});
final List<T> items = new ArrayList<T>();
try {
asyncOperation.toBlocking().forEach(new Action1<JsonDocument>() {
public void call(JsonDocument doc) {
T item = converter.fromDocument(doc);
items.add(item);
}
});
} catch (Exception e) {
logger.error("Error during bulk get", e);
}
return items;
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class AbstractCrudService method create.
@Override
public void create(T t) {
if (t.getId() == null) {
t.setId(UUID.randomUUID().toString());
}
JsonDocument doc = converter.toDocument(t);
bucket.insert(doc);
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class AbstractCrudService method update.
@Override
public void update(T t) {
JsonDocument doc = converter.toDocument(t);
bucket.upsert(doc);
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class CodeSnippets method getLatestReplicaVersion.
static JsonDocument getLatestReplicaVersion(Bucket bucket, String id) {
long maxCasValue = -1;
JsonDocument latest = null;
for (JsonDocument replica : bucket.getFromReplica(id, ReplicaMode.ALL)) {
if (replica.cas() > maxCasValue) {
latest = replica;
maxCasValue = replica.cas();
}
}
return latest;
}
Aggregations