List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.lp.server.artikel.fastlanereader.HandlagerbewegungHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;//from www . java2 s . c o m 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(); session = setFilter(session); 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()) { Object[] o = (Object[]) resultListIterator.next(); FLRHandlagerbewegung handlagerbewegung = (FLRHandlagerbewegung) o[0]; rows[row][col++] = handlagerbewegung.getI_id(); rows[row][col++] = handlagerbewegung.getT_buchungszeit(); rows[row][col++] = handlagerbewegung.getFlrartikel().getC_nr(); rows[row][col++] = o[1]; rows[row][col++] = handlagerbewegung.getFlrlager().getC_nr(); // Wenn Lagerabgang, dann negative Menge if (Helper.short2boolean(handlagerbewegung.getB_abgang())) { rows[row][col++] = handlagerbewegung.getN_menge().negate(); } else { rows[row][col++] = handlagerbewegung.getN_menge(); } rows[row++][col++] = handlagerbewegung.getC_kommentar(); 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.artikel.fastlanereader.InventurHandler.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 = 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); 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()) { FLRInventur inventur = (FLRInventur) resultListIterator.next(); rows[row][col++] = inventur.getI_id(); rows[row][col++] = inventur.getT_inventurdatum(); rows[row][col++] = inventur.getC_bez(); if (inventur.getFlrlager() != null) { rows[row][col++] = inventur.getFlrlager().getC_nr(); } else { rows[row][col++] = null; } rows[row][col++] = Helper.short2Boolean(inventur.getB_inventurdurchgefuehrt()); String person = ""; if (inventur.getFlrpersonalinventurdurchgefuehrt() != null) { person = inventur.getFlrpersonalinventurdurchgefuehrt().getFlrpartner() .getC_name1nachnamefirmazeile1(); if (inventur.getFlrpersonalinventurdurchgefuehrt().getFlrpartner() .getC_name2vornamefirmazeile2() != null) { person += " " + inventur.getFlrpersonalinventurdurchgefuehrt().getFlrpartner() .getC_name2vornamefirmazeile2(); } } rows[row++][col++] = person; 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.artikel.fastlanereader.InventurlisteHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;/*from ww w. j a va 2 s . c om*/ 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(); session = setFilter(session); 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()) { Object o[] = (Object[]) resultListIterator.next(); rows[row][col++] = o[0]; String artikel = (String) o[1]; if (o[2] != null) { artikel += " " + (String) o[2]; } rows[row][col++] = artikel; rows[row][col++] = o[3]; rows[row][col++] = o[4]; rows[row++][col++] = o[5]; 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.artikel.fastlanereader.InventurprotokollHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;//w ww . j a v a2s .c om 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); 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()) { FLRInventurprotokoll inventurprotokoll = (FLRInventurprotokoll) resultListIterator.next(); rows[row][col++] = inventurprotokoll.getI_id(); rows[row][col++] = inventurprotokoll.getFlrinventurliste().getFlrartikel().getC_nr(); ArtikelDto artikelDto = getArtikelFac().artikelFindByPrimaryKeySmall( inventurprotokoll.getFlrinventurliste().getFlrartikel().getI_id(), theClientDto); rows[row][col++] = artikelDto.formatBezeichnung(); rows[row][col++] = inventurprotokoll.getFlrinventurliste().getFlrlager().getC_nr(); rows[row][col++] = new java.sql.Timestamp(inventurprotokoll.getT_zeitpunkt().getTime()); rows[row][col++] = inventurprotokoll.getFlrinventurliste().getC_seriennrchargennr(); rows[row++][col++] = inventurprotokoll.getN_korrekturmenge(); 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.artikel.fastlanereader.InventurstandHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;/*from w w w .j a v a2 s . co m*/ 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); 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; Integer lastArtikelId = new Integer(-1); ArtikelDto artikelDto = null; while (resultListIterator.hasNext()) { FLRInventurstand inventurliste = (FLRInventurstand) resultListIterator.next(); rows[row][col++] = inventurliste.getI_id(); if (!lastArtikelId.equals(inventurliste.getFlrartikel().getI_id())) { artikelDto = getArtikelFac() .artikelFindByPrimaryKeySmall(inventurliste.getFlrartikel().getI_id(), theClientDto); } rows[row][col++] = artikelDto.getCNr(); rows[row][col++] = artikelDto.formatBezeichnung(); rows[row][col++] = inventurliste.getFlrlager().getC_nr(); rows[row][col++] = inventurliste.getN_inventurmenge(); rows[row++][col++] = inventurliste.getN_inventurpreis(); col = 0; lastArtikelId = inventurliste.getFlrartikel().getI_id(); } 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.artikel.fastlanereader.KatalogHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;//from w w w . j ava 2s .c om 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); 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()) { FLRKatalog katalog = (FLRKatalog) resultListIterator.next(); rows[row][col++] = katalog.getI_id(); rows[row][col++] = katalog.getC_katalog(); rows[row++][col++] = katalog.getC_seite(); 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.artikel.fastlanereader.KundenidentnummerHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;// w w w. j a v a 2 s. com SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; Iterator resultListIterator = null; List resultList = null; Object[][] rows = 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 = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); query.setFirstResult(startIndex); query.setMaxResults(pageSize); resultList = query.list(); resultListIterator = resultList.iterator(); rows = new Object[resultList.size()][colCount]; resultListIterator = resultList.iterator(); int row = 0; while (resultListIterator.hasNext()) { Object o[] = (Object[]) resultListIterator.next(); Object[] rowToAddCandidate = new Object[colCount]; rowToAddCandidate[0] = o[0]; rowToAddCandidate[1] = o[1]; rowToAddCandidate[2] = o[2]; rowToAddCandidate[3] = o[3]; rowToAddCandidate[4] = o[4]; rowToAddCandidate[5] = o[5]; rowToAddCandidate[6] = o[6]; rows[row] = rowToAddCandidate; row++; } result = new QueryResult(rows, 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.artikel.fastlanereader.LagercockpitArtikelHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;// w w w .j ava2 s . c om 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(); session = setFilter(session); 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()) { Object[] o = (Object[]) resultListIterator.next(); FLRArtikellager artikellager = (FLRArtikellager) o[0]; FLRArtikellistespr artikellistespr = (FLRArtikellistespr) o[1]; rows[row][col++] = artikellager.getFlrartikel().getI_id(); rows[row][col++] = artikellager.getFlrartikel().getC_nr(); if (artikellistespr != null) { rows[row][col++] = artikellistespr.getC_bez(); } else { rows[row][col++] = null; } rows[row++][col++] = artikellager.getN_lagerstand(); 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.artikel.fastlanereader.LagercockpitFehlmengeHandler.java
License:Open Source License
public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null;/*from w w w . j a v a 2 s. c om*/ SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { int colCount = getTableInfo().getColumnClasses().length; int pageSize = 9999999; 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(); // Lagerstand BigDecimal lagerstand = null; HashMap<String, BigDecimal> hmLagerstaende = getLagerFac() .getLagerstaendeAllerLagerartenOhneKeinLager(artikelIId, theClientDto); lagerstand = hmLagerstaende.get(LagerFac.LAGERART_WARENEINGANG); if (lagerstand == null) { lagerstand = new BigDecimal(0); } Query query = session.createQuery(queryString); query.setFirstResult(startIndex); query.setMaxResults(pageSize); List<?> resultList = query.list(); Iterator<?> resultListIterator = resultList.iterator(); ArrayList alZeilen = new ArrayList(); int row = 0; int col = 0; while (resultListIterator.hasNext()) { Object[] o = (Object[]) resultListIterator.next(); FLRFehlmenge fm = (FLRFehlmenge) o[0]; Object[] zeile = new Object[colCount]; zeile[0] = fm.getI_id(); zeile[1] = fm.getFlrartikel().getC_nr(); zeile[2] = getArtikelFac().artikelFindByPrimaryKeySmall(fm.getFlrartikel().getI_id(), theClientDto) .formatBezeichnung(); zeile[3] = fm.getN_menge(); lagerstand = lagerstand.subtract(fm.getN_menge()); String losnummerProjekt = fm.getFlrlossollmaterial().getFlrlos().getC_nr(); if (fm.getFlrlossollmaterial().getFlrlos().getC_projekt() != null) { losnummerProjekt += " " + fm.getFlrlossollmaterial().getFlrlos().getC_projekt(); } zeile[4] = losnummerProjekt; Integer lagerIId = null; LagerDto lDto = getLagerFac().getLagerDesErstenArtikellagerplatzes(fm.getFlrartikel().getI_id(), theClientDto); if (lDto != null) { lagerIId = lDto.getIId(); } String sLagerplaetze = getLagerFac().getLagerplaezteEinesArtikels(fm.getFlrartikel().getI_id(), null); boolean bMehrerLagerplaetze = false; if (sLagerplaetze != null && sLagerplaetze.split(",").length > 2) { bMehrerLagerplaetze = true; } if (bMehrerLagerplaetze == true && lagerIId != null) { zeile[5] = getLagerFac().getLagerplaezteEinesArtikels(fm.getFlrartikel().getI_id(), lagerIId) + " ++"; } else { zeile[5] = getLagerFac().getLagerplaezteEinesArtikels(fm.getFlrartikel().getI_id(), lagerIId); } alZeilen.add(zeile); } if (lagerstand.doubleValue() > 0) { // Noch 2 Zeilen hinzufuegen Object[] zeile = new Object[colCount]; zeile[0] = -1; zeile[1] = "---------"; zeile[2] = "----------------------------------------------------------------------"; alZeilen.add(zeile); zeile = new Object[5]; ArtikelDto aDto = getArtikelFac().artikelFindByPrimaryKeySmall(artikelIId, theClientDto); zeile[0] = -1; zeile[1] = aDto.getCNr(); zeile[2] = "Verbleibende Menge:"; zeile[3] = lagerstand; alZeilen.add(zeile); } Object[][] rows = new Object[alZeilen.size()][colCount]; rows = (Object[][]) alZeilen.toArray(rows); result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0); } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { closeSession(session); } return result; }