use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method getAndLock.
/**
* Fetches a full document and write-locks it for the given duration with custom options.
* <p>
* Note that the client does not enforce an upper limit on the {@link Duration} lockTime. The maximum lock time
* by default on the server is 30 seconds. Any value larger than 30 seconds will be capped down by the server to
* the default lock time, which is 15 seconds unless modified on the server side.
*
* @param id the document id which is used to uniquely identify it.
* @param lockTime how long to write-lock the document for (any duration > 30s will be capped to server default of 15s).
* @param options custom options to change the default behavior.
* @return a {@link CompletableFuture} completing once loaded or failed.
*/
public CompletableFuture<GetResult> getAndLock(final String id, final Duration lockTime, final GetAndLockOptions options) {
notNull(options, "GetAndLockOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
GetAndLockOptions.Built opts = options.build();
final Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
return GetAccessor.getAndLock(core, getAndLockRequest(id, lockTime, opts), transcoder);
}
use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method get.
/**
* Fetches a full document (or a projection of it) from a collection with custom options.
*
* @param id the document id which is used to uniquely identify it.
* @param options custom options to change the default behavior.
* @return a {@link CompletableFuture} completing once loaded or failed.
*/
public CompletableFuture<GetResult> get(final String id, final GetOptions options) {
notNull(options, "GetOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
final GetOptions.Built opts = options.build();
final Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
if (opts.projections().isEmpty() && !opts.withExpiry()) {
return GetAccessor.get(core, fullGetRequest(id, opts), transcoder);
} else {
return GetAccessor.subdocGet(core, subdocGetRequest(id, opts), transcoder);
}
}
use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method getAllReplicas.
/**
* Reads from replicas or the active node based on the options and returns the results as a list
* of futures that might complete or fail.
*
* @param id the document id.
* @return a list of results from the active and the replica.
*/
public CompletableFuture<List<CompletableFuture<GetReplicaResult>>> getAllReplicas(final String id, final GetAllReplicasOptions options) {
notNull(options, "GetAllReplicasOptions");
GetAllReplicasOptions.Built opts = options.build();
Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
return ReplicaHelper.getAllReplicasAsync(core, collectionIdentifier, id, opts.timeout().orElse(environment.timeoutConfig().kvTimeout()), opts.retryStrategy().orElse(environment().retryStrategy()), opts.clientContext(), opts.parentSpan().orElse(null), response -> GetReplicaResult.from(response, transcoder));
}
use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method getAndTouch.
/**
* Fetches a full document and resets its expiration time to the value provided with custom
* options.
*
* @param id the document id which is used to uniquely identify it.
* @param expiry the new expiration time for the document.
* @param options custom options to change the default behavior.
* @return a {@link CompletableFuture} completing once loaded or failed.
*/
public CompletableFuture<GetResult> getAndTouch(final String id, final Duration expiry, final GetAndTouchOptions options) {
notNull(expiry, "Expiry", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(options, "GetAndTouchOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
GetAndTouchOptions.Built opts = options.build();
final Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
return GetAccessor.getAndTouch(core, getAndTouchRequest(id, Expiry.relative(expiry), opts), transcoder);
}
use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method replaceRequest.
/**
* Helper method to generate the replace request.
*
* @param id the document id to replace.
* @param content the document content to replace.
* @param opts custom options to customize the replace behavior.
* @return the replace request.
*/
ReplaceRequest replaceRequest(final String id, final Object content, final ReplaceOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(content, "Content", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
final RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_REPLACE, opts.parentSpan().orElse(null));
final RequestSpan encodeSpan = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ENCODING, span);
long start = System.nanoTime();
Transcoder.EncodedValue encoded;
try {
encoded = transcoder.encode(content);
} finally {
encodeSpan.end();
}
long end = System.nanoTime();
long expiry = opts.expiry().encode();
ReplaceRequest request = new ReplaceRequest(id, encoded.encoded(), expiry, opts.preserveExpiry(), encoded.flags(), timeout, opts.cas(), coreContext, collectionIdentifier, retryStrategy, opts.durabilityLevel(), span);
request.context().clientContext(opts.clientContext()).encodeLatency(end - start);
return request;
}
Aggregations