use of com.couchbase.client.java.kv.ReplaceOptions in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method replaceById.
@Test
public void replaceById() {
// 9
InsertOptions insertOptions = InsertOptions.insertOptions().timeout(Duration.ofSeconds(10));
ReplaceOptions options = ReplaceOptions.replaceOptions().timeout(Duration.ofSeconds(10));
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(insertOptions).one(vie.withIcao("lowe")).block();
Airport replaced = template.replaceById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(options).one(vie.withIcao("newIcao")).block();
try {
Airport found = template.findById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(getOptions).one(saved.getId()).block();
assertEquals(replaced, found);
} finally {
template.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId()).block();
}
}
use of com.couchbase.client.java.kv.ReplaceOptions in project couchbase-jvm-clients by couchbase.
the class ReactiveCollection method replace.
/**
* Replaces a full document which already exists with custom options.
*
* @param id the document id to replace.
* @param content the document content to replace.
* @param options custom options to customize the replace behavior.
* @return a {@link Mono} completing once replaced or failed.
*/
public Mono<MutationResult> replace(final String id, Object content, final ReplaceOptions options) {
return Mono.defer(() -> {
notNull(options, "ReplaceOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
ReplaceOptions.Built opts = options.build();
ReplaceRequest request = asyncCollection.replaceRequest(id, content, opts);
return Reactor.wrap(request, ReplaceAccessor.replace(core, request, id, opts.persistTo(), opts.replicateTo()), true);
});
}
Aggregations