Code review comment: Yes because the ID field name is always `_id` in MongoDB so it's easy to implement ;)

Code before review:
static String bindQuery(Class<?> clazz, String query, Object[] params) {
String bindQuery = null;
if (query.charAt(0) == '{') {
bindQuery = NativeQueryBinder.bindQuery(query, params);
} else {
bindQuery = PanacheQlQueryBinder.bindQuery(clazz, query, params);
}
LOGGER.debug(bindQuery);
return bindQuery;
}
/**
* We should have a query like <code>{'firstname': :firstname, 'lastname': :lastname}</code> for native one
* and like <code>firstname = :firstname and lastname = :lastname</code> for PanacheQL one.
*/
static String bindQuery(Class<?> clazz, String query, Map<String, Object> params) {
String bindQuery = null;
if (query.charAt(0) == '{') {
bindQuery = NativeQueryBinder.bindQuery(query, params);
} else {
bindQuery = PanacheQlQueryBinder.bindQuery(clazz, query, params);
}
LOGGER.debug(bindQuery);
return bindQuery;
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Map<String, Object> params) {
return find(entityClass, query, null, params);
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
Document docSort = sortToDocument(sort);
ReactiveMongoCollection collection = mongoCollection(entityClass);
return new ReactivePanacheQueryImpl(collection, entityClass, docQuery, docSort);
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Parameters params) {
return find(entityClass, query, null, params.map());
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Sort sort, Parameters params) {
return find(entityClass, query, sort, params.map());
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> find(Class<?> entityClass, Document query, Sort sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
return new ReactivePanacheQueryImpl(collection, entityClass, query, sortDoc);
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, Document query, Document sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
return new ReactivePanacheQueryImpl(collection, entityClass, query, sort);
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, Document query) {
return find(entityClass, query, (Document) null);
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Object... params) {
return (Uni) find(entityClass, query, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Sort sort, Object... params) {
return (Uni) find(entityClass, query, sort, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Map<String, Object> params) {
return (Uni) find(entityClass, query, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
return (Uni) find(entityClass, query, sort, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Parameters params) {
return (Uni) find(entityClass, query, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Sort sort, Parameters params) {
return (Uni) find(entityClass, query, sort, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, Document query) {
return (Uni) find(entityClass, query).list();
}
public static Uni<List<?>> list(Class<?> entityClass, Document query, Document sort) {
return (Uni) find(entityClass, query, sort).list();
}
public static Multi<?> stream(Class<?> entityClass, String query, Object... params) {
return find(entityClass, query, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Sort sort, Object... params) {
return find(entityClass, query, sort, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Map<String, Object> params) {
return find(entityClass, query, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
return find(entityClass, query, sort, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Parameters params) {
return find(entityClass, query, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Sort sort, Parameters params) {
return find(entityClass, query, sort, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, Document query) {
return find(entityClass, query).stream();
}
public static Multi<?> stream(Class<?> entityClass, Document query, Document sort) {
return find(entityClass, query, sort).stream();
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> findAll(Class<?> entityClass) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
return new ReactivePanacheQueryImpl(collection, entityClass, null, null);
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> findAll(Class<?> entityClass, Sort sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
return new ReactivePanacheQueryImpl(collection, entityClass, null, sortDoc);
}
private static Document sortToDocument(Sort sort) {
if (sort == null) {
return null;
}
Document sortDoc = new Document();
for (Sort.Column col : sort.getColumns()) {
sortDoc.append(col.getName(), col.getDirection() == Sort.Direction.Ascending ? 1 : -1);
}
return sortDoc;
}
public static Uni<List<?>> listAll(Class<?> entityClass) {
return (Uni) findAll(entityClass).list();
}
public static Uni<List<?>> listAll(Class<?> entityClass, Sort sort) {
return (Uni) findAll(entityClass, sort).list();
}
public static Multi<?> streamAll(Class<?> entityClass) {
return findAll(entityClass).stream();
}
public static Multi<?> streamAll(Class<?> entityClass, Sort sort) {
return findAll(entityClass, sort).stream();
}
public static Uni<Long> count(Class<?> entityClass) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
return collection.countDocuments();
}
public static Uni<Long> count(Class<?> entityClass, String query, Object... params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection collection = mongoCollection(entityClass);
return collection.countDocuments(docQuery);
}
public static Uni<Long> count(Class<?> entityClass, String query, Map<String, Object> params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection collection = mongoCollection(entityClass);
return collection.countDocuments(docQuery);
}
public static Uni<Long> count(Class<?> entityClass, String query, Parameters params) {
return count(entityClass, query, params.map());
}
public static Uni<Long> count(Class<?> entityClass, Document query) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.countDocuments(query);
}
public static Uni<Long> deleteAll(Class<?> entityClass) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(new Document()).map(deleteResult -> deleteResult.getDeletedCount());
}
public static Uni<Boolean> deleteById(Class<?> entityClass, Object id) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
Document query = new Document().append(ID, id);
return collection.deleteOne(query).map(results -> results.getDeletedCount() == 1);
}
public static Uni<Long> delete(Class<?> entityClass, String query, Object... params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(docQuery).map(deleteResult -> deleteResult.getDeletedCount());
}
public static Uni<Long> delete(Class<?> entityClass, String query, Map<String, Object> params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(docQuery).map(deleteResult -> deleteResult.getDeletedCount());
}
public static Uni<Long> delete(Class<?> entityClass, String query, Parameters params) {
return delete(entityClass, query, params.map());
}
public static Uni<Long> delete(Class<?> entityClass, Document query) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(query).map(deleteResult -> deleteResult.getDeletedCount());
}
public static IllegalStateException implementationInjectionMissing() {
return new IllegalStateException(
"This method is normally automatically overridden in subclasses");
}
}

Line under review: return collection.deleteOne(query).map(results -> results.getDeletedCount() == 1);

Code after addressing the review:
static String bindQuery(Class<?> clazz, String query, Object[] params) {
String bindQuery = null;
if (query.charAt(0) == '{') {
bindQuery = NativeQueryBinder.bindQuery(query, params);
} else {
bindQuery = PanacheQlQueryBinder.bindQuery(clazz, query, params);
}
LOGGER.debug(bindQuery);
return bindQuery;
}
/**
* We should have a query like <code>{'firstname': :firstname, 'lastname': :lastname}</code> for native one
* and like <code>firstname = :firstname and lastname = :lastname</code> for PanacheQL one.
*/
static String bindQuery(Class<?> clazz, String query, Map<String, Object> params) {
String bindQuery = null;
if (query.charAt(0) == '{') {
bindQuery = NativeQueryBinder.bindQuery(query, params);
} else {
bindQuery = PanacheQlQueryBinder.bindQuery(clazz, query, params);
}
LOGGER.debug(bindQuery);
return bindQuery;
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Map<String, Object> params) {
return find(entityClass, query, null, params);
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
Document docSort = sortToDocument(sort);
ReactiveMongoCollection collection = mongoCollection(entityClass);
return new ReactivePanacheQueryImpl(collection, entityClass, docQuery, docSort);
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Parameters params) {
return find(entityClass, query, null, params.map());
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, String query, Sort sort, Parameters params) {
return find(entityClass, query, sort, params.map());
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> find(Class<?> entityClass, Document query, Sort sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
return new ReactivePanacheQueryImpl(collection, entityClass, query, sortDoc);
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, Document query, Document sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
return new ReactivePanacheQueryImpl(collection, entityClass, query, sort);
}
public static ReactivePanacheQuery<?> find(Class<?> entityClass, Document query) {
return find(entityClass, query, (Document) null);
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Object... params) {
return (Uni) find(entityClass, query, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Sort sort, Object... params) {
return (Uni) find(entityClass, query, sort, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Map<String, Object> params) {
return (Uni) find(entityClass, query, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
return (Uni) find(entityClass, query, sort, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Parameters params) {
return (Uni) find(entityClass, query, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, String query, Sort sort, Parameters params) {
return (Uni) find(entityClass, query, sort, params).list();
}
public static Uni<List<?>> list(Class<?> entityClass, Document query) {
return (Uni) find(entityClass, query).list();
}
public static Uni<List<?>> list(Class<?> entityClass, Document query, Document sort) {
return (Uni) find(entityClass, query, sort).list();
}
public static Multi<?> stream(Class<?> entityClass, String query, Object... params) {
return find(entityClass, query, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Sort sort, Object... params) {
return find(entityClass, query, sort, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Map<String, Object> params) {
return find(entityClass, query, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Sort sort, Map<String, Object> params) {
return find(entityClass, query, sort, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Parameters params) {
return find(entityClass, query, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, String query, Sort sort, Parameters params) {
return find(entityClass, query, sort, params).stream();
}
public static Multi<?> stream(Class<?> entityClass, Document query) {
return find(entityClass, query).stream();
}
public static Multi<?> stream(Class<?> entityClass, Document query, Document sort) {
return find(entityClass, query, sort).stream();
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> findAll(Class<?> entityClass) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
return new ReactivePanacheQueryImpl(collection, entityClass, null, null);
}
@SuppressWarnings("rawtypes")
public static ReactivePanacheQuery<?> findAll(Class<?> entityClass, Sort sort) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
Document sortDoc = sortToDocument(sort);
return new ReactivePanacheQueryImpl(collection, entityClass, null, sortDoc);
}
private static Document sortToDocument(Sort sort) {
if (sort == null) {
return null;
}
Document sortDoc = new Document();
for (Sort.Column col : sort.getColumns()) {
sortDoc.append(col.getName(), col.getDirection() == Sort.Direction.Ascending ? 1 : -1);
}
return sortDoc;
}
public static Uni<List<?>> listAll(Class<?> entityClass) {
return (Uni) findAll(entityClass).list();
}
public static Uni<List<?>> listAll(Class<?> entityClass, Sort sort) {
return (Uni) findAll(entityClass, sort).list();
}
public static Multi<?> streamAll(Class<?> entityClass) {
return findAll(entityClass).stream();
}
public static Multi<?> streamAll(Class<?> entityClass, Sort sort) {
return findAll(entityClass, sort).stream();
}
public static Uni<Long> count(Class<?> entityClass) {
ReactiveMongoCollection collection = mongoCollection(entityClass);
return collection.countDocuments();
}
public static Uni<Long> count(Class<?> entityClass, String query, Object... params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection collection = mongoCollection(entityClass);
return collection.countDocuments(docQuery);
}
public static Uni<Long> count(Class<?> entityClass, String query, Map<String, Object> params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection collection = mongoCollection(entityClass);
return collection.countDocuments(docQuery);
}
public static Uni<Long> count(Class<?> entityClass, String query, Parameters params) {
return count(entityClass, query, params.map());
}
public static Uni<Long> count(Class<?> entityClass, Document query) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.countDocuments(query);
}
public static Uni<Long> deleteAll(Class<?> entityClass) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(new Document()).map(deleteResult -> deleteResult.getDeletedCount());
}
public static Uni<Boolean> deleteById(Class<?> entityClass, Object id) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
Document query = new Document().append(ID, id);
return collection.deleteOne(query).map(results -> results.getDeletedCount() == 1);
}
public static Uni<Long> delete(Class<?> entityClass, String query, Object... params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(docQuery).map(deleteResult -> deleteResult.getDeletedCount());
}
public static Uni<Long> delete(Class<?> entityClass, String query, Map<String, Object> params) {
String bindQuery = bindQuery(entityClass, query, params);
Document docQuery = Document.parse(bindQuery);
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(docQuery).map(deleteResult -> deleteResult.getDeletedCount());
}
public static Uni<Long> delete(Class<?> entityClass, String query, Parameters params) {
return delete(entityClass, query, params.map());
}
public static Uni<Long> delete(Class<?> entityClass, Document query) {
ReactiveMongoCollection<?> collection = mongoCollection(entityClass);
return collection.deleteMany(query).map(deleteResult -> deleteResult.getDeletedCount());
}
public static IllegalStateException implementationInjectionMissing() {
return new IllegalStateException(
"This method is normally automatically overridden in subclasses");
}
}