Commit 2579eda5 authored by michael.simon's avatar michael.simon
Browse files

fix count bug in filtered tables

parent 9c87f0fd
......@@ -31,7 +31,7 @@ public interface BaseDao<T extends BaseEntity<PK>, PK extends Serializable> {
List<T> findAllPaging(int first, int pageSize, String sortField, GenericSortOrder sortOrder,
Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs);
Number countAll(Map<String, Object> filterMap);
Number countAll(Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap);
T findById(PK id);
......
......@@ -119,13 +119,14 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
}
@Override
public Number countAll(Map<String, Object> filterMap) {
public Number countAll(Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<T> root = criteria.from(getEntityClass());
List<Predicate> predicates = predicatesFromFilterMap(builder, root, filterMap);
predicates.addAll(predicatesFromAdditionalFilterMap(builder, root, additionalFilterMap));
criteria.select(builder.count(root));
criteria.where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
......@@ -133,7 +134,7 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
TypedQuery<Long> q = em.createQuery(criteria);
return q.getSingleResult();
}
@Override
public T findById(PK id) {
return em.find(getEntityClass(), id);
......
......@@ -38,7 +38,7 @@ public interface BaseService<T extends BaseEntity<PK>, PK extends Serializable>
List<T> findAllPaging(int first, int pageSize, String sortField,
GenericSortOrder sortOrder, Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs);
Number countAll(Map<String, Object> filterMap);
Number countAll(Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap);
List<T> findByMultipleId(List<PK> ids);
}
......@@ -59,8 +59,8 @@ public abstract class BaseServiceImpl<T extends BaseEntity<PK>, PK extends Seria
}
@Override
public Number countAll(Map<String, Object> filterMap) {
return getDao().countAll(filterMap);
public Number countAll(Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap) {
return getDao().countAll(filterMap, additionalFilterMap);
}
@Override
......
......@@ -69,7 +69,7 @@ public class GenericLazyDataModelImpl<E extends BaseEntity<PK>, T extends BaseSe
setPageSize(pageSize);
Number n = getService().countAll(filterMap);
Number n = getService().countAll(filterMap, additionalFilterMap);
if (n != null)
setRowCount(n.intValue());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment