Search in sources :

Example 1 with InsertOptions

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);
    });
}
Also used : InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) InsertOptions(com.couchbase.client.java.kv.InsertOptions)

Example 2 with InsertOptions

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())));
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) InsertOptions(com.couchbase.client.java.kv.InsertOptions) Test(org.junit.jupiter.api.Test)

Example 3 with InsertOptions

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());
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) ReplaceOptions(com.couchbase.client.java.kv.ReplaceOptions) InsertOptions(com.couchbase.client.java.kv.InsertOptions) GetOptions(com.couchbase.client.java.kv.GetOptions) Test(org.junit.jupiter.api.Test)

Example 4 with InsertOptions

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();
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) InsertOptions(com.couchbase.client.java.kv.InsertOptions) GetOptions(com.couchbase.client.java.kv.GetOptions) Test(org.junit.jupiter.api.Test)

Example 5 with InsertOptions

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();
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) ReplaceOptions(com.couchbase.client.java.kv.ReplaceOptions) InsertOptions(com.couchbase.client.java.kv.InsertOptions) GetOptions(com.couchbase.client.java.kv.GetOptions) Test(org.junit.jupiter.api.Test)

Aggregations

InsertOptions (com.couchbase.client.java.kv.InsertOptions)12 Test (org.junit.jupiter.api.Test)11 Airport (org.springframework.data.couchbase.domain.Airport)9 GetOptions (com.couchbase.client.java.kv.GetOptions)8 ReplaceOptions (com.couchbase.client.java.kv.ReplaceOptions)4 DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)1 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)1 JsonObject (com.couchbase.client.java.json.JsonObject)1 ExistsResult (com.couchbase.client.java.kv.ExistsResult)1 GetResult (com.couchbase.client.java.kv.GetResult)1 MutationResult (com.couchbase.client.java.kv.MutationResult)1 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)1 ClusterType (com.couchbase.client.test.ClusterType)1 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)1 Duration (java.time.Duration)1 Iterator (java.util.Iterator)1 List (java.util.List)1 AfterAll (org.junit.jupiter.api.AfterAll)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1