use of org.jnosql.diana.api.ExecuteAsyncQueryException in project jnosql-diana-driver by eclipse.
the class DefaultElasticsearchDocumentCollectionManagerAsync method delete.
@Override
public void delete(DocumentDeleteQuery query, Consumer<Void> callBack) {
requireNonNull(query, "query is required");
requireNonNull(callBack, "callBack is required");
query.getCondition().orElseThrow(() -> new IllegalArgumentException("condition is required"));
DocumentQuery select = new ElasticsearchDocumentQuery(query);
List<DocumentEntity> entities = EntityConverter.query(select, client, index);
if (entities.isEmpty()) {
callBack.accept(null);
return;
}
BulkRequest bulk = new BulkRequest();
entities.stream().map(entity -> entity.find(ID_FIELD).get().get(String.class)).map(id -> new DeleteRequest(index, query.getDocumentCollection(), id)).forEach(bulk::add);
ActionListener<BulkResponse> listener = new ActionListener<BulkResponse>() {
@Override
public void onResponse(BulkResponse bulkItemResponses) {
callBack.accept(null);
}
@Override
public void onFailure(Exception e) {
throw new ExecuteAsyncQueryException("An error when delete on elasticsearch", e);
}
};
client.bulkAsync(bulk, listener);
}
use of org.jnosql.diana.api.ExecuteAsyncQueryException in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsync method select.
@Override
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
String collectionName = query.getDocumentCollection();
MongoCollection<Document> collection = asyncMongoDatabase.getCollection(collectionName);
Bson mongoDBQuery = query.getCondition().map(DocumentQueryConversor::convert).orElse(EMPTY);
List<DocumentEntity> entities = new CopyOnWriteArrayList<>();
FindIterable<Document> result = collection.find(mongoDBQuery);
Block<Document> documentBlock = d -> entities.add(createEntity(collectionName, d));
SingleResultCallback<Void> voidSingleResultCallback = (v, e) -> callBack.accept(entities);
result.forEach(documentBlock, voidSingleResultCallback);
}
use of org.jnosql.diana.api.ExecuteAsyncQueryException 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);
}
use of org.jnosql.diana.api.ExecuteAsyncQueryException in project jnosql-diana-driver by eclipse.
the class CassandraReturnQueryAsync method run.
@Override
public void run() {
try {
ResultSet resultSet = this.resultSet.get();
List<ColumnEntity> entities = resultSet.all().stream().map(CassandraConverter::toDocumentEntity).collect(Collectors.toList());
consumer.accept(entities);
} catch (InterruptedException | ExecutionException e) {
throw new ExecuteAsyncQueryException(e);
}
}
Aggregations