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.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 a v a 2s  .c  om

        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);
    q.setMaxResults(count);//  w w w.j  av  a  2  s . c  o m
    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);
    q.setMaxResults(count);/*from   www.j  av a 2s . c  o  m*/
    return q.getResultList();
}

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

/**
 * query for a list of users/*from w  ww .j  a  v  a  2  s. c om*/
 * 
 * @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 {/*  w w w.ja va2s. c o m*/
        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//from  w  ww  . j  av a  2  s  . c  o m
 * 
 * @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   w w w.  j a  v  a  2s.  c o  m
 * @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;
}

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

public List<User> searchUserProfile(String searchTxt, String userOffers, String userSearchs, String orderBy,
        int start, int max, boolean asc) {
    try {/*from  ww w.j  av a2s  .c o  m*/

        String hql = "select c from User c " + "where c.deleted = false ";

        if (searchTxt.length() != 0 && userOffers.length() != 0 && userSearchs.length() != 0) {

            hql += "AND " + "(" + "(" + "lower(c.login) LIKE :search " + "OR lower(c.firstname) LIKE :search "
                    + "OR lower(c.lastname) LIKE :search " + "OR lower(c.adresses.email) LIKE :search "
                    + "OR lower(c.adresses.town) LIKE :search " + ")" + "AND" + "("
                    + "lower(c.userOffers) LIKE :userOffers " + ")" + "AND" + "("
                    + "lower(c.userSearchs) LIKE :userSearchs " + ")" + ")";

        } else if (searchTxt.length() != 0 && userOffers.length() != 0) {

            hql += "AND " + "(" + "(" + "lower(c.login) LIKE :search " + "OR lower(c.firstname) LIKE :search "
                    + "OR lower(c.lastname) LIKE :search " + "OR lower(c.adresses.email) LIKE :search "
                    + "OR lower(c.adresses.town) LIKE :search " + ")" + "AND" + "("
                    + "lower(c.userOffers) LIKE :userOffers " + ")" + ")";

        } else if (searchTxt.length() != 0 && userSearchs.length() != 0) {

            hql += "AND " + "(" + "(" + "lower(c.login) LIKE :search " + "OR lower(c.firstname) LIKE :search "
                    + "OR lower(c.lastname) LIKE :search " + "OR lower(c.adresses.email) LIKE :search "
                    + "OR lower(c.adresses.town) LIKE :search " + ")" + "AND" + "("
                    + "lower(c.userSearchs) LIKE :userSearchs " + ")" + ")";

        } else if (userOffers.length() != 0 && userSearchs.length() != 0) {

            hql += "AND " + "(" + "(" + "lower(c.userOffers) LIKE :userOffers " + ")" + "AND" + "("
                    + "lower(c.userSearchs) LIKE :userSearchs " + ")" + ")";

        } else if (searchTxt.length() != 0) {

            hql += "AND " + "(" + "(" + "lower(c.login) LIKE :search " + "OR lower(c.firstname) LIKE :search "
                    + "OR lower(c.lastname) LIKE :search " + "OR lower(c.adresses.email) LIKE :search "
                    + "OR lower(c.adresses.town) LIKE :search " + ")" + ")";

        } else if (userOffers.length() != 0) {

            hql += "AND " + "(" + "(" + "lower(c.userOffers) LIKE :userOffers " + ")" + ")";

        } else if (userSearchs.length() != 0) {

            hql += "AND " + "(" + "(" + "lower(c.userSearchs) LIKE :userSearchs " + ")" + ")";

        }

        hql += " ORDER BY " + orderBy;

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

        if (searchTxt.length() != 0) {
            searchTxt = "%" + searchTxt + "%";
        }

        if (userOffers.length() != 0) {
            userOffers = "%" + userOffers + "%";
        }

        if (userSearchs.length() != 0) {
            userSearchs = "%" + userSearchs + "%";
        }

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

        // get all users
        TypedQuery<User> query = em.createQuery(hql, User.class);

        if (searchTxt.length() != 0 && userOffers.length() != 0 && userSearchs.length() != 0) {

            query.setParameter("search", StringUtils.lowerCase(searchTxt));
            query.setParameter("userOffers", StringUtils.lowerCase(userOffers));
            query.setParameter("userSearchs", StringUtils.lowerCase(userSearchs));

        } else if (searchTxt.length() != 0 && userOffers.length() != 0) {

            query.setParameter("search", StringUtils.lowerCase(searchTxt));
            query.setParameter("userOffers", StringUtils.lowerCase(userOffers));

        } else if (searchTxt.length() != 0 && userSearchs.length() != 0) {

            query.setParameter("search", StringUtils.lowerCase(searchTxt));
            query.setParameter("userSearchs", StringUtils.lowerCase(userSearchs));

        } else if (userOffers.length() != 0 && userSearchs.length() != 0) {

            query.setParameter("userOffers", StringUtils.lowerCase(userOffers));
            query.setParameter("userSearchs", StringUtils.lowerCase(userSearchs));

        } else if (searchTxt.length() != 0) {

            query.setParameter("search", StringUtils.lowerCase(searchTxt));

        } else if (userOffers.length() != 0) {

            query.setParameter("userOffers", StringUtils.lowerCase(userOffers));

        } else if (userSearchs.length() != 0) {

            query.setParameter("userSearchs", StringUtils.lowerCase(userSearchs));

        }

        query.setMaxResults(max);
        query.setFirstResult(start);

        List<User> userList = query.getResultList();

        return userList;

    } catch (Exception ex2) {
        log.error("[getUsersList] ", ex2);
    }

    return null;
}

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

public List<User> get(String search, int start, int count, String sort, boolean isAdmin, long currentUserId) {
    TypedQuery<User> q = em.createQuery(DaoHelper.getSearchQuery("User", "u", search, true, false,
            getAdditionalWhere(isAdmin), sort, searchFields), User.class);
    q.setFirstResult(start);
    q.setMaxResults(count);//  w w  w . j  av  a  2s  .c  o m
    setAdditionalParams(q, isAdmin, currentUserId);
    return q.getResultList();
}

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

public List<User> searchUserProfile(long userId, String text, String offers, String search, String orderBy,
        int start, int max, boolean asc) {
    StringBuilder sb = getUserProfileQuery(false, text, offers, search);
    sb.append(" ORDER BY ").append(orderBy).append(asc ? " ASC" : " DESC");

    log.debug("hql :: " + sb.toString());
    TypedQuery<User> query = em.createQuery(sb.toString(), User.class);
    setAdditionalParams(query, false, userId);

    if (text != null && text.length() != 0) {
        query.setParameter("search", StringUtils.lowerCase("%" + text + "%"));
    }//from  w w  w . j  av  a  2  s. c  om
    if (offers != null && offers.length() != 0) {
        query.setParameter("userOffers", StringUtils.lowerCase("%" + offers + "%"));
    }
    if (search != null && search.length() != 0) {
        query.setParameter("userSearchs", StringUtils.lowerCase("%" + search + "%"));
    }
    return query.setFirstResult(start).setMaxResults(max).getResultList();
}