List of usage examples for javax.persistence Query setFirstResult
Query setFirstResult(int startPosition);
From source file:com.grummages.app.rest.entity.service.AuthoritiesRESTFacade.java
private List<Authorities> find(boolean all, int maxResults, int firstResult) { try {// w w w . j a v a 2 s . c o m Query query = entityManager.createQuery("SELECT object(o) FROM Authorities AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }
From source file:com.ny.apps.dao.BaseDaoImpl.java
@Override public List<?> find(int start, int delta, String queryStr, Object... params) { Query query = prepareParameterizedQuery(entityManager.createQuery(queryStr), params); query.setFirstResult(start); query.setMaxResults(delta);//from w w w . ja v a 2s .co m List<?> list = query.getResultList(); return list; }
From source file:com.sun.socialsite.business.impl.JPAContentManagerImpl.java
/** * Get content by category and tag./*from w w w.j av a 2 s . com*/ * * Note: using SuppressWarnings annotation because the JPA API is not genericized. */ @SuppressWarnings(value = "unchecked") public List<Content> getContentByCategory(Profile profile, String catscheme, String tag, int offset, int length) throws SocialSiteException { if (profile == null) { throw new SocialSiteException("profile is null"); } if (catscheme == null) { throw new SocialSiteException("category scheme is null"); } Query query = strategy.getNamedQuery("Content.getByProfileandCatscheme"); if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } query.setParameter(1, profile); query.setParameter(2, catscheme); return (List<Content>) query.getResultList(); }
From source file:com.sapito.db.dao.AbstractDao.java
public List<T> findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass));/*w ww . j a va 2 s . co m*/ javax.persistence.Query q = entityManager.createQuery(cq); q.setMaxResults(range[1] - range[0]); q.setFirstResult(range[0]); return q.getResultList(); }
From source file:org.synyx.hades.dao.query.ParameterBinder.java
/** * Binds the parameters to the given query and applies special parameter * types (e.g. pagination)./* w w w . j av a2 s. c o m*/ * * @param query * @return */ public Query bindAndPrepare(Query query) { Query result = bind(query); if (!parameters.hasPageableParameter() || getPageable() == null) { return result; } result.setFirstResult(getPageable().getFirstItem()); result.setMaxResults(getPageable().getPageSize()); return result; }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.ClaimDAOJPAImpl.java
@Override public List<Claim> getClaims(int start, int size) { List<Claim> list = new ArrayList<Claim>(); Query query = null; query = em.createQuery("select c from Claim c"); //@SuppressWarnings("rawtypes") List claimEntities = query.setFirstResult(start).setMaxResults(size).getResultList(); for (Object obj : claimEntities) { ClaimEntity entity = (ClaimEntity) obj; list.add(entity2domain(entity)); }//from ww w.j av a2 s . co m return list; }
From source file:org.oscarehr.common.dao.ConsultRequestDao.java
public List<Object[]> search(ConsultationRequestSearchFilter filter) { String sql = this.getSearchQuery(filter, false); MiscUtils.getLogger().info("sql=" + sql); Query query = entityManager.createQuery(sql); query.setFirstResult(filter.getStartIndex()); query.setMaxResults(filter.getNumToReturn()); return query.getResultList(); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.EntitlementDAOJPAImpl.java
@Override public List<Entitlement> getEntitlements(int start, int size) { List<Entitlement> list = new ArrayList<Entitlement>(); Query query = null; query = em.createQuery("select e from Entitlement e"); //@SuppressWarnings("rawtypes") List entitlementEntities = query.setFirstResult(start).setMaxResults(size).getResultList(); for (Object obj : entitlementEntities) { EntitlementEntity entity = (EntitlementEntity) obj; list.add(entity2domain(entity)); }/*w w w . j av a 2 s . c o m*/ return list; }
From source file:com.panguso.lc.analysis.format.dao.impl.DaoImpl.java
@Override public List<T> find(int pageNo, int pageSize) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = cb.createQuery(entityClass); Root<T> customer = criteriaQuery.from(entityClass); criteriaQuery.getRoots().add(customer); Query query = em.createQuery(criteriaQuery); query.setFirstResult(pageNo * pageSize); query.setMaxResults(pageSize);//from www .j ava2s. c o m return query.getResultList(); }
From source file:org.oscarehr.common.dao.ConsultRequestDao.java
@SuppressWarnings("unchecked") @Deprecated/*w ww . ja v a 2 s .co m*/ public List<ConsultationRequest> listConsultationRequests(ConsultationQuery consultationQuery) { StringBuilder sql = this.generateQuery(consultationQuery, false); Query query = entityManager.createQuery(sql.toString()); query.setFirstResult(consultationQuery.getStart()); query.setMaxResults(consultationQuery.getLimit()); return query.getResultList(); }