Search in sources :

Example 1 with MongoCollection

use of com.mongodb.async.client.MongoCollection 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);
}
Also used : FindIterable(com.mongodb.async.client.FindIterable) Document(org.bson.Document) MongoDBUtils.getDocument(org.jnosql.diana.mongodb.document.MongoDBUtils.getDocument) ExecuteAsyncQueryException(org.jnosql.diana.api.ExecuteAsyncQueryException) DocumentCollectionManagerAsync(org.jnosql.diana.api.document.DocumentCollectionManagerAsync) MongoCollection(com.mongodb.async.client.MongoCollection) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) BsonDocument(org.bson.BsonDocument) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Bson(org.bson.conversions.Bson) Consumer(java.util.function.Consumer) List(java.util.List) Documents(org.jnosql.diana.api.document.Documents) Block(com.mongodb.Block) MongoDatabase(com.mongodb.async.client.MongoDatabase) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Duration(java.time.Duration) DeleteResult(com.mongodb.client.result.DeleteResult) ID_FIELD(org.jnosql.diana.mongodb.document.MongoDBUtils.ID_FIELD) SingleResultCallback(com.mongodb.async.SingleResultCallback) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.bson.Document) MongoDBUtils.getDocument(org.jnosql.diana.mongodb.document.MongoDBUtils.getDocument) BsonDocument(org.bson.BsonDocument) Bson(org.bson.conversions.Bson) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

Block (com.mongodb.Block)1 SingleResultCallback (com.mongodb.async.SingleResultCallback)1 FindIterable (com.mongodb.async.client.FindIterable)1 MongoCollection (com.mongodb.async.client.MongoCollection)1 MongoDatabase (com.mongodb.async.client.MongoDatabase)1 DeleteResult (com.mongodb.client.result.DeleteResult)1 Duration (java.time.Duration)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Consumer (java.util.function.Consumer)1 BsonDocument (org.bson.BsonDocument)1 Document (org.bson.Document)1 Bson (org.bson.conversions.Bson)1 ExecuteAsyncQueryException (org.jnosql.diana.api.ExecuteAsyncQueryException)1 DocumentCollectionManagerAsync (org.jnosql.diana.api.document.DocumentCollectionManagerAsync)1 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)1 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)1 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)1 Documents (org.jnosql.diana.api.document.Documents)1 ID_FIELD (org.jnosql.diana.mongodb.document.MongoDBUtils.ID_FIELD)1