@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); } }
@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); }
@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); }
final ReplicateTo replicateTo = ReplicateTo.valueOf(context.getProperty(REPLICATE_TO).getValue()); final Bucket bucket = openBucket(context); doc = bucket.upsert(doc, persistTo, replicateTo);
@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()); }
/** * 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))); }
@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"); } }
public void upsert(String id, String content) { bucket.upsert(RawJsonDocument.create(id, content)); }
@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); }; }
@Override public void put(K key, V value) { int reloadTime = cacheConfig.getReloadTime(); bucket.upsert(SerializableDocument.create(key.toString(), reloadTime, (Serializable) value)); }
@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))); } }
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); } }
@Override public void clear() { //optimized version over AbstractMap's (which uses the entry set) bucket.upsert(JsonDocument.create(id, JsonObject.empty())); }
@Override public void clear() { //optimized version over AbstractList's (which iterates on all and remove) bucket.upsert(JsonArrayDocument.create(id, JsonArray.empty())); }
@Override public void clear() { bucket.upsert(JsonArrayDocument.create(id, JsonArray.empty())); }
@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; }
@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; }
/** {@inheritDoc} */ @Override public void update(Feature fp) { assertFeatureNotNull(fp); assertFeatureExist(fp.getUid()); getFeatureBucket().upsert(FEATURE_MAPPER.toStore(fp)); }
/** {@inheritDoc} */ @Override public void create(Feature fp) { assertFeatureNotNull(fp); assertFeatureNotExist(fp.getUid()); getFeatureBucket().upsert(FEATURE_MAPPER.toStore(fp)); }
/** {@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)); }