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.fertigung.fastlanereader.LosablieferungHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {

    QueryResult result = null;//from w w  w  . j av a2  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()) {
            FLRLosablieferung losab = (FLRLosablieferung) resultListIterator.next();
            rows[row][col++] = losab.getI_id();
            rows[row][col++] = losab.getT_aendern();
            rows[row][col++] = losab.getN_menge();
            rows[row][col++] = losab.getN_gestehungspreis();

            // PJ 17579
            List<SeriennrChargennrMitMengeDto> l = getLagerFac()
                    .getAllSeriennrchargennrEinerBelegartpositionUeberHibernate(
                            LocaleFac.BELEGART_LOSABLIEFERUNG, losab.getI_id());

            String snrchnr = null;

            if (l.size() > 0) {
                snrchnr = l.get(0).getCSeriennrChargennr();

                if (l.size() > 1) {
                    snrchnr += ",...";
                }
            }
            rows[row][col++] = snrchnr;
            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.fertigung.fastlanereader.LosbereichHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from  w ww.j  av  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);
        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()) {
            FLRLosbereich losbereich = (FLRLosbereich) resultListIterator.next();
            rows[row][col++] = losbereich.getI_id();
            rows[row][col++] = losbereich.getI_id();
            rows[row][col++] = losbereich.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.fertigung.fastlanereader.LosgutschlechtHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from  w  w  w  .j a  v a 2s  . co m*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int startIndex = Math.max(rowIndex.intValue() - (PAGE_SIZE / 2), 0);
        int endIndex = startIndex + PAGE_SIZE - 1;

        session = factory.openSession();
        String queryString = this.getFromClause() + this.buildWhereClause() + this.buildOrderByClause();
        Query query = session.createQuery(queryString);
        query.setFirstResult(startIndex);
        query.setMaxResults(PAGE_SIZE);
        List<?> resultList = query.list();
        Iterator<?> resultListIterator = resultList.iterator();
        Object[][] rows = new Object[resultList.size()][colCount];
        int row = 0;
        int col = 0;
        while (resultListIterator.hasNext()) {
            FLRLosgutschlecht losmat = (FLRLosgutschlecht) resultListIterator.next();
            rows[row][col++] = losmat.getI_id();

            if (losmat.getFlrzeitdaten() != null) {
                rows[row][col++] = losmat.getFlrzeitdaten().getT_zeit();

                String person = losmat.getFlrzeitdaten().getFlrpersonal().getFlrpartner()
                        .getC_name1nachnamefirmazeile1();

                if (losmat.getFlrzeitdaten().getFlrpersonal().getFlrpartner()
                        .getC_name2vornamefirmazeile2() != null) {
                    person = person + " " + losmat.getFlrzeitdaten().getFlrpersonal().getFlrpartner()
                            .getC_name2vornamefirmazeile2();
                }

                rows[row][col++] = person;
            } else {
                rows[row][col++] = losmat.getFlrmaschinenzeitdaten().getT_von();

                String maschine = "M: ";

                maschine += losmat.getFlrmaschinenzeitdaten().getFlrmaschine().getC_inventarnummer();

                if (losmat.getFlrmaschinenzeitdaten().getFlrmaschine().getC_bez() != null) {
                    maschine += " " + losmat.getFlrmaschinenzeitdaten().getFlrmaschine().getC_bez();
                }

                rows[row][col++] = maschine;
            }
            rows[row][col++] = losmat.getN_gut();
            rows[row][col++] = losmat.getN_schlecht();
            rows[row][col++] = losmat.getN_inarbeit();

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

From source file:com.lp.server.fertigung.fastlanereader.LosHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;//from ww w.  j  av  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();
        session = setFilter(session);

        String queryString = "SELECT distinct flrlos, flrlos.flrauftrag.c_nr,flrlos.flrauftrag.c_bez, flrlos.flrstueckliste.flrartikel, aspr FROM FLRLos AS flrlos LEFT OUTER JOIN flrlos.flrstueckliste.flrartikel.artikelsprset AS aspr LEFT OUTER JOIN flrlos.flrauftrag.flrkunde.flrpartner AS partner LEFT OUTER JOIN flrlos.flrkunde.flrpartner AS partnerK  LEFT OUTER JOIN flrlos.technikerset AS technikerset "
                + this.buildWhereClause() + this.buildOrderByClause();

        Query query = session.createQuery(queryString);
        query.setFirstResult(startIndex);
        query.setMaxResults(pageSize);
        List<?> resultList = query.list();

        Object[][] rows = new Object[resultList.size()][colCount];

        String in = "";

        if (resultList.size() > 0) {
            in = " AND flrlos.i_id IN(";

            Iterator it = resultList.iterator();

            while (it.hasNext()) {

                Object[] lose = (Object[]) it.next();
                FLRLos flrLos = (FLRLos) lose[0];
                if (it.hasNext() == false) {
                    in += flrLos.getI_id();
                } else {
                    in += flrLos.getI_id() + ",";
                }
            }
            in += ") ";

            session.close();
            session = factory.openSession();
            session = setFilter(session);
            queryString = this.getFromClause() + this.buildWhereClause() + in + this.buildOrderByClause();
            query = session.createQuery(queryString);
            resultList = query.list();

            if (resultList.size() > 50) {
                int i = 0;
            }
        } else {
            int k = 0;
        }
        Iterator<?> resultListIterator = resultList.iterator();
        int row = 0;
        int col = 0;

        while (resultListIterator.hasNext()) {
            Object o[] = (Object[]) resultListIterator.next();
            rows[row][col++] = o[0];

            rows[row][col++] = o[1];
            rows[row][col++] = new Integer(((BigDecimal) o[2]).intValue());

            if (bAuftragStattArtikel == true) {
                rows[row][col++] = o[14];
            } else {

                if (o[5] != null) {
                    rows[row][col++] = o[5];
                } else {
                    rows[row][col++] = sMaterialliste;
                }
            }

            if (bAuftragStattArtikel == true) {
                rows[row][col++] = o[15];
            } else {
                if (bKundeStattBezeichnung == true) {
                    rows[row][col++] = o[11];
                } else {
                    rows[row][col++] = o[6];

                }
            }

            rows[row][col++] = o[4];
            String sStatus = (String) o[3];
            rows[row][col++] = getStatusMitUebersetzung(sStatus);

            if (bEndeStattBeginnTermin) {
                rows[row][col++] = o[13];
            } else {
                rows[row][col++] = o[8];
            }

            // erledigte Menge
            rows[row][col++] = o[9];

            // Fehlmenge vorhanden
            if (o[10] != null && ((BigDecimal) o[10]).doubleValue() != 0) {
                rows[row][col++] = "F";
            } else {
                rows[row][col++] = "";
            }

            long lAnzahlZeitbuchungen = 0;
            if (o[16] != null) {
                lAnzahlZeitbuchungen = (Long) o[16];
            }

            if (o[12] != null && o[12].equals(new Short((short) 1))) {
                if (lAnzahlZeitbuchungen > 0) {
                    rows[row][col++] = Color.MAGENTA;
                } else {
                    rows[row][col++] = Color.RED;
                }

            } else {
                if (lAnzahlZeitbuchungen > 0) {
                    rows[row][col++] = new Color(0, 153, 51);// GRUEN
                } else {
                    rows[row][col++] = null;
                }
            }
            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.fertigung.fastlanereader.LosistmaterialHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/* w  w w  .  java2  s  . c om*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int startIndex = Math.max(rowIndex.intValue() - (PAGE_SIZE / 2), 0);
        int endIndex = startIndex + PAGE_SIZE - 1;

        session = factory.openSession();
        String queryString = this.getFromClause() + this.buildWhereClause() + this.buildOrderByClause();
        Query query = session.createQuery(queryString);
        query.setFirstResult(startIndex);
        query.setMaxResults(PAGE_SIZE);
        List<?> resultList = query.list();
        Iterator<?> resultListIterator = resultList.iterator();
        Object[][] rows = new Object[resultList.size()][colCount];
        int row = 0;
        int col = 0;
        while (resultListIterator.hasNext()) {
            FLRLosistmaterial losmat = (FLRLosistmaterial) resultListIterator.next();
            rows[row][col++] = losmat.getI_id();
            rows[row][col++] = losmat.getN_menge();
            rows[row][col++] = losmat.getFlrlager().getC_nr();
            rows[row][col++] = !Helper.short2boolean(losmat.getB_abgang());

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

From source file:com.lp.server.fertigung.fastlanereader.LosklasseHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from w w  w  .  ja va 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);
        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;
        Locale locUI = theClientDto.getLocUi();
        while (resultListIterator.hasNext()) {
            FLRLosklasse losklasse = (FLRLosklasse) resultListIterator.next();
            rows[row][col++] = losklasse.getI_id();
            rows[row][col++] = losklasse.getC_nr();
            String sBez = getFertigungServiceFac().uebersetzeLosklasseOptimal(losklasse.getI_id(), locUI,
                    locUI);
            if (sBez == null) {
                // keine Uebersetzung mit dem UI-Locale vorhanden
                LosklasseDto losklasseDto = getFertigungServiceFac()
                        .losklasseFindByPrimaryKey(losklasse.getI_id(), theClientDto);
                sBez = losklasseDto.getCNr();
            }
            rows[row][col++] = sBez;
            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.fertigung.fastlanereader.LoslagerentnahmeHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from  w  w  w.j  a  va  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];
        int row = 0;
        int col = 0;
        while (resultListIterator.hasNext()) {
            FLRLoslagerentnahme funktion = (FLRLoslagerentnahme) resultListIterator.next();
            rows[row][col++] = funktion.getI_id();
            rows[row][col++] = funktion.getI_sort();
            rows[row][col++] = funktion.getFlrlager().getC_nr();
            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.fertigung.fastlanereader.LoslosklasseHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*  w  w w.  j av  a  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;
        Locale locUI = theClientDto.getLocUi();
        while (resultListIterator.hasNext()) {
            FLRLoslosklasse losklasse = (FLRLoslosklasse) resultListIterator.next();
            rows[row][col++] = losklasse.getI_id();
            String sBez = getFertigungServiceFac()
                    .uebersetzeLosklasseOptimal(losklasse.getFlrlosklasse().getI_id(), locUI, locUI);
            if (sBez == null) {
                // keine Uebersetzung mit dem UI-Locale vorhanden
                LosklasseDto losklasseDto = getFertigungServiceFac()
                        .losklasseFindByPrimaryKey(losklasse.getFlrlosklasse().getI_id(), theClientDto);
                sBez = losklasseDto.getCNr();
            }

            rows[row][col++] = sBez;
            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.fertigung.fastlanereader.LossollarbeitsplanHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*from  w  w  w. java 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];
        int row = 0;
        int col = 0;

        FilterKriterium[] filterKriterien = this.getQuery().getFilterBlock().filterKrit;
        Integer losIId = null;
        for (int i = 0; i < filterKriterien.length; i++) {
            if (filterKriterien[i].kritName.equals(FertigungFac.FLR_LOSSOLLARBEITSPLAN_LOS_I_ID)) {
                losIId = new Integer(Integer.parseInt(filterKriterien[i].value.replaceAll("'", "")));
            }
        }

        boolean bZuvieleZeitbuchungen = getZeiterfassungFac()
                .sindZuvieleZeitdatenEinesBelegesVorhanden(LocaleFac.BELEGART_LOS, losIId, theClientDto);
        AuftragzeitenDto[] mannZeiten = null;
        if (bZuvieleZeitbuchungen == false) {
            mannZeiten = getZeiterfassungFac().getAllZeitenEinesBeleges(LocaleFac.BELEGART_LOS, losIId, null,
                    null, null, null, false, false, theClientDto);
        }

        AuftragzeitenDto[] maschinenZeiten = getZeiterfassungFac().getAllMaschinenzeitenEinesBeleges(losIId,
                null, null, null, theClientDto);

        while (resultListIterator.hasNext()) {
            FLRLossollarbeitsplan loszeit = (FLRLossollarbeitsplan) resultListIterator.next();
            rows[row][col++] = loszeit.getI_id();
            if (Helper.short2boolean(loszeit.getB_nachtraeglich()) == true) {
                // Nachtraeglich hinzugefuegte Arbeitsgaenge
                rows[row][col++] = "N";
            } else {
                // Arbeitsgaenge, die aus der Stueckliste uebernommen wurden
                rows[row][col++] = "S";
            }
            rows[row][col++] = loszeit.getI_arbeitsgangsnummer();
            rows[row][col++] = loszeit.getI_unterarbeitsgang();
            rows[row][col++] = loszeit.getI_maschinenversatztage();
            // Maschinen-identifikationsnummer
            if (loszeit.getFlrmaschine() != null) {
                rows[row][col++] = loszeit.getFlrmaschine().getC_identifikationsnr();
            } else {
                rows[row][col++] = "";
            }

            if (bMaschinenbezeichnungStattArtikelbezeichnung) {
                if (loszeit.getFlrmaschine() != null) {
                    rows[row][col++] = loszeit.getFlrmaschine().getC_bez();
                } else {
                    rows[row][col++] = "";
                }
                rows[row][col++] = loszeit.getC_kommentar();
                rows[row][col++] = loszeit.getFlrartikel().getC_nr();
            } else {
                rows[row][col++] = loszeit.getFlrartikel().getC_nr();
                rows[row][col++] = getArtikelFac()
                        .artikelFindByPrimaryKeySmall(loszeit.getFlrartikel().getI_id(), theClientDto)
                        .formatBezeichnung();
            }

            rows[row][col++] = loszeit.getN_gesamtzeit();
            BigDecimal bdZeit = new BigDecimal(0);

            if (bZuvieleZeitbuchungen == false) {

                for (int i = 0; i < mannZeiten.length; i++) {
                    if (loszeit.getI_id().equals(mannZeiten[i].getBelegpositionIId())) {
                        bdZeit = bdZeit.add(new BigDecimal(mannZeiten[i].getDdDauer().doubleValue()));
                    }
                }

                for (int i = 0; i < maschinenZeiten.length; i++) {
                    if (loszeit.getI_id().equals(maschinenZeiten[i].getBelegpositionIId())) {
                        bdZeit = bdZeit.add(new BigDecimal(maschinenZeiten[i].getDdDauer().doubleValue()));
                    }
                }

            } else {
                bdZeit = new BigDecimal(-1);
            }

            rows[row][col++] = bdZeit;
            // Optional: Stueckrueckmeldung
            if (bStueckrueckmeldung) {
                BigDecimal bdLosgroesse = loszeit.getFlrlos().getN_losgroesse();

                BigDecimal[] bdGutSchlechtInarbeit = getFertigungFac().getGutSchlechtInarbeit(loszeit.getI_id(),
                        theClientDto);

                rows[row][col++] = bdGutSchlechtInarbeit[0];
                rows[row][col++] = bdGutSchlechtInarbeit[1];
                rows[row][col++] = bdGutSchlechtInarbeit[2];
                rows[row][col++] = bdGutSchlechtInarbeit[3];

            }
            rows[row][col++] = Helper.short2Boolean(loszeit.getB_fertig());

            row++;
            col = 0;
        }
        result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0);
    } catch (RemoteException e) {
        throwEJBExceptionLPRespectOld(e);
    } finally {
        closeSession(session);
    }
    return result;
}

From source file:com.lp.server.fertigung.fastlanereader.LossollmaterialHandler.java

License:Open Source License

public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP {
    QueryResult result = null;/*w ww  .  jav  a2  s .  co  m*/
    SessionFactory factory = FLRSessionFactory.getFactory();
    Session session = null;
    try {
        int colCount = getTableInfo().getColumnClasses().length;
        int startIndex = Math.max(rowIndex.intValue() - (PAGE_SIZE / 2), 0);
        int endIndex = startIndex + PAGE_SIZE - 1;

        session = factory.openSession();
        String queryString = "SELECT flrlossollmaterial,(SELECT distinct s.artikel_i_id FROM FLRArtikelsperren as s WHERE s.artikel_i_id=flrlossollmaterial.flrartikel.i_id) as sperren from FLRLossollmaterial flrlossollmaterial "

                + this.buildWhereClause() + this.buildOrderByClause();
        Query query = session.createQuery(queryString);
        query.setFirstResult(startIndex);
        query.setMaxResults(PAGE_SIZE);
        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();
            FLRLossollmaterial losmat = (FLRLossollmaterial) o[0];

            rows[row][col++] = losmat.getI_id();
            if (Helper.short2boolean(losmat.getB_nachtraeglich())) {
                rows[row][col++] = "N";
            } else {
                rows[row][col++] = "S";
            }
            rows[row][col++] = losmat.getFlrartikel().getC_nr();
            rows[row][col++] = getArtikelFac()
                    .artikelFindByPrimaryKeySmall(losmat.getFlrartikel().getI_id(), theClientDto)
                    .formatBezeichnung();
            rows[row][col++] = losmat.getN_menge();
            // erledigte Menge
            BigDecimal bdAusgegeben = new BigDecimal(0);
            for (Iterator<?> iter = losmat.getIstmaterialset().iterator(); iter.hasNext();) {
                FLRLosistmaterial item = (FLRLosistmaterial) iter.next();
                if (Helper.short2boolean(item.getB_abgang()) == true) {
                    bdAusgegeben = bdAusgegeben.add(item.getN_menge());
                } else {
                    bdAusgegeben = bdAusgegeben.subtract(item.getN_menge());
                }
            }
            rows[row][col++] = bdAusgegeben;

            ArtikelfehlmengeDto artikelfehlmengeDto = getFehlmengeFac()
                    .artikelfehlmengeFindByBelegartCNrBelegartPositionIIdOhneExc(LocaleFac.BELEGART_LOS,
                            losmat.getI_id());

            if (bFehlmengeStattPreis) {

                if (Helper.short2boolean(losmat.getB_nachtraeglich()) && artikelfehlmengeDto == null) {
                    rows[row][col++] = null;
                } else {
                    rows[row][col++] = losmat.getN_menge().subtract(bdAusgegeben);
                }

            } else {

                rows[row][col++] = losmat.getN_sollpreis();
            }

            if (artikelfehlmengeDto != null) {
                rows[row][col++] = "F";
            } else {
                rows[row][col++] = "";
            }
            if (o[1] != null) {
                rows[row][col++] = LocaleFac.STATUS_GESPERRT;
            } else {
                rows[row][col++] = null;
            }

            if (losmat.getLossollmaterial_i_id_original() != null) {
                rows[row][col++] = new Color(89, 188, 41);
            } else {
                rows[row][col++] = null;
            }

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