List of usage examples for javax.persistence Query setMaxResults
Query setMaxResults(int maxResult);
From source file:org.eurekastreams.server.persistence.FeedReaderMapper.java
/** * Find the domain entity by id./* ww w . jav a2 s . c o m*/ * * @return the entity with the input */ @SuppressWarnings("unchecked") public List<FeedReaderUrlCount> findTop10PublicFeeds() { Query q = entityManager.createQuery("SELECT url, count(*), feedTitle from FeedReader" + " group by url, feedTitle ORDER BY count(*) desc"); // TODO find a better place to set this. 5+5 = magic number rule work around. q.setMaxResults(5 + 5); List<FeedReaderUrlCount> feedList = new LinkedList<FeedReaderUrlCount>(); List<Object[]> results = (List<Object[]>) q.getResultList(); for (Object[] result : results) { FeedReaderUrlCount resultItem = new FeedReaderUrlCount(); resultItem.setUrl((String) result[0]); resultItem.setCount((Long) result[1]); resultItem.setFeedTitle((String) result[2]); feedList.add(resultItem); } return feedList; }
From source file:com.sdl.odata.datasource.jpa.JPADatasourceProvider.java
private <T> List<T> executeQueryListResult(JPAQuery jpaQuery) { EntityManager em = entityManagerFactory.createEntityManager(); String queryString = jpaQuery.getQueryString(); Query query = em.createQuery(queryString); int nrOfResults = jpaQuery.getLimitCount(); int startPosition = jpaQuery.getSkipCount(); Map<String, Object> queryParams = jpaQuery.getQueryParams(); try {//from w w w . j a va2 s . c o m if (nrOfResults > 0) { query.setMaxResults(nrOfResults); } if (startPosition > 0) { query.setFirstResult(startPosition); } for (Map.Entry<String, Object> entry : queryParams.entrySet()) { query.setParameter(entry.getKey(), tryConvert(entry.getValue())); } return query.getResultList(); } finally { em.close(); } }
From source file:com.sun.socialsite.business.impl.JPASocialSiteActivityManagerImpl.java
/** * Note: using SuppressWarnings annotation because the JPA API is not genericized. *//* w ww . ja v a 2 s . c o m*/ @SuppressWarnings(value = "unchecked") public List<SocialSiteActivity> getUserActivities(Profile profile, int offset, int length) throws SocialSiteException { if (profile == null) { throw new SocialSiteException("profile is null"); } Query query = strategy.getNamedQuery("Activity.getByProfile"); if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } query.setParameter(1, profile); return (List<SocialSiteActivity>) query.getResultList(); }
From source file:org.apache.camel.component.jpa.JpaConsumer.java
protected void configureParameters(Query query) { int maxResults = endpoint.getMaximumResults(); if (maxResults > 0) { query.setMaxResults(maxResults); }//from ww w. ja va 2 s . c o m }
From source file:com.sun.socialsite.business.impl.JPASocialSiteActivityManagerImpl.java
/** * Note: using SuppressWarnings annotation because the JPA API is not genericized. *///www . ja v a 2 s .com @SuppressWarnings(value = "unchecked") public List<SocialSiteActivity> getUserActivities(Profile profile, String type, int offset, int length) throws SocialSiteException { if (profile == null) { throw new SocialSiteException("profile is null"); } Query query = strategy.getNamedQuery("Activity.getByProfileAndType"); if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } query.setParameter(1, profile); query.setParameter(2, type); return (List<SocialSiteActivity>) query.getResultList(); }
From source file:com.jdom.persist.persistence.AbstractDAS.java
/** * Run a specific query string and return the results. * /*from www. j a v a2 s .co m*/ * @param queryString * The query string to run * @param maxNumberOfResults * @return the result list */ @SuppressWarnings("unchecked") protected List<T> runQuery(String queryString, Map<String, Object> params, int maxNumberOfResults) { Query query = em.createQuery(queryString); for (Entry<String, Object> entry : params.entrySet()) { query.setParameter(entry.getKey(), entry.getValue()); } if (maxNumberOfResults != -1) { query.setMaxResults(maxNumberOfResults); } List<T> resultList = query.getResultList(); Collections.sort(resultList); return resultList; }
From source file:com.sun.socialsite.business.impl.JPAPermissionManagerImpl.java
/** * {@inheritDoc}/* w w w .j a v a 2s .co m*/ * Note: using SuppressWarnings annotation because the JPA API is not genericized. */ @SuppressWarnings(value = "unchecked") public List<PermissionGrant> getPermissionGrants(int offset, int length) throws SocialSiteException { Query query = strategy.getNamedQuery("PermissionGrant.getAll"); if (offset != 0) query.setFirstResult(offset); if (length != -1) query.setMaxResults(length); return (List<PermissionGrant>) query.getResultList(); }
From source file:com.sun.socialsite.business.impl.JPASocialSiteActivityManagerImpl.java
/** * Note: using SuppressWarnings annotation because the JPA API is not genericized. *///from ww w . jav a 2 s .co m @SuppressWarnings(value = "unchecked") public List<SocialSiteActivity> getUserAndFriendsActivities(Profile profile, int offset, int length) throws SocialSiteException { if (profile == null) { throw new SocialSiteException("profile is null"); } Query query = strategy.getNamedQuery("Activity.getFriendsActivityByProfile"); if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } query.setParameter(1, profile); return (List<SocialSiteActivity>) query.getResultList(); }
From source file:edu.umm.radonc.ca_dash.model.ActivityFacade.java
public List<ActivityAIPC> itemsDateRange(Date start, Date end, int[] range) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(ActivityAIPC.class); Root<ActivityAIPC> rt = cq.from(ActivityAIPC.class); cq.where(cb.and(rt.get(ActivityAIPC_.fromdateofservice).isNotNull(), cb.and(cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 528), cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 529), cb.notEqual(rt.get(ActivityAIPC_.procedurecodeser), 530), cb.between(rt.get(ActivityAIPC_.fromdateofservice), start, end)))); cq.orderBy(cb.asc(rt.get(ActivityAIPC_.fromdateofservice))); Query q = em.createQuery(cq); q.setMaxResults(range[1] - range[0] + 1); q.setFirstResult(range[0]);//from ww w. jav a 2 s. co m return q.getResultList(); }
From source file:eu.xipi.bro4xipi.brokermodel.BrokerJpaController.java
@SuppressWarnings("unchecked") /**/* ww w . ja va 2 s .co m*/ * return contracts by offeredServiceName * @param firstResult * @param maxResults * @param offeredServiceName * @return */ public List<ResourceServiceContract> readContracts(int firstResult, int maxResults, String offeredServiceName) { Query q = entityManager.createQuery("SELECT c " + "FROM ResourceServiceContract c " + "JOIN c.forOfferedService s " + "WHERE s.name= :offeredServiceName"); q.setParameter("offeredServiceName", offeredServiceName); q.setFirstResult(firstResult); q.setMaxResults(maxResults); return q.getResultList(); }