@SuppressWarnings("unchecked")
public SearchResult searchAndCount(EntityManager entityManager, Class<?> searchClass, ISearch search) {
if (searchClass == null || search == null)
return null;
SearchResult result = new SearchResult();
result.setResult(search(entityManager, searchClass, search));
if (search.getMaxResults() > 0) {
result.setTotalCount(count(entityManager, searchClass, search));
} else {
result.setTotalCount(result.getResult().size() + SearchUtil.calcFirstResult(search));
}
return result;
}