Example usage for javax.persistence TypedQuery setFirstResult

List of usage examples for javax.persistence TypedQuery setFirstResult

Introduction

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

Prototype

TypedQuery<X> setFirstResult(int startPosition);

Source Link

Document

Set the position of the first result to retrieve.

Usage

From source file:org.apache.openmeetings.db.dao.user.PrivateMessageDao.java

public List<PrivateMessage> get(Long ownerId, Long folderId, String search, String orderBy, boolean asc,
        int start, int max) {
    TypedQuery<PrivateMessage> query = em.createQuery(getQuery(false, search, orderBy, asc),
            PrivateMessage.class);
    query.setParameter("ownerId", ownerId);
    query.setParameter("folderId", folderId);
    if (!StringUtils.isEmpty(search)) {
        query.setParameter("search", StringUtils.lowerCase("%" + search + "%"));
    }/*from  w ww .  j ava 2 s .  c  o  m*/
    query.setFirstResult(start);
    query.setMaxResults(max);
    return query.getResultList();
}

From source file:org.apache.openmeetings.db.dao.user.UserDao.java

@Override
public List<User> get(int first, int count) {
    TypedQuery<User> q = em.createNamedQuery("getNondeletedUsers", User.class);
    q.setFirstResult(first);
    q.setMaxResults(count);//www  . j  a  va  2s  .c o  m
    return q.getResultList();
}

From source file:org.apache.openmeetings.db.dao.user.UserDao.java

public List<User> get(String search, int start, int count, String sort, boolean filterContacts,
        Long currentUserId) {/*from   w  w  w .j  a v  a 2  s .  c o m*/
    Map<String, Object> params = new HashMap<String, Object>();
    TypedQuery<User> q = em.createQuery(
            DaoHelper.getSearchQuery("User", "u", getAdditionalJoin(filterContacts), search, true, true, false,
                    getAdditionalWhere(filterContacts, currentUserId, params), sort, searchFields),
            User.class);
    q.setFirstResult(start);
    q.setMaxResults(count);
    setAdditionalParams(q, params);
    return q.getResultList();
}

From source file:org.apache.openmeetings.db.dao.user.UserDao.java

public List<User> get(String search, boolean excludeContacts, int first, int count) {
    Map<String, Object> params = new HashMap<String, Object>();
    TypedQuery<User> q = em.createQuery(DaoHelper.getSearchQuery("User", "u", null, search, true, true, false,
            getAdditionalWhere(excludeContacts, params), null, searchFields), User.class);
    setAdditionalParams(q, params);//ww  w .j  a v  a2s .  c  o m
    q.setFirstResult(first);
    q.setMaxResults(count);
    return q.getResultList();
}

From source file:org.apache.openmeetings.db.util.DaoHelper.java

public static <T> TypedQuery<T> setLimits(TypedQuery<T> q, Long first, Long max) {
    if (first != null) {
        q.setFirstResult(first.intValue());
    }//ww  w.  j a va  2  s  .  com
    if (max != null) {
        q.setMaxResults(max.intValue());
    }
    return q;
}

From source file:org.apache.syncope.core.persistence.jpa.dao.JPAAccessTokenDAO.java

@Transactional(readOnly = true)
@Override/*w w w  .  j a v a 2 s .c  o  m*/
public List<AccessToken> findAll(final int page, final int itemsPerPage,
        final List<OrderByClause> orderByClauses) {
    StringBuilder queryString = buildFindAllQuery().append(toOrderByStatement(orderByClauses));

    TypedQuery<AccessToken> query = entityManager().createQuery(queryString.toString(), AccessToken.class);

    query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1));

    if (itemsPerPage > 0) {
        query.setMaxResults(itemsPerPage);
    }

    return query.getResultList();
}

From source file:org.apache.syncope.core.persistence.jpa.dao.JPAAnyObjectDAO.java

@Override
public List<AnyObject> findAll(final int page, final int itemsPerPage) {
    TypedQuery<AnyObject> query = entityManager().createQuery(
            "SELECT e FROM  " + JPAAnyObject.class.getSimpleName() + " e ORDER BY e.id", AnyObject.class);
    query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1));
    query.setMaxResults(itemsPerPage);/* w  w w.ja va  2s .c o m*/

    return query.getResultList();
}

From source file:org.apache.syncope.core.persistence.jpa.dao.JPAGroupDAO.java

@Override
public List<Group> findAll(final int page, final int itemsPerPage) {
    TypedQuery<Group> query = entityManager()
            .createQuery("SELECT e FROM  " + JPAGroup.class.getSimpleName() + " e ORDER BY e.id", Group.class);
    query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1));
    query.setMaxResults(itemsPerPage);/*from   w  w w . j a  v a2  s  .  co m*/

    return query.getResultList();
}

From source file:org.apache.syncope.core.persistence.jpa.dao.JPAUserDAO.java

@Override
public List<User> findAll(final int page, final int itemsPerPage) {
    TypedQuery<User> query = entityManager()
            .createQuery("SELECT e FROM  " + JPAUser.class.getSimpleName() + " e ORDER BY e.id", User.class);
    query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1));
    query.setMaxResults(itemsPerPage);// w ww  .  ja va  2  s.c o m

    return query.getResultList();
}

From source file:org.broadleafcommerce.core.catalog.dao.ProductDaoImpl.java

@Override
public List<Product> readProductsByName(@Nonnull String searchName, @Nonnull int limit, @Nonnull int offset) {
    TypedQuery<Product> query = em.createNamedQuery("BC_READ_PRODUCTS_BY_NAME", Product.class);
    query.setParameter("name", searchName + '%');
    query.setFirstResult(offset);
    query.setMaxResults(limit);//from  w  w  w  .  j a va  2  s.  c o  m
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    return query.getResultList();
}