Example usage for org.hibernate Query setFirstResult

List of usage examples for org.hibernate Query setFirstResult

Introduction

In this page you can find the example usage for org.hibernate Query setFirstResult.

Prototype

@Override
    Query<R> setFirstResult(int startPosition);

Source Link

Usage

From source file:com.lp.server.instandhaltung.fastlanereader.GeraetehistorieMitGeraetHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from ww w  .  j  ava2 s .c o  m*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        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()) {
            FLRGeraetehistorie historie = (FLRGeraetehistorie) resultListIterator.next();
            rows[row][col++] = historie.getI_id();
            rows[row][col++] = historie.getFlrgeraet().getC_bez();
            rows[row][col++] = historie.getT_wartung();
            rows[row][col++] = historie.getFlrpersonal_techniker().getFlrpartner()
                    .getC_name1nachnamefirmazeile1();
            rows[row][col++] = Helper.short2Boolean(historie.getB_nichtmoeglich());
            rows[row][col++] = historie.getT_aendern();
            rows[row][col++] = historie.getFlrpersonal_aendern().getFlrpartner()
                    .getC_name1nachnamefirmazeile1();

            row++;
            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.instandhaltung.fastlanereader.GeraetetypHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;//w w w .  j a v a2 s.co m
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        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()) {
            FLRGeraetetyp maschinengruppe = (FLRGeraetetyp) resultListIterator.next();
            rows[row][col++] = maschinengruppe.getI_id();
            rows[row++][col++] = maschinengruppe.getC_bez();

            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.instandhaltung.fastlanereader.GeraetHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from ww  w. j a v  a  2 s .c om*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        query.setFirstResult(startIndex);
        query.setMaxResults(pageSize);
        List<?> resultList = query.list();
        Iterator<?> resultListIterator = resultList.iterator();
        Object[][] rows = new Object[resultList.size()][colCount];
        String[] tooltipData = new String[resultList.size()];
        int row = 0;
        int col = 0;
        while (resultListIterator.hasNext()) {
            Object[] o = (Object[]) resultListIterator.next();
            FLRGeraet maschinengruppe = (FLRGeraet) o[0];
            rows[row][col++] = maschinengruppe.getI_id();

            if (maschinengruppe.getX_bemerkung() != null) {
                tooltipData[row] = Helper.strippHTML(maschinengruppe.getX_bemerkung());

            }
            if (maschinengruppe.getFlrgewerk() != null) {
                rows[row][col++] = maschinengruppe.getFlrgewerk().getC_bez();
            } else {
                rows[row][col++] = null;
            }

            if (maschinengruppe.getFlrhalle() != null) {
                rows[row][col++] = maschinengruppe.getFlrhalle().getC_bez();
            } else {
                rows[row][col++] = null;
            }

            if (maschinengruppe.getFlrgeraetetyp() != null) {
                rows[row][col++] = maschinengruppe.getFlrgeraetetyp().getC_bez();
            } else {
                rows[row][col++] = null;
            }

            if (maschinengruppe.getFlrhersteller() != null) {
                rows[row][col++] = maschinengruppe.getFlrhersteller().getC_nr();
            } else {
                rows[row][col++] = null;
            }
            row++;
            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0, tooltipData);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.instandhaltung.fastlanereader.GewerkHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*w w  w .j  a v  a2  s. co  m*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        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()) {
            FLRGewerk anlage = (FLRGewerk) resultListIterator.next();
            rows[row][col++] = anlage.getI_id();
            rows[row++][col++] = anlage.getC_bez();

            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.instandhaltung.fastlanereader.HalleHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;//from   w  ww.  j  a v a2s  . co m
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        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()) {
            FLRHalle halle = (FLRHalle) resultListIterator.next();
            rows[row][col++] = halle.getI_id();
            rows[row][col++] = halle.getC_bez();
            rows[row++][col++] = halle.getFlrstandort().getFlrpartner().getC_name1nachnamefirmazeile1();

            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.instandhaltung.fastlanereader.InstandhaltungHandler.java

License:Open Source License

/**
 * The information needed for the kundes table.
 * // ww  w  .j  av  a 2 s  .  c om
 * @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 = "SELECT distinct instandhaltung.i_id, instandhaltung.flrkunde.flrpartner.c_name1nachnamefirmazeile1, instandhaltung, instandhaltung.flrkunde.flrpartner.flrlandplzort.flrland.c_lkz, instandhaltung.flrkunde.flrpartner.flrlandplzort.c_plz FROM FLRInstandhaltung AS instandhaltung  LEFT JOIN instandhaltung.standortset AS standortset LEFT JOIN standortset.flrpartner AS partner  LEFT JOIN partner.flrlandplzort AS landplzort LEFT JOIN landplzort.flrort AS ort"
                + this.buildWhereClause() + this.buildOrderByClause();

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

        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()) {

            Object[] o = (Object[]) resultListIterator.next();
            FLRInstandhaltung artikelkommentarart = (FLRInstandhaltung) o[2];

            rows[row][col++] = artikelkommentarart.getI_id();
            rows[row][col++] = artikelkommentarart.getFlrkunde().getFlrpartner()
                    .getC_name1nachnamefirmazeile1();

            String cAnschrift = null;

            if (artikelkommentarart.getFlrkunde() != null) {
                FLRLandplzort flranschrift = artikelkommentarart.getFlrkunde().getFlrpartner()
                        .getFlrlandplzort();

                if (flranschrift != null) {
                    cAnschrift = flranschrift.getFlrland().getC_lkz() + "-" + flranschrift.getC_plz() + " "
                            + flranschrift.getFlrort().getC_name();
                }
            }

            rows[row][col++] = cAnschrift;

            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;
}

From source file:com.lp.server.instandhaltung.fastlanereader.IskategorieHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from w  ww.  j  ava2 s . c  o m*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        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()) {
            FLRIskategorie anlage = (FLRIskategorie) resultListIterator.next();
            rows[row][col++] = anlage.getI_id();
            rows[row++][col++] = anlage.getC_bez();

            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.instandhaltung.fastlanereader.IsmaschineHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;//from w  ww . j av  a  2s .co m
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        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()) {
            FLRIsmaschine maschinengruppe = (FLRIsmaschine) resultListIterator.next();
            rows[row][col++] = maschinengruppe.getI_id();
            rows[row][col++] = maschinengruppe.getC_bez();
            rows[row++][col++] = maschinengruppe.getFlranlage().getC_bez();

            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.instandhaltung.fastlanereader.StandortHandler.java

License:Open Source License

/**
 * The information needed for the kundes table.
 * //from   www  .j a  v a 2s  . com
 * @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()) {

            Object[] o = (Object[]) resultListIterator.next();

            FLRStandort artikelkommentarart = (FLRStandort) o[0];

            rows[row][col++] = artikelkommentarart.getI_id();
            rows[row][col++] = artikelkommentarart.getFlrinstandhaltung().getFlrkunde().getFlrpartner()
                    .getC_name1nachnamefirmazeile1();
            rows[row][col++] = artikelkommentarart.getFlrpartner().getC_name1nachnamefirmazeile1();

            String cAnschrift = null;

            FLRLandplzort flranschrift = artikelkommentarart.getFlrpartner().getFlrlandplzort();

            if (flranschrift != null) {
                cAnschrift = flranschrift.getFlrland().getC_lkz() + "-" + flranschrift.getC_plz() + " "
                        + flranschrift.getFlrort().getC_name();
            }

            rows[row][col++] = cAnschrift;

            rows[row][col++] = artikelkommentarart.getFlrpartner().getC_strasse();

            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;
}

From source file:com.lp.server.instandhaltung.fastlanereader.StandorttechnikerHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;//  w  w w .  j av  a  2  s .  co m
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = 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);
        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()) {
            FLRStandorttechniker historie = (FLRStandorttechniker) resultListIterator.next();
            rows[row][col++] = historie.getI_id();
            rows[row][col++] = historie.getFlrpersonal().getFlrpartner().getC_name1nachnamefirmazeile1();
            rows[row][col++] = historie.getFlrpersonal().getFlrpartner().getC_name2vornamefirmazeile2();
            rows[row][col++] = Helper.short2Boolean(historie.getB_verantwortlicher());

            row++;
            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (HibernateException e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
        }
    }
    return result;
}