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;
}
Aggregations