Example usage for org.hibernate Query setFetchSize

List of usage examples for org.hibernate Query setFetchSize

Introduction

In this page you can find the example usage for org.hibernate Query setFetchSize.

Prototype

Query<R> setFetchSize(int fetchSize);

Source Link

Document

Sets a JDBC fetch size hint for the query.

Usage

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * @see edu.ur.ir.user.IrUserDAO#getUsersPendingAffiliationApprovals(int, int, String)
 *//*from w  w  w  .java2s. com*/
@SuppressWarnings("unchecked")
public List<IrUser> getUsersPendingAffiliationApprovals(final int rowStart, final int numberOfResultsToShow,
        final String sortType) {
    List<IrUser> users = (List<IrUser>) hbCrudDAO.getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Query q = null;
            if (sortType.equalsIgnoreCase("asc")) {
                q = session.getNamedQuery("getPendingApprovalsOrderByNameAsc");
            } else {
                q = session.getNamedQuery("getPendingApprovalsOrderByNameDesc");
            }

            q.setFirstResult(rowStart);
            q.setMaxResults(numberOfResultsToShow);
            q.setReadOnly(true);
            q.setFetchSize(numberOfResultsToShow);
            return q.list();
        }
    });

    return users;
}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users for a specified sort criteria.
 * /*  ww w  .ja  va2 s .  com*/
 * @param rowStart - Start row to fetch the data from
 * @param numberOfResultsToShow - maximum number of results to fetch
 * @param sortElement - column to sort on 
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsers(final int rowStart, final int numberOfResultsToShow, final String sortElement,
        final OrderType orderType) {

    Query q = null;
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    if (sortElement.equalsIgnoreCase("lastName") && orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByLastNameOrderAsc");
    } else if (sortElement.equalsIgnoreCase("lastName") && orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByLastNameOrderDesc");
    } else if (sortElement.equalsIgnoreCase("username") && orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByUserNameOrderAsc");
    } else if (sortElement.equalsIgnoreCase("username") && orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByUserNameOrderDesc");
    } else if (sortElement.equalsIgnoreCase("email") && orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByEmailOrderAsc");
    } else if (sortElement.equalsIgnoreCase("email") && orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByEmailOrderDesc");
    }

    q.setFirstResult(rowStart);
    q.setMaxResults(numberOfResultsToShow);
    q.setFetchSize(numberOfResultsToShow);
    return q.list();
}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users by last name order
 * //from  www. j  a  va 2  s  .c o  m
 * @param rowStart - Start row to fetch the data from
 * @param numberOfResultsToShow - maximum number of results to fetch
 * @param sortElement - column to sort on 
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByLastNameOrder(final int rowStart, final int numberOfResultsToShow,
        final OrderType orderType) {

    Query q = null;
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    if (orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByLastNameOrderAsc");
    } else {
        q = session.getNamedQuery("getUsersByLastNameOrderDesc");
    }

    q.setFirstResult(rowStart);
    q.setMaxResults(numberOfResultsToShow);
    q.setFetchSize(numberOfResultsToShow);
    return q.list();
}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users by last name order
 * /*w  w w. j av a 2  s.c  om*/
 * @param rowStart - Start row to fetch the data from
 * @param numberOfResultsToShow - maximum number of results to fetch
 * @param sortElement - column to sort on 
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByUsernameOrder(final int rowStart, final int numberOfResultsToShow,
        final OrderType orderType) {
    Query q = null;
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();

    if (orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByUserNameOrderAsc");
    } else {
        q = session.getNamedQuery("getUsersByUserNameOrderDesc");
    }

    q.setFirstResult(rowStart);
    q.setMaxResults(numberOfResultsToShow);
    q.setFetchSize(numberOfResultsToShow);
    return q.list();
}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users by last name order
 * //from ww  w.j  av  a 2 s .com
 * @param rowStart - Start row to fetch the data from
 * @param numberOfResultsToShow - maximum number of results to fetch
 * @param sortElement - column to sort on 
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByEmailOrder(final int rowStart, final int numberOfResultsToShow,
        final OrderType orderType) {
    Query q = null;
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();

    if (orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("getUsersByEmailOrderAsc");
    } else {
        q = session.getNamedQuery("getUsersByEmailOrderDesc");
    }

    q.setFirstResult(rowStart);
    q.setMaxResults(numberOfResultsToShow);
    q.setFetchSize(numberOfResultsToShow);
    return q.list();
}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users ordered by last name, first name by role
 * //  ww w  .jav a 2 s  .c om
 * @param roleId - the role id
 * @param rowStart - Start row to fetch the data from
 * @param maxResults - maximum number of results to fetch
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByRoleFullNameOrder(Long roleId, int rowStart, int maxResults,
        OrderType orderType) {
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getUserByRoleOrderByNameDesc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getUserByRoleOrderByNameAsc");
    }

    q.setParameter("roleId", roleId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return (List<IrUser>) q.list();
}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users ordered with a specified role by Username
 * /*www.j  av a 2 s. c  o  m*/
 * @param roleId - the role id
 * @param rowStart - Start row to fetch the data from
 * @param maxResults - maximum number of results to fetch
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByRoleUsernameOrder(Long roleId, int rowStart, int maxResults,
        OrderType orderType) {
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getUserByRoleOrderByUsernameDesc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getUserByRoleOrderByUsernameAsc");
    }

    q.setParameter("roleId", roleId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return (List<IrUser>) q.list();

}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users ordered by username for the specified role
 * // w w  w .  j ava2 s  .  c om
 * @param roleId - the role id
 * @param rowStart - Start row to fetch the data from
 * @param maxResults - maximum number of results to fetch
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByRoleEmailOrder(Long roleId, int rowStart, int maxResults, OrderType orderType) {
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getUsersByRoleOrderByEmailDesc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getUsersByRoleOrderByEmailAsc");
    }

    q.setParameter("roleId", roleId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return (List<IrUser>) q.list();

}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users ordered by last name, first name by affiliation
 * /*from www  .  ja  v a 2 s.  com*/
 * @param affiliationId - the affiliation id
 * @param rowStart - Start row to fetch the data from
 * @param maxResults - maximum number of results to fetch
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByAffiliationFullNameOrder(Long affiliationId, int rowStart, int maxResults,
        OrderType orderType) {
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getUserByAffiliationOrderByNameDesc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getUserByAffiliationOrderByNameAsc");
    }

    q.setParameter("affiliationId", affiliationId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return (List<IrUser>) q.list();
}

From source file:edu.ur.hibernate.ir.user.db.HbIrUserDAO.java

License:Apache License

/**
 * Get a list of users ordered with a specified role by Username by affiliation
 * //from w  w w. j a v a2  s . c  om
 * @param affiliationId - the affiliation id
 * @param rowStart - Start row to fetch the data from
 * @param maxResults - maximum number of results to fetch
 * @param sortType - The order to sort by (ascending/descending)
 * 
 * @return List of users
 */
@SuppressWarnings("unchecked")
public List<IrUser> getUsersByAffiliationUsernameOrder(Long affiliationId, int rowStart, int maxResults,
        OrderType orderType) {
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getUserByAffiliationOrderByUsernameDesc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getUserByAffiliationOrderByUsernameAsc");
    }

    q.setParameter("affiliationId", affiliationId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return (List<IrUser>) q.list();
}