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.ApplicationDAOJPAImpl.java

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

    Query query = null;
    query = em.createQuery("select a from Application a");

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

    for (Object obj : serviceEntities) {
        ApplicationEntity entity = (ApplicationEntity) obj;
        list.add(entity2domain(entity, expandList));
    }/*from   w ww.  j  a  va2s. c o m*/
    return list;
}

From source file:de.iai.ilcd.model.dao.UserGroupDao.java

@SuppressWarnings("unchecked")
public List<UserGroup> getGroups(Organization org, Integer first, Integer pageSize) {
    if (org == null) {
        return null;
    }/*  ww w  .j a  v  a 2 s . co m*/
    EntityManager em = PersistenceUtil.getEntityManager();

    try {
        Query q = em.createQuery(
                "SELECT DISTINCT g FROM UserGroup g WHERE g.organization.id = :orgId ORDER BY g.groupName");
        q.setParameter("orgId", org.getId());
        if (first != null) {
            q.setFirstResult(first.intValue());
        }
        if (pageSize != null) {
            q.setMaxResults(pageSize.intValue());
        }
        return (List<UserGroup>) q.getResultList();
    } catch (Exception e) {
        return null;
    }
}

From source file:es.alvsanand.webpage.db.dao.DAOHelper.java

protected Query getNamedQuery(EntityManager entityManager, String queryName, QueryBean queryBean) {
    Query q = entityManager.createNamedQuery(queryName);

    if (queryBean != null) {
        if (queryBean.getLimit() > 0) {
            q.setMaxResults(queryBean.getLimit());
        }/*w w  w.ja  v a2s.  c om*/
        if (queryBean.getOffset() > 0) {
            q.setFirstResult(queryBean.getOffset());
        }
    }

    return q;
}

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

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

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

@SuppressWarnings("unchecked")
public final List<AuditLog> findByExample(AuditLog example, int start, int total) {
    if (example instanceof Searchable) {
        Searchable criteria = (Searchable) example;
        String whereClause = CrudUtil.buildJpaQueryString(criteria, false);
        String orderClause = " " + appendOrderToExample(example);
        String append = appendClauseToExample(example);
        whereClause = doSQLAppend(whereClause, append);
        if (_log.isDebugEnabled())
            _log.debug("QBE >> " + whereClause + orderClause);
        Query query = getEntityManager().createQuery("from AuditLog obj " + whereClause + orderClause);
        if (start > -1)
            query.setFirstResult(start);
        if (total > -1)
            query.setMaxResults(total);/*from  w w  w .ja  v  a  2 s .  co m*/
        return query.getResultList();
    } else {
        throw new InvalidImplementationException(
                "Parameter example [" + example.getClass().getName() + "] is not an instance of Searchable");
    }
}

From source file:org.asqatasun.entity.dao.subject.WebResourceDAOImpl.java

@Override
public List<WebResource> findWebResourceFromItsParent(WebResource webResource, int start, int chunkSize) {
    Query query = entityManager.createQuery("SELECT wr FROM " + getEntityClass().getName() + " wr"
            + " JOIN wr.parent p" + " WHERE p=:webResource");
    query.setParameter("webResource", webResource);
    query.setFirstResult(start);
    query.setMaxResults(chunkSize);//from   w w w. j a  v  a2 s .c om
    return (List<WebResource>) query.getResultList();
}

From source file:org.springframework.integration.jpa.core.DefaultJpaOperations.java

@Override
public List<?> getResultListForQuery(String queryString, ParameterSource source, int firstResult,
        int maxNumberOfResults) {

    Query query = getQuery(queryString, source);

    if (firstResult > 0) {
        query.setFirstResult(firstResult);
    }/*w  w  w  .j av  a 2 s  .  com*/
    if (maxNumberOfResults > 0) {
        query.setMaxResults(maxNumberOfResults);
    }

    return query.getResultList();
}

From source file:de.iai.ilcd.model.dao.UserDao.java

@SuppressWarnings("unchecked")
public List<User> getUsers(Organization org, Integer first, Integer pageSize) {
    if (org == null) {
        return null;
    }/* w  w w .  j av  a 2s .c  o m*/
    EntityManager em = PersistenceUtil.getEntityManager();

    try {
        Query q = em.createQuery(
                "SELECT DISTINCT u FROM User u WHERE u.organization.id = :orgId ORDER BY u.userName");
        q.setParameter("orgId", org.getId());
        if (first != null) {
            q.setFirstResult(first.intValue());
        }
        if (pageSize != null) {
            q.setMaxResults(pageSize.intValue());
        }
        return (List<User>) q.getResultList();
    } catch (Exception e) {
        return null;
    }
}

From source file:com.dbs.sdwt.jpa.JpaUtil.java

public void applyPagination(Query query, SearchParameters sp) {
    if (sp.getFirst() > 0) {
        query.setFirstResult(sp.getFirst());
    }//from   w ww  .j av  a  2s .c  o  m
    if (sp.getPageSize() > 0) {
        query.setMaxResults(sp.getPageSize());
    } else if (sp.getMaxResults() > 0) {
        query.setMaxResults(sp.getMaxResults());
    }
}

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

/**
 * Get notifications for a group//from   w  w  w  .  java 2s .c om
 *
 * Note: using SuppressWarnings annotation because the JPA API is not genericized.
 */
@SuppressWarnings(value = "unchecked")
public List<MessageContent> getNotificationsByGroup(int offset, int length, String handle)
        throws SocialSiteException {

    GroupManager gmgr = Factory.getSocialSite().getGroupManager();
    Group grp = gmgr.getGroupByHandle(handle);
    if (grp == null)
        throw new SocialSiteException("No group found with handle " + handle);
    Query query = strategy.getNamedQuery("MessageContent.getGroupNotification");
    query.setParameter(1, grp);

    if (offset != 0) {
        query.setFirstResult(offset);
    }
    if (length != -1) {
        query.setMaxResults(length);
    }
    return (List<MessageContent>) query.getResultList();
}