Search in sources :

Example 1 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class AsyncQueryIndexManager method toQueryOptions.

private static QueryOptions toQueryOptions(CommonOptions<?>.BuiltCommonOptions options) {
    QueryOptions result = QueryOptions.queryOptions();
    options.timeout().ifPresent(result::timeout);
    options.retryStrategy().ifPresent(result::retryStrategy);
    result.clientContext(options.clientContext());
    return result;
}
Also used : QueryOptions(com.couchbase.client.java.query.QueryOptions)

Example 2 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class AsyncScope method query.

/**
 * Performs a N1QL query with custom {@link QueryOptions} in a Scope.
 *
 * @param statement the N1QL query statement as a raw string.
 * @param options the custom options for this query.
 * @return the {@link QueryResult} once the response arrives successfully.
 */
public CompletableFuture<QueryResult> query(final String statement, final QueryOptions options) {
    notNull(options, "QueryOptions", () -> new ReducedQueryErrorContext(statement));
    final QueryOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment.jsonSerializer() : opts.serializer();
    return queryAccessor.queryAsync(queryRequest(bucketName(), scopeName, statement, opts, core, environment()), opts, serializer);
}
Also used : JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) ReducedQueryErrorContext(com.couchbase.client.core.error.context.ReducedQueryErrorContext) QueryOptions(com.couchbase.client.java.query.QueryOptions)

Example 3 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class ReactiveScope method query.

/**
 * Performs a N1QL query with custom {@link QueryOptions} in a Scope
 *
 * @param statement the N1QL query statement as a raw string.
 * @param options the custom options for this query.
 * @return the {@link ReactiveQueryResult} once the response arrives successfully.
 */
public Mono<ReactiveQueryResult> query(final String statement, final QueryOptions options) {
    notNull(options, "QueryOptions", () -> new ReducedQueryErrorContext(statement));
    final QueryOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment().jsonSerializer() : opts.serializer();
    return Mono.defer(() -> {
        return async().queryAccessor().queryReactive(async().queryRequest(bucketName(), name(), statement, opts, core(), environment()), opts, serializer);
    });
}
Also used : JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) ReducedQueryErrorContext(com.couchbase.client.core.error.context.ReducedQueryErrorContext) QueryOptions(com.couchbase.client.java.query.QueryOptions)

Example 4 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class ReactiveCluster method query.

/**
 * Performs a N1QL query with custom {@link QueryOptions}.
 *
 * @param statement the N1QL query statement as a raw string.
 * @param options the custom options for this query.
 * @return the {@link ReactiveQueryResult} once the response arrives successfully.
 */
public Mono<ReactiveQueryResult> query(final String statement, final QueryOptions options) {
    notNull(options, "QueryOptions", () -> new ReducedQueryErrorContext(statement));
    final QueryOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment().jsonSerializer() : opts.serializer();
    return Mono.defer(() -> {
        return asyncCluster.queryAccessor().queryReactive(asyncCluster.queryRequest(statement, opts), opts, serializer);
    });
}
Also used : JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) ReducedQueryErrorContext(com.couchbase.client.core.error.context.ReducedQueryErrorContext) QueryOptions(com.couchbase.client.java.query.QueryOptions)

Example 5 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class QueryCollectionIntegrationTest method consistentWith.

// Test for MB-46876
@Test
void consistentWith() {
    String id = UUID.randomUUID().toString();
    Scope scope = cluster.bucket(config().bucketname()).scope(SCOPE_NAME);
    Collection collection = scope.collection(COLLECTION_NAME);
    MutationResult mr = collection.insert(id, FOO_CONTENT);
    QueryOptions options = queryOptions().consistentWith(MutationState.from(mr.mutationToken().get())).parameters(JsonArray.from(id));
    QueryResult result = scope.query("select * from `" + COLLECTION_NAME + "` where meta().id=$1", options);
    List<JsonObject> rows = result.rowsAs(JsonObject.class);
    assertEquals(1, rows.size());
    assertEquals(FOO_CONTENT, rows.get(0).getObject(COLLECTION_NAME));
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) 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