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:org.apache.cxf.fediz.service.idp.service.jpa.RoleDAOJPAImpl.java

@Override
public List<Role> getRoles(int start, int size, List<String> expandList) {
    List<Role> list = new ArrayList<Role>();

    Query query = null;
    query = em.createQuery("select r from Role r");

    //@SuppressWarnings("rawtypes")
    List roleEntities = query.setFirstResult(start).setMaxResults(size).getResultList();

    for (Object obj : roleEntities) {
        RoleEntity entity = (RoleEntity) obj;
        list.add(entity2domain(entity, expandList));
    }/*from ww w. ja  va 2s.co  m*/
    return list;
}

From source file:org.mitre.openid.connect.repository.impl.JpaEventRepository.java

@SuppressWarnings("unchecked")
@Override//from   w ww . j  a  va 2  s  . c o m
@Transactional
public Collection<Event> getEventsDuringPeriod(Date start, Date end, int startChunk, int chunkSize) {

    Query query = manager.createQuery("SELECT e FROM Event e WHERE e.timestamp BETWEEN :start AND :end");

    query = query.setParameter("start", start, TemporalType.DATE);
    query = query.setParameter("end", end, TemporalType.DATE);
    query = query.setFirstResult(startChunk);
    query = query.setMaxResults(chunkSize);

    return query.getResultList();
}

From source file:es.caib.sgtsic.ejb3.AbstractFacade.java

public List<T> findRange(int[] range) {
    javax.persistence.Query q = getEntityManager()
            .createQuery("select object(o) from " + entityClass.getSimpleName() + " as o");
    q.setMaxResults(range[1] - range[0] + 1);
    q.setFirstResult(range[0]);
    return q.getResultList();
}

From source file:org.opentides.persistence.impl.AuditLogDAOImpl.java

@SuppressWarnings("unchecked")
public final List<AuditLog> findAll(int start, int total) {
    Query query = getEntityManager().createQuery("from AuditLog obj");
    if (start > -1)
        query.setFirstResult(start);
    if (total > -1)
        query.setMaxResults(total);/*from  w  ww.j  a va 2 s .c o  m*/
    return query.getResultList();
}

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

/**
 * /*from ww  w  . ja  v  a2  s  .c  om*/
 *
 * @param jpql
 * @param params
 * @param pageNo
 * @param pageSize
 * @return
 */
public PageData<T> query(String jpql, MapSqlParameterSource params, int pageNo, int pageSize) {
    // Count
    String countQueryString = " select count (*) " + removeSelect(removeOrders(jpql));
    Query countQuery = createQuery(countQueryString, params);
    Long totalCount = (Long) countQuery.getSingleResult();
    if (totalCount < 1) {
        return new PageData<T>();
    }

    // 
    int startIndex = PageData.getStartOfPage(pageNo, pageSize);
    Query query = createQuery(jpql, params);
    query.setFirstResult(startIndex);
    query.setMaxResults(pageSize);
    List<T> rows = query.getResultList();

    return new PageData<T>(startIndex, totalCount, pageSize, rows);
}

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

/**
 * Note: using SuppressWarnings annotation because the JPA API is not genericized.
 *///from w w w  .ja va 2  s.c  o  m
@SuppressWarnings(value = "unchecked")
public List<SocialSiteActivity> getActivitiesByGroup(Group group, int offset, int length)
        throws SocialSiteException {
    if (group == null) {
        throw new SocialSiteException("Group cannot be null");
    }
    Query query = strategy.getNamedQuery("Activity.getByGroup");
    if (offset != 0) {
        query.setFirstResult(offset);
    }
    if (length != -1) {
        query.setMaxResults(length);
    }
    query.setParameter(1, group);
    return (List<SocialSiteActivity>) query.getResultList();
}

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

/**
 * Note: using SuppressWarnings annotation because the JPA API is not genericized.
 *///w ww . j a va 2  s  . c o  m
@SuppressWarnings(value = "unchecked")
public List<SocialSiteActivity> getActivitiesByGadget(String gadgetId, int offset, int length)
        throws SocialSiteException {
    if (gadgetId == null) {
        throw new SocialSiteException("Gadget ID is null");
    }
    Query query = strategy.getNamedQuery("Activity.getByGadget");
    if (offset != 0) {
        query.setFirstResult(offset);
    }
    if (length != -1) {
        query.setMaxResults(length);
    }
    query.setParameter(1, gadgetId);
    return (List<SocialSiteActivity>) query.getResultList();
}

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

/**
 * Note: using SuppressWarnings annotation because the JPA API is not genericized.
 *///from   w  w  w  .j a  v  a 2 s .  c om
@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:com.sun.socialsite.business.impl.JPASocialSiteActivityManagerImpl.java

/**
 * Note: using SuppressWarnings annotation because the JPA API is not genericized.
 *///from   ww  w . j  a v  a2s .  c o  m
@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.sun.socialsite.business.impl.JPASocialSiteActivityManagerImpl.java

/**
 * Note: using SuppressWarnings annotation because the JPA API is not genericized.
 *//*from w w  w . java  2 s . com*/
@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();
}