use of com.couchbase.client.java.kv.MutateInOptions in project kafka-connect-couchbase by couchbase.
the class SubDocumentSinkHandler method handle.
@Override
public SinkAction handle(SinkHandlerParams params) {
String documentId = getDocumentId(params);
SinkDocument doc = params.document().orElse(null);
if (doc == null) {
return SinkAction.remove(params, params.collection(), documentId);
}
SubdocOperation operation = getOperation(documentId, doc);
MutateInSpec mutation;
switch(mode) {
case UPSERT:
mutation = MutateInSpec.upsert(operation.getPath(), operation.getData());
if (createPaths) {
mutation = ((Upsert) mutation).createPath();
}
break;
case ARRAY_APPEND:
mutation = MutateInSpec.arrayAppend(operation.getPath(), singletonList(operation.getData()));
if (createPaths) {
mutation = ((ArrayAppend) mutation).createPath();
}
break;
case ARRAY_PREPEND:
mutation = MutateInSpec.arrayPrepend(operation.getPath(), singletonList(operation.getData()));
if (createPaths) {
mutation = ((ArrayPrepend) mutation).createPath();
}
break;
default:
throw new RuntimeException("Unsupported subdoc mode: " + mode);
}
MutateInOptions options = mutateInOptions().storeSemantics(createDocuments ? UPSERT : REPLACE);
params.expiry().ifPresent(options::expiry);
params.configureDurability(options);
Mono<?> action = params.collection().mutateIn(documentId, singletonList(mutation), options);
return new SinkAction(action, ConcurrencyHint.of(documentId));
}
use of com.couchbase.client.java.kv.MutateInOptions in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method mutateIn.
/**
* Performs mutations to document fragments with custom options.
*
* @param id the outer document ID.
* @param specs the spec which specifies the type of mutations to perform.
* @param options custom options to modify the mutation options.
* @return the {@link MutateInResult} once the mutation has been performed or failed.
*/
public CompletableFuture<MutateInResult> mutateIn(final String id, final List<MutateInSpec> specs, final MutateInOptions options) {
notNull(options, "MutateInOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
MutateInOptions.Built opts = options.build();
Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
return mutateInRequest(id, specs, opts, timeout).thenCompose(request -> MutateInAccessor.mutateIn(core, request, id, opts.persistTo(), opts.replicateTo(), opts.storeSemantics() == StoreSemantics.INSERT, environment.jsonSerializer()));
}
use of com.couchbase.client.java.kv.MutateInOptions in project couchbase-jvm-clients by couchbase.
the class ReactiveCollection method mutateIn.
/**
* Performs mutations to document fragments with custom options.
*
* @param id the outer document ID.
* @param specs the spec which specifies the type of mutations to perform.
* @param options custom options to modify the mutation options.
* @return the {@link MutateInResult} once the mutation has been performed or failed.
*/
public Mono<MutateInResult> mutateIn(final String id, final List<MutateInSpec> specs, final MutateInOptions options) {
return Mono.defer(() -> {
notNull(options, "MutateInOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
MutateInOptions.Built opts = options.build();
Duration timeout = AsyncCollection.decideKvTimeout(opts, environment().timeoutConfig());
return Mono.fromFuture(asyncCollection.mutateInRequest(id, specs, opts, timeout)).flatMap(request -> Reactor.wrap(request, MutateInAccessor.mutateIn(core, request, id, opts.persistTo(), opts.replicateTo(), opts.storeSemantics() == StoreSemantics.INSERT, environment().jsonSerializer()), true));
});
}
Aggregations