All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.couchbase.client.core.api.kv.CoreKvOps Maven / Gradle / Ivy

There is a newer version: 3.7.2
Show newest version
/*
 * Copyright 2023 Couchbase, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.couchbase.client.core.api.kv;

import com.couchbase.client.core.annotation.Stability;
import com.couchbase.client.core.endpoint.http.CoreCommonOptions;
import com.couchbase.client.core.error.InvalidArgumentException;
import com.couchbase.client.core.kv.CoreRangeScanItem;
import com.couchbase.client.core.kv.CoreScanOptions;
import com.couchbase.client.core.kv.CoreScanType;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import java.util.stream.Stream;

@Stability.Internal
public interface CoreKvOps {

  CoreAsyncResponse getAsync(
      CoreCommonOptions common,
      String key,
      List projections,
      boolean withExpiry
  );

  default CoreGetResult getBlocking(
      CoreCommonOptions common,
      String key,
      List projections,
      boolean withExpiry
  ) {
    return getAsync(common, key, projections, withExpiry).toBlocking();
  }

  default Mono getReactive(
      CoreCommonOptions common,
      String key,
      List projections,
      boolean withExpiry
  ) {
    return Mono.defer(() -> getAsync(common, key, projections, withExpiry).toMono());
  }

  default void checkProjectionLimits(
      List projections,
      boolean withExpiry
  ) {
    if (withExpiry) {
      if (projections.size() > 15) {
        throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be "
            + "projected per request due to a server limitation (includes the expiration macro as one field).");
      }
    } else if (projections.size() > 16) {
      throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be "
          + "projected per request due to a server limitation.");
    }
  }

  CoreAsyncResponse getAndLockAsync(
      CoreCommonOptions common,
      String key,
      Duration lockTime
  );

  default CoreGetResult getAndLockBlocking(
      CoreCommonOptions common,
      String key,
      Duration lockTime
  ) {
    return getAndLockAsync(common, key, lockTime).toBlocking();
  }

  default Mono getAndLockReactive(
      CoreCommonOptions common,
      String key,
      Duration lockTime
  ) {
    return Mono.defer(() -> getAndLockAsync(common, key, lockTime).toMono());
  }

  CoreAsyncResponse getAndTouchAsync(
      CoreCommonOptions common,
      String key,
      CoreExpiry expiry
  );

  default CoreGetResult getAndTouchBlocking(
      CoreCommonOptions common,
      String key,
      CoreExpiry expiry
  ) {
    return getAndTouchAsync(common, key, expiry).toBlocking();
  }

  default Mono getAndTouchReactive(
      CoreCommonOptions common,
      String key,
      CoreExpiry expiry
  ) {
    return Mono.defer(() -> getAndTouchAsync(common, key, expiry).toMono());
  }

  CoreAsyncResponse insertAsync(
      CoreCommonOptions common,
      String key,
      Supplier content,
      CoreDurability durability,
      CoreExpiry expiry
  );

  default CoreMutationResult insertBlocking(
      CoreCommonOptions common,
      String key,
      Supplier content,
      CoreDurability durability,
      CoreExpiry expiry
  ) {
    return insertAsync(common, key, content, durability, expiry).toBlocking();
  }

  default Mono insertReactive(
      CoreCommonOptions common,
      String key,
      Supplier content,
      CoreDurability durability,
      CoreExpiry expiry
  ) {
    return Mono.defer(() -> insertAsync(common, key, content, durability, expiry).toMono());
  }

  CoreAsyncResponse upsertAsync(
      CoreCommonOptions common,
      String key,
      Supplier content,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry
  );

  default CoreMutationResult upsertBlocking(
      CoreCommonOptions common,
      String key,
      Supplier content,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry
  ) {
    return upsertAsync(common, key, content, durability, expiry, preserveExpiry).toBlocking();
  }

  default Mono upsertReactive(
      CoreCommonOptions common,
      String key,
      Supplier content,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry
  ) {
    return Mono.defer(() -> upsertAsync(common, key, content, durability, expiry, preserveExpiry).toMono());
  }

  CoreAsyncResponse replaceAsync(
      CoreCommonOptions common,
      String key,
      Supplier content,
      long cas,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry
  );

  default CoreMutationResult replaceBlocking(
      CoreCommonOptions common,
      String key,
      Supplier content,
      long cas,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry
  ) {
    return replaceAsync(common, key, content, cas, durability, expiry, preserveExpiry).toBlocking();
  }

  default Mono replaceReactive(
      CoreCommonOptions common,
      String key,
      Supplier content,
      long cas,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry
  ) {
    return Mono.defer(() -> replaceAsync(common, key, content, cas, durability, expiry, preserveExpiry).toMono());
  }

  CoreAsyncResponse removeAsync(
      CoreCommonOptions common,
      String key,
      long cas,
      CoreDurability durability
  );

  default CoreMutationResult removeBlocking(
      CoreCommonOptions common,
      String key,
      long cas,
      CoreDurability durability
  ) {
    return removeAsync(common, key, cas, durability).toBlocking();
  }

  default Mono removeReactive(
      CoreCommonOptions common,
      String key,
      long cas,
      CoreDurability durability
  ) {
    return Mono.defer(() -> removeAsync(common, key, cas, durability).toMono());
  }

  CoreAsyncResponse existsAsync(
      CoreCommonOptions common,
      String key
  );

  default CoreExistsResult existsBlocking(
      CoreCommonOptions common,
      String key
  ) {
    return existsAsync(common, key).toBlocking();
  }

  default Mono existsReactive(
      CoreCommonOptions common,
      String key
  ) {
    return Mono.defer(() -> existsAsync(common, key).toMono());
  }

  CoreAsyncResponse touchAsync(
      CoreCommonOptions common,
      String key,
      CoreExpiry expiry
  );

  default CoreMutationResult touchBlocking(
      CoreCommonOptions common,
      String key,
      CoreExpiry expiry
  ) {
    return touchAsync(common, key, expiry).toBlocking();
  }

  default Mono touchReactive(
      CoreCommonOptions common,
      String key,
      CoreExpiry expiry
  ) {
    return Mono.defer(() -> touchAsync(common, key, expiry).toMono());
  }

  CoreAsyncResponse unlockAsync(
      CoreCommonOptions common,
      String key,
      long cas
  );

  default void unlockBlocking(
      CoreCommonOptions common,
      String key,
      long cas
  ) {
    unlockAsync(common, key, cas).toBlocking();
  }

  default Mono unlockReactive(
      CoreCommonOptions common,
      String key,
      long cas
  ) {
    return Mono.defer(() -> unlockAsync(common, key, cas).toMono());
  }

  CoreAsyncResponse subdocGetAsync(
      CoreCommonOptions common,
      String key,
      List commands,
      boolean accessDeleted
  );

  default CoreSubdocGetResult subdocGetBlocking(
      CoreCommonOptions common,
      String key,
      List commands,
      boolean accessDeleted
  ) {
    return subdocGetAsync(common, key, commands, accessDeleted).toBlocking();
  }

  default Mono subdocGetReactive(
      CoreCommonOptions common,
      String key,
      List commands,
      boolean accessDeleted
  ) {
    return Mono.defer(() -> subdocGetAsync(common, key, commands, accessDeleted).toMono());
  }


  Flux subdocGetAllReplicasReactive(
      CoreCommonOptions common,
      String key,
      List commands
  );

  Mono subdocGetAnyReplicaReactive(
      CoreCommonOptions common,
      String key,
      List commands
  );

  Flux getAllReplicasReactive(
      CoreCommonOptions common,
      String key
  );

  Mono getAnyReplicaReactive(
      CoreCommonOptions common,
      String key
  );

  CoreAsyncResponse subdocMutateAsync(
      CoreCommonOptions common,
      String key,
      Supplier> commands,
      CoreStoreSemantics storeSemantics,
      long cas,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry,
      boolean accessDeleted,
      boolean createAsDeleted
  );

  default CoreSubdocMutateResult subdocMutateBlocking(
      CoreCommonOptions common,
      String key,
      Supplier> commands,
      CoreStoreSemantics storeSemantics,
      long cas,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry,
      boolean accessDeleted,
      boolean createAsDeleted
  ) {
    return subdocMutateAsync(
        common,
        key,
        commands,
        storeSemantics,
        cas,
        durability,
        expiry,
        preserveExpiry,
        accessDeleted,
        createAsDeleted
    ).toBlocking();
  }

  default Mono subdocMutateReactive(
      CoreCommonOptions common,
      String key,
      Supplier> commands,
      CoreStoreSemantics storeSemantics,
      long cas,
      CoreDurability durability,
      CoreExpiry expiry,
      boolean preserveExpiry,
      boolean accessDeleted,
      boolean createAsDeleted
  ) {
    return Mono.defer(() -> subdocMutateAsync(
        common,
        key,
        commands,
        storeSemantics,
        cas,
        durability,
        expiry,
        preserveExpiry,
        accessDeleted,
        createAsDeleted
    ).toMono());
  }

  Flux scanRequestReactive(
    CoreScanType scanType,
    CoreScanOptions options);

  default CompletableFuture> scanRequestAsync(
    CoreScanType coreScanType,
    CoreScanOptions coreScanOptions) {
    return scanRequestReactive(coreScanType, coreScanOptions).collectList().toFuture();
  }

  default Stream scanRequestBlocking(
    CoreScanType coreScanType,
    CoreScanOptions coreScanOptions) {
    return scanRequestReactive(coreScanType, coreScanOptions).toStream();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy