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();
});
}
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);
}
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();
}
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);
}
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();
});
}
Aggregations