List of usage examples for org.hibernate Criteria setMaxResults
public Criteria setMaxResults(int maxResults);
From source file:com.bookselling.dao.SellingPostDaoImpl.java
@Override public PaginationData<SellingPost> get(User user, int first, int items) { Criteria criteria = getSession().createCriteria(SellingPost.class); criteria.createAlias("seller", "sl").add(Restrictions.eq("sl.id", user.getId())); criteria.setFirstResult(first);//w w w . j a va 2s. c o m criteria.setMaxResults(items); List<SellingPost> posts = criteria.list(); HibernateInitSupport.setCls(SellingPost.class); for (SellingPost post : posts) HibernateInitSupport.initDomain(post); PaginationData paginationData = new PaginationData( (long) criteria.setProjection(Projections.countDistinct("id")).uniqueResult(), items, first, posts); return paginationData; }
From source file:com.bookselling.dao.TradeDaoImpl.java
@Override public PaginationData<Trade> get(User user, int first, int items) { Criteria criteria = getSession().createCriteria(Trade.class); criteria.createAlias("buyer", "byer").add(Restrictions.eq("byer.id", user.getId())); criteria.setFirstResult(first);/*w w w .j a v a 2 s. c o m*/ criteria.setMaxResults(items); Set<Trade> trades = new HashSet<>(criteria.list()); HibernateInitSupport.setCls(Trade.class); for (Trade trade : trades) HibernateInitSupport.initDomain(trade); PaginationData paginationData = new PaginationData( (long) criteria.setProjection(Projections.rowCount()).uniqueResult(), items, first, trades); return paginationData; }
From source file:com.bplow.look.bass.dao.HibernateDao.java
License:Apache License
/** * ?Criteria,.// w w w. jav a 2 s. com */ protected Criteria setPageParameter(final Criteria c, final Page<T> page) { //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:com.cloudoa.framework.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Criteria,./*from ww w. j a v a 2 s.co m*/ */ protected Criteria setPageParameterToCriteria(final Criteria c, final Page<T> page) { Assert.isTrue(page.getPageSize() >= 0, "Page Size must larger than zero"); if (page.getPageSize() > 0) { //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:com.cms.utils.BaseFWDAOImpl.java
License:Open Source License
public List<T> findByCriteria(String sessionName, int firstResult, int maxResult, ProjectionList projs, Criterion[] criterion, Order[] orders) { Criteria crit = getSession().createCriteria(model.getClass()); if (projs != null) { crit.setProjection(projs);// w w w . j av a 2 s.c o m } if (criterion != null && criterion.length > 0) { for (Criterion c : criterion) { crit.add(c); } } if (orders != null && orders.length > 0) { for (Order o : orders) { crit.addOrder(o); } } if (firstResult > 0) { crit.setFirstResult(firstResult); } if (maxResult > 0) { crit.setMaxResults(maxResult); } return crit.list(); }
From source file:com.core.controller.Kimera.java
public <T> T entityByRestrictions(List<Criterion> restrictions, Class type) { Session s = sf.openSession();/*www . ja v a2s.com*/ Criteria cri = s.createCriteria(type); Iterator i = restrictions.iterator(); while (i.hasNext()) { Criterion c = (Criterion) i.next(); cri.add(c); } T result = (T) cri.setMaxResults(1).uniqueResult(); Hibernate.initialize(result); s.close(); return result; }
From source file:com.core.controller.Kimera.java
public <T> T entityWithParams(Map<String, Object> restrictions, Class type) { Session s = sf.openSession();//from w w w .j a va 2 s. c o m Criteria cri = s.createCriteria(type); for (Map.Entry<String, Object> entry : restrictions.entrySet()) { cri.add(Restrictions.eq(entry.getKey(), entry.getValue())); } T output = (T) cri.setMaxResults(1).uniqueResult(); Hibernate.initialize(output); s.close(); return output; }
From source file:com.coroptis.coidi.op.view.dao.impl.IdentityDaoImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from w ww. ja va 2s . c o m*/ public List<Identity> getChunk(Integer startIndex, Integer endIndex) { Criteria criteria = session.createCriteria(IdentityImpl.class).addOrder(Order.asc("idIdentity")); if (startIndex != null) { criteria.setFirstResult(startIndex); } if (endIndex != null) { if (startIndex == null) { criteria.setMaxResults(endIndex); } else { criteria.setMaxResults(endIndex - startIndex + 1); } } return criteria.list(); }
From source file:com.court.controller.AssignNewLoanFxmlController.java
public String fillMemberLoanCodeTxt() { DocSeqHandler seqHandler = new DocSeqHandler(); Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(MemberLoan.class); c.addOrder(Order.desc("id")); c.setMaxResults(1); MemberLoan ln = (MemberLoan) c.uniqueResult(); session.close();/*from ww w. j a v a 2 s.co m*/ if (ln != null) { seqHandler.reqTable(TABLE_NAME, Integer.parseInt(ln.getMemberLoanCode().replaceAll("\\D+", "")) + 1); return seqHandler.getSeq_code(); } else { seqHandler.reqTable(TABLE_NAME, 0); return seqHandler.getSeq_code(); } }
From source file:com.court.controller.BranchFxmlController.java
private void fillBranchCodeTxt(TextField branchCodeField) { DocSeqHandler seqHandler = new DocSeqHandler(); Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(Branch.class); c.addOrder(Order.desc("id")); c.setMaxResults(1); Branch br = (Branch) c.uniqueResult(); session.close();/*from w w w .j a va2 s . co m*/ if (br != null) { seqHandler.reqTable(TABLE_NAME, Integer.parseInt(br.getBranchCode().replaceAll("\\D+", "")) + 1); branchCodeField.setText(seqHandler.getSeq_code()); } else { seqHandler.reqTable(TABLE_NAME, 0); branchCodeField.setText(seqHandler.getSeq_code()); } }