Example usage for javax.persistence TypedQuery setMaxResults

List of usage examples for javax.persistence TypedQuery setMaxResults

Introduction

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

Prototype

TypedQuery<X> setMaxResults(int maxResult);

Source Link

Document

Set the maximum number of results to retrieve.

Usage

From source file:org.apache.openmeetings.data.user.dao.PrivateMessagesDao.java

public List<PrivateMessage> getPrivateMessagesByUser(Long toUserId, String search, String orderBy, int start,
        Boolean asc, Long privateMessageFolderId, int max) {
    try {//from w  w  w  .  j a v a  2 s  . c  o m

        String hql = "select c from PrivateMessage c " + "where c.to.user_id = :toUserId "
                + "AND c.isTrash = :isTrash " + "AND c.owner.user_id = :toUserId "
                + "AND c.privateMessageFolderId = :privateMessageFolderId ";

        if (search.length() != 0) {
            hql += "AND ( ";
            hql += "lower(c.subject) LIKE :search ";
            hql += "OR lower(c.message) LIKE :search ";
            hql += "OR lower(c.from.firstname) LIKE :search ";
            hql += "OR lower(c.from.lastname) LIKE :search ";
            hql += "OR lower(c.from.login) LIKE :search ";
            hql += "OR lower(c.from.adresses.email) LIKE :search ";
            hql += " ) ";
        }

        hql += "ORDER BY " + orderBy;

        if (asc) {
            hql += " ASC";
        } else {
            hql += " DESC";
        }

        TypedQuery<PrivateMessage> query = em.createQuery(hql, PrivateMessage.class);
        query.setParameter("toUserId", toUserId);
        query.setParameter("isTrash", false);
        query.setParameter("privateMessageFolderId", privateMessageFolderId);
        if (search.length() != 0) {
            query.setParameter("search", StringUtils.lowerCase("%" + search + "%"));
        }
        query.setFirstResult(start);
        query.setMaxResults(max);
        List<PrivateMessage> ll = query.getResultList();

        return ll;
    } catch (Exception e) {
        log.error("[getPrivateMessagesByUser]", e);
    }
    return null;
}

From source file:org.apache.openmeetings.data.user.dao.PrivateMessagesDao.java

public List<PrivateMessage> getTrashPrivateMessagesByUser(Long user_id, String search, String orderBy,
        int start, Boolean asc, int max) {
    try {/*from  w  w w.  j  a v a 2 s  . c o m*/

        String hql = "select c from PrivateMessage c " + "where c.isTrash = true "
                + "AND c.owner.user_id = :user_id ";

        if (search.length() != 0) {
            hql += "AND ( ";
            hql += "lower(c.subject) LIKE :search ";
            hql += "OR lower(c.message) LIKE :search ";
            hql += "OR lower(c.from.firstname) LIKE :search ";
            hql += "OR lower(c.from.lastname) LIKE :search ";
            hql += "OR lower(c.from.login) LIKE :search ";
            hql += "OR lower(c.from.adresses.email) LIKE :search ";
            hql += " ) ";
        }

        hql += "ORDER BY " + orderBy;

        if (asc) {
            hql += " ASC";
        } else {
            hql += " DESC";
        }

        TypedQuery<PrivateMessage> query = em.createQuery(hql, PrivateMessage.class);
        if (search.length() != 0) {
            query.setParameter("search", StringUtils.lowerCase("%" + search + "%"));
        }
        query.setParameter("user_id", user_id);
        query.setFirstResult(start);
        query.setMaxResults(max);
        List<PrivateMessage> ll = query.getResultList();

        return ll;
    } catch (Exception e) {
        log.error("[getTrashPrivateMessagesByUser]", e);
    }
    return null;
}

From source file:org.apache.openmeetings.data.user.dao.PrivateMessagesDao.java

