From a9f5bab381322e27596b056cd0836c756def0f7a Mon Sep 17 00:00:00 2001 From: Josefina Revilla Date: Tue, 7 Nov 2023 20:01:42 -0300 Subject: [PATCH] DBManager: get all now accepts DBFilter... --- .../src/main/java/org/jpos/ee/DBManager.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java b/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java index 21226bc138..2d67a0b819 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java @@ -80,8 +80,11 @@ public int getItemCount(DBFilter... filters) { return totalCount.intValue(); } - public List getAll(int offset, int limit, Map orders) { + return this.getAll(offset, limit, orders, null); + } + + public List getAll(int offset, int limit, Map orders, DBFilter... filters) { CriteriaBuilder criteriaBuilder = db.session().getCriteriaBuilder(); CriteriaQuery query = criteriaBuilder.createQuery(clazz); Root root = query.from(clazz); @@ -93,9 +96,21 @@ public List getAll(int offset, int limit, Map orders) { orderList.add(order); } } - Predicate[] predicates = buildFilters(root); - if (predicates != null) - query.where(predicates); + Predicate combinedPredicate = null; + if (filters != null) { + combinedPredicate = criteriaBuilder.and(Arrays.stream(filters) + .filter(f -> f != null) + .map(f -> f.createPredicate(criteriaBuilder, root)) + .toArray(Predicate[]::new)); + } + Predicate[] mgrFilters = buildFilters(root); + if (mgrFilters != null) { + Predicate[] nonNullPredicates = Arrays.stream(mgrFilters).filter(f -> f != null).toArray(Predicate[]::new); + Predicate mgrPredicate = criteriaBuilder.and(nonNullPredicates); + combinedPredicate = combinedPredicate != null ? criteriaBuilder.and(mgrPredicate, combinedPredicate) : mgrPredicate; + } + if (combinedPredicate != null) + query.where(combinedPredicate); query.select(root); query.orderBy(orderList); Query queryImp = db.session().createQuery(query);