Exemplo n.º 1
0
  /**
   * 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());
  }
Exemplo n.º 2
0
  /**
   * Executes a paginated request with 2 native queries (one to count the number of results, and one
   * to return the page).
   *
   * @param paginatedList Paginated list object containing parameters, and into which results are
   *     added by side effects
   * @param queryParam Query parameters
   * @param sortCriteria Sort criteria
   * @return List of results
   */
  public static <E> List<Object[]> executePaginatedQuery(
      PaginatedList<E> paginatedList, QueryParam queryParam, SortCriteria sortCriteria) {
    StringBuilder sb = new StringBuilder(queryParam.getQueryString());
    sb.append(" order by c");
    sb.append(sortCriteria.getColumn());
    sb.append(sortCriteria.isAsc() ? " asc" : " desc");

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

    executeCountQuery(paginatedList, sortedQueryParam);
    return executeResultQuery(paginatedList, sortedQueryParam);
  }