diff --git a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/ReactiveMongoOperations.java b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/ReactiveMongoOperations.java index 2ba4c3a035b3fa..e3917489804f87 100644 --- a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/ReactiveMongoOperations.java +++ b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/reactive/runtime/ReactiveMongoOperations.java @@ -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; @@ -74,7 +75,7 @@ public Uni 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); @@ -99,7 +100,7 @@ public Uni persist(Object firstEntity, Object... entities) { public Uni persist(Stream entities) { return Uni.createFrom().deferred(() -> { List 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); @@ -122,7 +123,7 @@ public Uni 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); @@ -147,7 +148,7 @@ public Uni update(Object firstEntity, Object... entities) { public Uni update(Stream entities) { return Uni.createFrom().deferred(() -> { List 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); @@ -170,7 +171,7 @@ public Uni 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); @@ -195,7 +196,7 @@ public Uni persistOrUpdate(Object firstEntity, Object... entities) { public Uni persistOrUpdate(Stream entities) { return Uni.createFrom().deferred(() -> { List 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); @@ -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); @@ -445,7 +445,6 @@ public QueryType find(Class entityClass, String query, Map pa return find(entityClass, query, null, params); } - @SuppressWarnings("rawtypes") public QueryType find(Class entityClass, String query, Sort sort, Map params) { String bindQuery = bindFilter(entityClass, query, params); Document docQuery = Document.parse(bindQuery); @@ -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); @@ -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); @@ -621,7 +617,7 @@ public Uni count(Class entityClass, Document query) { public Uni 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 deleteById(Class entityClass, Object id) { @@ -634,14 +630,14 @@ public Uni 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 delete(Class entityClass, String query, Map 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 delete(Class entityClass, String query, Parameters params) { @@ -651,7 +647,7 @@ public Uni delete(Class entityClass, String query, Parameters params) { //specific Mongo query public Uni 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 params) { diff --git a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/MongoOperations.java b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/MongoOperations.java index 27ef1a5c68452d..b6ede48cea7a71 100644 --- a/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/MongoOperations.java +++ b/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/MongoOperations.java @@ -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); @@ -134,7 +134,7 @@ public void update(Object firstEntity, Object... entities) { public void update(Stream entities) { List 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); @@ -214,7 +214,7 @@ private void persist(MongoCollection collection, Object entity) { } private void persist(List 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); @@ -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); @@ -511,7 +510,6 @@ public QueryType find(Class entityClass, String query, Map pa return find(entityClass, query, null, params); } - @SuppressWarnings("rawtypes") public QueryType find(Class entityClass, String query, Sort sort, Map params) { String bindQuery = bindFilter(entityClass, query, params); Document docQuery = Document.parse(bindQuery); @@ -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); @@ -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);