List of usage examples for org.hibernate Query setFirstResult
@Override
Query<R> setFirstResult(int startPosition);
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ?Query,.// w w w . j av a 2s . c o m */ protected Query setPageParameterMap(final Query q, final Page<?> page) { // hibernatefirstResult??0 if (page.getPageSize() > 0) { q.setFirstResult(page.getFirst() - 1); q.setMaxResults(page.getPageSize()); } return q; }
From source file:com.adibrata.smartdealer.dao.purchase.PurchaseEntryDao.java
@Override public List<PurchaseOrderHdr> Paging(final int CurrentPage, final String WhereCond, final String SortBy) throws Exception { // TODO Auto-generated method stub final StringBuilder hql = new StringBuilder(); List<PurchaseOrderHdr> list = null; try {/* w w w . j a va 2s .co m*/ hql.append(this.strStatement); if (!WhereCond.equals("")) { hql.append(WhereCond); } final Query selectQuery = this.session.createQuery(hql.toString()); selectQuery.setFirstResult((CurrentPage - 1) * this.pagesize); selectQuery.setMaxResults(this.pagesize); list = selectQuery.list(); } catch (final Exception exp) { final ExceptionEntities lEntExp = new ExceptionEntities(); lEntExp.setJavaClass(Thread.currentThread().getStackTrace()[1].getClassName()); lEntExp.setMethodName(Thread.currentThread().getStackTrace()[1].getMethodName()); ExceptionHelper.WriteException(lEntExp, exp); } return list; }
From source file:com.adibrata.smartdealer.dao.purchase.PurchaseEntryDao.java
@Override public List<PurchaseOrderHdr> Paging(final int CurrentPage, final String WhereCond, final String SortBy, final boolean islast) throws Exception { // TODO Auto-generated method stub final StringBuilder hql = new StringBuilder(); List<PurchaseOrderHdr> list = null; try {//from w ww .j av a2 s.c o m hql.append(this.strStatement); if (!WhereCond.equals("")) { hql.append(" where "); hql.append(WhereCond); } final Query selectQuery = this.session.createQuery(hql.toString()); final Long totalrecord = this.TotalRecord(this.strStatement, WhereCond); selectQuery.setFirstResult((int) ((totalrecord - 1) * this.pagesize)); selectQuery.setMaxResults(this.pagesize); list = selectQuery.list(); } catch (final Exception exp) { final ExceptionEntities lEntExp = new ExceptionEntities(); lEntExp.setJavaClass(Thread.currentThread().getStackTrace()[1].getClassName()); lEntExp.setMethodName(Thread.currentThread().getStackTrace()[1].getMethodName()); ExceptionHelper.WriteException(lEntExp, exp); } return list; }
From source file:com.algoTrader.entity.marketData.BarDaoBase.java
/** * Executes and returns the given Hibernate queryObject as a {@link PaginationResult} instance. * @param queryObject/*from w w w . j a v a 2 s. c o m*/ * @param transform * @param pageNumber * @param pageSize * @return PaginationResult */ @SuppressWarnings({ "unchecked" }) protected PaginationResult getPaginationResult(final Query queryObject, final int transform, int pageNumber, int pageSize) { try { final ScrollableResults scrollableResults = queryObject.scroll(); scrollableResults.last(); int totalCount = scrollableResults.getRowNumber(); totalCount = totalCount >= 0 ? totalCount + 1 : 0; if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } // Unchecked transformation because Set object is reused, cannot be strongly typed. Set results = new LinkedHashSet(queryObject.list()); transformEntities(transform, results); return new PaginationResult(results.toArray(new Object[results.size()]), totalCount); } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:com.algoTrader.entity.PositionDaoBase.java
/** * {@inheritDoc}/*from ww w . j ava 2 s . c o m*/ */ @Override @SuppressWarnings("unchecked") public List<?> findOpenPositions(final int transform, final String queryString, int pageNumber, int pageSize) { try { Query queryObject = super.getSession(false).createQuery(queryString); queryObject.setCacheable(true); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } List results = queryObject.list(); transformEntities(transform, results); return results; } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:com.algoTrader.entity.PositionDaoBase.java
/** * {@inheritDoc}// w ww . j a v a 2 s . c o m */ @Override @SuppressWarnings("unchecked") public List<?> findOpenPositionsByStrategy(final int transform, final String queryString, int pageNumber, int pageSize, final String strategyName) { try { Query queryObject = super.getSession(false).createQuery(queryString); queryObject.setCacheable(true); queryObject.setParameter("strategyName", strategyName); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } List results = queryObject.list(); transformEntities(transform, results); return results; } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:com.algoTrader.entity.security.SecurityDaoBase.java
/** * {@inheritDoc}// w w w .ja va 2 s . co m */ @Override @SuppressWarnings("unchecked") public List<?> findSecuritiesInPortfolio(final int transform, final String queryString, int pageNumber, int pageSize) { try { Query queryObject = super.getSession(false).createQuery(queryString); queryObject.setCacheable(true); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } List results = queryObject.list(); transformEntities(transform, results); return results; } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:com.algoTrader.entity.security.SecurityDaoBase.java
/** * {@inheritDoc}/*from w w w .j av a 2 s . c o m*/ */ @Override @SuppressWarnings("unchecked") public List<?> findSecuritiesOnWatchlist(final int transform, final String queryString, int pageNumber, int pageSize) { try { Query queryObject = super.getSession(false).createQuery(queryString); queryObject.setCacheable(true); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } List results = queryObject.list(); transformEntities(transform, results); return results; } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:com.algoTrader.entity.security.SecurityDaoBase.java
/** * {@inheritDoc}/*from w w w .j a va2 s .c om*/ */ @Override @SuppressWarnings("unchecked") public List<?> findSecuritiesOnActiveWatchlist(final int transform, final String queryString, int pageNumber, int pageSize) { try { Query queryObject = super.getSession(false).createQuery(queryString); queryObject.setCacheable(true); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } List results = queryObject.list(); transformEntities(transform, results); return results; } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:com.algoTrader.entity.StrategyDaoBase.java
/** * {@inheritDoc}/*ww w . j ava 2s . co m*/ */ @Override @SuppressWarnings("unchecked") public List<?> findAutoActivateStrategies(final int transform, final String queryString, int pageNumber, int pageSize) { try { Query queryObject = super.getSession(false).createQuery(queryString); queryObject.setCacheable(true); if (pageNumber > 0 && pageSize > 0) { queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize)); queryObject.setMaxResults(pageSize); } List results = queryObject.list(); transformEntities(transform, results); return results; } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }