Search in sources :

Example 1 with RemoveOptions

use of com.couchbase.client.java.kv.RemoveOptions in project couchbase-jvm-clients by couchbase.

the class ReactiveCollection method remove.

/**
 * Removes a Document from a collection with custom options.
 *
 * @param id the id of the document to remove.
 * @param options custom options to change the default behavior.
 * @return a {@link Mono} completing once removed or failed.
 */
public Mono<MutationResult> remove(final String id, final RemoveOptions options) {
    return Mono.defer(() -> {
        notNull(options, "RemoveOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
        RemoveOptions.Built opts = options.build();
        RemoveRequest request = asyncCollection.removeRequest(id, opts);
        return Reactor.wrap(request, RemoveAccessor.remove(core, request, id, opts.persistTo(), opts.replicateTo()), true);
    });
}
Also used : RemoveRequest(com.couchbase.client.core.msg.kv.RemoveRequest) RemoveOptions(com.couchbase.client.java.kv.RemoveOptions)

Example 2 with RemoveOptions

use of com.couchbase.client.java.kv.RemoveOptions in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method removeByIdOther.

@Test
public void removeByIdOther() {
    // 7
    RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("638"));
    RemoveResult removeResult = couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).withOptions(options).one(saved.getId());
    assertEquals(saved.getId(), removeResult.getId());
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) RemoveOptions(com.couchbase.client.java.kv.RemoveOptions) Test(org.junit.jupiter.api.Test)

Example 3 with RemoveOptions

use of com.couchbase.client.java.kv.RemoveOptions in project spring-data-couchbase by spring-projects.

the class OptionsBuilder method buildRemoveOptions.

public static RemoveOptions buildRemoveOptions(RemoveOptions options, PersistTo persistTo, ReplicateTo replicateTo, DurabilityLevel durabilityLevel, Long cas) {
    options = options != null ? options : RemoveOptions.removeOptions();
    if (persistTo != PersistTo.NONE || replicateTo != ReplicateTo.NONE) {
        options.durability(persistTo, replicateTo);
    } else if (durabilityLevel != DurabilityLevel.NONE) {
        options.durability(durabilityLevel);
    }
    RemoveOptions.Built optsBuilt = options.build();
    Duration timeout = fromFirst(Duration.ofSeconds(0), optsBuilt.timeout());
    RetryStrategy retryStrategy = fromFirst(null, optsBuilt.retryStrategy());
    if (timeout != null) {
        options.timeout(timeout);
    }
    if (retryStrategy != null) {
        options.retryStrategy(retryStrategy);
    }
    if (cas != null) {
        options.cas(cas);
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("remove options: {}" + toString(options));
    }
    return options;
}
Also used : Duration(java.time.Duration) RemoveOptions(com.couchbase.client.java.kv.RemoveOptions) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy)

Example 4 with RemoveOptions

use of com.couchbase.client.java.kv.RemoveOptions in project spring-data-couchbase by spring-projects.

the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method removeByIdOther.

@Test
public void removeByIdOther() {
    // 7
    RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10));
    Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowm")).block();
    RemoveResult removeResult = template.removeById().inScope(otherScope).inCollection(otherCollection).withOptions(options).one(saved.getId()).block();
    assertEquals(saved.getId(), removeResult.getId());
}
Also used : RemoveResult(org.springframework.data.couchbase.core.RemoveResult) Airport(org.springframework.data.couchbase.domain.Airport) RemoveOptions(com.couchbase.client.java.kv.RemoveOptions) Test(org.junit.jupiter.api.Test)

Example 5 with RemoveOptions

use of com.couchbase.client.java.kv.RemoveOptions in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method removeById.

@Test
public void removeById() {
    // 7
    RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("485"));
    RemoveResult removeResult = couchbaseTemplate.removeById().inScope(scopeName).inCollection(collectionName).withOptions(options).one(saved.getId());
    assertEquals(saved.getId(), removeResult.getId());
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) RemoveOptions(com.couchbase.client.java.kv.RemoveOptions) Test(org.junit.jupiter.api.Test)

Aggregations

RemoveOptions (com.couchbase.client.java.kv.RemoveOptions)9 Test (org.junit.jupiter.api.Test)6 Airport (org.springframework.data.couchbase.domain.Airport)6 RemoveResult (org.springframework.data.couchbase.core.RemoveResult)2 RemoveRequest (com.couchbase.client.core.msg.kv.RemoveRequest)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 Duration (java.time.Duration)1