List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:cn.com.jandar.lawyer.service.LawFirmService.java
@SuppressWarnings("unchecked") public List<LawFirm> findByParam(Date lastUpdateDate, Integer pageNum, Integer pageSize) { Criteria c = lawFirmDao.getSession().createCriteria(LawFirm.class); if (lastUpdateDate != null) { c.add(Restrictions.ge("lastUpdateDate", lastUpdateDate)); }//from w w w . j a va 2 s . c o m c.setMaxResults(pageSize); c.setFirstResult(pageNum * pageSize + 1); c.addOrder(Order.desc("laseUpdateDate")); return c.list(); }
From source file:cn.com.jandar.lawyer.service.LawyerService.java
/** * ?//w w w. j av a 2 s. c o m * @param lastUpdateDate * @param pageNum * @param pageSize * @return */ @SuppressWarnings("unchecked") public List<Lawyer> findByParam(Date lastUpdateDate, Integer pageNum, Integer pageSize) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); if (lastUpdateDate != null) { c.add(Restrictions.ge("lastUpdateDate", lastUpdateDate)); } c.setMaxResults(pageSize); c.setFirstResult(pageNum * pageSize + 1); c.addOrder(Order.desc("laseUpdateDate")); return c.list(); }
From source file:cn.dayuanzi.dao.BaseDao.java
License:Apache License
/** * ?/*from w w w . j av a 2s. co m*/ * * @param current_page >=1 * @param max_num >=1 <=1000 * @param map * @param orderByProperty * @param isAsc * @return */ public List<T> findForPage(int current_page, int max_num, Map<String, Object> map, String orderByProperty, boolean isAsc) { List<T> result = null; if (current_page <= 0) { current_page = 1; } if (max_num > 20) { max_num = 20; } else if (max_num <= 0) { max_num = 1; } Criteria c = createCriteria(); if (MapUtils.isNotEmpty(map)) { Iterator<String> it = map.keySet().iterator(); while (it.hasNext()) { String key = it.next(); c.add(Restrictions.eq(key, map.get(key))); } } c.setFirstResult(((current_page - 1)) * max_num); c.setMaxResults(max_num); if (StringUtils.isNotBlank(orderByProperty)) { if (isAsc) { c.addOrder(Order.asc(orderByProperty)); } else { c.addOrder(Order.desc(orderByProperty)); } } result = c.list(); return result; }
From source file:cn.dayuanzi.dao.BaseDao.java
License:Apache License
public List<T> findForPage(int current_page, int max_num, String orderByProperty, boolean isAsc, final Criterion... criterions) { List<T> result = null;// ww w .j a va 2s . c om if (current_page <= 0) { current_page = 1; } if (max_num > 20) { max_num = 20; } else if (max_num <= 0) { max_num = 1; } Criteria c = createCriteria(criterions); c.setFirstResult(((current_page - 1)) * max_num); c.setMaxResults(max_num); if (StringUtils.isNotBlank(orderByProperty)) { if (isAsc) { c.addOrder(Order.asc(orderByProperty)); } else { c.addOrder(Order.desc(orderByProperty)); } } result = c.list(); return result; }
From source file:cn.hxh.springside.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Criteria,./*w w w.j av a 2 s. c o m*/ */ protected Criteria setPageRequestToCriteria(final Criteria c, final PageRequest pageRequest) { AssertUtils.isTrue(pageRequest.getPageSize() > 0, "Page Size must larger than zero"); c.setFirstResult(pageRequest.getOffset()); c.setMaxResults(pageRequest.getPageSize()); if (pageRequest.isOrderBySetted()) { for (Sort sort : pageRequest.getSort()) { if (Sort.ASC.equals(sort.getDir())) { c.addOrder(Order.asc(sort.getProperty())); } else { c.addOrder(Order.desc(sort.getProperty())); } } } return c; }
From source file:cn.lhfei.airqa.dao.impl.CompanyDao.java
License:Apache License
@Override public PageModel findCompany(int page, int rows) { PageModel pageModel = new PageModel(); Criteria criteria = getCriteria(); criteria.add(Restrictions.ne("dataStatus", Constants.STATUS_DELETE)); // ???//from ww w . ja v a 2 s . c om int total = criteria.list().size(); pageModel.setTotal(total); criteria.setFirstResult((page - 1) * rows).setMaxResults(rows); pageModel.setRows(criteria.list()); return pageModel; }
From source file:cn.lhfei.airqa.dao.support.Hibernate4DaoSupport.java
License:Apache License
@Override public Page<E> findPageByCriteria(Criterion criterion, Page<E> page) { Criteria criteria = getCurrentSession().createCriteria(entityClass); int count = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue(); criteria.setProjection(null);//from w w w . j a v a 2s.c om if (criterion != null) { criteria.add(criterion); } page.setTotalCount(count); int startCount = (page.getCurPage() - 1) * page.getPageSize(); int endCount = startCount + page.getPageSize(); criteria.setFirstResult(startCount); criteria.setMaxResults(endCount); page.setResult(criteria.list()); return page; }
From source file:cn.lhfei.fu.orm.persistence.impl.HomeworkBaseDAOImpl.java
License:Apache License
@Override public SearchAndCountModel<HomeworkBase> getPageAndCount(HomeworkBaseModel homeworkModel) { SearchAndCountModel<HomeworkBase> resultModel = new SearchAndCountModel<HomeworkBase>(); List<HomeworkBase> list = new ArrayList<HomeworkBase>(); //String sql = "From HomeworkBase as hb left join hb.archives with hb.className = :className "; Session session = null;/*from ww w . j ava 2 s.c o m*/ int total; try { session = getSessionFactory().getCurrentSession(); } catch (HibernateException e) { session = getSessionFactory().openSession(); } Criteria criteria = session.createCriteria(HomeworkBase.class, "homeworkBase"); for (SimpleExpression exp : homeworkModel.wrapperFilter()) { criteria.add(exp); } //criteria.setFetchMode("homeworkBase.archives", FetchMode.JOIN); criteria.createCriteria("homeworkBase.archives", JoinType.LEFT_OUTER_JOIN); // criteria.createAlias("homeworkBase.archives", "archives"); total = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue(); criteria.setProjection(null); list = criteria.setFirstResult(homeworkModel.getFirst()).setMaxResults(homeworkModel.getPageSize()) .setCacheable(true).list(); resultModel.setTotal(total); resultModel.setRows(list); return resultModel; }
From source file:cn.newtouch.util.hibernate.HibernateDao.java
License:Apache License
/** * ?Criteria,.// w w w. j av a 2s . c o m */ protected Criteria setPageParameterToCriteria(final Criteria c, final Page<T> page) { Assert.isTrue(page.getPageSize() > 0, "Page Size must larger than zero"); // hibernatefirstResult??0 c.setFirstResult(page.getFirst() - 1); c.setMaxResults(page.getPageSize()); if (page.isOrderBySetted()) { String[] orderByArray = StringUtils.split(page.getOrderBy(), ','); String[] orderArray = StringUtils.split(page.getOrder(), ','); Assert.isTrue(orderByArray.length == orderArray.length, "???,????"); for (int i = 0; i < orderByArray.length; i++) { if (Page.ASC.equals(orderArray[i])) { c.addOrder(Order.asc(orderByArray[i])); } else { c.addOrder(Order.desc(orderByArray[i])); } } } return c; }
From source file:cn.newtouch.util.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Criteria,.//from www . j a v a 2 s . c om */ protected Criteria setPageParameterToCriteria(final Criteria c, final Page<T> page) { Assert.isTrue(page.getPageSize() > 0, "Page Size must larger than zero"); //hibernatefirstResult??0 c.setFirstResult(page.getFirst() - 1); c.setMaxResults(page.getPageSize()); if (page.isOrderBySetted()) { String[] orderByArray = StringUtils.split(page.getOrderBy(), ','); String[] orderArray = StringUtils.split(page.getOrder(), ','); Assert.isTrue(orderByArray.length == orderArray.length, "???,????"); for (int i = 0; i < orderByArray.length; i++) { if (Page.ASC.equals(orderArray[i])) { c.addOrder(Order.asc(orderByArray[i])); } else { c.addOrder(Order.desc(orderByArray[i])); } } } return c; }