List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.javaweb.service.ChuyenbayService.java
public ArrayList<Chuyenbay> SearchChuyenbay(int pageSize, int pageNumber, String Tu, String Den, String NgayKhoiHanh) {/* w ww. j a va2 s .com*/ Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null; ArrayList listChuyenbay = new ArrayList<Chuyenbay>(); try { tx = session.getTransaction(); tx.begin(); Query query = session.createQuery("from Chuyenbay where " + "Tu like '" + Tu + "' and " + "Den like '" + Den + "' " + "and NgayKhoiHanh = '" + NgayKhoiHanh + "'"); chuyenbaycount = query.list().size(); query = query.setFirstResult(pageSize * (pageNumber - 1)); query.setMaxResults(pageSize); listChuyenbay = (ArrayList) query.list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } } finally { session.close(); } return listChuyenbay; }
From source file:com.javaweb.service.TaikhoanService.java
public ArrayList<Taikhoan> GetAllTaikhoan(int pageSize, int pageNumber) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;//from www. j ava 2 s . c o m ArrayList<Taikhoan> listTaikhoan = new ArrayList<Taikhoan>(); try { tx = session.getTransaction(); tx.begin(); Query query = session.createQuery("from Taikhoan"); taikhoancount = query.list().size(); query = query.setFirstResult(pageSize * (pageNumber - 1)); query.setMaxResults(pageSize); listTaikhoan = (ArrayList) query.list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } } finally { session.close(); } return listTaikhoan; }
From source file:com.javaweb.service.TaikhoanService.java
public ArrayList<Taikhoan> SearchTaikhoan(int pageSize, int pageNumber, String Email) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/*from www .jav a 2 s . c o m*/ ArrayList listTaikhoan = new ArrayList<Taikhoan>(); try { tx = session.getTransaction(); tx.begin(); Query query = session.createQuery("from Taikhoan where Email like '%" + Email + "%'"); taikhoancount = query.list().size(); query = query.setFirstResult(pageSize * (pageNumber - 1)); query.setMaxResults(pageSize); listTaikhoan = (ArrayList) query.list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } } finally { session.close(); } return listTaikhoan; }
From source file:com.javaweb.service.TintucService.java
public ArrayList<Tintuc> GetAllTintuc(int pageSize, int pageNumber) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/*from w w w . j av a 2 s . c om*/ ArrayList<Tintuc> listTintuc = new ArrayList<Tintuc>(); try { tx = session.getTransaction(); tx.begin(); Query query = session.createQuery("from Tintuc"); tintuccount = query.list().size(); query = query.setFirstResult(pageSize * (pageNumber - 1)); query.setMaxResults(pageSize); listTintuc = (ArrayList) query.list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } } finally { session.close(); } return listTintuc; }
From source file:com.javaweb.service.TintucService.java
public ArrayList<Tintuc> SearchTintuc(int pageSize, int pageNumber, String TintucKey) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/*from w w w . j a v a 2 s. c o m*/ ArrayList listTintuc = new ArrayList<Tintuc>(); try { tx = session.getTransaction(); tx.begin(); Query query = session.createQuery("from Tintuc where NgayDang = '" + TintucKey + "'"); tintuccount = query.list().size(); query = query.setFirstResult(pageSize * (pageNumber - 1)); query.setMaxResults(pageSize); listTintuc = (ArrayList) query.list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } } finally { session.close(); } return listTintuc; }
From source file:com.javaweb.service.VeService.java
public ArrayList<Ve> GetAllVe(int pageSize, int pageNumber) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;// www. j av a 2 s. c om ArrayList<Ve> listVe = new ArrayList<Ve>(); try { tx = session.getTransaction(); tx.begin(); Query query = session.createQuery("from Ve"); vecount = query.list().size(); query = query.setFirstResult(pageSize * (pageNumber - 1)); query.setMaxResults(pageSize); listVe = (ArrayList) query.list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } } finally { session.close(); } return listVe; }
From source file:com.jdon.persistence.hibernate.HibernateTemplate.java
License:Apache License
/** * Prepare the given Query object, applying cache settings and/or a * transaction timeout.//from w w w. ja va 2s. c o m * * @param queryObject * the Query object to prepare * @see #setCacheQueries * @see #setQueryCacheRegion * @see SessionProviderHolder#applyTransactionTimeout */ protected void prepareQuery(Query queryObject) { if (isCacheQueries()) { queryObject.setCacheable(true); if (getQueryCacheRegion() != null) { queryObject.setCacheRegion(getQueryCacheRegion()); } } if (getFetchSize() > 0) { queryObject.setFetchSize(getFetchSize()); } if (getMaxResults() > 0) { queryObject.setMaxResults(getMaxResults()); } if (getFirstResult() > 0) { queryObject.setFirstResult(getFirstResult()); } }
From source file:com.jeysan.modules.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Query,.// w ww . j a v a 2s .com */ protected Query setPageParameterToQuery(final Query q, final Page<T> page) { if (page.getPageSize() != -1) { //Assert.isTrue(page.getPageSize() > 0, "Page Size must larger than zero"); //hibernatefirstResult??0 q.setFirstResult(page.getFirst() - 1); q.setMaxResults(page.getPageSize()); return q; } return q; }
From source file:com.jshop.dao.impl.JshopbasicInfoTDaoImpl.java
@SuppressWarnings("unchecked") public List<JshopbasicInfoT> findAllJshopbasicInfo(final int currentPage, final int lineSize, final String creatorid) { log.debug("find all JshopbasicInfoT"); try {// ww w .ja va 2 s. co m List<JshopbasicInfoT> list = this.getHibernateTemplate().executeFind(new HibernateCallback() { String queryString = "from JshopbasicInfoT as jbi where jbi.creatorid=:creatorid"; public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(queryString); query.setFirstResult((currentPage - 1) * lineSize); query.setMaxResults(lineSize); query.setParameter("creatorid", creatorid); List list = query.list(); return list; } }); return list; } catch (RuntimeException re) { log.error("find all brand error", re); throw re; } }
From source file:com.jshop.dao.impl.JshopbasicInfoTDaoImpl.java
@SuppressWarnings("unchecked") public JshopbasicInfoT findJshopbasicInfoSingleForExpress(final String creatorid) { log.debug("find findJshopbasicInfoSingleForExpress"); try {//from ww w .java 2 s . co m List<JshopbasicInfoT> list = this.getHibernateTemplate().executeFind(new HibernateCallback() { String queryString = "from JshopbasicInfoT as jbi where jbi.state='1' and jbi.creatorid=:creatorid"; public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(queryString); query.setMaxResults(1); query.setParameter("creatorid", creatorid); List list = query.list(); return list; } }); if (!list.isEmpty()) { return list.get(0); } return null; } catch (RuntimeException re) { log.error("find all brand error", re); throw re; } }