@Override public void serialize(final BaseDocument value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException { final Map<String, Object> doc = new HashMap<>(); doc.putAll(value.getProperties()); doc.put(DocumentField.Type.ID.getSerializeName(), value.getId()); doc.put(DocumentField.Type.KEY.getSerializeName(), value.getKey()); doc.put(DocumentField.Type.REV.getSerializeName(), value.getRevision()); gen.writeObject(doc); } };
static DocumentEntity toEntity(BaseDocument document) { Map<String, Object> properties = document.getProperties(); List<Document> documents = properties.keySet().stream() .map(k -> toDocument(k, properties)) .collect(Collectors.toList()); documents.add(Document.of(KEY, document.getKey())); documents.add(Document.of(ID, document.getId())); documents.add(Document.of(REV, document.getRevision())); String collection = document.getId().split("/")[0]; return DocumentEntity.of(collection, documents); }
@Override public void serialize( final VPackBuilder builder, final String attribute, final BaseDocument value, final VPackSerializationContext context) throws VPackException { final Map<String, Object> doc = new HashMap<String, Object>(); doc.putAll(value.getProperties()); doc.put(DocumentField.Type.ID.getSerializeName(), value.getId()); doc.put(DocumentField.Type.KEY.getSerializeName(), value.getKey()); doc.put(DocumentField.Type.REV.getSerializeName(), value.getRevision()); context.serialize(builder, attribute, doc); } };
@Override public void update(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException { requireNonNull(entity, "entity is required"); requireNonNull(callBack, "callBack is required"); String collectionName = entity.getName(); checkCollection(collectionName); BaseDocument baseDocument = getBaseDocument(entity); CompletableFuture<DocumentUpdateEntity<BaseDocument>> future = arangoDBAsync.db(database).collection(collectionName) .updateDocument(baseDocument.getKey(), baseDocument); future.thenAccept(d -> createConsumer(entity, callBack, d.getKey(), d.getId(), d.getRev())); }
private void writeBaseDocument( final String attribute, final BaseDocument source, final VPackBuilder sink, final TypeInformation<?> definedType) { final VPackBuilder builder = new VPackBuilder(); writeMap(attribute, source.getProperties(), builder, definedType); builder.add(_ID, source.getId()); builder.add(_KEY, source.getKey()); builder.add(_REV, source.getRevision()); sink.add(attribute, builder.slice()); }
private void writeBaseDocument( final String attribute, final BaseDocument source, final VPackBuilder sink, final TypeInformation<?> definedType) { final VPackBuilder builder = new VPackBuilder(); writeMap(attribute, source.getProperties(), builder, definedType); builder.add(_ID, source.getId()); builder.add(_KEY, source.getKey()); builder.add(_REV, source.getRevision()); sink.add(attribute, builder.slice()); }
@Override public DocumentEntity update(DocumentEntity entity) { String collectionName = entity.getName(); checkCollection(collectionName); BaseDocument baseDocument = getBaseDocument(entity); DocumentUpdateEntity<BaseDocument> arandoDocument = arangoDB.db(database) .collection(collectionName).updateDocument(baseDocument.getKey(), baseDocument); updateEntity(entity, arandoDocument.getKey(), arandoDocument.getId(), arandoDocument.getRev()); return entity; }