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:myjpa.guest.model.Guests.java

public List<Guest> findAll(int start, int size) {

    Query query = getJpqlQuery();
    query.setFirstResult(start);
    query.setMaxResults(size);/*  w  ww  .  ja  va  2s  .  c  om*/

    return query.getResultList();
}

From source file:com.wpl.db.query.jpa.Limit.java

public void setParameter(final IQuery query) {

    final Query q = (Query) query.getQuery();

    if (mFirst != null) {
        q.setFirstResult(mFirst);
    }//from  ww  w .  j  a  va  2 s .co m

    if (mMax != null) {
        q.setMaxResults(mMax);
    }
}

From source file:almira.sample.dao.CatapultDaoHibernateSearch.java

@Override
@SuppressWarnings("unchecked")
public List<Catapult> searchByName(final String searchQuery, final int startIndex, final int fetchSize)
        throws ParseException {

    Query query = createQuery(searchQuery);
    query.setFirstResult(startIndex).setMaxResults(fetchSize);
    return query.getResultList();
}

From source file:com.june.app.site.repository.jpa.VideoRepositoryImpl.java

@SuppressWarnings("unchecked")
@Override/*  ww  w  .ja va  2 s.c  om*/
public Collection<Video> videoListWithPaging(Video vo) {

    int pageSize = vo.getPageSize();
    int pageNumber = (int) vo.getPageIndex();

    String queryString = "SELECT video FROM Video video WHERE video.useYn ='Y' ORDER BY video.regiDate desc";
    Query query = this.em.createQuery(queryString);
    query.setFirstResult((pageNumber - 1) * pageSize);
    query.setMaxResults(pageSize);

    return query.getResultList();
}

From source file:org.eurekastreams.server.persistence.mappers.stream.GetFlaggedActivities.java

/**
 * Get all flagged activities.//from  www .  ja  v  a  2 s .  c om
 * 
 * @param inRequest
 *            the request containing the start and end index
 * @return a paged set of ActivityDTOs
 */
@Override
@SuppressWarnings("unchecked")
public PagedSet<ActivityDTO> execute(final GetFlaggedActivitiesRequest inRequest) {
    if (inRequest.getRequestingUserAccountId() == null) {
        log.error("Missing requesting user account.");
        throw new RuntimeException("Missing requesting user account.");
    }

    // get the total number of flagged activities
    Long flaggedActivityCount = (Long) buildQuery("count(*)").getSingleResult();

    List<ActivityDTO> activities;
    if (flaggedActivityCount > 0) {
        log.info("Found " + flaggedActivityCount
                + " flagged activity ids - passing them to the bulk activity mapper for ActivityDTOs.");

        Query q = buildQuery("id");
        q.setFirstResult(inRequest.getStartIndex());
        q.setMaxResults(inRequest.getEndIndex() - inRequest.getStartIndex() + 1);
        List<Long> activityIds = q.getResultList();

        activities = activitiesMapper.execute(activityIds);
    } else {
        log.info("Found no flagged activity ids.");
        activities = new ArrayList<ActivityDTO>();
    }
    return new PagedSet<ActivityDTO>(inRequest.getStartIndex(), inRequest.getEndIndex(),
            flaggedActivityCount.intValue(), activities);
}

From source file:org.eurekastreams.server.persistence.mappers.db.GetRequestsForGroupMembershipByGroup.java

/**
 * Get all flagged activities./*from  w w  w.ja v  a 2s.c  om*/
 * 
 * @param inRequest
 *            the request containing the start and end index
 * @return a paged set of ActivityDTOs
 */
@Override
@SuppressWarnings("unchecked")
public PagedSet<Long> execute(final GetRequestForGroupMembershipRequest inRequest) {
    final long groupId = inRequest.getGroupId();
    final int startIndex = inRequest.getStartIndex();
    final int numDesired = inRequest.getEndIndex() - startIndex + 1;

    Query q = buildQuery("pk.personId", groupId);
    q.setFirstResult(startIndex);
    q.setMaxResults(numDesired);
    List<Long> list = q.getResultList();

    // Get/compute the total count: If we didn't get all we asked for, then we know where the end of the list is,
    // and thus can calculate the total count without doing a query. Otherwise we'll have to ask.
    int totalCount;
    if (list.size() < numDesired) {
        totalCount = startIndex + list.size();
    } else {
        totalCount = ((Long) buildQuery("count(*)", groupId).getSingleResult()).intValue();
    }

    int endIndex = startIndex + list.size() - 1;

    if (log.isInfoEnabled()) {
        log.info("Request for membership requests for group " + groupId + " from " + startIndex + "-"
                + inRequest.getEndIndex() + " yielded " + list.size() + " results and a total count of "
                + totalCount + ".");
    }

    return new PagedSet<Long>(startIndex, endIndex, totalCount, list);
}

From source file:com.eu.evaluation.server.dao.DefaultDAO.java

/**
 * ??/*ww w. j a va 2s  .  c om*/
 * @param jpql
 * @param params
 * @return 
 */
public <T> T findOnylFirst(String jpql, MapSqlParameterSource params) {
    Query query = this.createQuery(jpql, params);
    query.setFirstResult(0);
    query.setMaxResults(1);
    List<T> result = query.getResultList();
    if (result.isEmpty()) {
        return null;
    } else {
        return result.get(0);
    }
}

From source file:gumga.framework.application.GumgaCrudAndQueryNotOnlyTypedRepositoryImpl.java

@Override
public List getResultList(String hql, Map<String, Object> param, int firstresult, int maxResult) {
    javax.persistence.Query query = entityManager.createQuery(hql);
    query.setMaxResults(maxResult);//from  w w w  .j a v a 2 s.  co m
    query.setFirstResult(firstresult);
    addParam(query, param);
    return query.getResultList();
}

From source file:ro.alexdutescu.coduribare.service.AbstractFacade.java

public List<T> findRange(int[] range) {
    javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
    cq.select(cq.from(entityClass));/* www  .  j ava 2s.  co m*/
    javax.persistence.Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(range[1] - range[0] + 1);
    q.setFirstResult(range[0]);
    return q.getResultList();
}

From source file:de.inetsource.jsfforum.db.PostFacade.java

public List<Post> findRange(Thread thread, int[] rangeArray) {
    Query query = getEntityManager().createNamedQuery("Post.findByThreadId");
    query.setParameter("id", thread.getId());
    query.setFirstResult(rangeArray[0]);
    query.setMaxResults(rangeArray[1]);//ww  w .  j a va2  s.c o m
    return query.getResultList();
}