fjtirado commented on code in PR #2196:
URL: 
https://github.com/apache/incubator-kie-kogito-apps/pull/2196#discussion_r1970477168


##########
data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/JPAQuery.java:
##########
@@ -195,4 +191,21 @@ private List<Predicate> 
getRecursivePredicate(AttributeFilter<?> filter, Root<E>
                 .collect(toList());
     }
 
+    @Override
+    public long count() {
+        CriteriaBuilder builder = 
repository.getEntityManager().getCriteriaBuilder();
+        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
+        Root<E> root = criteriaQuery.from(entityClass);
+        criteriaQuery.select(builder.count(root));
+        addWhere(builder, criteriaQuery, root);
+        return 
repository.getEntityManager().createQuery(criteriaQuery).getSingleResult();
+    }
+
+    private <V> void addWhere(CriteriaBuilder builder, CriteriaQuery<V> 
criteriaQuery, Root<E> root) {
+        if (filters != null && !filters.isEmpty()) {
+            List<Predicate> predicates = getPredicates(builder, root);
+            criteriaQuery.where(predicates.toArray(new Predicate[] {}));

Review Comment:
   I do not change the original code, but actually, it should be 
predicates.toArray(new Predicate[predicates.size()])



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to