use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class AbstractCrudService method createBulk.
@Override
public void createBulk(Iterable<T> items) {
final AsyncBucket asyncBucket = bucket.async();
Observable.from(items).flatMap(new Func1<T, Observable<JsonDocument>>() {
@SuppressWarnings("unchecked")
@Override
public Observable<JsonDocument> call(final T t) {
if (t.getId() == null) {
t.setId(UUID.randomUUID().toString());
}
JsonDocument doc = converter.toDocument(t);
return asyncBucket.insert(doc).retryWhen(RetryBuilder.anyOf(BackpressureException.class).delay(Delay.exponential(TimeUnit.MILLISECONDS, 100)).max(10).build());
}
}).last().toBlocking().single();
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class AbstractCrudService method updateBulk.
@Override
public void updateBulk(Iterable<T> items) {
final AsyncBucket asyncBucket = bucket.async();
Observable.from(items).flatMap(new Func1<T, Observable<JsonDocument>>() {
@SuppressWarnings("unchecked")
@Override
public Observable<JsonDocument> call(final T t) {
JsonDocument doc = converter.toDocument(t);
return asyncBucket.upsert(doc).retryWhen(RetryBuilder.anyOf(BackpressureException.class).delay(Delay.exponential(TimeUnit.MILLISECONDS, 100)).max(10).build());
}
}).last().toBlocking().single();
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class AbstractCrudService method deleteBulk.
@Override
public void deleteBulk(Iterable<String> ids) {
final AsyncBucket asyncBucket = bucket.async();
Observable.from(ids).flatMap(new Func1<String, Observable<JsonDocument>>() {
@SuppressWarnings("unchecked")
@Override
public Observable<JsonDocument> call(String key) {
return asyncBucket.remove(key).retryWhen(RetryBuilder.anyOf(BackpressureException.class).delay(Delay.exponential(TimeUnit.MILLISECONDS, 100)).max(10).build());
}
}).last().toBlocking().single();
}
use of com.couchbase.client.java.document.JsonDocument in project jnosql-diana-driver by eclipse.
the class CouchbaseBucketManager method put.
@Override
public <K> void put(KeyValueEntity<K> entity, Duration ttl) {
requireNonNull(entity, "entity is required");
requireNonNull(ttl, "ttl is required");
if (JsonValue.checkType(entity.get())) {
RawJsonDocument jsonDocument = RawJsonDocument.create(entity.getKey().toString(), (int) ttl.getSeconds(), JSONB.toJson(entity.get().toString()));
bucket.upsert(jsonDocument);
} else {
JsonObject jsonObject = JsonObjectCouchbaseUtil.toJson(JSONB, entity.get());
JsonDocument jsonDocument = JsonDocument.create(entity.getKey().toString(), (int) ttl.getSeconds(), jsonObject);
bucket.upsert(jsonDocument);
}
}
use of com.couchbase.client.java.document.JsonDocument in project incubator-gobblin by apache.
the class CouchbaseTestServer method testServer.
@Test
public static void testServer() throws InterruptedException, IOException {
CouchbaseTestServer couchbaseTestServer = new CouchbaseTestServer(TestUtils.findFreePort());
couchbaseTestServer.start();
int port = couchbaseTestServer.getPort();
int serverPort = couchbaseTestServer.getServerPort();
try {
CouchbaseEnvironment cbEnv = DefaultCouchbaseEnvironment.builder().bootstrapHttpEnabled(true).bootstrapHttpDirectPort(port).bootstrapCarrierDirectPort(serverPort).connectTimeout(TimeUnit.SECONDS.toMillis(15)).bootstrapCarrierEnabled(true).build();
CouchbaseCluster cbCluster = CouchbaseCluster.create(cbEnv, "localhost");
Bucket bucket = cbCluster.openBucket("default", "");
try {
JsonObject content = JsonObject.empty().put("name", "Michael");
JsonDocument doc = JsonDocument.create("docId", content);
JsonDocument inserted = bucket.insert(doc);
} catch (Exception e) {
Assert.fail("Should not throw exception on insert", e);
}
} finally {
couchbaseTestServer.stop();
}
}
Aggregations