Search in sources :

Example 1 with ExistsOptions

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

the class AsyncCollection method existsRequest.

/**
 * Helper method to create the exists request from its options.
 *
 * @param id the document ID
 * @param options custom options to change the default behavior
 * @return the observe request used for exists.
 */
GetMetaRequest existsRequest(final String id, final ExistsOptions options) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(options, "ExistsOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    ExistsOptions.Built opts = options.build();
    Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_EXISTS, opts.parentSpan().orElse(null));
    GetMetaRequest request = new GetMetaRequest(id, timeout, coreContext, collectionIdentifier, retryStrategy, span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : GetMetaRequest(com.couchbase.client.core.msg.kv.GetMetaRequest) Duration(java.time.Duration) ExistsOptions(com.couchbase.client.java.kv.ExistsOptions) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 2 with ExistsOptions

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

the class CouchbaseTemplateQueryCollectionIntegrationTests method existsById.

/**
 * find . -name 'Exec*OperationSupport.java'|awk -F/ '{print $NF}'|sort| awk -F. '{print "* ", NR, ")",$1, ""}'<br>
 * 1) ExecutableExistsByIdOperationSupport <br>
 * 2) ExecutableFindByAnalyticsOperationSupport <br>
 * 3) ExecutableFindByIdOperationSupport <br>
 * 4) ExecutableFindByQueryOperationSupport <br>
 * 5) ExecutableFindFromReplicasByIdOperationSupport <br>
 * 6) ExecutableInsertByIdOperationSupport <br>
 * 7) ExecutableRemoveByIdOperationSupport <br>
 * 8) ExecutableRemoveByQueryOperationSupport <br>
 * 9) ExecutableReplaceByIdOperationSupport <br>
 * 10)ExecutableUpsertByIdOperationSupport <br>
 */
@Test
public void existsById() {
    // 1
    GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
    ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("398"));
    try {
        Boolean exists = couchbaseTemplate.existsById().inScope(scopeName).inCollection(collectionName).withOptions(existsOptions).one(saved.getId());
        assertTrue(exists, "Airport should exist: " + saved.getId());
    } finally {
        couchbaseTemplate.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId());
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) ExistsOptions(com.couchbase.client.java.kv.ExistsOptions) GetOptions(com.couchbase.client.java.kv.GetOptions) Test(org.junit.jupiter.api.Test)

Example 3 with ExistsOptions

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

the class CouchbaseTemplateQueryCollectionIntegrationTests method existsByIdOptions.

@Test
public void existsByIdOptions() {
    // 1 - Options
    ExistsOptions options = ExistsOptions.existsOptions().timeout(Duration.ofNanos(10));
    assertThrows(UnambiguousTimeoutException.class, () -> couchbaseTemplate.existsById().inScope(otherScope).inCollection(otherCollection).withOptions(options).one(vie.getId()));
}
Also used : ExistsOptions(com.couchbase.client.java.kv.ExistsOptions) Test(org.junit.jupiter.api.Test)

Example 4 with ExistsOptions

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

the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method existsById.

/**
 * find . -name 'Exec*OperationSupport.java'|awk -F/ '{print $NF}'|sort| awk -F. '{print "* ", NR, ")",$1, ""}'<br>
 * 1) ExecutableExistsByIdOperationSupport <br>
 * 2) ExecutableFindByAnalyticsOperationSupport <br>
 * 3) ExecutableFindByIdOperationSupport <br>
 * 4) ExecutableFindByQueryOperationSupport <br>
 * 5) ExecutableFindFromReplicasByIdOperationSupport <br>
 * 6) ExecutableInsertByIdOperationSupport <br>
 * 7) ExecutableRemoveByIdOperationSupport <br>
 * 8) ExecutableRemoveByQueryOperationSupport <br>
 * 9) ExecutableReplaceByIdOperationSupport <br>
 * 10)ExecutableUpsertByIdOperationSupport <br>
 */
@Test
public void existsById() {
    // 1
    GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
    ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
    Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("low7")).block();
    try {
        Boolean exists = template.existsById().inScope(scopeName).inCollection(collectionName).withOptions(existsOptions).one(saved.getId()).block();
        assertTrue(exists, "Airport should exist: " + saved.getId());
    } finally {
        template.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId()).block();
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) ExistsOptions(com.couchbase.client.java.kv.ExistsOptions) GetOptions(com.couchbase.client.java.kv.GetOptions) Test(org.junit.jupiter.api.Test)

Example 5 with ExistsOptions

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

the class CouchbaseTemplateQueryCollectionIntegrationTests method existsByIdOther.

@Test
public void existsByIdOther() {
    // 1
    GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
    ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowg"));
    try {
        Boolean exists = couchbaseTemplate.existsById().inScope(otherScope).inCollection(otherCollection).withOptions(existsOptions).one(vie.getId());
        assertTrue(exists, "Airport should exist: " + vie.getId());
    } finally {
        couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(vie.getId());
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) ExistsOptions(com.couchbase.client.java.kv.ExistsOptions) GetOptions(com.couchbase.client.java.kv.GetOptions) Test(org.junit.jupiter.api.Test)

Aggregations

ExistsOptions (com.couchbase.client.java.kv.ExistsOptions)7 Test (org.junit.jupiter.api.Test)6 GetOptions (com.couchbase.client.java.kv.GetOptions)4 Airport (org.springframework.data.couchbase.domain.Airport)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 GetMetaRequest (com.couchbase.client.core.msg.kv.GetMetaRequest)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 Duration (java.time.Duration)1