Example usage for javax.persistence Query setMaxResults

List of usage examples for javax.persistence Query setMaxResults

Introduction

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

Prototype

Query setMaxResults(int maxResult);

Source Link

Document

Set the maximum number of results to retrieve.

Usage

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}/*w  ww.j  a va  2 s  .co m*/
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findNextHistoryCursorFromDocument(User user, Integer idUserHistory, Integer entryId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory > ");
    queryString.append(idUserHistory);
    queryString.append(" AND (document IS NULL OR document.entryId !=");
    queryString.append(entryId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory ASC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}//from   w w w.j  a  v  a  2  s.  c o m
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findNextHistoryCursorFromPerson(User user, Integer idUserHistory, Integer personId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory > ");
    queryString.append(idUserHistory);
    queryString.append(" AND (person IS NULL OR person.personId !=");
    queryString.append(personId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory ASC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}/*from   w  w w . j  ava2  s  .  c  o  m*/
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findNextHistoryCursorFromPlace(User user, Integer idUserHistory, Integer placeAllId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory > ");
    queryString.append(idUserHistory);
    queryString.append(" AND (place IS NULL OR place.placeAllId !=");
    queryString.append(placeAllId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory ASC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}/* w  w  w . j ava 2  s  .  co  m*/
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findNextHistoryCursorFromVolume(User user, Integer idUserHistory, Integer summaryId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory > ");
    queryString.append(idUserHistory);
    queryString.append(" AND (volume IS NULL OR volume.summaryId !=");
    queryString.append(summaryId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory ASC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}//from  w  w  w  .jav  a 2  s. c  o m
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findPreviousHistoryCursorFromDocument(User user, Integer idUserHistory, Integer entryId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory < ");
    queryString.append(idUserHistory);
    queryString.append(" AND (document IS NULL OR document.entryId != ");
    queryString.append(entryId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory DESC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}/*from  w ww  .j a  v  a  2  s  .c o  m*/
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findPreviousHistoryCursorFromPerson(User user, Integer idUserHistory, Integer personId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory < ");
    queryString.append(idUserHistory);
    queryString.append(" AND (person IS NULL OR person.personId != ");
    queryString.append(personId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory DESC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}/*from w ww  . j a va2s  .co m*/
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findPreviousHistoryCursorFromPlace(User user, Integer idUserHistory, Integer placeAllId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory < ");
    queryString.append(idUserHistory);
    queryString.append(" AND (place IS NULL OR place.placeAllId != ");
    queryString.append(placeAllId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory DESC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}//from   ww w  .  j  a  va2s .c  o m
 */
@SuppressWarnings("unchecked")
@Override
public UserHistory findPreviousHistoryCursorFromVolume(User user, Integer idUserHistory, Integer summaryId)
        throws PersistenceException {
    StringBuilder queryString = new StringBuilder("FROM UserHistory WHERE user.account='");
    queryString.append(user.getAccount());
    queryString.append('\'');
    queryString.append(" AND (category NOT LIKE '");
    queryString.append(Category.FORUM.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_TOPIC.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.FORUM_POST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.MARKED_LIST.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_DOCUMENT.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PEOPLE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_PLACE.name());
    queryString.append("' AND category NOT LIKE '");
    queryString.append(Category.SEARCH_VOLUME.name());
    queryString.append("')");
    queryString.append(" AND idUserHistory < ");
    queryString.append(idUserHistory);
    queryString.append(" AND (volume IS NULL OR volume.summaryId != ");
    queryString.append(summaryId);

    queryString.append(") AND logicalDelete = false ORDER BY idUserHistory DESC LIMIT 1");

    Query query = getEntityManager().createQuery(queryString.toString());
    query.setMaxResults(1);

    List<UserHistory> result = query.getResultList();

    if (result.size() > 0) {
        return result.get(0);
    }

    return null;
}

From source file:org.medici.bia.dao.user.UserDAOJpaImpl.java

/**
 * {@inheritDoc}/*  w w w .  ja  v a2  s .c  om*/
 */
@SuppressWarnings("unchecked")
@Override
public Page findForumMembers(String letter, PaginationFilter paginationFilter) {
    String queryString;
    if (letter.equals("All")) {
        queryString = "FROM User WHERE forumJoinedDate IS NOT NULL ORDER BY account";
    } else {
        queryString = "FROM User WHERE forumJoinedDate IS NOT NULL AND account LIKE '" + letter
                + "%' ORDER BY account";

    }
    // We prepare object of return method.
    Page page = new Page(paginationFilter);
    Query query = null;

    // We set size of result.
    if (paginationFilter.getPageTotal() == null) {
        String countQuery = "SELECT COUNT(*) " + queryString;

        query = getEntityManager().createQuery(countQuery);
        page.setTotal(new Long((Long) query.getSingleResult()));
        page.setTotalPages(PageUtils.calculeTotalPages(page.getTotal(), page.getElementsForPage()));
    } else {
        page.setTotal(paginationFilter.getTotal());
        page.setTotalPages(paginationFilter.getPageTotal());
    }

    query = getEntityManager().createQuery(queryString);

    // We set pagination  
    query.setFirstResult(PageUtils.calculeStart(page.getThisPage(), page.getElementsForPage()));
    query.setMaxResults(page.getElementsForPage());
    // We manage sorting (this manages sorting on multiple fields)
    List<User> list = (List<User>) query.getResultList();
    // We set search result on return method
    page.setList(list);

    return page;
}

From source file:org.medici.bia.dao.userhistory.UserHistoryDAOJpaImpl.java

/**
 * {@inheritDoc}/*from w  w  w . j  a  va2 s  .  com*/
 */
@SuppressWarnings("unchecked")
@Override
public List<UserHistory> findHistory(User user, Integer resultSize) {
    String queryString = "FROM UserHistory WHERE user=:user and logicalDelete=false ORDER BY dateAndTime DESC";

    Query query = getEntityManager().createQuery(queryString);

    query.setParameter("user", user);
    query.setMaxResults(resultSize);

    return query.getResultList();
}