Search in sources :

Example 1 with ReducedQueryErrorContext

use of com.couchbase.client.core.error.context.ReducedQueryErrorContext 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 2 with ReducedQueryErrorContext

use of com.couchbase.client.core.error.context.ReducedQueryErrorContext 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 3 with ReducedQueryErrorContext

use of com.couchbase.client.core.error.context.ReducedQueryErrorContext 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 4 with ReducedQueryErrorContext

use of com.couchbase.client.core.error.context.ReducedQueryErrorContext in project couchbase-jvm-clients by couchbase.

the class AsyncScope method queryRequest.

/**
 * Helper method to construct the query request. ( copied from Cluster )
 *
 * @param statement the statement of the query.
 * @param options the options.
 * @return the constructed query request.
 */
static QueryRequest queryRequest(final String bucketName, final String scopeName, final String statement, final QueryOptions.Built options, final Core core, final ClusterEnvironment environment) {
    notNullOrEmpty(statement, "Statement", () -> new ReducedQueryErrorContext(statement));
    Duration timeout = options.timeout().orElse(environment.timeoutConfig().queryTimeout());
    RetryStrategy retryStrategy = options.retryStrategy().orElse(environment.retryStrategy());
    final JsonObject query = JsonObject.create();
    query.put("statement", statement);
    query.put("timeout", encodeDurationToMs(timeout));
    String queryContext = QueryRequest.queryContext(bucketName, scopeName);
    query.put("query_context", queryContext);
    options.injectParams(query);
    final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
    final String clientContextId = query.getString("client_context_id");
    final RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_QUERY, options.parentSpan().orElse(null));
    QueryRequest request = new QueryRequest(timeout, core.context(), retryStrategy, core.context().authenticator(), statement, queryBytes, options.readonly(), clientContextId, span, bucketName, scopeName, null);
    request.context().clientContext(options.clientContext());
    return request;
}
Also used : QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) JsonObject(com.couchbase.client.java.json.JsonObject) Duration(java.time.Duration) ReducedQueryErrorContext(com.couchbase.client.core.error.context.ReducedQueryErrorContext) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 5 with ReducedQueryErrorContext

use of com.couchbase.client.core.error.context.ReducedQueryErrorContext in project couchbase-jvm-clients by couchbase.

the class AsyncCluster method queryRequest.

/**
 * Helper method to construct the query request.
 *
 * @param statement the statement of the query.
 * @param options the options.
 * @return the constructed query request.
 */
QueryRequest queryRequest(final String statement, final QueryOptions.Built options) {
    notNullOrEmpty(statement, "Statement", () -> new ReducedQueryErrorContext(statement));
    Duration timeout = options.timeout().orElse(environment.get().timeoutConfig().queryTimeout());
    RetryStrategy retryStrategy = options.retryStrategy().orElse(environment.get().retryStrategy());
    final JsonObject query = JsonObject.create();
    query.put("statement", statement);
    query.put("timeout", encodeDurationToMs(timeout));
    options.injectParams(query);
    final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
    final String clientContextId = query.getString("client_context_id");
    final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_QUERY, options.parentSpan().orElse(null));
    QueryRequest request = new QueryRequest(timeout, core.context(), retryStrategy, authenticator, statement, queryBytes, options.readonly(), clientContextId, span, null, null, null);
    request.context().clientContext(options.clientContext());
    return request;
}
Also used : QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) JsonObject(com.couchbase.client.java.json.JsonObject) Duration(java.time.Duration) ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionStringUtil.checkConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString) ReducedQueryErrorContext(com.couchbase.client.core.error.context.ReducedQueryErrorContext) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

ReducedQueryErrorContext (com.couchbase.client.core.error.context.ReducedQueryErrorContext)6 JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)4 QueryOptions (com.couchbase.client.java.query.QueryOptions)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 QueryRequest (com.couchbase.client.core.msg.query.QueryRequest)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)2 JsonObject (com.couchbase.client.java.json.JsonObject)2 Duration (java.time.Duration)2 ConnectionString (com.couchbase.client.core.util.ConnectionString)1 ConnectionStringUtil.asConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString)1 ConnectionStringUtil.checkConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString)1