use of com.couchbase.client.java.kv.UpsertOptions in project kafka-connect-couchbase by couchbase.
the class SinkAction method upsertJson.
/**
* Returns an action that upserts a JSON document to Couchbase.
* Uses the document ID as the concurrency hint.
*
* @param params conveys expiry and durability settings
* @param collection the collection where the document should be upserted.
* @param documentId ID to use for the Couchbase document
* @param json document content to upsert
*/
public static SinkAction upsertJson(SinkHandlerParams params, ReactiveCollection collection, String documentId, byte[] json) {
UpsertOptions options = upsertOptions().transcoder(RawJsonTranscoder.INSTANCE);
params.configureDurability(options);
params.expiry().ifPresent(options::expiry);
Mono<?> action = collection.upsert(documentId, json, options);
return new SinkAction(action, ConcurrencyHint.of(documentId));
}
use of com.couchbase.client.java.kv.UpsertOptions in project couchbase-jvm-clients by couchbase.
the class ReactiveCollection method upsert.
/**
* Upserts a full document which might or might not exist yet with custom options.
*
* @param id the document id to upsert.
* @param content the document content to upsert.
* @param options custom options to customize the upsert behavior.
* @return a {@link Mono} completing once upserted or failed.
*/
public Mono<MutationResult> upsert(final String id, Object content, final UpsertOptions options) {
return Mono.defer(() -> {
notNull(options, "UpsertOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
UpsertOptions.Built opts = options.build();
UpsertRequest request = asyncCollection.upsertRequest(id, content, opts);
return Reactor.wrap(request, UpsertAccessor.upsert(core, request, id, opts.persistTo(), opts.replicateTo()), true);
});
}
use of com.couchbase.client.java.kv.UpsertOptions in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryCollectionIntegrationTests method upsertByIdOptions.
@Test
public void upsertByIdOptions() {
// 10 - options
UpsertOptions options = UpsertOptions.upsertOptions().timeout(Duration.ofNanos(10));
assertThrows(AmbiguousTimeoutException.class, () -> couchbaseTemplate.upsertById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).one(vie.withIcao("770")));
}
use of com.couchbase.client.java.kv.UpsertOptions in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method upsertByIdOptions.
@Test
public void upsertByIdOptions() {
// 10 - options
UpsertOptions options = UpsertOptions.upsertOptions().timeout(Duration.ofNanos(10));
assertThrows(AmbiguousTimeoutException.class, () -> template.upsertById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).one(vie.withIcao("760")).block());
}
use of com.couchbase.client.java.kv.UpsertOptions in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method upsertById.
@Test
public void upsertById() {
// 10
UpsertOptions options = UpsertOptions.upsertOptions().timeout(Duration.ofSeconds(10));
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.upsertById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(options).one(vie.withIcao("lowf")).block();
try {
Airport found = template.findById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(getOptions).one(saved.getId()).block();
assertEquals(saved, found);
} finally {
template.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId()).block();
}
}
Aggregations