List of usage examples for org.hibernate ScrollableResults get
Object get(int i);
From source file:com.liferay.jbpm.util.QueryUtil.java
License:Open Source License
public static List<?> list(Query query, Dialect dialect, int begin, int end) { if ((begin == ALL_POS) && (end == ALL_POS)) { return query.list(); } else {/* w w w. j a v a 2 s .c om*/ if (dialect.supportsLimit()) { query.setMaxResults(end - begin); query.setFirstResult(begin); return query.list(); } else { List<Object> list = new ArrayList<Object>(); ScrollableResults sr = query.scroll(); if (sr.first() && sr.scroll(begin)) { for (int i = begin; i < end; i++) { Object obj = sr.get(0); list.add(obj); if (!sr.next()) { break; } } } return list; } } }
From source file:com.liferay.jbpm.util.QueryUtil.java
License:Open Source License
public static List<?> randomList(Query query, Dialect dialect, int total, int num) { if ((total == 0) || (num == 0)) { return new ArrayList<Object>(); }//from w w w . j a v a 2 s . c o m if (num >= total) { return list(query, dialect, ALL_POS, ALL_POS); } int[] scrollIds = Randomizer.getInstance().nextInt(total, num); List<Object> list = new ArrayList<Object>(); ScrollableResults sr = query.scroll(); for (int i = 0; i < scrollIds.length; i++) { if (sr.scroll(scrollIds[i])) { Object obj = sr.get(0); list.add(obj); sr.first(); } } return list; }
From source file:com.liferay.jbpm.util.QueryUtil.java
License:Open Source License
public static Comparable<?>[] getPrevAndNext(Query query, int count, OrderByComparator obc, Comparable<?> comparable) { int pos = count; int boundary = 0; Comparable<?>[] array = new Comparable[3]; ScrollableResults sr = query.scroll(); if (sr.first()) { while (true) { Object obj = sr.get(0); if (obj == null) { if (_log.isWarnEnabled()) { _log.warn("Object is null"); }//w w w .j ava2 s . c o m break; } Comparable<?> curComparable = (Comparable<?>) obj; int value = obc.compare(comparable, curComparable); if (_log.isDebugEnabled()) { _log.debug("Comparison result is " + value); } if (value == 0) { if (!comparable.equals(curComparable)) { break; } array[1] = curComparable; if (sr.previous()) { array[0] = (Comparable<?>) sr.get(0); } sr.next(); if (sr.next()) { array[2] = (Comparable<?>) sr.get(0); } break; } if (pos == 1) { break; } pos = (int) Math.ceil(pos / 2.0); int scrollPos = pos; if (value < 0) { scrollPos = scrollPos * -1; } boundary += scrollPos; if (boundary < 0) { scrollPos = scrollPos + (boundary * -1) + 1; boundary = 0; } if (boundary > count) { scrollPos = scrollPos - (boundary - count); boundary = scrollPos; } if (_log.isDebugEnabled()) { _log.debug("Scroll " + scrollPos); } if (!sr.scroll(scrollPos)) { if (value < 0) { if (!sr.next()) { break; } } else { if (!sr.previous()) { break; } } } } } return array; }
From source file:com.lp.server.anfrage.fastlanereader.AnfrageartHandler.java
License:Open Source License
/** * sorts the data of the current query using the specified criterias and * returns the page of data where the row of selectedId is contained. * /*from www . j av a 2 s .com*/ * @param sortierKriterien * nach diesen Kriterien wird das Ergebnis sortiert * @param selectedId * auf diesem Datensatz soll der Cursor stehen * @return QueryResult das Ergebnis der Abfrage * @throws EJBExceptionLP * Ausnahme * @see UseCaseHandler#sort(SortierKriterium[], Object) */ public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null; int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRAnfrageart anfrageart = (FLRAnfrageart) scrollableResult.get(0); String c_nr = anfrageart.getC_nr(); if (selectedId.equals(c_nr)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.angebot.fastlanereader.AngebotartHandler.java
License:Open Source License
/** * sorts the data of the current query using the specified criterias and * returns the page of data where the row of selectedId is contained. * /*from w w w .j a v a2 s . c om*/ * @param sortierKriterien * nach diesen Kriterien wird das Ergebnis sortiert * @param selectedId * auf diesem Datensatz soll der Cursor stehen * @return QueryResult das Ergebnis der Abfrage * @throws EJBExceptionLP * Ausnahme * @see UseCaseHandler#sort(SortierKriterium[], Object) */ public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null; int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRAngebotart angebotart = (FLRAngebotart) scrollableResult.get(0); String cNr = angebotart.getC_nr(); if (selectedId.equals(cNr)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.angebot.fastlanereader.AngeboterledigungsgrundHandler.java
License:Open Source License
/** * sorts the data of the current query using the specified criterias and * returns the page of data where the row of selectedId is contained. * /*from w w w .java 2 s . c o m*/ * @param sortierKriterien * nach diesen Kriterien wird das Ergebnis sortiert * @param selectedId * auf diesem Datensatz soll der Cursor stehen * @return QueryResult das Ergebnis der Abfrage * @throws EJBExceptionLP * Ausnahme * @see UseCaseHandler#sort(SortierKriterium[], Object) */ public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null; int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRAngeboterledigungsgrund angeboterledigungsgrund = (FLRAngeboterledigungsgrund) scrollableResult .get(0); String cNr = angeboterledigungsgrund.getC_nr(); if (selectedId.equals(cNr)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.artikel.fastlanereader.ArtikelgruHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { getQuery().setSortKrit(sortierKriterien); QueryResult result = null;//from w ww . j a v a 2 s . c o m int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRArtikelgruppe artikelgruppe = (FLRArtikelgruppe) scrollableResult.get(0); Integer iId = artikelgruppe.getI_id(); if (selectedId.equals(iId)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.artikel.fastlanereader.ArtikelklaHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;/*w w w. j a v a2 s .c o m*/ int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRArtikelklasse artikelklasse = (FLRArtikelklasse) scrollableResult.get(0); Integer iId = artikelklasse.getI_id(); if (selectedId.equals(iId)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.artikel.fastlanereader.ArtikelkommentarartHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { getQuery().setSortKrit(sortierKriterien); QueryResult result = null;/* w ww . java 2 s. co m*/ int rowNumber = 0; if (selectedId != null) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); session = setFilter(session); String queryString = getFromClause() + buildWhereClause() + buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { FLRArtikelkommentarart artikelkommentarart = (FLRArtikelkommentarart) scrollableResult .get(0); Integer iId = artikelkommentarart.getI_id(); if (selectedId.equals(iId)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }
From source file:com.lp.server.artikel.fastlanereader.ArtikelshopgruppeHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;// www . j a v a 2 s . c om int rowNumber = 0; if (selectedId != null /* && ((String) selectedId).length() > 0 */) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); String queryString = "select artikelshopgruppe.i_id from FLRArtikelshopgruppe artikelshopgruppe " + this.buildWhereClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { if (selectedId.equals(scrollableResult.get(0))) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he); } } } if (rowNumber < 0 || rowNumber >= this.getRowCount()) { rowNumber = 0; } result = this.getPageAt(new Integer(rowNumber)); result.setIndexOfSelectedRow(rowNumber); return result; }