/**
   * The information needed for the kundes table.
   *
   * @param rowIndex Integer
   * @throws EJBExceptionLP
   * @return QueryResult
   */
  public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
      int colCount = this.getTableInfo().getColumnClasses().length;
      int pageSize = PAGE_SIZE;
      int startIndex = Math.max(rowIndex.intValue() - (pageSize / 2), 0);
      int endIndex = startIndex + pageSize - 1;

      session = factory.openSession();
      String queryString =
          this.getFromClause() + this.buildWhereClause() + this.buildOrderByClause();

      Query query = session.createQuery(queryString);
      session = setFilter(session);

      query.setFirstResult(startIndex);
      query.setMaxResults(pageSize);
      List<?> resultList = query.list();
      Iterator<?> resultListIterator = resultList.iterator();

      Object[][] rows = new Object[resultList.size()][colCount];
      int row = 0;
      int col = 0;

      while (resultListIterator.hasNext()) {

        FLRLohnartstundenfaktor lohnartstundenfaktor =
            (FLRLohnartstundenfaktor) resultListIterator.next();

        rows[row][col++] = lohnartstundenfaktor.getI_id();
        rows[row][col++] = lohnartstundenfaktor.getFlrlohnart().getI_lohnart();
        rows[row][col++] = lohnartstundenfaktor.getFlrlohnart().getC_bez();
        rows[row][col++] = lohnartstundenfaktor.getFlrlohnart().getPersonalart_c_nr();
        rows[row][col++] = lohnartstundenfaktor.getF_faktor();

        String s = lohnartstundenfaktor.getFlrlohnstundenart().getC_nr();
        if (lohnartstundenfaktor.getFlrlohnstundenart().getC_bez() != null) {
          s = lohnartstundenfaktor.getFlrlohnstundenart().getC_bez();
        }
        rows[row][col++] = s;

        row++;
        col = 0;
      }
      result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (Exception e) {
      throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
      try {
        session.close();
      } catch (HibernateException he) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he);
      }
    }
    return result;
  }
  public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId)
      throws EJBExceptionLP {

    getQuery().setSortKrit(sortierKriterien);

    QueryResult result = null;
    int rowNumber = 0;

    if (selectedId != null) {
      SessionFactory factory = FLRSessionFactory.getFactory();
      Session session = null;

      try {
        session = factory.openSession();
        session = setFilter(session);
        String queryString = getFromClause() + buildWhereClause() + buildOrderByClause();

        Query query = session.createQuery(queryString);
        ScrollableResults scrollableResult = query.scroll();
        if (scrollableResult != null) {
          scrollableResult.beforeFirst();
          while (scrollableResult.next()) {
            FLRLohnartstundenfaktor artikelkommentarart =
                (FLRLohnartstundenfaktor) scrollableResult.get(0);
            Integer iId = artikelkommentarart.getI_id();
            if (selectedId.equals(iId)) {
              rowNumber = scrollableResult.getRowNumber();
              break;
            }
          }
        }
      } catch (Exception e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
      } finally {
        try {
          session.close();
        } catch (HibernateException he) {
          throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
      }
    }

    if (rowNumber < 0 || rowNumber >= this.getRowCount()) {
      rowNumber = 0;
    }

    result = this.getPageAt(new Integer(rowNumber));
    result.setIndexOfSelectedRow(rowNumber);

    return result;
  }