List of usage examples for org.hibernate Query setFirstResult
@Override
Query<R> setFirstResult(int startPosition);
From source file:com.app.usercenter.dao.impl.SysFunctionDaoImpl.java
License:Open Source License
@SuppressWarnings("rawtypes") @Override//from w w w . j a va 2 s . c om public Wrapper getAllFunctionsByCataLogId(Long id, PageExtNative page) { String hqlCount = "select count(*) from SysFunction sf "; String hql = "select sf.sfunId,sf.sfunName,sf.sfunDesc,sf.sfunUrl," + "sf.sfunIndex,sf.sfunCode,sf.sfunIsHidden from SysFunction sf where sf.parentCatalog.scatId=" + id + " or sf.parentCatalog.parentCatalog.scatId=" + id; List listCount = super.getSession().createQuery(hqlCount).list(); Query q = super.getSession().createQuery(hql); if (page != null && page.getLimit() != 0) { q.setFirstResult(page.getStart()); q.setMaxResults(page.getLimit()); } List list = q.list(); if (list == null || list.size() == 0) { list = super.getSession() .createQuery(hql.substring(0, hql.indexOf("where")) + " where sf.sfunId=" + id).list(); } return new Wrapper(list, listCount.get(0).toString()); }
From source file:com.aptech.model.AbstractDao.java
public List paging(Class clazz, Integer pageNumber, Integer perPage) { List objects = null;//from w w w.j av a2s.co m try { startOperation(); Query query = session.createQuery("from " + clazz.getName()); query.setMaxResults(perPage); query.setFirstResult(pageNumber); objects = query.list(); tx.commit(); } catch (HibernateException e) { handleException(e); } finally { HibernateFactory.close(session); } return objects; }
From source file:com.aptech.model.ProductDao.java
public List paging(Integer pageNumber, Integer perPage) { List objects = null;/*from w w w . j a v a 2 s. com*/ try { startOperation2(); Query query = session.createQuery("from " + Product.class.getName()); query.setMaxResults(perPage); query.setFirstResult(pageNumber); objects = query.list(); tx.commit(); } catch (HibernateException e) { handleException(e); } finally { HibernateFactory.close(session); } return objects; }
From source file:com.aptech.model.ProductDao.java
public List pagingWithCategoryId(Integer pageNumber, Integer perPage, Integer catId) { List objects = null;// www .j av a 2s . c o m try { startOperation2(); Query query = session .createQuery("from " + Product.class.getName() + " p where p.category.id = " + catId); query.setMaxResults(perPage); query.setFirstResult(pageNumber); objects = query.list(); tx.commit(); } catch (HibernateException e) { handleException(e); } finally { HibernateFactory.close(session); } return objects; }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
private void setPagination(final Query query, final int firstResult, final int maxResults) { query.setFirstResult(firstResult); if (maxResults > 0) { query.setMaxResults(maxResults); }//from ww w . j ava 2s. c o m }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w. j a v a 2 s. com public <T> Pair<List<T>, Long> findAndCountByNamedQueryWithInStatements(final String namedQuery, final String countNamedQuery, final int firstResult, final int maxResults, final Object... params) { return (Pair<List<T>, Long>) getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { final Query countQuery = session.getNamedQuery(countNamedQuery); addParamsToQueryCheckingIfIsListType(countQuery, params); final Long countResult = (Long) countQuery.list().get(0); final Query query = session.getNamedQuery(namedQuery); addParamsToQueryCheckingIfIsListType(query, params); query.setFirstResult(firstResult); query.setMaxResults(maxResults); return new Pair<List<T>, Long>(query.list(), countResult); } }); }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w ww .j a v a2 s. co m*/ public <T> Pair<List<T>, Long> findAndCountByHqlQueryWithInStatements(final String hqlQuery, final int firstResult, final int maxResults, final Object... params) { return (Pair<List<T>, Long>) getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { final Query query = session.createQuery(hqlQuery); addParamsToQueryCheckingIfIsListType(query, params); query.setFirstResult(firstResult); query.setMaxResults(maxResults); final List<T> result = query.list(); return new Pair<List<T>, Long>(result, Long.valueOf(result.size())); } }); }
From source file:com.baomidou.hibernateplus.utils.HibernateUtils.java
License:Open Source License
/** * /* w w w .ja va 2s.c om*/ * * @param page * @param rows * @param query * @return */ public static void setPage(int page, int rows, Query query) { if (0 != rows) { // ?row , page ?1 page = TypeConvert.toInteger(page, 1); query.setFirstResult((page - 1) * rows).setMaxResults(rows); } }
From source file:com.Bean.PostinfoHelper.java
public List<Post> getAllPost(int page) { List<Post> postList = new ArrayList<Post>(); try {// www . ja va 2s . c om Query q = session.createQuery("from Post as p order by p.creationTime desc "); maxPage = q.list().size() / itemsPerPage; q.setFirstResult(page * itemsPerPage); q.setMaxResults(itemsPerPage); postList = (List<Post>) q.list(); return postList; } catch (HibernateException e) { System.err.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.Bean.PostinfoHelper.java
public List<Post> getMyPost(int page, int userid) { List<Post> postList = new ArrayList<Post>(); try {/*from w w w . ja v a2s . c o m*/ Query q = session .createQuery("from Post as p where p.userId =" + userid + "order by p.creationTime desc"); maxPage = q.list().size() / itemsPerPage; q.setFirstResult(page * itemsPerPage); q.setMaxResults(itemsPerPage); postList = (List<Post>) q.list(); return postList; } catch (HibernateException e) { System.err.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } return null; }