public List<PrivateMessage> getSendPrivateMessagesByUser(Long toUserId, String search, String orderBy,
        int start, Boolean asc, Long privateMessageFolderId, int max) {
    try {/*  ww w . j  a  v a 2s  .  c o  m*/

        String hql = "select c from PrivateMessage c " + "where c.from.user_id = :toUserId "
                + "AND c.isTrash = false " + "AND c.owner.user_id = :toUserId "
                + "AND c.privateMessageFolderId = :privateMessageFolderId ";

        if (search.length() != 0) {
            hql += "AND ( ";
            hql += "lower(c.subject) LIKE :search ";
            hql += "OR lower(c.message) LIKE :search ";
            hql += "OR lower(c.from.firstname) LIKE :search ";
            hql += "OR lower(c.from.lastname) LIKE :search ";
            hql += "OR lower(c.from.login) LIKE :search ";
            hql += "OR lower(c.from.adresses.email) LIKE :search ";
            hql += " ) ";
        }

        hql += "ORDER BY " + orderBy;

        if (asc) {
            hql += " ASC";
        } else {
            hql += " DESC";
        }

        TypedQuery<PrivateMessage> query = em.createQuery(hql, PrivateMessage.class);
        query.setParameter("toUserId", toUserId);
        query.setParameter("privateMessageFolderId", privateMessageFolderId);
        if (search.length() != 0) {
            query.setParameter("search", StringUtils.lowerCase("%" + search + "%"));
        }
        query.setFirstResult(start);
        query.setMaxResults(max);
        List<PrivateMessage> ll = query.getResultList();

        return ll;
    } catch (Exception e) {
        log.error("[getSendPrivateMessagesByUser]", e);
    }
    return null;
}

From source file:org.apache.openmeetings.data.user.dao.PrivateMessagesDao.java

public List<PrivateMessage> getFolderPrivateMessagesByUser(Long toUserId, String search, String orderBy,
        int start, Boolean asc, Long privateMessageFolderId, int max) {
    try {/*from   w  w  w . j  av  a 2s.c  o  m*/

        String hql = "select c from PrivateMessage c " + "where c.isTrash = :isTrash "
                + "AND c.owner.user_id = :toUserId "
                + "AND c.privateMessageFolderId = :privateMessageFolderId ";

        if (search.length() != 0) {
            hql += "AND ( ";
            hql += "lower(c.subject) LIKE :search ";
            hql += "OR lower(c.message) LIKE :search ";
            hql += "OR lower(c.from.firstname) LIKE :search ";
            hql += "OR lower(c.from.lastname) LIKE :search ";
            hql += "OR lower(c.from.login) LIKE :search ";
            hql += "OR lower(c.from.adresses.email) LIKE :search ";
            hql += " ) ";
        }

        hql += "ORDER BY " + orderBy;

        if (asc) {
            hql += " ASC";
        } else {
            hql += " DESC";
        }

        log.debug("HQL " + hql);

        log.debug("privateMessageFolderId " + privateMessageFolderId);

        TypedQuery<PrivateMessage> query = em.createQuery(hql, PrivateMessage.class);
        query.setParameter("toUserId", toUserId);
        query.setParameter("isTrash", false);
        query.setParameter("privateMessageFolderId", privateMessageFolderId);
        if (search.length() != 0) {
            query.setParameter("search", StringUtils.lowerCase("%" + search + "%"));
        }
        query.setFirstResult(start);
        query.setMaxResults(max);
        List<PrivateMessage> ll = query.getResultList();

        return ll;

    } catch (Exception e) {
        log.error("[getFolderPrivateMessagesByUser]", e);
    }
    return null;
}

From source file:org.apache.openmeetings.data.user.dao.UsersDao.java

public List<User> get(int first, int count) {
    TypedQuery<User> q = em.createNamedQuery("getNondeletedUsers", User.class);
    q.setFirstResult(first);//from   w w  w  .j  ava 2  s  .c om
    q.setMaxResults(count);
    return q.getResultList();
}

From source file:org.apache.openmeetings.data.user.dao.UsersDao.java

public List<User> get(String search, int start, int count, String sort) {
    TypedQuery<User> q = em.createQuery(
            DaoHelper.getSearchQuery("User", "u", search, true, false, sort, searchFields), User.class);
    q.setFirstResult(start);/* ww w. jav  a 2s . c om*/
    q.setMaxResults(count);
    return q.getResultList();
}

From source file:org.apache.openmeetings.data.user.UserManager.java

/**
 * query for a list of users//  ww w  . j  a  va  2s.c o m
 * 
 * @param users_id
 * @param user_level
 * @param start
 * @param max
 * @param orderby
 * @return
 */
public SearchResult<User> getUsersList(long user_level, int start, int max, String orderby, boolean asc) {
    try {
        if (authLevelUtil.checkAdminLevel(user_level)) {
            SearchResult<User> sresult = new SearchResult<User>();
            sresult.setObjectName(User.class.getName());
            sresult.setRecords(usersDao.count());

            // get all users
            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery<User> cq = cb.createQuery(User.class);
            Root<User> c = cq.from(User.class);
            Predicate condition = cb.equal(c.get("deleted"), false);
            cq.where(condition);
            cq.distinct(asc);
            if (asc) {
                cq.orderBy(cb.asc(c.get(orderby)));
            } else {
                cq.orderBy(cb.desc(c.get(orderby)));
            }
            TypedQuery<User> q = em.createQuery(cq);
            q.setFirstResult(start);
            q.setMaxResults(max);
            List<User> ll = q.getResultList();
            sresult.setResult(ll);
            return sresult;
        }
    } catch (Exception ex2) {
        log.error("[getUsersList] " + ex2);
    }
    return null;
}

