public static List<BlgComment> findByBlog(EntityManager em, String blogId, PagingParams pagingParams) { Query query = em.createQuery("select bc from BlgComment bc, BlgPost bp " + " where bp.blogId.id =:blogId and bc.postId.id=bp.id " + " and bp.commentsEnabled='1' " + " order by bc.dateCommented desc"); query.setParameter("blogId", blogId); if (pagingParams != null) { query.setFirstResult((pagingParams.getCurrentPage() - 1) * pagingParams.getPageSize()); query.setMaxResults(pagingParams.getPageSize()); } return query.getResultList(); }
public static List<BlgPost> findByBlog(EntityManager em, String blogId, PagingParams pagingParams) { Query query = em.createQuery("select bp from BlgPost bp, BlgComment bc " + " where bp.blogId.id =:blogId" + " and bp.id = bc.postId.id" + " group by bc.postId.id" + " order by count(bc.postId.id) desc"); query.setParameter("blogId", blogId); if (pagingParams != null) { query.setFirstResult((pagingParams.getCurrentPage() - 1) * pagingParams.getPageSize()); query.setMaxResults(pagingParams.getPageSize()); } return query.getResultList(); }
public static List<BlgPost> getPostsByBlog(EntityManager em, String blogId, boolean includeNotPublished, PagingParams pagingParams) { String queryString = "SELECT p FROM BlgPost p WHERE p.blogId.id = :blogId"; if (!includeNotPublished) { queryString = queryString.concat(" AND p.published = '1'"); } queryString = queryString.concat(" ORDER BY p.datePosted DESC"); Query query = em.createQuery(queryString); query.setParameter("blogId", blogId); if (pagingParams != null) { query.setFirstResult((pagingParams.getCurrentPage() - 1) * pagingParams.getPageSize()); query.setMaxResults(pagingParams.getPageSize()); } return query.getResultList(); }
if ((pagingParams != null) && (pagingParams.getCurrentPage() > -1)) { query.setFirstResult((pagingParams.getCurrentPage() - 1) * pagingParams.getPageSize()); query.setMaxResults(pagingParams.getPageSize());
* pagingParams.getPageSize()); query.setMaxResults(pagingParams.getPageSize());