use of com.couchbase.client.java.kv.LookupInSpec in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method lookupInRequest.
/**
* Helper method to create the underlying lookup subdoc request.
*
* @param id the outer document ID.
* @param specs the spec which specifies the type of lookups to perform.
* @param opts custom options to modify the lookup options.
* @return the subdoc lookup request.
*/
SubdocGetRequest lookupInRequest(final String id, final List<LookupInSpec> specs, final LookupInOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNullOrEmpty(specs, "LookupInSpecs", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
ArrayList<SubdocGetRequest.Command> commands = new ArrayList<>(specs.size());
for (int i = 0; i < specs.size(); i++) {
LookupInSpec spec = specs.get(i);
commands.add(spec.export(i));
}
// xattrs come first
commands.sort(Comparator.comparing(v -> !v.xattr()));
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
byte flags = 0;
if (opts.accessDeleted()) {
flags |= SubdocMutateRequest.SUBDOC_DOC_FLAG_ACCESS_DELETED;
}
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_LOOKUP_IN, opts.parentSpan().orElse(null));
SubdocGetRequest request = new SubdocGetRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, flags, commands, span);
request.context().clientContext(opts.clientContext());
return request;
}
Aggregations