Skip to content

Commit

Permalink
chore: ReactiveMongoOperations and MongoOperations code clean up (mon…
Browse files Browse the repository at this point in the history
…go-pananche-common)
  • Loading branch information
pedroh-pereira committed Nov 28, 2022
1 parent 3fc0563 commit 4ba82f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.mongodb.client.model.ReplaceOneModel;
import com.mongodb.client.model.ReplaceOptions;
import com.mongodb.client.model.WriteModel;
import com.mongodb.client.result.DeleteResult;

import io.quarkus.mongodb.panache.common.MongoEntity;
import io.quarkus.mongodb.panache.common.binder.NativeQueryBinder;
Expand Down Expand Up @@ -74,7 +75,7 @@ public Uni<Void> persist(Iterable<?> entities) {
objects.add(entity);
}

if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
ReactiveMongoCollection collection = mongoCollection(firstEntity);
Expand All @@ -99,7 +100,7 @@ public Uni<Void> persist(Object firstEntity, Object... entities) {
public Uni<Void> persist(Stream<?> entities) {
return Uni.createFrom().deferred(() -> {
List<Object> objects = entities.collect(Collectors.toList());
if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
ReactiveMongoCollection collection = mongoCollection(firstEntity);
Expand All @@ -122,7 +123,7 @@ public Uni<Void> update(Iterable<?> entities) {
objects.add(entity);
}

if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
ReactiveMongoCollection collection = mongoCollection(firstEntity);
Expand All @@ -147,7 +148,7 @@ public Uni<Void> update(Object firstEntity, Object... entities) {
public Uni<Void> update(Stream<?> entities) {
return Uni.createFrom().deferred(() -> {
List<Object> objects = entities.collect(Collectors.toList());
if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
ReactiveMongoCollection collection = mongoCollection(firstEntity);
Expand All @@ -170,7 +171,7 @@ public Uni<Void> persistOrUpdate(Iterable<?> entities) {
objects.add(entity);
}

if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
ReactiveMongoCollection collection = mongoCollection(firstEntity);
Expand All @@ -195,7 +196,7 @@ public Uni<Void> persistOrUpdate(Object firstEntity, Object... entities) {
public Uni<Void> persistOrUpdate(Stream<?> entities) {
return Uni.createFrom().deferred(() -> {
List<Object> objects = entities.collect(Collectors.toList());
if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
ReactiveMongoCollection collection = mongoCollection(firstEntity);
Expand Down Expand Up @@ -345,7 +346,6 @@ public QueryType find(Class<?> entityClass, String query, Object... params) {
return find(entityClass, query, null, params);
}

@SuppressWarnings("rawtypes")
public QueryType find(Class<?> entityClass, String query, Sort sort, Object... params) {
String bindQuery = bindFilter(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
Expand Down Expand Up @@ -445,7 +445,6 @@ public QueryType find(Class<?> entityClass, String query, Map<String, Object> pa
return find(entityClass, query, null, params);
}

@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);
Expand All @@ -462,7 +461,6 @@ public QueryType find(Class<?> entityClass, String query, Sort sort, Parameters
return find(entityClass, query, sort, params.map());
}

@SuppressWarnings("rawtypes")
public QueryType find(Class<?> entityClass, Document query, Sort sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
Expand Down Expand Up @@ -546,13 +544,11 @@ public Multi<?> stream(Class<?> entityClass, Document query, Document sort) {
return stream(find(entityClass, query, sort));
}

@SuppressWarnings("rawtypes")
public QueryType findAll(Class<?> entityClass) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
return createQuery(collection, null, null);
}

@SuppressWarnings("rawtypes")
public QueryType findAll(Class<?> entityClass, Sort sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
Expand Down Expand Up @@ -621,7 +617,7 @@ public Uni<Long> count(Class<?> entityClass, Document query) {

public Uni<Long> deleteAll(Class<?> entityClass) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(new Document()).map(deleteResult -> deleteResult.getDeletedCount());
return collection.deleteMany(new Document()).map(DeleteResult::getDeletedCount);
}

public Uni<Boolean> deleteById(Class<?> entityClass, Object id) {
Expand All @@ -634,14 +630,14 @@ public Uni<Long> delete(Class<?> entityClass, String query, Object... params) {
String bindQuery = bindFilter(entityClass, query, params);
BsonDocument docQuery = BsonDocument.parse(bindQuery);
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(docQuery).map(deleteResult -> deleteResult.getDeletedCount());
return collection.deleteMany(docQuery).map(DeleteResult::getDeletedCount);
}

public Uni<Long> delete(Class<?> entityClass, String query, Map<String, Object> params) {
String bindQuery = bindFilter(entityClass, query, params);
BsonDocument docQuery = BsonDocument.parse(bindQuery);
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(docQuery).map(deleteResult -> deleteResult.getDeletedCount());
return collection.deleteMany(docQuery).map(DeleteResult::getDeletedCount);
}

public Uni<Long> delete(Class<?> entityClass, String query, Parameters params) {
Expand All @@ -651,7 +647,7 @@ public Uni<Long> delete(Class<?> entityClass, String query, Parameters params) {
//specific Mongo query
public Uni<Long> delete(Class<?> entityClass, Document query) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(query).map(deleteResult -> deleteResult.getDeletedCount());
return collection.deleteMany(query).map(DeleteResult::getDeletedCount);
}

public UpdateType update(Class<?> entityClass, String update, Map<String, Object> params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void update(Iterable<?> entities) {
objects.add(entity);
}

if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
MongoCollection collection = mongoCollection(firstEntity);
Expand All @@ -134,7 +134,7 @@ public void update(Object firstEntity, Object... entities) {

public void update(Stream<?> entities) {
List<Object> objects = entities.collect(Collectors.toList());
if (objects.size() > 0) {
if (!objects.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = objects.get(0);
MongoCollection collection = mongoCollection(firstEntity);
Expand Down Expand Up @@ -214,7 +214,7 @@ private void persist(MongoCollection collection, Object entity) {
}

private void persist(List<Object> entities) {
if (entities.size() > 0) {
if (!entities.isEmpty()) {
// get the first entity to be able to retrieve the collection with it
Object firstEntity = entities.get(0);
MongoCollection collection = mongoCollection(firstEntity);
Expand Down Expand Up @@ -414,7 +414,6 @@ public QueryType find(Class<?> entityClass, String query, Object... params) {
return find(entityClass, query, null, params);
}

@SuppressWarnings("rawtypes")
public QueryType find(Class<?> entityClass, String query, Sort sort, Object... params) {
String bindQuery = bindFilter(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
Expand Down Expand Up @@ -511,7 +510,6 @@ public QueryType find(Class<?> entityClass, String query, Map<String, Object> pa
return find(entityClass, query, null, params);
}

@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);
Expand All @@ -529,7 +527,6 @@ public QueryType find(Class<?> entityClass, String query, Sort sort, Parameters
return find(entityClass, query, sort, params.map());
}

@SuppressWarnings("rawtypes")
public QueryType find(Class<?> entityClass, Document query, Sort sort) {
MongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
Expand Down Expand Up @@ -615,14 +612,12 @@ public Stream<?> stream(Class<?> entityClass, Document query, Document sort) {
return stream(find(entityClass, query, sort));
}

@SuppressWarnings("rawtypes")
public QueryType findAll(Class<?> entityClass) {
MongoCollection collection = mongoCollection(entityClass);
ClientSession session = getSession(entityClass);
return createQuery(collection, session, null, null);
}

@SuppressWarnings("rawtypes")
public QueryType findAll(Class<?> entityClass, Sort sort) {
MongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
Expand Down

0 comments on commit 4ba82f6

Please sign in to comment.