From source file:org.apache.openmeetings.data.user.UserManager.java

public SearchResult<User> getAllUserByRange(String search, int start, int max, String orderby, boolean asc) {
    try {//  www  .  ja va  2 s . c om
        SearchResult<User> sresult = new SearchResult<User>();
        sresult.setObjectName(User.class.getName());
        sresult.setRecords(usersDao.count(search));

        String sort = null;
        if (orderby != null && orderby.length() > 0) {
            sort = orderby;
        }
        if (asc) {
            sort += " ASC ";
        } else {
            sort += " DESC ";
        }
        String hql = DaoHelper.getSearchQuery("User", "u", search, true, false, sort, UsersDao.searchFields);

        log.debug("Show HQL: " + hql);

        TypedQuery<User> query = em.createQuery(hql, User.class);
        // query.setParameter("macomUserId", userId);

        // query
        // if (asc) ((Criteria) query).addOrder(Order.asc(orderby));
        // else ((Criteria) query).addOrder(Order.desc(orderby));
        query.setFirstResult(start);
        query.setMaxResults(max);
        List<User> ll = query.getResultList();

        sresult.setResult(ll);

        return sresult;

    } catch (Exception ex2) {
        log.error("[getAllUserByRange] ", ex2);
        ex2.printStackTrace();
    }
    return null;
}

From source file:org.apache.openmeetings.data.user.UserManager.java

/**
 * suche eines Bentzers// w  w w  . j ava2  s  . c om
 * 
 * @param user_level
 * @param searchstring
 * @param max
 * @param start
 * @return
 */
public List<User> searchUser(long user_level, String searchcriteria, String searchstring, int max, int start,
        String orderby, boolean asc) {
    if (authLevelUtil.checkAdminLevel(user_level)) {
        try {
            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery<User> cq = cb.createQuery(User.class);
            Root<User> c = cq.from(User.class);
            Expression<String> literal = cb.literal("%" + searchstring + "%");
            Path<String> path = c.get(searchcriteria);
            Predicate predicate = cb.like(path, literal);
            Predicate condition = cb.notEqual(c.get("deleted"), true);
            cq.where(condition, predicate);
            cq.distinct(asc);
            if (asc) {
                cq.orderBy(cb.asc(c.get(orderby)));
            } else {
                cq.orderBy(cb.desc(c.get(orderby)));
            }
            TypedQuery<User> q = em.createQuery(cq);
            q.setFirstResult(start);
            q.setMaxResults(max);
            List<User> contactsZ = q.getResultList();
            return contactsZ;
        } catch (Exception ex2) {
            log.error("searchUser", ex2);
        }
    }
    return null;
}

From source file:org.apache.openmeetings.data.user.UserManager.java

/**
 * @param user_level/*from   ww w. ja  va 2  s  .c  om*/
 * @param start
 * @param max
 * @param orderby
 * @param asc
 * @param search
 * @return
 */
public SearchResult<User> getUsersListWithSearch(Long user_level, int start, int max, String orderby,
        boolean asc, String search) {
    try {
        if (authLevelUtil.checkAdminLevel(user_level)) {

            String hql = "select c from User c " + "where c.deleted = false " + "AND ("
                    + "lower(c.login) LIKE :search " + "OR lower(c.firstname) LIKE :search "
                    + "OR lower(c.lastname) LIKE :search " + ")";

            if (orderby.startsWith("c.")) {
                hql += "ORDER BY " + orderby;
            } else {
                hql += "ORDER BY " + "c." + orderby;
            }

            if (asc) {
                hql += " ASC";
            } else {
                hql += " DESC";
            }

            if (search.length() == 0) {
                search = "%";
            } else {
                search = "%" + search + "%";
            }
            log.debug("getUsersList search: " + search);

            SearchResult<User> sresult = new SearchResult<User>();
            sresult.setObjectName(User.class.getName());
            sresult.setRecords(usersDao.selectMaxFromUsersWithSearch(search));

            // get all users
            TypedQuery<User> query = em.createQuery(hql, User.class);
            query.setParameter("search", StringUtils.lowerCase(search));
            query.setMaxResults(max);
            query.setFirstResult(start);

            sresult.setResult(query.getResultList());

            return sresult;
        }
    } catch (Exception ex2) {
        log.error("[getUsersList] " + ex2);
    }
    return null;
}