Search in sources :

Example 11 with QueryRequest

use of com.couchbase.client.core.msg.query.QueryRequest 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

QueryRequest (com.couchbase.client.core.msg.query.QueryRequest)11 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)4 ClusterConfig (com.couchbase.client.core.config.ClusterConfig)3 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)3 Duration (java.time.Duration)3 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)2 DefaultHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpContent)2 DefaultHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse)2 DefaultLastHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent)2 HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)2 ReducedQueryErrorContext (com.couchbase.client.core.error.context.ReducedQueryErrorContext)2 QueryResponse (com.couchbase.client.core.msg.query.QueryResponse)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)2 Service (com.couchbase.client.core.service.Service)2 ServiceType (com.couchbase.client.core.service.ServiceType)2 JsonObject (com.couchbase.client.java.json.JsonObject)2 Optional (java.util.Optional)2 Core (com.couchbase.client.core.Core)1