List of usage examples for org.hibernate Query scroll
ScrollableResults scroll();
From source file:com.lp.server.system.fastlanereader.WaehrungHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;/*from www. jav a2s.c o m*/ int rowNumber = 0; if (selectedId != null /* && ( (Integer) selectedId).intValue() >= 0 */) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); String queryString = "select waehrung.c_nr from FLRWaehrung waehrung " + this.buildWhereClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); boolean idFound = false; if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { String id = (String) scrollableResult.getString(0); // TYPE // OF // KEY // ATTRIBUTE // ! // ! // ! if (selectedId.equals(id)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { closeSession(session); } } 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.system.fastlanereader.WechselkursHandler.java
License:Open Source License
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP { this.getQuery().setSortKrit(sortierKriterien); QueryResult result = null;/*from ww w.j a v a2s . c om*/ int rowNumber = 0; if (selectedId != null /* && ( (Integer) selectedId).intValue() >= 0 */) { SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { session = factory.openSession(); String queryString = "select kurs." + SystemFac.FLR_WECHSELKURS_WAEHRUNG_C_NR_ZU + " from FLRWechselkurs kurs " + this.buildWhereClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); ScrollableResults scrollableResult = query.scroll(); boolean idFound = false; if (scrollableResult != null) { scrollableResult.beforeFirst(); while (scrollableResult.next()) { String id = (String) scrollableResult.getString(0); // TYPE // OF // KEY // ATTRIBUTE // ! // ! // ! if (selectedId.equals(id)) { 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.system.fastlanereader.ZahlungszielHandler.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 2s . co m*/ int rowNumber = 0; if (selectedId != null && ((Integer) selectedId).intValue() >= 0) { 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()) { FLRZahlungsziel zahlungsziel = (FLRZahlungsziel) scrollableResult.get(0); Integer id = zahlungsziel.getId(); if (selectedId.equals(id)) { rowNumber = scrollableResult.getRowNumber(); break; } } } } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER, 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.lynn.dao.BaseDao.java
/** * <HQL>// w w w.j a v a 2 s .c o m * @param hql HQL? * @param countHql ?HQL? * @param pageNo * @param pageSize ? * @param values ?Object? * @return PageResults???????List? */ public PageResults<T> findPageByFetchedHql(String hql, String countHql, int pageNo, int pageSize, Object... values) { PageResults<T> retValue = new PageResults<T>(); Query query = this.getSession().createQuery(hql); if (values != null) { for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); } } int currentPage = pageNo > 1 ? pageNo : 1; retValue.setCurrentPage(currentPage); retValue.setPageSize(pageSize); if (countHql == null) { ScrollableResults results = query.scroll(); results.last(); retValue.setTotalCount(results.getRowNumber() + 1);// } else { Long count = countByHql(countHql, values); retValue.setTotalCount(count.intValue()); } retValue.resetPageNo(); List<T> itemList = query.setFirstResult((currentPage - 1) * pageSize).setMaxResults(pageSize).list(); if (itemList == null) { itemList = new ArrayList<T>(); } retValue.setResults(itemList); return retValue; }
From source file:com.sapienter.jbilling.server.process.db.BillingProcessDAS.java
License:Open Source License
public ScrollableResults findBillableUsersToProcess(int entityId, Date processDate) { Query query = getSession().createQuery(BILLABLE_USERS_TO_PROCESS); query.setParameter("dueDate", processDate); query.setParameter("entity", entityId); return query.scroll(); }
From source file:com.sapienter.jbilling.server.process.db.BillingProcessDAS.java
License:Open Source License
/** * Returns all billable users with an order to process. This can be either any open one-time * order or an active recurring order with a valid next billable date. * * @param entityId entity id to find orders for * @param processDate billing process run date * @return billable users/*w w w . j a v a 2 s.co m*/ */ public ScrollableResults findBillableUsersWithOrdersToProcess(int entityId, Date processDate) { Query query = getSession().createQuery(BILLABLE_USERS_WITH_ORDER_HQL); query.setParameter("entity_id", entityId); query.setParameter("active_status_id", Constants.ORDER_STATUS_ACTIVE); query.setParameter("process_date", processDate); return query.scroll(); }
From source file:debop4k.data.orm.hibernate.dao.HibernateDao.java
License:Apache License
public ScrollableResults scroll(@NonNull Query query) { return query.scroll(); }
From source file:net.firejack.platform.core.store.BaseStore.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)/*from w ww. ja v a 2 s . c om*/ public int count(final String queryName, final boolean useScroll, final Object... params) throws DataAccessException { return (Integer) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.getNamedQuery(queryName); setQueryParams(query, params); Integer count; if (useScroll) { ScrollableResults scroll = query.scroll(); count = scroll.last() ? scroll.getRowNumber() + 1 : 0; } else { count = ((Number) query.uniqueResult()).intValue(); } return count; } }); }
From source file:net.mlw.vlh.adapter.hibernate3.HibernateAdapter.java
License:Open Source License
/** * @param query/*from ww w. j a v a 2s . c om*/ * @param info ValueListInfo This info will be set to validator. * @return ScrollableResults, if is set non null _validator, it returns the * ScrollableResultsDecorator. * @throws HibernateException */ private ScrollableResults getScrollableResults(Query query, ValueListInfo info) throws HibernateException { ScrollableResults results; if (_validator == null) { LOGGER.debug("Validator is null, using normal ScrollableResults"); results = query.scroll(); } else { LOGGER.info("Using decorator of the ScrollableResults with your validator."); _validator.setValueListInfo(info); results = new ScrollableResultsDecorator(query.scroll(), _validator); } return results; }
From source file:net.sf.oreka.services.RecSegmentServiceHbn.java
License:Open Source License
public int getResults(RecSegmentFilter filter, int offset, int number, String orderBy, boolean ascending, List results) {/*w w w . ja v a 2 s . co m*/ firstCriterium = true; int numResults = 0; logger.log(Level.DEBUG, "Entering getResults"); //logger.log(Level.INFO, System.getProperty("java.class.path")); //RecSegment seg1 = new RecSegment(); //RecSegment seg2 = new RecSegment(); //RecTape tape1 = new RecTape(); //RecTape tape2 = new RecTape(); /* RecSegmentResult result1 = new RecSegmentResult(); RecSegmentResult result2 = new RecSegmentResult(); result1.getRecSegment().setDuration(10); result1.getRecSegment().setLocalParty("01223"); results.add(result1); result2.getRecSegment().setDuration(11); result2.getRecSegment().setLocalParty("01440"); results.add(result2); */ /* for (int i=0; i<number; i++) { RecSegmentResult result = new RecSegmentResult(); result.getRecSegment().setDuration(offset + i); result.getRecSegment().setLocalParty(orderBy); result.getRecTape().setId(ascending ? 0:1); results.add(result); } numResults = 502; */ Transaction tx = null; Session session = null; try { session = OrkWeb.hibernateManager.getSession(); StringBuffer queryString = new StringBuffer( "from OrkSegment as seg left join seg.tape as tape left join tape.service as srv "); //StringBuffer queryString = new StringBuffer("from RecSegment as seg "); //boolean firstCriterium = false; if (filter.getStartDate() != null && filter.getEndDate() != null) queryString.append(" where seg.timestamp between :startDate and :endDate "); else if (filter.getStartDate() != null) queryString.append(" where seg.timestamp > :startDate "); else if (filter.getEndDate() != null) queryString.append(" where seg.timestamp < :endDate "); if (filter.getLocalParty().length() > 0) { queryString.append(" and seg.localParty=:localParty "); } if (filter.getRemoteParty().length() > 0) { queryString.append(" and seg.remoteParty=:remoteParty "); } if (filter.getMinDuration().length() > 0) { queryString.append(" and seg.duration>:minDuration "); } if (filter.getMaxDuration().length() > 0) { queryString.append(" and seg.duration<:maxDuration "); } if (filter.getDirection() != Direction.ALL) { queryString.append(" and seg.direction=:direction "); } if (orderBy.length() == 0) { orderBy = "seg.timestamp"; } queryString.append(" order by "); queryString.append(orderBy); if (ascending) { queryString.append(" asc"); } else { queryString.append(" desc"); } Query query = session.createQuery(queryString.toString()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); if (filter.getStartDate() != null) { logger.debug("Filter start date:" + dateFormat.format(filter.getStartDate())); query.setTimestamp("startDate", filter.getStartDate()); } if (filter.getEndDate() != null) { logger.debug("Filter end date:" + dateFormat.format(filter.getEndDate())); query.setTimestamp("endDate", filter.getEndDate()); } if (filter.getLocalParty().length() > 0) { query.setString("localParty", filter.getLocalParty()); } if (filter.getRemoteParty().length() > 0) { query.setString("remoteParty", filter.getRemoteParty()); } if (filter.getMinDuration().length() > 0) { query.setString("minDuration", filter.getMinDuration()); } if (filter.getMaxDuration().length() > 0) { query.setString("maxDuration", filter.getMaxDuration()); } if (filter.getDirection() != Direction.ALL) { query.setParameter("direction", filter.getDirection().ordinal()); //query.setParameter( "direction", filter.getDirection().name() ); } // Criteria crit = session.createCriteria(RecSegment.class); // //crit.setFetchMode("RecTape",FetchMode.EAGER); // crit.setFetchMode(null, FetchMode.LAZY); ScrollableResults scrollDocs = query.scroll(); if (scrollDocs.last()) { numResults = scrollDocs.getRowNumber() + 1; logger.debug("Num res:" + numResults); } //scrollDocs.beforeFirst(); scrollDocs.setRowNumber(offset); int rowsSoFar = 0; while (scrollDocs.get() != null && rowsSoFar < number) { rowsSoFar++; OrkSegment seg = (OrkSegment) scrollDocs.get(0); //logger.log(Level.ERROR, seg.getRecTape().getUrl()); //RecTape tape = (RecTape)scrollDocs.get(1); //RecTape tape = new RecTape(); RecSegmentResult res = new RecSegmentResult(); res.setRecSegment(seg); //res.setRecTape(tape); results.add(res); scrollDocs.next(); } } catch (HibernateException he) { if (tx != null) tx.rollback(); logger.log(Level.ERROR, he.toString()); he.printStackTrace(); } catch (Exception e) { logger.error(e); e.printStackTrace(); } finally { session.close(); } return numResults; }