use of org.jnosql.diana.orientdb.document.OrientDBConverter.VERSION_FIELD in project jnosql-diana-driver by eclipse.
the class DefaultOrientDBDocumentCollectionManagerAsync method insert.
@Override
public void insert(DocumentEntity entity, Consumer<DocumentEntity> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
requireNonNull(entity, "Entity is required");
requireNonNull(callBack, "Callback is required");
ODatabaseDocumentTx tx = pool.acquire();
ODocument document = new ODocument(entity.getName());
Map<String, Object> entityValues = entity.toMap();
entityValues.keySet().stream().forEach(k -> document.field(k, entityValues.get(k)));
ORecordCallback<Number> createCallBack = (rid, clusterPosition) -> {
entity.add(Document.of(RID_FIELD, rid.toString()));
callBack.accept(entity);
};
ORecordCallback<Integer> updateCallback = (rid, version) -> {
entity.add(Document.of(RID_FIELD, rid.toString()));
entity.add(Document.of(VERSION_FIELD, version));
callBack.accept(entity);
};
tx.save(document, null, ASYNCHRONOUS, false, createCallBack, updateCallback);
}
Aggregations