예제 #1
0
  /**
   * 按SQL分页查询对象列表.
   *
   * @param values 命名参数,按名称绑定.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public <X> SearchResult<X> findPageWithNameParamByNativeSQL(
      final int firstResult, final int maxResult, final String sql, final Map<String, ?> values) {

    SearchResult searResult = new SearchResult();

    List<Object[]> objectList =
        createNativeQueryWithNameParam(sql, values)
            .setFirstResult(firstResult)
            .setMaxResults(maxResult)
            .getResultList();
    String databaseType = DialectUtils.getDataBaseType(smartDataSource.getDataSource());
    if (databaseType.equals("db2")) {
      List<Object[]> newobjectList = new ArrayList();
      for (Object[] object : objectList) {
        Object[] newobject = new Object[object.length - 1];
        for (int i = 0; i < object.length - 1; i++) {
          newobject[i] = object[i + 1];
        }
        newobjectList.add(newobject);
      }
      objectList = newobjectList;
    }

    // 查询记录总数
    String countSql = SQLUtils.buildCountSQL(sql);
    Object totalCount = createNativeQueryWithNameParam(countSql, values).getSingleResult();
    searResult.setResult(objectList);
    searResult.setTotalCount(totalCount);

    return searResult;
  }
예제 #2
0
  /**
   * 按JQL分页查询对象列表.
   *
   * @param values 命名参数,按名称绑定.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public <X> SearchResult<X> findPageWithNameParam(
      final int firstResult, final int maxResult, final String jql, final Map<String, ?> values) {
    SearchResult searResult = new SearchResult();

    List objectList =
        this.getEntityManager()
            .createQueryWithNameParam(jql, values)
            .setFirstResult(firstResult)
            .setMaxResults(maxResult)
            .getResultList();
    // 查询记录总数
    String countJql = SQLUtils.buildCountSQL(jql);
    Long totalCount =
        (Long) this.getEntityManager().createQueryWithNameParam(countJql, values).getSingleResult();

    searResult.setResult(objectList);
    searResult.setTotalCount(totalCount.intValue());

    return searResult;
  }