本文整理了Java中com.couchbase.client.java.Bucket.upsert()
方法的一些代码示例,展示了Bucket.upsert()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.upsert()
方法的具体详情如下:
包路径:com.couchbase.client.java.Bucket
类名称:Bucket
方法名:upsert
[英]Insert or overwrite a Document with the default key/value timeout. If the given Document (identified by its unique ID) already exists, it will be overridden by the current one. The returned Document contains original properties, but has the refreshed CAS value set. Please note that this method will not use the Document#cas() for optimistic concurrency checks. If this behavior is needed, the #replace(Document) method needs to be used. 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, #upsert(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 request content is too big: RequestTooBigException- The operation had to be cancelled while on the wire or the retry strategy cancelled it instead of retrying: RequestCancelledException- 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标识)已存在,则它将被当前文档覆盖。返回的文档包含原始属性,但已设置刷新的CAS值。请注意,此方法不会使用文档#cas()进行乐观并发检查。如果需要这种行为,则需要使用#replace(Document)方法。如果已在主服务器节点上的托管缓存层中确认文档,则此操作将成功返回。如果增加数据持久性是一个问题,则应改用#upsert(Document、PersistTo、ReplicateTo)。此方法在以下条件下引发:-操作花费的时间超过指定的超时时间:RuntimeException中包装的TimeoutException-生产者超过SDK:BackpressureException-请求内容太大:RequestTooBigException-必须在连线时取消操作或取消重试策略它没有重试:RequestCancelledException-服务器当前无法处理请求,重试可能会有帮助:暂时性故障异常-服务器内存不足:CouchbaseOutOfMemoryException-捕获意外错误并将其包含在通用CouchbaseException中。
代码示例来源:origin: apache/incubator-gobblin
@Override
public WriteResponse write(D record)
throws IOException {
try {
D doc = _bucket.upsert(record);
return new GenericWriteResponse(doc);
} catch (Exception e) {
throw new IOException("Failed to write to Couchbase cluster", e);
}
}
代码示例来源:origin: apache/nifi
@Override
public <K, V> void put(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws IOException {
final String docId = toDocumentId(key, keySerializer);
final Document doc = toDocument(docId, value, valueSerializer);
bucket.upsert(doc);
}
代码示例来源:origin: jooby-project/jooby
@Override
public void save(final Session session) {
JsonObject json = JsonObject.from(session.attributes());
// session metadata
json.put("_accessedAt", session.accessedAt());
json.put("_createdAt", session.createdAt());
json.put("_savedAt", session.savedAt());
JsonDocument doc = JsonDocument.create(N1Q.qualifyId(SESSION, session.id()), expiry, json);
bucket.upsert(doc);
}
代码示例来源:origin: apache/nifi
final ReplicateTo replicateTo = ReplicateTo.valueOf(context.getProperty(REPLICATE_TO).getValue());
final Bucket bucket = openBucket(context);
doc = bucket.upsert(doc, persistTo, replicateTo);
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void shouldInsertDocument() {
RawJsonDocument expected = RawJsonDocument.create(ID, DOCUMENT);
getBucket().upsert(expected);
RawJsonDocument result = getBucket().get(ID, RawJsonDocument.class);
Assert.assertEquals(expected.content(), result.content());
}
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
/**
* Inserts or overwrites a {@link JsonDocument}.
*
* @param documentId the unique ID of the document
* @param json the JSON String representing the document to store
* @return the newly created or overwritten {@link JsonDocument}
* @see Bucket#upsert(Document)
*/
public JsonDocument upsert(String documentId, String json) {
return this.bucket.upsert(JsonDocument.create(documentId, JsonObject.fromJson(json)));
}
代码示例来源:origin: Impetus/Kundera
@Override
protected void onPersist(EntityMetadata entityMetadata, Object entity, Object id, List<RelationHolder> rlHolders)
{
JsonDocument doc = handler.getDocumentFromEntity(entityMetadata, entity, kunderaMetadata);
if (!isUpdate)
{
bucket.insert(doc);
LOGGER.debug("Inserted document with ID : " + doc.id() + " in the " + bucket.name() + " Bucket");
}
else
{
bucket.upsert(doc);
LOGGER.debug("Updated document with ID : " + doc.id() + " in the " + bucket.name() + " Bucket");
}
}
代码示例来源:origin: Talend/components
public void upsert(String id, String content) {
bucket.upsert(RawJsonDocument.create(id, content));
}
代码示例来源:origin: simonbasle/practicalRx
@Bean
@ConditionalOnBean(value = Bucket.class)
@Order(value = 1)
CommandLineRunner userCreation(Bucket couchbaseBucket) {
return args -> {
JsonDocument u1 = JsonDocument.create(String.valueOf(User.USER.id), User.USER.toJsonObject());
JsonDocument u2 = JsonDocument.create(String.valueOf(User.OTHERUSER.id), User.OTHERUSER.toJsonObject());
couchbaseBucket.upsert(u1);
couchbaseBucket.upsert(u2);
};
}
代码示例来源:origin: rpatil26/webutilities
@Override
public void put(K key, V value) {
int reloadTime = cacheConfig.getReloadTime();
bucket.upsert(SerializableDocument.create(key.toString(), reloadTime, (Serializable) value));
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public <K, V> void put(K key, V value) {
requireNonNull(key, "key is required");
requireNonNull(value, "value is required");
if (JsonValue.checkType(value)) {
bucket.upsert(RawJsonDocument.create(key.toString(), JSONB.toJson(value.toString())));
} else {
bucket.upsert(JsonDocument.create(key.toString(), JsonObjectCouchbaseUtil.toJson(JSONB, value)));
}
}
代码示例来源:origin: lordofthejars/nosql-unit
private void insertDocuments(final Map<String, Document> documentsIterator) {
for (final Map.Entry<String, Document> documentEntry : documentsIterator.entrySet()) {
final Document document = documentEntry.getValue();
final JsonDocument jsonDocument = JsonDocument.create(documentEntry.getKey(), document.getExpirationSecs(), document.getDocument());
bucket.upsert(jsonDocument, 15, TimeUnit.SECONDS);
}
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public void clear() {
//optimized version over AbstractMap's (which uses the entry set)
bucket.upsert(JsonDocument.create(id, JsonObject.empty()));
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public void clear() {
//optimized version over AbstractList's (which iterates on all and remove)
bucket.upsert(JsonArrayDocument.create(id, JsonArray.empty()));
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public void clear() {
bucket.upsert(JsonArrayDocument.create(id, JsonArray.empty()));
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public DocumentEntity insert(DocumentEntity entity, Duration ttl) {
requireNonNull(entity, "entity is required");
requireNonNull(ttl, "ttl is required");
JsonObject jsonObject = convert(entity);
Document id = entity.find(ID_FIELD)
.orElseThrow(() -> new CouchbaseNoKeyFoundException(entity.toString()));
String prefix = getPrefix(id, entity.getName());
jsonObject.put(KEY_FIELD, prefix);
bucket.upsert(JsonDocument.create(prefix, (int) ttl.getSeconds(), jsonObject));
return entity;
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public DocumentEntity insert(DocumentEntity entity) throws NullPointerException {
requireNonNull(entity, "entity is required");
JsonObject jsonObject = convert(entity);
Document id = entity.find(ID_FIELD)
.orElseThrow(() -> new CouchbaseNoKeyFoundException(entity.toString()));
String prefix = getPrefix(id, entity.getName());
jsonObject.put(KEY_FIELD, prefix);
bucket.upsert(JsonDocument.create(prefix, jsonObject));
entity.add(Document.of(ID_FIELD, prefix));
return entity;
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
@Override
public void update(Feature fp) {
assertFeatureNotNull(fp);
assertFeatureExist(fp.getUid());
getFeatureBucket().upsert(FEATURE_MAPPER.toStore(fp));
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
@Override
public void create(Feature fp) {
assertFeatureNotNull(fp);
assertFeatureNotExist(fp.getUid());
getFeatureBucket().upsert(FEATURE_MAPPER.toStore(fp));
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
@Override
public <T> void createProperty(Property<T> prop) {
assertPropertyNotNull(prop);
assertPropertyNotExist(prop.getName());
if (prop.getFixedValues() != null && !prop.getFixedValues().isEmpty() && !prop.getFixedValues().contains(prop.getValue())) {
throw new IllegalArgumentException("Value " + prop.getValue() + " is not within fixed values " + prop.getFixedValues());
}
getPropertyBucket().upsert(PROPERTY_MAPPER.toStore(prop));
}
内容来源于网络,如有侵权,请联系作者删除!