Search in sources :

Example 11 with Transcoder

use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.

the class ReactiveCollection method get.

/**
 * Fetches a Document 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 Mono} indicating once loaded or failed
 */
public Mono<GetResult> get(final String id, final GetOptions options) {
    return Mono.defer(() -> {
        GetOptions.Built opts = options.build();
        final Transcoder transcoder = opts.transcoder() == null ? environment().transcoder() : opts.transcoder();
        if (opts.projections().isEmpty() && !opts.withExpiry()) {
            GetRequest request = asyncCollection.fullGetRequest(id, opts);
            return Reactor.wrap(request, GetAccessor.get(core, request, transcoder), true);
        } else {
            SubdocGetRequest request = asyncCollection.subdocGetRequest(id, opts);
            return Reactor.wrap(request, GetAccessor.subdocGet(core, request, transcoder), true);
        }
    });
}
Also used : SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) Transcoder(com.couchbase.client.java.codec.Transcoder) GetOptions(com.couchbase.client.java.kv.GetOptions) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest)

Example 12 with Transcoder

use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.

the class ReactiveCollection 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 Mono} completing once loaded or failed.
 */
public Mono<GetResult> getAndTouch(final String id, final Duration expiry, final GetAndTouchOptions options) {
    return Mono.defer(() -> {
        GetAndTouchOptions.Built opts = options.build();
        final Transcoder transcoder = opts.transcoder() == null ? environment().transcoder() : opts.transcoder();
        GetAndTouchRequest request = asyncCollection.getAndTouchRequest(id, Expiry.relative(expiry), opts);
        return Reactor.wrap(request, GetAccessor.getAndTouch(core, request, transcoder), true);
    });
}
Also used : GetAndTouchRequest(com.couchbase.client.core.msg.kv.GetAndTouchRequest) GetAndTouchOptions(com.couchbase.client.java.kv.GetAndTouchOptions) Transcoder(com.couchbase.client.java.codec.Transcoder)

Example 13 with Transcoder

use of com.couchbase.client.java.codec.Transcoder in project couchbase-jvm-clients by couchbase.

the class ReactiveCollection method getAnyReplica.

/**
 * Reads all available replicas, and returns the first found.
 * <p>
 * If the read requests all fail, the mono emits nothing.
 *
 * @param id the document id.
 * @param options the custom options.
 * @return a mono containing the first available replica.
 */
public Mono<GetReplicaResult> getAnyReplica(final String id, final GetAnyReplicaOptions options) {
    GetAnyReplicaOptions.Built opts = options.build();
    final Transcoder transcoder = Optional.ofNullable(opts.transcoder()).orElse(environment().transcoder());
    return ReplicaHelper.getAnyReplicaReactive(core, asyncCollection.collectionIdentifier(), id, opts.timeout().orElse(environment().timeoutConfig().kvTimeout()), opts.retryStrategy().orElse(environment().retryStrategy()), opts.clientContext(), opts.parentSpan().orElse(null)).map(response -> GetReplicaResult.from(response, transcoder));
}
Also used : Transcoder(com.couchbase.client.java.codec.Transcoder) GetAnyReplicaOptions(com.couchbase.client.java.kv.GetAnyReplicaOptions)

Aggregations

Transcoder (com.couchbase.client.java.codec.Transcoder)13 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)3 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)3 Duration (java.time.Duration)3 GetAllReplicasOptions (com.couchbase.client.java.kv.GetAllReplicasOptions)2 GetAndLockOptions (com.couchbase.client.java.kv.GetAndLockOptions)2 GetAndTouchOptions (com.couchbase.client.java.kv.GetAndTouchOptions)2 GetAnyReplicaOptions (com.couchbase.client.java.kv.GetAnyReplicaOptions)2 GetOptions (com.couchbase.client.java.kv.GetOptions)2 GetAndLockRequest (com.couchbase.client.core.msg.kv.GetAndLockRequest)1 GetAndTouchRequest (com.couchbase.client.core.msg.kv.GetAndTouchRequest)1 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)1 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)1 ReplaceRequest (com.couchbase.client.core.msg.kv.ReplaceRequest)1 SubdocGetRequest (com.couchbase.client.core.msg.kv.SubdocGetRequest)1 UpsertRequest (com.couchbase.client.core.msg.kv.UpsertRequest)1