List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:com.google.api.ads.adwords.jaxws.extensions.report.model.persistence.sql.SqlReportEntitiesPersister.java
License:Open Source License
/** * Create a paginated query//from ww w . ja v a 2 s .c o m * * @param clazz the entity class * @param numToSkip the first result * @param limit the max number of results * @return the list of results */ private <T> Criteria createPaginatedCriteria(Class<T> clazz, int numToSkip, int limit) { Criteria criteria = this.createCriteria(clazz); criteria.setFirstResult(numToSkip); criteria.setMaxResults(limit); return criteria; }
From source file:com.googlecode.jbp.hibernate.AbstractHibernateRepository.java
License:Apache License
/** * Adds the specified paging to the specified criteria. * * @param criteriaParam The criteria whose results must be paged. * @param pageParam The paging setting. * @return The specified criteria, with paging set. *///w w w . ja v a 2 s . c o m protected final Criteria addPagingToCriteria(final Criteria criteriaParam, final Page pageParam) { PARAM_REQ.Object.requireNotNull(criteriaParam); PARAM_REQ.Object.requireNotNull(pageParam); PARAM_REQ.Number.requireNotStrictlyNegative(pageParam.getFirstResult()); PARAM_REQ.Number.requireNotStrictlyNegative(pageParam.getMaxResults()); criteriaParam.setFirstResult(pageParam.getFirstResult()).setMaxResults(pageParam.getMaxResults()); return criteriaParam; }
From source file:com.googlecode.jbp.hibernate.GenericHibernateRepository.java
License:Apache License
protected final Criteria addPagingToCriteria(final Criteria criteriaParam, final Page pageParam) { PARAM_REQ.Object.requireNotNull(criteriaParam); PARAM_REQ.Object.requireNotNull(pageParam); PARAM_REQ.Number.requireNotStrictlyNegative(pageParam.getFirstResult()); PARAM_REQ.Number.requireNotStrictlyNegative(pageParam.getMaxResults()); criteriaParam.setFirstResult(pageParam.getFirstResult()).setMaxResults(pageParam.getMaxResults()); return criteriaParam; }
From source file:com.googlecode.ouvidoria.model.complaint.ComplaintDaoImpl.java
@Override @SuppressWarnings("unchecked") public List<?> searchByCriteria(final int transform, final String queryString, int pageNumber, int pageSize, final ComplaintVO vo) { Criteria criteria = this.getSession().createCriteria(Complaint.class); if (vo != null) { if (vo.getId() != null) { criteria.add(Restrictions.idEq(vo.getId())); } else {//from w ww.ja v a2 s. c om if (vo.getStatus() != null) { System.out.println("DAO .... " + vo.getStatus()); criteria.add(Restrictions.eq("status", vo.getStatus())); } //TODO demandant if (vo.getSubjectId() != null) { criteria.createCriteria("subject").add(Restrictions.idEq(vo.getSubjectId())); } if (vo.getText() != null) { criteria.add(Restrictions.ilike("text", "%" + vo.getText() + "%")); } if (vo.getTypeId() != null) { criteria.createCriteria("type").add(Restrictions.idEq(vo.getTypeId())); } } } criteria.addOrder(Order.desc("date")); if (pageNumber > 0 && pageSize > 0) { criteria.setFirstResult(super.calculateFirstResult(pageNumber, pageSize)); criteria.setMaxResults(pageSize); } List results = criteria.list(); transformEntities(transform, results); return results; }
From source file:com.gotour.daos.GenericDaoImpl.java
@Override public List<T> getPage(int pageNumber, int pageSize) { Criteria crit = getSession().createCriteria(type); crit.setFirstResult((pageNumber - 1) * pageSize); crit.setMaxResults(pageSize);//from w w w . j a va 2 s . c o m return crit.list(); }
From source file:com.gotour.daos.GenericDaoImpl.java
protected List<T> getPageByCriteria(int pageNumber, int pageSize, Criteria crit) { crit.setFirstResult((pageNumber - 1) * pageSize); crit.setMaxResults(pageSize);//from w w w. ja va2 s . com return crit.list(); }
From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java
License:Apache License
/** * Initializes a Criteria Query.//from w w w . j a v a2s . c o m * Mandatory Attributes:<ul> * <li><b>name</b>: The unqualified class name driving the criteria query.</li> * </ul> * Optional Attributes:<ul> * <li><b>prefix</b>: The package name of the class driving the criteria query. If null, no package is assumed.</li> * <li><b>maxSize</b>: The maximum number of rows to return from the database.</li> * <li><b>fetchSize</b>: The number of rows to fetch when rows are requested. Usually not useful for AA4H.</li> * <li><b>cacheEnabled</b>: Enables or disables caching for the queried objects.</li> * <li><b>cacheMode</b>: The cache options for the queried objects.</li> * <li><b>flushMode</b>: The session flush options.</li> * <li><b>fetchMode</b>: The collection fetch options for the query.</li> * <li><b>lockMode</b>: The row lock options for the queried rows.</li> * <li><b>timeOut</b>: The query timeout option.</li> * <li><b>rowCountOnly</b>: Returns a count of the query rows only.</li> * </ul> * @param attrs The attributes of the processed node. * @return An appended or new CriteriaSpecification * @throws SAXException */ protected CriteriaSpecification processCriteria(Attributes attrs) throws SAXException { if (inDetached) { return criteriaStack.peek(); } String name = attrs.getValue("name"); String prefix = attrs.getValue("prefix"); if (prefix != null) { className = prefix + "." + name; } else { className = name; } String maxSize = attrs.getValue("maxSize"); String fetchSize = attrs.getValue("fetchSize"); String firstResult = attrs.getValue("firstResult"); String cacheEnabled = attrs.getValue("cacheEnabled"); String cacheMode = attrs.getValue("cacheMode"); String flushMode = attrs.getValue("flushMode"); String fetchMode = attrs.getValue("fetchMode"); String lockMode = attrs.getValue("lockMode"); String timeOut = attrs.getValue("timeOut"); String rowCountOnly = attrs.getValue("rowCountOnly"); Criteria newCriteria = null; try { if (criteriaStack.size() == 0) { newCriteria = session.createCriteria(className); } else { newCriteria = ((Criteria) criteriaStack.peek()).createCriteria(className); } criteriaStack.push(newCriteria); if ("true".equalsIgnoreCase(rowCountOnly)) { newCriteria.setProjection(Projections.projectionList().add(Projections.rowCount()) ); setRowCountOnly(true); } if (maxSize != null && isRowCountOnly() == false) { newCriteria.setMaxResults(Integer.parseInt(maxSize)); } if (fetchSize != null && isRowCountOnly() == false) { newCriteria.setFetchSize(Integer.parseInt(fetchSize)); } if (firstResult != null && isRowCountOnly() == false) { newCriteria.setFirstResult(Integer.parseInt(firstResult)); } if (timeOut != null) { newCriteria.setTimeout(Integer.parseInt(timeOut)); } if ("true".equalsIgnoreCase(cacheEnabled)) { newCriteria.setCacheable(true); } else if ("false".equalsIgnoreCase(cacheEnabled)) { newCriteria.setCacheable(false); } if (fetchMode != null && fetchMode.length() > 0) { if ("JOIN".equalsIgnoreCase(fetchMode)) { newCriteria.setFetchMode(name, FetchMode.JOIN); } else if ("SELECT".equalsIgnoreCase(fetchMode)) { newCriteria.setFetchMode(name, FetchMode.SELECT); } else { newCriteria.setFetchMode(name, FetchMode.DEFAULT); } } else { newCriteria.setFetchMode(name, FetchMode.DEFAULT); } if (cacheMode != null && cacheMode.length() > 0) { if ("GET".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.GET); } else if ("IGNORE".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.IGNORE); } else if ("NORMAL".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.NORMAL); } else if ("PUT".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.PUT); } else if ("REFRESH".equalsIgnoreCase(cacheMode)) { newCriteria.setCacheMode(CacheMode.REFRESH); } else { newCriteria.setCacheMode(CacheMode.NORMAL); } } if (lockMode != null && lockMode.length() > 0) { if ("NONE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.NONE); } else if ("READ".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.READ); } else if ("UPGRADE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.UPGRADE); } else if ("UPGRADE_NOWAIT".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.UPGRADE_NOWAIT); } else if ("WRITE".equalsIgnoreCase(lockMode)) { newCriteria.setLockMode(LockMode.WRITE); } else { throw new SAXException("lockMode[" + lockMode + "] Not Recognized"); } } if (flushMode != null && flushMode.length() > 0) { if ("ALWAYS".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.ALWAYS); } else if ("AUTO".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.AUTO); } else if ("COMMIT".equalsIgnoreCase(flushMode)) { newCriteria.setFlushMode(FlushMode.COMMIT); } else if ("NEVER".equalsIgnoreCase(flushMode)) { // NEVER is deprecated, so we won't throw an exception but we'll ignore it. } else { throw new SAXException("flushMode[" + flushMode + "] Not Recognized"); } } return newCriteria; } catch (Exception e) { throw new SAXException("Unable to configure class " + className, e); } }
From source file:com.hmsinc.epicenter.model.surveillance.impl.SurveillanceRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Anomaly> getAnomalies(final DateTime startDate, final DateTime endDate, final boolean includeAll, final Geometry filter, final Geometry excludeFacilityEventsFilter, Integer offset, Integer numRows) { final Criteria c = criteriaQuery(entityManager, Anomaly.class); c.setCacheable(true);//w w w . j av a 2 s . c o m applyAnomalyCriteria(c, startDate, endDate, includeAll, filter, excludeFacilityEventsFilter); if (offset != null) { c.setFirstResult(offset); } if (numRows != null) { c.setMaxResults(numRows); } return c.addOrder(Order.desc("analysisTimestamp")).list(); }
From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Investigation> getInvestigations(DateTime startDate, DateTime endDate, Geometry geometry, Collection<Organization> organizations, boolean showAll, Integer offset, Integer numRows) { final Criteria c = criteriaQuery(entityManager, Investigation.class, "investigation"); applyInvestigationCriteria(c, startDate, endDate, geometry, organizations, showAll); if (offset != null) { c.setFirstResult(offset); }//from w ww . j av a 2 s . c om if (numRows != null) { c.setMaxResults(numRows); } c.addOrder(Order.desc("timestamp")); return c.list(); }
From source file:com.hypersocket.repository.AbstractRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from w ww . ja va2 s. co m public <T> List<T> search(Class<T> clz, final String searchColumn, final String searchPattern, final int start, final int length, final ColumnSort[] sorting, CriteriaConfiguration... configs) { Criteria criteria = createCriteria(clz); if (!StringUtils.isEmpty(searchPattern)) { criteria.add(Restrictions.ilike(searchColumn, searchPattern)); } for (CriteriaConfiguration c : configs) { c.configure(criteria); } for (ColumnSort sort : sorting) { criteria.addOrder(sort.getSort() == Sort.ASC ? Order.asc(sort.getColumn().getColumnName()) : Order.desc(sort.getColumn().getColumnName())); } criteria.setProjection(Projections.distinct(Projections.id())); criteria.setFirstResult(start); criteria.setMaxResults(length); List<T> ids = (List<T>) criteria.list(); if (ids.isEmpty()) { return new ArrayList<T>(); } criteria = createCriteria(clz); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.in("id", ids)); return ((List<T>) criteria.list()); }