List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:com.klistret.cmdb.dao.RelationDAOImpl.java
License:Open Source License
/** * Finds relations based on XPath expressions * /* w w w .ja v a 2 s . co m*/ */ public List<Relation> find(List<String> expressions, int start, int limit) { try { logger.debug("Finding relations by expression from start position [{}] with limit [{}]", start, limit); if (expressions == null) throw new ApplicationException("Expressions parameter is null", new IllegalArgumentException()); Criteria criteria = new XPathCriteria(expressions, getSession()).getCriteria(); String alias = criteria.getAlias(); criteria.setProjection(Projections.projectionList().add(Projections.property(alias + ".id")) .add(Projections.property(alias + ".type")).add(Projections.property(alias + ".source")) .add(Projections.property(alias + ".destination")) .add(Projections.property(alias + ".fromTimeStamp")) .add(Projections.property(alias + ".toTimeStamp")) .add(Projections.property(alias + ".createId")) .add(Projections.property(alias + ".createTimeStamp")) .add(Projections.property(alias + ".updateTimeStamp")) .add(Projections.property(alias + ".version")) .add(Projections.property(alias + ".configuration"))); criteria.setFirstResult(start); criteria.setMaxResults(limit); criteria.setFetchSize(limit); Object[] results = criteria.list().toArray(); List<Relation> relations = new ArrayList<Relation>(results.length); logger.debug("Results length [{}]", results.length); for (int index = 0; index < results.length; index++) { Object[] row = (Object[]) results[index]; Relation relation = new Relation(); relation.setId((Long) row[0]); relation.setType((RelationType) row[1]); relation.setSource((Element) row[2]); relation.setDestination((Element) row[3]); relation.setFromTimeStamp((Date) row[4]); relation.setToTimeStamp((Date) row[5]); relation.setCreateId((String) row[6]); relation.setCreateTimeStamp((Date) row[7]); relation.setUpdateTimeStamp((Date) row[8]); relation.setVersion((Long) row[9]); relation.setConfiguration((com.klistret.cmdb.ci.commons.Relation) row[10]); relations.add(relation); } results = null; return relations; } catch (StaleStateException e) { throw new ApplicationException( "Relation(s) found are stale which means newer version exists (Hibernate)."); } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.koylubaevnt.library.db.DataHelper.java
private void runBookListCriteria() { Criteria criteria = bookListCriteria.getExecutableCriteria(getSession()); criteria.addOrder(Order.asc("b.name")).setProjection(bookProjectionList) .setResultTransformer(Transformers.aliasToBean(Book.class)); criteria.setFirstResult(pager.getFrom()).setMaxResults(pager.getTo()); pager.setList(criteria.list());/*from ww w .j a v a 2 s . c om*/ }
From source file:com.krawler.crm.savedsearch.dao.SavedSearchDAOImpl.java
License:Open Source License
@Override public List getSavedSearchQueries(String userid, int firstResult, int maxResults) throws ServiceException { List ll = null;/*from w ww . ja v a2s .c o m*/ try { Criteria crit = getSavedSearchCriteria(userid); crit.setFirstResult(firstResult); crit.setMaxResults(maxResults); BuildCriteria.buildCriteria(BuildCriteria.OPERATORORDERDESC, BuildCriteria.ORDER, crit, Constants.updatedOn); ll = crit.list(); } catch (Exception e) { throw ServiceException.FAILURE("RememberSearchDAOImpl.getSavedSearchQueries : " + e.getMessage(), e); } return ll; }
From source file:com.kunckle.jetpower.core.base.repository.impl.BaseRepositorySupport.java
License:Apache License
/** * ?/*from w w w . j a v a 2 s.c o m*/ * * @param searchAdapter ?? * @return ?null * @throws IndexOutOfBoundsException */ @Override @SuppressWarnings("unchecked") public Page<E> findAll(SearchAdapter searchAdapter, PageAdapter pageAdapter) { pageAdapter.setCountOfElements(count(searchAdapter)); if (pageAdapter.exists() && pageAdapter.getPageNumber() != 0) { throw new IndexOutOfBoundsException("?"); } else if (pageAdapter.getCountOfElements() == 0) { return null; } if (searchAdapter.getPrepQL() != null) { Query query = getSession().createQuery("from " + entityClass.getSimpleName() + " " + searchAdapter.getPrepQL() + " " + pageAdapter.getPageSortAdapter().getPrepQL()); query.setParameter(0, entityClass.getName()); query.setFirstResult(pageAdapter.getPageOffset() * pageAdapter.getPageSize()); query.setMaxResults(pageAdapter.getPageSize()); return new Page<E>(pageAdapter, query.list()); } else { Criteria criteria = searchAdapter.getCriteria(getSession().createCriteria(entityClass)); criteria = pageAdapter.getPageSortAdapter().getCriteria(criteria); criteria.setFirstResult(pageAdapter.getPageOffset() * pageAdapter.getPageSize()); criteria.setMaxResults(pageAdapter.getPageSize()); return new Page<E>(pageAdapter, criteria.list()); } }
From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java
License:Open Source License
protected void addPagination(Criteria criteria, int start, int end) { if ((start != QueryUtil.ALL_POS) && (end != QueryUtil.ALL_POS)) { criteria.setFirstResult(start); criteria.setMaxResults(end - start); }// w ww .j a v a 2s . c o m }
From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java
License:Open Source License
protected ProcessDefinition findProcessDefinition(String name) { try {/* ww w . j av a 2s .c om*/ Criteria criteria = _session.createCriteria(ProcessDefinition.class); criteria.add(Restrictions.eq("name", name)); Order order = Order.desc("version"); criteria.addOrder(order); criteria.setFirstResult(0); criteria.setMaxResults(1); return (ProcessDefinition) criteria.uniqueResult(); } catch (Exception e) { throw new JbpmException(e); } }
From source file:com.lighting.platform.base.dao.HibernateDao.java
License:Apache License
/** * ?Criteria,./* w ww. j a va 2 s . c o m*/ */ protected Criteria setPageParameterToCriteria(final Criteria c, final Page<T> page) { AssertUtils.isTrue(page.getPageSize() > 0, "Page Size must larger than zero"); c.setFirstResult(page.getOffset()); c.setMaxResults(page.getPageSize()); if (page.isOrderBySetted()) { String[] orderByArray = StringUtils.split(page.getOrderBy(), ','); String[] orderArray = StringUtils.split(page.getOrder(), ','); AssertUtils.isTrue(orderByArray.length == orderArray.length, "???,????"); for (int i = 0; i < orderByArray.length; i++) { if (PageConfig.ASC.equals(orderArray[i])) { c.addOrder(Order.asc(orderByArray[i])); } else { c.addOrder(Order.desc(orderByArray[i])); } } } return c; }
From source file:com.liusoft.dlog4j.dao.CommentDAO.java
License:Open Source License
/** * //from w w w . j a v a 2 s . c om * @param eid * @param etype * @param fromIdx * @param fetchSize * @param reverse * @param withContent * @return */ public static List listComments(int otype, int oid, int eid, int etype, int fromIdx, int fetchSize, boolean reverse, boolean withContent) { Session ssn = getSession(); Criteria crit = ssn.createCriteria(withContent ? CommentBean.class : CommentOutlineBean.class); crit.add(Expression.eq("ownerType", otype)); crit.add(Expression.eq("ownerIdent", oid)); if (eid > 0) crit.add(Expression.eq("eid", eid)); if (etype >= 0) crit.add(Expression.eq("etype", etype)); crit.addOrder(reverse ? Order.desc("id") : Order.asc("id")); if (fromIdx > 0) crit.setFirstResult(fromIdx); if (fetchSize > 0) crit.setMaxResults(fetchSize); return crit.list(); }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findInUseIsvProdLicenses(String isvId, String prodId, String prodDefId, String storeId, String platformId, Integer firstResult, Integer maxResults, String orderBy, String orderDir, Date startDate, Date endDate) { List<License> licenses = null; try {// w ww. j a v a 2s . c om Criteria mainCriteria = getSession().createCriteria(License.class); ProductInstanceCriterias prodInstCriterias = addIsvProductInstProductDefStorePlatfrmCriteria(isvId, prodId, prodDefId, storeId, platformId, mainCriteria); addDateRangeRestrictions(TIME_ACTIVATED, startDate, endDate, mainCriteria); mainCriteria.add(Restrictions.eq("inUse", true)); mainCriteria.add(Restrictions.eq("decom", false)); mainCriteria.setFirstResult(firstResult); mainCriteria.setMaxResults(maxResults); addOrderByToCriteria(orderBy, orderDir, mainCriteria, prodInstCriterias); licenses = mainCriteria.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } return licenses; }
From source file:com.lm.lic.manager.hibernate.LicenseDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<License> findInUseIsvProdTrialLicenses(String isvId, String prodId, String prodDefId, String storeId, String platformId, Integer firstResult, Integer maxResults, String orderBy, String orderDir, Date startDate, Date endDate) { List<License> licenses = null; try {// ww w.j a v a 2 s .c om Criteria mainCriteria = getSession().createCriteria(License.class); ProductInstanceCriterias prodInstCriterias = addIsvProductInstProductDefStorePlatfrmCriteria(isvId, prodId, prodDefId, storeId, platformId, mainCriteria); addDateRangeRestrictions(TIME_ACTIVATED, startDate, endDate, mainCriteria); mainCriteria.add(Restrictions.eq("inUse", true)); mainCriteria.add(Restrictions.eq("decom", false)); mainCriteria.add(Restrictions.lt("lifeInDays", 365)); mainCriteria.setFirstResult(firstResult); mainCriteria.setMaxResults(maxResults); addOrderByToCriteria(orderBy, orderDir, mainCriteria, prodInstCriterias); licenses = mainCriteria.list(); } catch (RuntimeException re) { log.error("findInUseIsvProdTrialLicenses failed", re); throw re; } return licenses; }