List of usage examples for javax.persistence Query setFirstResult
Query setFirstResult(int startPosition);
From source file:utils.jpa.EntityResource.java
private List<T> getAllPriv(@BeanParam TableSearchQuery tb, List<String> fieldsSearchBy) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(entityClass); Root<T> root = cq.from(entityClass); cq.select(root);/*from w w w.java 2 s.co m*/ //setting order if (tb.getOrderType().equals(OrderType.DESC)) { cq.orderBy(cb.desc(root.get(tb.getOrder()))); } else { cq.orderBy(cb.asc(root.get(tb.getOrder()))); } Query query = tb.createQuery(em, cb, cq, root); if (query == null) { query = createCommonQuery(cb, cq, root, tb, fieldsSearchBy); } if (tb.getOffset() > 0) { query.setFirstResult(tb.getOffset()); } if (tb.getLimit() > 0) { query.setMaxResults(tb.getLimit()); } return query.getResultList(); }
From source file:org.apache.roller.planet.business.jpa.JPAPlanetManagerImpl.java
/** * Get top X subscriptions, restricted by group. *///from w ww . j a v a2 s. c om public List getTopSubscriptions(PlanetGroup group, int offset, int len) throws PlanetException { List result = null; if (group != null) { Query q = strategy.getNamedQuery("Subscription.getByGroupOrderByInboundBlogsDesc"); q.setParameter(1, group); if (offset != 0) q.setFirstResult(offset); if (len != -1) q.setMaxResults(len); result = q.getResultList(); } else { Query q = strategy.getNamedQuery("Subscription.getAllOrderByInboundBlogsDesc"); if (offset != 0) q.setFirstResult(offset); if (len != -1) q.setMaxResults(len); result = q.getResultList(); } return result; }
From source file:uk.ac.ebi.intact.editor.util.HqlLazyDataModel.java
@Override public List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { log.debug("Loading the lazy data between " + first + " and " + (first + pageSize)); String queryToRun = hqlQuery; if (var != null) { if (sortField != null) { queryToRun = queryToRun + " order by " + var + "." + sortField + " " + (sortOrder == SortOrder.DESCENDING ? "desc" : "asc"); } else if (initialSortField != null) { queryToRun = queryToRun + " order by " + var + "." + initialSortField + " " + (initialSortOrder ? "asc" : "desc"); }// w ww . ja va2 s .com } log.debug("HQL: " + queryToRun); Query query = entityManager.createQuery(queryToRun); if (queryParameters != null) { for (Map.Entry<String, String> entry : queryParameters.entrySet()) { log.debug("HQL param: " + entry.getKey() + " -> " + entry.getValue()); query.setParameter(entry.getKey(), entry.getValue()); } } query.setFirstResult(first); query.setMaxResults(pageSize); List<T> results = query.getResultList(); log.debug("Returning " + results.size() + " results"); return results; }
From source file:org.makersoft.activerecord.jpa.JPQL.java
@SuppressWarnings("unchecked") public <T> List<T> list() { // String hql = select + BLANK_STRING + "from" + BLANK_STRING + entityName + " as " + alias + BLANK_STRING + joins + BLANK_STRING + where + BLANK_STRING + group + BLANK_STRING + order + BLANK_STRING; StringBuffer hql = new StringBuffer(); hql.append(select);//from ww w . j a v a 2 s . co m hql.append(" from "); hql.append(entityName); hql.append(" as "); hql.append(alias); hql.append(joins); hql.append(where); hql.append(group); hql.append(order); System.out.println("===" + hql.toString()); Query query = em().createQuery(hql.toString()); bindParameters(query, parameters); query.setFirstResult(offset); if (limit > 0) { query.setMaxResults(limit); } return query.getResultList(); }
From source file:org.broadleafcommerce.inventory.dao.InventoryDaoImpl.java
@SuppressWarnings("unchecked") @Override// w ww. j a v a 2 s. c o m public List<Inventory> readSkuByPriceAndCurrency(BigDecimal amount, BroadleafCurrency currency, List<FulfillmentLocation> locations, int start, int size) { Query query = em.createNamedQuery("SSB_READ_INVS_BY_PRICE_CURRENCY"); query.setParameter("price", amount); query.setParameter("currency", currency); query.setParameter("locations", locations); query.setFirstResult(start); query.setMaxResults(size); return query.getResultList(); }
From source file:com.xyz.framework.data.impl.JpaDao.java
/** * .// www .ja v a 2s . c o m * * @param page * ?.??orderBy?. * @param jdoQl * hql?. * @param values * ????,?. * * @return , ??. */ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true) public Page<T> findPage(final Page<T> page) { Assert.notNull(page, "page?"); String sql = getBaseSql(); sql = dealOrder(sql, page); Query query = entityManager.createQuery(sql); if (page.isAutoCount()) { int totalCount = countJpaQlResult(""); page.setTotalCount(totalCount); } query.setFirstResult(page.getStart()); query.setMaxResults(page.getLimit()); List<T> lt = query.getResultList(); page.setResult(lt); return page; }
From source file:com.xyz.framework.data.impl.JpaDao.java
/** * jdoQL.//from w w w .ja v a 2s. co m * * @param page * ?.??orderBy?. * @param jdoQl * hql?. * @param values * ????,?. * * @return , ??. */ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true) public Page<T> findPage(final Page<T> page, final String jpaQl) { Assert.notNull(page, "page?"); String sql = getBaseSql(); if (jpaQl != null && jpaQl.trim().length() > 0) sql += " where " + jpaQl; sql = dealOrder(sql, page); Query query = entityManager.createQuery(sql); if (page.isAutoCount()) { int totalCount = countJpaQlResult(jpaQl); page.setTotalCount(totalCount); } query.setFirstResult(page.getStart()); query.setMaxResults(page.getLimit()); List<T> lt = query.getResultList(); page.setResult(lt); return page; }
From source file:com.xyz.framework.data.impl.JpaDao.java
/** * ,??.//from w ww .ja v a 2s. c om */ @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true) public Page<T> findBy(final Page page, final String propertyName, final Object value) { Assert.hasText(propertyName, "propertyName?"); Assert.notNull(value, "value?"); final String filter = buildPropertyFilterCriterion(propertyName, value, MatchType.EQ); String sql = getBaseSql() + " where " + filter; sql = dealOrder(sql, page); Query query = entityManager.createQuery(sql); if (page.isAutoCount()) { int totalCount = countJpaQlResult(filter); page.setTotalCount(totalCount); } query.setFirstResult(page.getStart()); query.setMaxResults(page.getLimit()); List<T> lt = query.getResultList(); page.setResult(lt); return page; }
From source file:corner.orm.gae.impl.PaginatedJapEntityService.java
License:asdf
public Iterator find(final Class<?> persistClass, final Object conditions, final String order, final int start, final int offset) { return (Iterator) this.template.execute(new JpaCallback() { @Override//from w ww.ja v a2s . com public Object doInJpa(EntityManager entityManager) throws PersistenceException { Iterable con = typeCoercer.coerce(conditions, Iterable.class); final Iterator it = con == null ? null : con.iterator(); final StringBuffer sb = buildConditionJPQL(persistClass, it); appendOrder(sb, order); sb.insert(0, "select root." + EntityConstants.ID_PROPERTY_NAME); Query query = entityManager.createQuery(sb.toString()); if (it != null) { int i = 0; while (it.hasNext()) { query.setParameter(String.valueOf(++i), it.next()); } } query.setFirstResult(start); query.setMaxResults(offset); return query.getResultList().iterator(); } }); }
From source file:com.sun.socialsite.business.impl.JPANotificationManagerImpl.java
/** * Note: using SuppressWarnings annotation because the JPA API is not genericized. *//*from ww w. j a v a2 s. co m*/ @SuppressWarnings(value = "unchecked") private List<MessageContent> getNotificationsByTypeAndLabel(Profile p, String type, String label, int offset, int length) throws SocialSiteException { Query query = strategy.getNamedQuery("MessageContent.getByToProfileTypeLabel"); query.setParameter(1, p.getUserId()); query.setParameter(2, type); query.setParameter(3, label); if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } return (List<MessageContent>) query.getResultList(); }