List of usage examples for javax.persistence TypedQuery setMaxResults
TypedQuery<X> setMaxResults(int maxResult);
From source file:com.epam.ipodromproject.repository.jpa.JPABetRepository.java
@Override public List<Bet> getArchivedBetsPageMadeByUser(String username, int startingResult, int resultsCount) { TypedQuery<Bet> query = entityManager.createNamedQuery("Bet.findArchivedPageByUsername", Bet.class); query.setParameter("username", username); query.setParameter("betResult", BetResult.NOT_CONSIDERED); return query.setMaxResults(resultsCount).setFirstResult(startingResult).getResultList(); }
From source file:net.groupbuy.dao.impl.ProductCategoryDaoImpl.java
public List<ProductCategory> findRoots(Integer count) { String jpql = "select productCategory from ProductCategory productCategory where productCategory.parent is null order by productCategory.order asc"; TypedQuery<ProductCategory> query = entityManager.createQuery(jpql, ProductCategory.class) .setFlushMode(FlushModeType.COMMIT); if (count != null) { query.setMaxResults(count); }//w ww. j av a 2 s. c om return query.getResultList(); }
From source file:com.pingdu.dao.licenseDao.LicenseDao.java
public List<License> getLicenseList(int page, int rows) { int head = (page - 1) * rows; String jpql = "select l from License l where 1=1 "; TypedQuery<License> query = em().createQuery(jpql, License.class); // query.setHint(QueryHints.RESULT_TYPE, ResultType.Map); query.setFirstResult(head);//from w w w . j ava 2s. c o m query.setMaxResults(rows); List<License> list = query.getResultList(); return list; }
From source file:com.music.dao.Dao.java
public <T> List<T> getPagedListByPropertyValue(Class<T> clazz, String propertyName, Object propertyValue, int page, int pageSize) { String queryString = "SELECT o FROM " + clazz.getName() + " o WHERE " + propertyName + "=:" + propertyName; TypedQuery<T> query = getEntityManager().createQuery(queryString, clazz); query.setFirstResult(page * pageSize); query.setMaxResults(pageSize); query.setParameter(propertyName, propertyValue); return query.getResultList(); }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaAccountDao.java
private List<Account> getSearchResultList(String searchTerm, int count, int offset) { String qlString = "SELECT a FROM Account a WHERE a.accountPath like :q " + "OR a.owner.name like :q OR a.owner.email like :q"; List<Account> accounts = null; try {//ww w.ja va 2s .c o m TypedQuery<Account> query = em.createQuery(qlString, Account.class); query.setParameter("q", searchTerm); query.setMaxResults(count); query.setFirstResult(offset); accounts = query.getResultList(); } catch (NoResultException e) { // Do nothing; } return accounts; }
From source file:org.osiam.resource_server.storage.dao.ResourceDao.java
public <T extends ResourceEntity> SearchResult<T> search(Class<T> clazz, ParseTree filterTree, int count, int startIndex, String sortBy, String sortOrder, FilterParser<T> filterParser) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> resourceQuery = cb.createQuery(clazz); Root<T> resourceRoot = resourceQuery.from(clazz); Subquery<Long> internalIdQuery = resourceQuery.subquery(Long.class); Root<T> internalIdRoot = internalIdQuery.from(clazz); internalIdQuery.select(internalIdRoot.get(ResourceEntity_.internalId)); if (filterTree != null && filterTree.getChildCount() > 0) { Predicate predicate = filterParser.createPredicateAndJoin(filterTree, internalIdRoot); internalIdQuery.where(predicate); }//from w w w . j av a2 s . com resourceQuery.select(resourceRoot) .where(cb.in(resourceRoot.get(ResourceEntity_.internalId)).value(internalIdQuery)); // TODO: evaluate if a User-/GroupDao supplied default sortBy field is possible Expression<?> sortByField = resourceRoot.get(ResourceEntity_.id); if (sortBy != null && !sortBy.isEmpty()) { sortByField = filterParser.createSortByField(sortBy, resourceRoot); } // default order is ascending Order order = cb.asc(sortByField); if (sortOrder.equalsIgnoreCase("descending")) { order = cb.desc(sortByField); } resourceQuery.orderBy(order); TypedQuery<T> query = em.createQuery(resourceQuery); query.setFirstResult(startIndex); query.setMaxResults(count); List<T> results = query.getResultList(); long totalResult = getTotalResults(clazz, internalIdQuery); return new SearchResult<>(results, totalResult); }
From source file:org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl.java
public List<LdapConfig> getLdapConfigs(int start, int max, String orderby, boolean asc) { try {/*ww w .j av a 2 s . c o m*/ CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<LdapConfig> cq = cb.createQuery(LdapConfig.class); Root<LdapConfig> c = cq.from(LdapConfig.class); Predicate condition = cb.equal(c.get("deleted"), "false"); cq.where(condition); cq.distinct(asc); if (asc) { cq.orderBy(cb.asc(c.get(orderby))); } else { cq.orderBy(cb.desc(c.get(orderby))); } TypedQuery<LdapConfig> q = em.createQuery(cq); q.setFirstResult(start); q.setMaxResults(max); List<LdapConfig> ll = q.getResultList(); return ll; } catch (Exception ex2) { log.error("[getLdapConfigs]", ex2); } return null; }
From source file:com.epam.ipodromproject.repository.jpa.JPACompetitionRepository.java
@Override public List<Competition> getAllCompetitionsAfter(Date date, int startingResult, int resultsCount) { TypedQuery<Competition> query = entityManager.createNamedQuery("Competition.findAfterDate", Competition.class); query.setParameter("date", date); query.setParameter("state", CompetitionState.NOT_REGISTERED); List<Competition> resultList = query.setMaxResults(resultsCount).setFirstResult(startingResult) .getResultList();//from w w w . j a va 2 s. c o m for (Competition competition : resultList) { Hibernate.initialize(competition.getHorses()); } return resultList; }
From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.LexiconBuilderController.java
/** * Gets the unseen document with the next highest weight. * @param em the {@link EntityManager} to use. * @param builder the {@link LexiconBuilderDocumentStore} to use. * @return the {@link LexiconBuilderDocument} with the highest weight among unseen documents. *//* w ww .j av a 2s.co m*/ public LexiconBuilderDocument getNextDocument(EntityManager em, LexiconBuilderDocumentStore builder) { Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em"); Validate.notNull(builder, CannedMessages.NULL_ARGUMENT, "builder"); TypedQuery<LexiconBuilderDocument> query = this.getDocumentsQuery(em, builder, false); query.setMaxResults(1); if (query.getResultList().size() != 1) { return null; } LexiconBuilderDocument document = query.getSingleResult(); query = this.getDocumentsQuery(em, builder, null); document.setRank((long) query.getResultList().indexOf(document)); return document; }
From source file:com.epam.ipodromproject.repository.jpa.JPACompetitionRepository.java
@Override public List<Competition> getUnoperatedCompetitions(int startingResult, int resultsCount) { TypedQuery<Competition> query = entityManager.createNamedQuery("Competition.findUnoperated", Competition.class); query.setParameter("state", CompetitionState.NOT_REGISTERED); query.setParameter("date", new Date()); List<Competition> resultList = query.setMaxResults(resultsCount).setFirstResult(startingResult) .getResultList();/*from ww w.j a v a 2 s .c o m*/ for (Competition competition : resultList) { Hibernate.initialize(competition.getHorses()); } return resultList; }