@Override public void insert(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<DocumentCreateEntity<BaseDocument>> future = arangoDBAsync.db(database) .collection(collectionName).insertDocument(baseDocument); future.thenAccept(d -> createConsumer(entity, callBack, d.getKey(), d.getId(), d.getRev())); }
@SuppressWarnings("unchecked") @Override public DocumentCreateEntity<T> deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody(); final DocumentCreateEntity<T> doc = util().deserialize(body, DocumentCreateEntity.class); final VPackSlice newDoc = body.get(NEW); if (newDoc.isObject()) { doc.setNew((T) util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); values.put(DocumentField.Type.ID, doc.getId()); values.put(DocumentField.Type.KEY, doc.getKey()); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); } return doc; } };
@Override public DocumentEntity insert(DocumentEntity entity) throws NullPointerException { String collectionName = entity.getName(); checkCollection(collectionName); BaseDocument baseDocument = getBaseDocument(entity); DocumentCreateEntity<BaseDocument> arandoDocument = arangoDB.db(database).collection(collectionName).insertDocument(baseDocument); updateEntity(entity, arandoDocument.getKey(), arandoDocument.getId(), arandoDocument.getRev()); return entity; }