Example usage for javax.persistence Query setFirstResult

List of usage examples for javax.persistence Query setFirstResult

Introduction

In this page you can find the example usage for javax.persistence Query setFirstResult.

Prototype

Query setFirstResult(int startPosition);

Source Link

Document

Set the position of the first result to retrieve.

Usage

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public List<Category> readCategories(int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM Category m  ORDER BY m.id");
    q.setFirstResult(firstResult);
    q.setMaxResults(maxResults);//from   www .ja  v  a2 s  .  c  om
    return q.getResultList();
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public List<FStoreProperty> readProperties(int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM FStoreProperty m  ORDER BY m.id");
    q.setFirstResult(firstResult);
    q.setMaxResults(maxResults);//from w w w  .j ava2  s.  c om
    return q.getResultList();

}

From source file:org.easy.criteria.QueryProperties.java

public void applyProperties(Query query) {
    if (flashMode != null) {
        log.debug("flashMode = " + flashMode);
        query.setFlushMode(flashMode);/*ww w  .  j  ava  2s.  c  om*/
    }

    if (lockMode != null) {
        log.debug("lockMode = " + lockMode);
        query.setLockMode(lockMode);
    }

    if (hintKey != null) {
        log.debug("hintKey = " + hintKey);
        log.debug("hintValue = " + hintValue);
        query.setHint(hintKey, hintValue);
    }

    if (startIndex >= 0 && maxResult > 0) {
        log.debug("startIndex = " + startIndex * maxResult);
        query.setFirstResult(startIndex * maxResult);
    }

    if (maxResult > 0) {
        log.debug("maxResult = " + maxResult);
        query.setMaxResults(maxResult);
    }
}

From source file:com.impetus.ankush.common.dao.impl.GenericDaoJpa.java

@SuppressWarnings(UNCHECKED)
public List<T> getAllByPropertyValue(Map<String, Object> propertyValueMap, int start, int maxResults,
        String... orderBy) {//from   ww  w.j a v a 2 s  . c  om
    Query query = createSelectQuery(propertyValueMap, orderBy);
    query.setFirstResult(start);
    query.setMaxResults(maxResults);
    return query.getResultList();
}

From source file:org.kuali.student.r2.common.criteria.impl.CriteriaLookupDaoJpaImpl.java

/** gets results where the actual rows are requested. */
private <T> GenericQueryResults<T> forRowResults(final Class<T> queryClass, final QueryByCriteria criteria,
        final Criteria jpaCriteria, CountFlag flag, LookupCustomizer.Transform<T, T> transform) {
    final Query jpaQuery = new org.kuali.student.r2.common.criteria.QueryByCriteria(entityManager, jpaCriteria)
            .toQuery();/*w  w  w.ja v  a 2 s.c o m*/
    final GenericQueryResults.Builder<T> results = GenericQueryResults.Builder.<T>create();

    //ojb's is 1 based, our query api is zero based
    jpaQuery.setFirstResult(criteria.getStartAtIndex() != null ? criteria.getStartAtIndex() : 0);

    if (criteria.getMaxResults() != null) {
        //adding one to MaxResults in order to retrieve
        //one extra row so that the MoreResultsAvailable field can be set
        jpaQuery.setMaxResults(criteria.getMaxResults() + 1);
    }

    @SuppressWarnings("unchecked")
    final List<T> rows = new ArrayList<T>(jpaQuery.getResultList());
    if (flag == CountFlag.INCLUDE) {
        results.setTotalRowCount(rows.size());
    }

    if (criteria.getMaxResults() != null && rows.size() > criteria.getMaxResults()) {
        results.setMoreResultsAvailable(true);
        //remove the extra row that was returned
        rows.remove(criteria.getMaxResults().intValue());
    }

    results.setResults(transformResults(rows, transform));
    return results.build();
}

From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java

public List<TxInstance> itemsDateRange(Date startDate, Date endDate, int[] range) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery(TxInstance.class);
    Root<TxInstance> rt = cq.from(TxInstance.class);
    cq.where(cb.and(rt.get(TxInstance_.completed).isNotNull(),
            cb.between(rt.get(TxInstance_.completed), startDate, endDate)));
    cq.orderBy(cb.asc(rt.get(TxInstance_.completed)));
    Query q = em.createQuery(cq);
    q.setMaxResults(range[1] - range[0] + 1);
    q.setFirstResult(range[0]);
    return q.getResultList();
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public List<Widget> readWidgetMetadataByOwnerId(int userid, int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    Query q;

    q = entityManager.createQuery("SELECT a FROM Widget a WHERE a.owner.id=" + userid + " ORDER BY a.id");

    q.setFirstResult(firstResult);
    q.setMaxResults(maxResults);/*from  w w w  .ja  v a 2 s. c  o m*/
    return q.getResultList();
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public List<Course> readCoursesMetadataByOwnerId(int userid, int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    Query q;

    q = entityManager.createQuery("SELECT a FROM Course a WHERE a.owner.id=" + userid + " ORDER BY a.id");

    q.setFirstResult(firstResult);
    q.setMaxResults(maxResults);//from w w  w . j av a2 s .  c om
    return q.getResultList();
}

From source file:com.sun.socialsite.business.impl.JPAGroupManagerImpl.java

/**
 * Note: using SuppressWarnings annotation because the JPA API is not genericized.
 *//*from w  w w  .  jav  a2s . c  om*/
@SuppressWarnings(value = "unchecked")
public List<Group> getGroups(int offset, int length) throws SocialSiteException {
    Query query = strategy.getNamedQuery("Group.getAll");
    if (offset != 0) {
        query.setFirstResult(offset);
    }
    if (length != -1) {
        query.setMaxResults(length);
    }
    return (List<Group>) query.getResultList();
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public List<FIREAdapter> readFIREAdaptersMetadataByOwnerId(int userid, int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    Query q;

    q = entityManager.createQuery("SELECT a FROM FIREAdapter a WHERE a.owner.id=" + userid + " ORDER BY a.id");

    q.setFirstResult(firstResult);
    q.setMaxResults(maxResults);// w w w .jav a  2  s .c o m
    return q.getResultList();
}