Search in sources :

Example 6 with ReplaceOptions

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();
    }
}
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 7 with ReplaceOptions

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

Aggregations

ReplaceOptions (com.couchbase.client.java.kv.ReplaceOptions)7 Test (org.junit.jupiter.api.Test)6 Airport (org.springframework.data.couchbase.domain.Airport)5 GetOptions (com.couchbase.client.java.kv.GetOptions)4 InsertOptions (com.couchbase.client.java.kv.InsertOptions)4 ReplaceRequest (com.couchbase.client.core.msg.kv.ReplaceRequest)1