List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:com.bookselling.dao.SellerInvoiceDaoImpl.java
@Override public PaginationData<SellerInvoice> get(User user, int first, int items) { Criteria criteria = getSession().createCriteria(SellerInvoice.class); criteria.createAlias("seller", "sl").add(Restrictions.eq("sl.id", user.getId())); criteria.setFirstResult(first); criteria.setMaxResults(items);// www. j av a 2 s . c o m Set<SellerInvoice> sellerInvoices = new HashSet<>(criteria.list()); HibernateInitSupport.setCls(SellerInvoice.class); for (SellerInvoice invoice : sellerInvoices) HibernateInitSupport.initDomain(invoice); PaginationData paginationData = new PaginationData( (long) criteria.setProjection(Projections.rowCount()).uniqueResult(), items, first, sellerInvoices); return paginationData; }
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); criteria.setMaxResults(items);/*from w w w. j a v a 2 s. c o m*/ 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); criteria.setMaxResults(items);/*from ww w .j av a 2 s.c o m*/ 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 .j ava 2s .c om*/ */ 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 www. ja va 2s .com */ 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);/*from w w w . j av a2 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.coroptis.coidi.op.view.dao.impl.IdentityDaoImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w ww. j a v a 2 s . 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.cubeia.backoffice.accounting.core.dao.AccountingDAOImpl.java
License:Open Source License
private Criteria createFindEntriesCriteria(Long accountId, int offset, int limit, Boolean ascending) { Session hbSession = getHibernateSession(); Criteria c = hbSession.createCriteria(Entry.class); if (accountId != null) { c.add(Restrictions.eq("account.id", accountId)); }/* w w w . j ava 2 s. c o m*/ if (ascending != null) { if (ascending) { c.addOrder(Order.asc("id")); } else { c.addOrder(Order.desc("id")); } } c.setFirstResult(offset); c.setMaxResults(limit); return c; }
From source file:com.cubeia.backoffice.users.dao.UserDAOImpl.java
License:Open Source License
private Criteria createFindUserCriteria(Long userId, Long operatorId, String name, Collection<UserStatus> includeStatuses, int offset, int limit, UserOrder order, boolean ascending) { Session hbSession = getHibernateSession(); Criteria c = hbSession.createCriteria(User.class); c.createAlias("information", "information", JoinType.LEFT_OUTER_JOIN); c.setFetchMode("attributes", FetchMode.SELECT); if (userId != null) { c.add(eq("id", userId)); }/*from w w w. j av a2s . com*/ if (operatorId != null) { c.add(eq("operatorId", operatorId)); } if (name != null && !name.isEmpty()) { c.add(Restrictions.disjunction().add(like("userName", name)).add(like("information.firstName", name)) .add(like("information.lastName", name))); } if (includeStatuses != null) { c.add(Restrictions.in("status", includeStatuses)); } if (order != null) { if (ascending) { c.addOrder(Order.asc(order.getColumnName())); } else { c.addOrder(Order.desc(order.getColumnName())); } } c.setFirstResult(offset); c.setMaxResults(limit); return c; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceConfigureDAO.java
License:Open Source License
/** * /* www. ja v a 2s . c o m*/ * @param sortInfos * @param filterInfos * @param paginationInfo * @return */ public List<DeviceConfigureEntity> getAllDeviceConfigureEntities(List<SortParamParser.SortInfo> sortInfos, List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo) { Session session = null; Transaction tx = null; List<DeviceConfigureEntity> entityList = new ArrayList<DeviceConfigureEntity>(); try { int offset = paginationInfo.getOffset(); int limit = paginationInfo.getLimit(); int pageSize = limit; session = _dao._database.getNewSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(DeviceConfigureEntity.class); BaseDAO.addSortCriteria(criteria, sortInfos); BaseDAO.addFilterCriteria(criteria, filterInfos, DeviceConfigureEntity.class); criteria.setFirstResult(offset); criteria.setMaxResults(pageSize); entityList = criteria.list(); tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get all DeviceConfigureEntities: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get all DeviceConfigureEntities: " + ex); } throw new AsmManagerInternalErrorException("Error Getting DeviceConfigureEntities", "DeviceConfigureDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get all DeviceConfigureEntities: " + ex); } } return entityList; }