Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public Page<T> findPage(final Page<T> page, final Criterion... criterions) {

    Criteria c = createCriteria(criterions);

    if (page.isAutoCount()) {
      int totalCount = countCriteriaResult(c);
      page.setTotalCount(totalCount);
    }

    setPageParameter(c, page);
    List<T> result = c.list();
    page.setResult(result);
    return page;
  }
Exemplo n.º 2
0
  @SuppressWarnings("unchecked")
  public Page<T> findPage(final Page<T> page, final String hql, final Object... values) {

    Query q = createQuery(hql, values);

    if (page.isAutoCount()) {
      long totalCount = countHqlResult(hql, values);
      page.setTotalCount(totalCount);
    }

    setPageParameter(q, page);
    List<T> result = q.list();
    page.setResult(result);
    return page;
  }
Exemplo n.º 3
0
  protected Criteria setPageParameter(final Criteria c, final Page<T> page) {
    c.setFirstResult(page.getFirst() - 1);
    c.setMaxResults(page.getPageSize());

    if (page.isOrderBySetted()) {
      String[] orderByArray = StringUtils.split(page.getOrderBy(), ',');
      String[] orderArray = StringUtils.split(page.getOrder(), ',');

      for (int i = 0; i < orderByArray.length; i++) {
        if (Page.ASC.equals(orderArray[i])) {
          c.addOrder(Order.asc(orderByArray[i]));
        } else {
          c.addOrder(Order.desc(orderByArray[i]));
        }
      }
    }
    return c;
  }
Exemplo n.º 4
0
 protected Query setPageParameter(final Query q, final Page<T> page) {
   q.setFirstResult(page.getFirst() - 1);
   q.setMaxResults(page.getPageSize());
   return q;
 }