Search in sources :

Example 1 with ReactiveMongoCollection

use of io.quarkus.mongodb.reactive.ReactiveMongoCollection in project quarkus by quarkusio.

the class ReactiveMongoOperations method persistOrUpdate.

public Uni<Void> persistOrUpdate(Stream<?> entities) {
    return Uni.createFrom().deferred(() -> {
        List<Object> objects = entities.collect(Collectors.toList());
        if (objects.size() > 0) {
            // get the first entity to be able to retrieve the collection with it
            Object firstEntity = objects.get(0);
            ReactiveMongoCollection collection = mongoCollection(firstEntity);
            return persistOrUpdate(collection, objects);
        }
        return nullUni();
    });
}
Also used : ReactiveMongoCollection(io.quarkus.mongodb.reactive.ReactiveMongoCollection)

Example 2 with ReactiveMongoCollection

use of io.quarkus.mongodb.reactive.ReactiveMongoCollection in project quarkus by quarkusio.

the class ReactiveMongoOperations method find.

@SuppressWarnings("rawtypes")
public QueryType find(Class<?> entityClass, Document query, Sort sort) {
    ReactiveMongoCollection collection = mongoCollection(entityClass);
    Document sortDoc = sortToDocument(sort);
    return createQuery(collection, query, sortDoc);
}
Also used : Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) ReactiveMongoCollection(io.quarkus.mongodb.reactive.ReactiveMongoCollection)

Example 3 with ReactiveMongoCollection

use of io.quarkus.mongodb.reactive.ReactiveMongoCollection in project quarkus by quarkusio.

the class ReactiveMongoOperations method delete.

public Uni<Void> delete(Object entity) {
    ReactiveMongoCollection collection = mongoCollection(entity);
    BsonDocument document = getBsonDocument(collection, entity);
    BsonValue id = document.get(ID);
    BsonDocument query = new BsonDocument().append(ID, id);
    return collection.deleteOne(query).onItem().ignore().andContinueWithNull();
}
Also used : BsonDocument(org.bson.BsonDocument) ReactiveMongoCollection(io.quarkus.mongodb.reactive.ReactiveMongoCollection) BsonValue(org.bson.BsonValue)

Example 4 with ReactiveMongoCollection

use of io.quarkus.mongodb.reactive.ReactiveMongoCollection in project quarkus by quarkusio.

the class ReactiveMongoOperations method find.

@SuppressWarnings("rawtypes")
public QueryType find(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
    String bindQuery = bindFilter(entityClass, query, params);
    Document docQuery = Document.parse(bindQuery);
    Document docSort = sortToDocument(sort);
    ReactiveMongoCollection collection = mongoCollection(entityClass);
    return createQuery(collection, docQuery, docSort);
}
Also used : Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) ReactiveMongoCollection(io.quarkus.mongodb.reactive.ReactiveMongoCollection)

Example 5 with ReactiveMongoCollection

use of io.quarkus.mongodb.reactive.ReactiveMongoCollection in project quarkus by quarkusio.

the class ReactiveMongoOperations method persist.

public Uni<Void> persist(Iterable<?> entities) {
    return Uni.createFrom().deferred(() -> {
        // not all iterables are re-traversal, so we traverse it once for copying inside a list
        List<Object> objects = new ArrayList<>();
        for (Object entity : entities) {
            objects.add(entity);
        }
        if (objects.size() > 0) {
            // get the first entity to be able to retrieve the collection with it
            Object firstEntity = objects.get(0);
            ReactiveMongoCollection collection = mongoCollection(firstEntity);
            return persist(collection, objects);
        }
        return nullUni();
    });
}
Also used : ArrayList(java.util.ArrayList) ReactiveMongoCollection(io.quarkus.mongodb.reactive.ReactiveMongoCollection)

Aggregations

ReactiveMongoCollection (io.quarkus.mongodb.reactive.ReactiveMongoCollection)16 BsonDocument (org.bson.BsonDocument)7 ArrayList (java.util.ArrayList)6 Document (org.bson.Document)4 BsonValue (org.bson.BsonValue)1