use of com.couchbase.client.java.error.DocumentAlreadyExistsException in project sling by apache.
the class CouchbaseNoSqlAdapter method store.
@Override
public boolean store(NoSqlData data) {
Bucket bucket = couchbaseClient.getBucket();
String cacheKey = CouchbaseKey.build(data.getPath(), cacheKeyPrefix);
JsonObject envelope = JsonObject.create();
envelope.put(PN_PATH, data.getPath());
envelope.put(PN_DATA, JsonObject.from(data.getProperties(MultiValueMode.LISTS)));
// for list-children query efficiency store parent path as well
String parentPath = ResourceUtil.getParent(data.getPath());
if (parentPath != null) {
envelope.put(PN_PARENT_PATH, parentPath);
}
JsonDocument doc = JsonDocument.create(cacheKey, envelope);
try {
bucket.insert(doc);
// created
return true;
} catch (DocumentAlreadyExistsException ex) {
bucket.upsert(doc);
// updated
return false;
}
}
Aggregations