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.partner.fastlanereader.BrancheHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;//from w ww. jav a  2  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);
        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;

        String sLocUI = Helper.locale2String(theClientDto.getLocUi());

        while (resultListIterator.hasNext()) {
            Object o[] = (Object[]) resultListIterator.next();
            FLRBranche branche = (FLRBranche) o[0];

            Iterator<?> sprsetIterator = branche.getBranche_branchespr_set().iterator();

            rows[row][col++] = branche.getI_id();
            rows[row][col++] = branche.getC_nr();

            rows[row][col++] = findSpr(sLocUI, sprsetIterator);

            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.partner.fastlanereader.generated.AnsprechpartnerPartnerHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;/*from  w w w .  j  a  v a 2s . c  om*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int pageSize = AnsprechpartnerPartnerHandler.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()) {
            FLRAnsprechpartner ansprechpartner = (FLRAnsprechpartner) resultListIterator.next();
            rows[row][col++] = ansprechpartner.getI_id();
            rows[row][col++] = ansprechpartner.getFlrpartner().getPartnerart_c_nr();
            rows[row][col++] = ansprechpartner.getFlrpartner().getC_name1nachnamefirmazeile1();
            rows[row][col++] = ansprechpartner.getFlrpartner().getC_name2vornamefirmazeile2();

            if (ansprechpartner.getFlrpartner().getFlrlandplzort() != null) {
                rows[row][col++] = ansprechpartner.getFlrpartner().getFlrlandplzort().getFlrland().getC_lkz();
                rows[row][col++] = ansprechpartner.getFlrpartner().getFlrlandplzort().getC_plz();
                rows[row][col++] = ansprechpartner.getFlrpartner().getFlrlandplzort().getFlrort().getC_name();
            }

            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.partner.fastlanereader.generated.SerienbriefselektionHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*w w  w .j a  va 2s. 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()) {
            // flrjoin: 1
            FLRSerienbriefselektion serienbriefselektion = (FLRSerienbriefselektion) resultListIterator.next();

            rows[row][col++] = serienbriefselektion.getId_comp();
            rows[row][col++] = serienbriefselektion.getFlrselektion().getC_nr();
            rows[row][col++] = serienbriefselektion.getC_bemerkung();
            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.partner.fastlanereader.KommunikationsartHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;/*from   w w  w. 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 = getFromClause() + buildWhereClause() + 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;

        String sLocUI = Helper.locale2String(theClientDto.getLocUi());

        while (resultListIterator.hasNext()) {
            Object o[] = (Object[]) resultListIterator.next();
            FLRKommunikationsart kommunikationart = (FLRKommunikationsart) o[0];

            Iterator<?> sprsetIterator = kommunikationart.getKommunikationsart_kommunikationsartspr_set()
                    .iterator();

            Object[] rowToAddCandidate = new Object[colCount];
            rowToAddCandidate[0] = kommunikationart.getC_nr();
            rowToAddCandidate[1] = kommunikationart.getC_nr();
            rowToAddCandidate[2] = findSpr(sLocUI, sprsetIterator);

            int idx = -1;
            if ((idx = findRowidx(rows, row, kommunikationart.getC_nr(),
                    findSpr(sLocUI, sprsetIterator))) > -1) {
                if (idx < row) {
                    // ueberschreiben
                    rows[idx] = rowToAddCandidate;
                } else {
                    // hinten anfuegen
                    rows[idx] = rowToAddCandidate;
                    row++;
                }
            }
        }
        result = new QueryResult(rows, getRowCount(), startIndex, endIndex, 0);
    } catch (Exception e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he);
        }
    }
    return result;
}

From source file:com.lp.server.partner.fastlanereader.KontaktartHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;//from w  ww .j a v a2  s. co m
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int pageSize = SelektionHandler.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()) {
            FLRKontaktart selektion = (FLRKontaktart) resultListIterator.next();

            rows[row][col++] = selektion.getI_id();
            rows[row][col++] = selektion.getC_bez();

            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.partner.fastlanereader.KontaktHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;/* w w  w  .  j a v  a2 s  .c o  m*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int pageSize = SelektionHandler.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();

            FLRKontakt selektion = (FLRKontakt) o[0];

            rows[row][col++] = selektion.getI_id();
            rows[row][col++] = selektion.getT_kontakt();
            rows[row][col++] = selektion.getC_titel();

            if (selektion.getFlransprechpartner() != null) {

                String sPerson = "";

                if (selektion.getFlransprechpartner().getFlrpartneransprechpartner()
                        .getC_name2vornamefirmazeile2() != null) {
                    sPerson = selektion.getFlransprechpartner().getFlrpartneransprechpartner()
                            .getC_name2vornamefirmazeile2() + " ";
                }
                sPerson += selektion.getFlransprechpartner().getFlrpartneransprechpartner()
                        .getC_name1nachnamefirmazeile1();
                rows[row][col++] = sPerson;

            } else {
                rows[row][col++] = "";
            }

            rows[row][col++] = selektion.getFlrpersonal().getC_kurzzeichen();
            rows[row][col++] = selektion.getT_erledigt();

            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.partner.fastlanereader.KundeHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;/*from w  w w . ja  v a 2 s .  co m*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        // spalteres: 1 auch hier via lazy loading.
        int colCount = getTableInfo().getColumnClasses().length;
        //         int pageSize = KundeHandler.PAGE_SIZE;
        int pageSize = getLimit();
        int startIndex = Math.max(rowIndex.intValue() - (pageSize / 2), 0);
        int endIndex = startIndex + pageSize - 1;

        session = factory.openSession();
        String queryString = getFromClause() + buildWhereClause() + 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()) {
            Object[] o = (Object[]) resultListIterator.next();
            // FLRKunde kunde = (FLRKunde) (o[0]);

            rows[row][col++] = o[0];
            rows[row][col++] = o[12];
            rows[row][col++] = o[1];
            rows[row][col++] = o[2];
            rows[row][col++] = o[3];
            rows[row][col++] = o[4];
            if (o[5] != null) {
                rows[row][col++] = LocaleFac.STATUS_GESPERRT;
            } else {
                rows[row][col++] = null;
            }
            rows[row][col++] = o[6];
            rows[row][col++] = o[7];
            rows[row][col++] = o[8];
            rows[row][col++] = o[9];
            if (bMitKundennummer == false) {
                rows[row][col++] = o[10];
            } else {
                rows[row][col++] = o[11];
            }

            rows[row][col++] = o[13];

            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_FLR, he);
        }
    }
    return result;
}

From source file:com.lp.server.partner.fastlanereader.KundesokoHandler.java

License:Open Source License

/**
 * gets the page of data for the specified row using the current
 * queryParameters.//from w w w . ja  v  a 2s .c  o m
 * 
 * @param rowIndex
 *            diese Zeile soll selektiert sein
 * @return QueryResult das Ergebnis der Abfrage
 * @throws EJBExceptionLP
 *             Ausnahme
 * @see UseCaseHandler#getPageAt(java.lang.Integer)
 */
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int pageSize = KundesokoHandler.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();
        // myLogger.info("HQL: " + queryString);
        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();
            FLRKundesoko kundesoko = (FLRKundesoko) o[0];

            rows[row][col++] = kundesoko.getI_id();
            rows[row][col++] = kundesoko.getArtgru_i_id() == null ? null : "G";

            // Artikel oder Artikelgruppe
            rows[row][col++] = kundesoko.getArtikel_i_id() == null ? kundesoko.getFlrartikelgruppe().getC_nr()
                    : kundesoko.getFlrartikel().getC_nr();

            // die hinterlegten Mengenstaffeln holen
            KundesokomengenstaffelDto[] aMengenstaffelDtos = getKundesokoFac()
                    .kundesokomengenstaffelFindByKundesokoIId(kundesoko.getI_id(), theClientDto);

            BigDecimal nBerechneterPreis = null;
            if (aMengenstaffelDtos != null && aMengenstaffelDtos.length > 0) {
                if (kundesoko.getArtikel_i_id() != null) {
                    // der Preis muss an dieser Stelle berechnet werden
                    nBerechneterPreis = new BigDecimal(0);
                    if (aMengenstaffelDtos[0].getNArtikelfixpreis() != null) {
                        nBerechneterPreis = aMengenstaffelDtos[0].getNArtikelfixpreis();
                    } else {
                        BigDecimal nPreisbasis = null;
                        if (iPreisbasis == 0 || iPreisbasis == 2) {

                            // WH 21.06.06 Es gilt die VK-Basis, die zu
                            // Beginn
                            // der Mengenstaffel gueltig ist
                            nPreisbasis = getVkPreisfindungFac().ermittlePreisbasis(kundesoko.getArtikel_i_id(),
                                    new java.sql.Date(kundesoko.getT_preisgueltigab().getTime()), null,
                                    theClientDto.getSMandantenwaehrung(), theClientDto);
                        } else {
                            nPreisbasis = getVkPreisfindungFac().ermittlePreisbasis(kundesoko.getArtikel_i_id(),
                                    new java.sql.Date(kundesoko.getT_preisgueltigab().getTime()),
                                    kundesoko.getFlrkunde().getVkpfartikelpreisliste_i_id_stdpreisliste(),
                                    theClientDto.getSMandantenwaehrung(), theClientDto);
                        }

                        if (nPreisbasis != null) {

                            VerkaufspreisDto vkpfDto = getVkPreisfindungFac().berechneVerkaufspreis(nPreisbasis,
                                    aMengenstaffelDtos[0].getFArtikelstandardrabattsatz());

                            nBerechneterPreis = vkpfDto.nettopreis;
                        }
                    }
                }
            }

            rows[row][col++] = nBerechneterPreis;
            rows[row][col++] = kundesoko.getT_preisgueltigab();
            rows[row][col++] = kundesoko.getT_preisgueltigbis() == null ? null
                    : kundesoko.getT_preisgueltigbis();
            rows[row][col++] = kundesoko.getC_kundeartikelnummer();

            if (kundesoko.getArtikel_i_id() != null) {

                if (Helper.short2boolean(
                        getArtikelFac().artikelFindByPrimaryKeySmall(kundesoko.getArtikel_i_id(), theClientDto)
                                .getBRabattierbar())) {
                    rows[row][col++] = null;
                } else {
                    rows[row][col++] = Color.RED;
                }

            } else {
                rows[row][col++] = null;
            }
            row++;
            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (Exception e) {
        e.printStackTrace();
        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.partner.fastlanereader.KundesokomengenstaffelHandler.java

License:Open Source License

/**
 * gets the page of data for the specified row using the current
 * queryParameters./*from  w  ww. ja  v  a2  s  . co  m*/
 * 
 * @param rowIndex
 *            diese Zeile soll selektiert sein
 * @return QueryResult das Ergebnis der Abfrage
 * @throws EJBExceptionLP
 *             Ausnahme
 * @see UseCaseHandler#getPageAt(java.lang.Integer)
 */
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int pageSize = KundesokomengenstaffelHandler.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();
        // myLogger.info("HQL: " + queryString);
        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()) {
            FLRKundesokomengenstaffel mengenstaffel = (FLRKundesokomengenstaffel) resultListIterator.next();

            rows[row][col++] = mengenstaffel.getI_id();

            // Artikel oder Artikelgruppe
            rows[row][col++] = mengenstaffel.getFlrkundesoko().getArtgru_i_id() == null ? null : "G";
            rows[row][col++] = mengenstaffel.getFlrkundesoko().getArtikel_i_id() == null
                    ? mengenstaffel.getFlrkundesoko().getFlrartikelgruppe().getC_nr()
                    : mengenstaffel.getFlrkundesoko().getFlrartikel().getC_nr();

            rows[row][col++] = mengenstaffel.getN_menge();
            rows[row][col++] = mengenstaffel.getN_fixpreis();
            rows[row][col++] = mengenstaffel.getF_rabattsatz();

            // zugehoerige Kundesoko
            KundesokoDto kundesokoDto = getKundesokoFac()
                    .kundesokoFindByPrimaryKey(mengenstaffel.getKundesoko_i_id());

            BigDecimal nBerechneterPreis = null;

            if (kundesokoDto.getArtikelIId() != null) {
                // der Preis muss an dieser Stelle berechnet werden
                nBerechneterPreis = new BigDecimal(0);

                if (mengenstaffel.getN_fixpreis() != null) {
                    nBerechneterPreis = mengenstaffel.getN_fixpreis();
                } else {
                    // WH 21.06.06 Es gilt die VK-Basis, die zu Beginn der
                    // Mengenstaffel gueltig ist
                    BigDecimal nPreisbasis = null;
                    if (iPreisbasis == 0 || iPreisbasis == 2) {

                        nPreisbasis = getVkPreisfindungFac().ermittlePreisbasis(kundesokoDto.getArtikelIId(),
                                new java.sql.Date(kundesokoDto.getTPreisgueltigab().getTime()), null,
                                theClientDto.getSMandantenwaehrung(), theClientDto);
                    } else {
                        nPreisbasis = getVkPreisfindungFac().ermittlePreisbasis(kundesokoDto.getArtikelIId(),
                                new java.sql.Date(kundesokoDto.getTPreisgueltigab().getTime()),
                                mengenstaffel.getFlrkundesoko().getFlrkunde()
                                        .getVkpfartikelpreisliste_i_id_stdpreisliste(),
                                theClientDto.getSMandantenwaehrung(), theClientDto);
                    }

                    VerkaufspreisDto vkpfDto = getVkPreisfindungFac().berechneVerkaufspreis(nPreisbasis,
                            mengenstaffel.getF_rabattsatz());

                    if (vkpfDto != null) {
                        nBerechneterPreis = vkpfDto.nettopreis;
                    }
                }
            }

            rows[row][col++] = nBerechneterPreis;
            rows[row][col++] = kundesokoDto.getTPreisgueltigab();
            rows[row++][col++] = kundesokoDto.getTPreisgueltigbis() == null ? null
                    : kundesokoDto.getTPreisgueltigbis();

            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.partner.fastlanereader.LFLiefergruppenHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;//ww w  . j  a v a 2s  . 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];
        int row = 0;
        int col = 0;
        while (resultListIterator.hasNext()) {
            FLRLFLiefergruppe lflliefergruppe = (FLRLFLiefergruppe) resultListIterator.next();
            rows[row][col++] = lflliefergruppe.getId_comp();
            rows[row][col++] = lflliefergruppe.getFlrliefergruppe().getC_nr();
            row++;
            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (Exception e) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER, e);
    } finally {
        try {
            session.close();
        } catch (HibernateException he) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he);
        }
    }
    return result;
}