com.couchbase.client.java.Bucket.replace()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中com.couchbase.client.java.Bucket.replace()方法的一些代码示例,展示了Bucket.replace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.replace()方法的具体详情如下:
包路径:com.couchbase.client.java.Bucket
类名称:Bucket
方法名:replace

Bucket.replace介绍

[英]Replace a Document if it does already exist with the default key/value timeout. If the given Document (identified by its unique ID) does not exist already, the method errors with a DocumentDoesNotExistException. If the operation should also insert the Document, #upsert(Document) should be used instead. It will always either return a document or fail with an error. The returned Document contains original properties, but has the refreshed CAS value set. This operation will return successfully if the Document has been acknowledged in the managed cache layer on the master server node. If increased data durability is a concern, #replace(Document,PersistTo,ReplicateTo) should be used instead. This method throws under the following conditions: - The operation takes longer than the specified timeout: TimeoutException wrapped in a RuntimeException- The producer outpaces the SDK: BackpressureException- The operation had to be cancelled while on the wire or the retry strategy cancelled it instead of retrying: RequestCancelledException- The original replace failed because the document does not exist: DocumentDoesNotExistException- The request content is too big: RequestTooBigException- A CAS value was set and it did not match with the server: CASMismatchException- The server is currently not able to process the request, retrying may help: TemporaryFailureException- The server is out of memory: CouchbaseOutOfMemoryException- Unexpected errors are caught and contained in a generic CouchbaseException.
[中]如果文档已存在,请使用默认键/值超时替换该文档。如果给定文档(由其唯一ID标识)不存在,则该方法会出现DocumentDoesNotExistException错误。如果操作还应插入文档,则应使用#upsert(文档)。它将始终返回文档或失败并出现错误。返回的文档包含原始属性,但已设置刷新的CAS值。如果已在主服务器节点上的托管缓存层中确认文档,则此操作将成功返回。如果担心数据持久性增加,则应使用#替换(Document、Persisto、ReplicateTo)。此方法在以下条件下引发:-该操作花费的时间超过指定的超时时间:RuntimeException中包装的TimeoutException-生产者的速度超过SDK:BackpressureException-必须在连线时取消该操作,或者重试策略取消了它,而不是重试:RequestCancelleException-原始替换失败,因为文档不存在:DocumentDoesNotExistException-请求内容太大:RequestTooBigException-设置了CAS值,但该值与服务器不匹配:CASMismatchException-服务器当前无法处理请求,重试可能有帮助:暂时性故障异常-服务器内存不足:CouchbaseOutOfMemoryException-捕获意外错误并将其包含在通用CouchbaseException中。

代码示例

代码示例来源:origin: apache/nifi

@Override
public <K, V> boolean replace(AtomicCacheEntry<K, V, Long> entry, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws IOException {
  final Long revision = entry.getRevision().orElse(0L);
  final String docId = toDocumentId(entry.getKey(), keySerializer);
  final Document doc = toDocument(docId, entry.getValue(), valueSerializer, revision);
  try {
    if (revision < 0) {
      // If the document does not exist yet, try to create one.
      try {
        bucket.insert(doc);
        return true;
      } catch (DocumentAlreadyExistsException e) {
        return false;
      }
    }
    bucket.replace(doc);
    return true;
  } catch (DocumentDoesNotExistException|CASMismatchException e) {
    return false;
  }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

/**
 * Replaces a {@link JsonDocument} if it does already exist.
 *
 * @param documentId the unique ID of the document
 * @param json       the JSON String representing the document to replace
 * @return the replaced {@link Document}
 * @see Bucket#replace(Document)
 */
public JsonDocument replace(String documentId, String json) {
  return this.bucket.replace(JsonDocument.create(documentId, JsonObject.fromJson(json)));
}

代码示例来源:origin: lukas-krecan/ShedLock

@Override
  public void unlock(LockConfiguration lockConfiguration) {
    JsonDocument document = bucket.get(lockConfiguration.getName());
    document.content().put(LOCK_UNTIL, toIsoString(lockConfiguration.getUnlockTime()));
    bucket.replace(document);
  }
}

代码示例来源:origin: lukas-krecan/ShedLock

@Override
public boolean updateRecord(LockConfiguration lockConfiguration) {
  try {
    JsonDocument document = bucket.get(lockConfiguration.getName());
    Instant lockUntil = parse(document.content().get(LOCK_UNTIL));
    Instant now = Instant.now();
    if (lockUntil.isAfter(now)) {
      return false;
    }
    document.content().put(LOCK_UNTIL, toIsoString(lockConfiguration.getLockAtMostUntil()));
    document.content().put(LOCKED_AT, toIsoString(now));
    document.content().put(LOCKED_BY, getHostname());
    bucket.replace(document);
    return true;
  }catch (CASMismatchException e){
    return false;
  }
}

代码示例来源:origin: spring-projects/spring-data-couchbase

} else if (existingDocument) {
  storedDoc = client.replace(doc, persistTo, replicateTo);
 } else {
 storedDoc = client.replace(doc, persistTo, replicateTo);
 break;
case INSERT:

代码示例来源:origin: org.springframework.data/spring-data-couchbase

} else if (existingDocument) {
  storedDoc = client.replace(doc, persistTo, replicateTo);
 } else {
 storedDoc = client.replace(doc, persistTo, replicateTo);
 break;
case INSERT:

相关文章