use of com.couchbase.client.java.kv.InsertOptions in project couchbase-jvm-clients by couchbase.
the class ReactiveCollection method insert.
/**
* Inserts a full document which does not exist yet with custom options.
*
* @param id the document id to insert.
* @param content the document content to insert.
* @param options custom options to customize the insert behavior.
* @return a {@link Mono} completing once inserted or failed.
*/
public Mono<MutationResult> insert(final String id, Object content, final InsertOptions options) {
return Mono.defer(() -> {
notNull(options, "InsertOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
InsertOptions.Built opts = options.build();
InsertRequest request = asyncCollection.insertRequest(id, content, opts);
return Reactor.wrap(request, InsertAccessor.insert(core, request, id, opts.persistTo(), opts.replicateTo()), true);
});
}
use of com.couchbase.client.java.kv.InsertOptions in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryCollectionIntegrationTests method insertByIdOptions.
@Test
public void insertByIdOptions() {
// 6
InsertOptions options = InsertOptions.insertOptions().timeout(Duration.ofNanos(10));
assertThrows(AmbiguousTimeoutException.class, () -> couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).one(vie.withId(UUID.randomUUID().toString())));
}
use of com.couchbase.client.java.kv.InsertOptions in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryCollectionIntegrationTests method replaceByIdOther.
@Test
public void replaceByIdOther() {
// 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 = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(insertOptions).one(vie.withIcao("661"));
Airport replaced = couchbaseTemplate.replaceById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).one(vie.withIcao("newIcao"));
try {
Airport found = couchbaseTemplate.findById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(getOptions).one(saved.getId());
assertEquals(replaced, found);
} finally {
couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId());
}
}
use of com.couchbase.client.java.kv.InsertOptions in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method insertById.
@Test
public void insertById() {
// 6
InsertOptions options = InsertOptions.insertOptions().timeout(Duration.ofSeconds(10));
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(options).one(vie.withIcao("lowc").withId(UUID.randomUUID().toString())).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();
}
}
use of com.couchbase.client.java.kv.InsertOptions in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method replaceByIdOther.
@Test
public void replaceByIdOther() {
// 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(otherScope).inCollection(otherCollection).withOptions(insertOptions).one(vie.withIcao("lown")).block();
Airport replaced = template.replaceById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).one(vie.withIcao("newIcao")).block();
try {
Airport found = template.findById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(getOptions).one(saved.getId()).block();
assertEquals(replaced, found);
} finally {
template.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId()).block();
}
}
Aggregations