Search in sources :

Example 21 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project spring-data-couchbase by spring-projects.

the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method removeByQueryOptions.

@Test
public void removeByQueryOptions() {
    // 8 - options
    QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofNanos(10));
    assertThrows(AmbiguousTimeoutException.class, () -> template.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection).withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all().collectList().block());
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) QueryOptions(com.couchbase.client.java.query.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 22 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project spring-data-couchbase by spring-projects.

the class OptionsBuilder method buildQueryOptions.

static QueryOptions buildQueryOptions(Query query, QueryOptions options, QueryScanConsistency scanConsistency) {
    options = options != null ? options : QueryOptions.queryOptions();
    if (query.getParameters() != null) {
        if (query.getParameters() instanceof JsonArray) {
            options.parameters((JsonArray) query.getParameters());
        } else {
            options.parameters((JsonObject) query.getParameters());
        }
    }
    Meta meta = query.getMeta() != null ? query.getMeta() : new Meta();
    QueryOptions.Built optsBuilt = options.build();
    JsonObject optsJson = getQueryOpts(optsBuilt);
    QueryScanConsistency metaQueryScanConsistency = meta.get(SCAN_CONSISTENCY) != null ? ((ScanConsistency) meta.get(SCAN_CONSISTENCY)).query() : null;
    QueryScanConsistency qsc = fromFirst(QueryScanConsistency.NOT_BOUNDED, getScanConsistency(optsJson), scanConsistency, metaQueryScanConsistency);
    Duration timeout = fromFirst(Duration.ofSeconds(0), getTimeout(optsBuilt), meta.get(TIMEOUT));
    RetryStrategy retryStrategy = fromFirst(null, getRetryStrategy(optsBuilt), meta.get(RETRY_STRATEGY));
    if (qsc != null) {
        options.scanConsistency(qsc);
    }
    if (timeout != null) {
        options.timeout(timeout);
    }
    if (retryStrategy != null) {
        options.retryStrategy(retryStrategy);
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("query options: {}", getQueryOpts(options.build()));
    }
    return options;
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) JsonObject(com.couchbase.client.java.json.JsonObject) QueryScanConsistency(com.couchbase.client.java.query.QueryScanConsistency) Duration(java.time.Duration) QueryOptions(com.couchbase.client.java.query.QueryOptions) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy)

Example 23 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method removeByQueryOther.

@Test
public void removeByQueryOther() {
    // 8
    QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("648"));
    List<RemoveResult> removeResults = couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection).withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all();
    assertEquals(saved.getId(), removeResults.get(0).getId());
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) QueryOptions(com.couchbase.client.java.query.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 24 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method findByQuery.

@Test
public void findByQuery() {
    // 4
    QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("441"));
    try {
        List<Airport> found = couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName).withOptions(options).all();
        assertEquals(saved.getId(), found.get(0).getId());
    } finally {
        couchbaseTemplate.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId());
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) QueryOptions(com.couchbase.client.java.query.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 25 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method findByQueryOther.

@Test
public void findByQueryOther() {
    // 4
    QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("594"));
    try {
        List<Airport> found = couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection).withOptions(options).all();
        assertEquals(saved.getId(), found.get(0).getId());
    } finally {
        couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId());
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) QueryOptions(com.couchbase.client.java.query.QueryOptions) Test(org.junit.jupiter.api.Test)

Aggregations

QueryOptions (com.couchbase.client.java.query.QueryOptions)40 Test (org.junit.jupiter.api.Test)31 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)19 ReactiveQueryResult (com.couchbase.client.java.query.ReactiveQueryResult)18 QueryResult (com.couchbase.client.java.query.QueryResult)16 JsonObject (com.couchbase.client.java.json.JsonObject)15 Airport (org.springframework.data.couchbase.domain.Airport)10 ReducedQueryErrorContext (com.couchbase.client.core.error.context.ReducedQueryErrorContext)4 JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)4 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)2 JsonArray (com.couchbase.client.java.json.JsonArray)2 MutationResult (com.couchbase.client.java.kv.MutationResult)2 Duration (java.time.Duration)2 RemoveResult (org.springframework.data.couchbase.core.RemoveResult)2 Reactor (com.couchbase.client.core.Reactor)1 Stability (com.couchbase.client.core.annotation.Stability)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)1 IndexFailureException (com.couchbase.client.core.error.IndexFailureException)1