コード例 #1
0
ファイル: PaginatedLists.java プロジェクト: ranger101/reader
  /**
   * Executes a query and returns the data of the currunt page.
   *
   * @param em EntityManager
   * @param paginatedList Paginated list object containing parameters, and into which results are
   *     added by side effects
   * @param queryParam Query parameters
   * @return List of results
   */
  @SuppressWarnings("unchecked")
  private static <E> List<Object[]> executeResultQuery(
      PaginatedList<E> paginatedList, QueryParam queryParam) {
    Query q = QueryUtil.getNativeQuery(queryParam);

    q.setFirstResult(paginatedList.getOffset());
    q.setMaxResults(paginatedList.getLimit());
    return q.getResultList();
  }
コード例 #2
0
ファイル: PaginatedLists.java プロジェクト: ranger101/reader
  /**
   * Executes a native count(*) request to count the number of results.
   *
   * @param paginatedList Paginated list object containing parameters, and into which results are
   *     added by side effects
   * @param queryParam Query parameters
   */
  public static <E> void executeCountQuery(PaginatedList<E> paginatedList, QueryParam queryParam) {
    StringBuilder sb = new StringBuilder("select count(*) as result_count from (");
    sb.append(queryParam.getQueryString());
    sb.append(") as t1");

    QueryParam countQueryParam = new QueryParam(sb.toString(), queryParam.getParameterMap());

    Query q = QueryUtil.getNativeQuery(countQueryParam);

    Number resultCount = (Number) q.getSingleResult();
    paginatedList.setResultCount(resultCount.intValue());
  }