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.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getCollectionItemsBetweenChar(int, int, edu.ur.ir.institution.InstitutionalCollection, char, char, java.lang.String)
 *///from  ww w .ja  v a 2s  .c o m
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getCollectionItemsBetweenChar(final int rowStart, final int maxResults,
        final InstitutionalCollection collection, final char firstChar, final char lastChar,
        final OrderType orderType) {

    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getCollectionItemsByCharRangeOrderDesc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getCollectionItemsByCharRangeOrderAsc");
    }

    q.setLong("leftVal", collection.getLeftValue());
    q.setLong("rightVal", collection.getRightValue());
    q.setLong("rootId", collection.getTreeRoot().getId());
    q.setCharacter("firstChar", Character.toLowerCase(firstChar));
    q.setCharacter("lastChar", Character.toLowerCase(lastChar));
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();

}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * //  w ww. j  a v a2  s  . com
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getCollectionItemsByChar(int, int, edu.ur.ir.institution.InstitutionalCollection, char, java.lang.String)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getCollectionItemsByChar(final int rowStart, final int maxResults,
        final InstitutionalCollection collection, final char firstChar, final OrderType orderType) {

    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();

    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getInstitutionalCollectionItemsByCharOrderDesc");
    } else {
        q = session.getNamedQuery("getInstitutionalCollectionItemsByCharOrderAsc");
    }

    q.setLong("leftVal", collection.getLeftValue());
    q.setLong("rightVal", collection.getRightValue());
    q.setLong("rootId", collection.getTreeRoot().getId());
    q.setCharacter("firstChar", Character.toLowerCase(firstChar));
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();
}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getItems(int, int, edu.ur.ir.institution.InstitutionalCollection, java.util.Date, java.util.Date)
 *///from  w w  w  .  j a v a  2s .c  o m
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getItemsOrderByDate(final int rowStart, final int maxResults,
        final InstitutionalCollection collection, final OrderType orderType) {

    List<InstitutionalItem> foundItems = (List<InstitutionalItem>) hbCrudDAO.getHibernateTemplate()
            .execute(new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException, SQLException {
                    Query q = null;

                    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
                        q = session.getNamedQuery("getInstitutionalCollectionItemsByAcceptedDateDesc");
                    } else {
                        q = session.getNamedQuery("getInstitutionalCollectionItemsByAcceptedDateAsc");
                    }

                    q.setLong(0, collection.getId());

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

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * Get the list of collection items by id.
 * /*from   w w w.j  a  v  a 2 s.  c o  m*/
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getCollectionItemsById(int, int, edu.ur.ir.institution.InstitutionalCollection, edu.ur.order.OrderType)
 */
@SuppressWarnings("unchecked")
public List<Long> getCollectionItemsIds(final int rowStart, final int maxResults,
        final InstitutionalCollection collection, final OrderType orderType) {
    List<Long> foundIds = (List<Long>) hbCrudDAO.getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = null;
            if (orderType.equals(OrderType.DESCENDING_ORDER)) {
                q = session.getNamedQuery("getInstitutionalCollectionItemIdsOrderDesc");
            } else {
                q = session.getNamedQuery("getInstitutionalCollectionItemIdsOrderAsc");
            }

            q.setLong(0, collection.getLeftValue());
            q.setLong(1, collection.getRightValue());
            q.setLong(2, collection.getTreeRoot().getId());
            q.setFirstResult(rowStart);
            q.setMaxResults(maxResults);
            q.setFetchSize(maxResults);
            return q.list();
        }
    });

    return foundIds;
}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * Get a list of items for a specified repository by between the that have titles
 * that start between the specified characters
 * /*from w ww . j  ava 2  s .c om*/
 * NOTE: This search includes all items in child collections
 * 
 * @param rowStart - Start row to fetch the data from
 * @param maxResulsts - maximum number of results to fetch
 * @param collection - the institutional collection 
 * @param contentTypeId - content type id the items must have
 * @param firstChar - first character in range that the first letter of the name can have
 * @param lastChar - last character in range that the first letter of the name can have
 * @param orderType - The order to sort by (asc/desc)
 * 
 * @return list of items matching the specified criteria
 * 
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getCollectionItemsBetweenChar(int, int, edu.ur.ir.institution.InstitutionalCollection, java.lang.Long, char, char, edu.ur.order.OrderType)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getCollectionItemsBetweenChar(int rowStart, int maxResults,
        InstitutionalCollection collection, Long contentTypeId, char firstChar, char lastChar,
        OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getCollectionItemsContentTypeByCharRangeOrderDesc");
    } else {
        q = session.getNamedQuery("getCollectionItemsContentTypeByCharRangeOrderAsc");
    }

    q.setParameter("leftVal", collection.getLeftValue());
    q.setParameter("rightVal", collection.getRightValue());
    q.setParameter("rootId", collection.getTreeRoot().getId());
    q.setParameter("firstChar", Character.valueOf(Character.toLowerCase(firstChar)));
    q.setParameter("lastChar", Character.valueOf(Character.toLowerCase(lastChar)));
    q.setParameter("contentTypeId", contentTypeId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();

}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * Get a list of items for a specified collection by first character of the name
 * /* w w  w.  j a  v a 2  s .  c  om*/
 * NOTE: This search includes all items in child collections
 * 
 * @param rowStart - Start row to fetch the data from
 * @param maxResulsts - maximum number of results to fetch
 * @param institutional collection - the institutional collection 
 * @param contentTypeId - id of the content type 
 * @param firstChar - first character that the name should have
 * @param orderType - The order to sort by (asc/desc)
 * 
 * @return List of institutional items
 * 
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getCollectionItemsByChar(int, int, edu.ur.ir.institution.InstitutionalCollection, java.lang.Long, char, edu.ur.order.OrderType)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getCollectionItemsByChar(int rowStart, int maxResults,
        InstitutionalCollection collection, Long contentTypeId, char firstChar, OrderType orderType) {

    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getInstitutionalCollectionItemsContentTypeByCharOrderDesc");
    } else {
        q = session.getNamedQuery("getInstitutionalCollectionItemsContentTypeByCharOrderAsc");
    }

    q.setParameter("leftVal", collection.getLeftValue());
    q.setParameter("rightVal", collection.getRightValue());
    q.setParameter("rootId", collection.getTreeRoot().getId());
    q.setParameter("firstChar", Character.valueOf(Character.toLowerCase(firstChar)));
    q.setParameter("contentTypeId", contentTypeId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();
}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * Get the list of items for the specified collection with the given 
 * content type id.  This includes items in child collections
 * //from w  w w .ja  va2 s  .co  m
 * @param rowStart - Start row to fetch the data from
 * @param maxResults -  maximum number of results to return
 * @param collection - the collection to get items 
 * @param contentTypeId - id of the content type
 * @param orderType - The order to sort by (ascending/descending)
 * 
 * @return List of institutional items
 * 
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getCollectionItemsByName(int, int, edu.ur.ir.institution.InstitutionalCollection, java.lang.Long, edu.ur.order.OrderType)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getCollectionItemsByName(int rowStart, int maxResults,
        InstitutionalCollection collection, Long contentTypeId, OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getInstitutionalCollectionItemsContentTypeByNameOrderDesc");
    } else {
        q = session.getNamedQuery("getInstitutionalCollectionItemsContentTypeByNameOrderAsc");
    }

    q.setParameter("leftVal", collection.getLeftValue());
    q.setParameter("rightVal", collection.getRightValue());
    q.setParameter("rootId", collection.getTreeRoot().getId());
    q.setParameter("contentTypeId", contentTypeId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();
}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * Get a list of items for a specified repository by between the that have titles
 * that start between the specified characters with the given content type id
 * //  w  w w .  ja  v a2  s  .c om
 * @param rowStart - Start row to fetch the data from
 * @param maxResulsts - maximum number of results to fetch
 * @param repositoryId - id of the repository to get items 
 * @param firstChar - first character in range that the first letter of the name can have
 * @param lastChar - last character in range that the first letter of the name can have
 * @param contentTypeId - id of the content type
 * @param orderType - The order to sort by (asc/desc)
 * 
 * @return List of institutional items
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getRepositoryItemsBetweenChar(int, int, java.lang.Long, char, char, java.lang.Long, edu.ur.order.OrderType)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getRepositoryItemsBetweenChar(int rowStart, int maxResults, Long repositoryId,
        char firstChar, char lastChar, Long contentTypeId, OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getRepositoryItemsContentTypeByCharRangeOrderDesc");
    } else {
        q = session.getNamedQuery("getRepositoryItemsContentTypeByCharRangeOrderAsc");
    }

    q.setParameter("repositoryId", repositoryId);
    q.setParameter("firstChar", Character.valueOf(Character.toLowerCase(firstChar)));
    q.setParameter("lastChar", Character.valueOf(Character.toLowerCase(lastChar)));
    q.setParameter("contentTypeId", contentTypeId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();
}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * Get a list of items for a specified repository by first character of the name and
 * the given content type id// w w w .j av a  2  s  .c om
 * 
 * @param rowStart - Start row to fetch the data from
 * @param maxResults - maximum number of results to fetch
 * @param repositoryId - id of the repository to get items 
 * @param contentTypeId - id of the content type
 * @param firstChar - first character that the name should have
 * @param orderType - The order to sort by (asc/desc)
 * 
 * @return List of institutional items
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getRepositoryItemsByChar(int rowStart, int maxResults, Long repositoryId,
        Long contentTypeId, char firstChar, OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getRepositoryItemsContentTypeByCharOrderDesc");
    } else {
        q = session.getNamedQuery("getRepositoryItemsContentTypeByCharOrderAsc");
    }

    q.setParameter("repositoryId", repositoryId);
    q.setParameter("char", Character.valueOf(Character.toLowerCase(firstChar)));
    q.setParameter("contentTypeId", contentTypeId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();
}

From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java

License:Apache License

/**
 * Get a list of items for a specified repository with the given content type id.
 * //from www .  j a va 2s  . co m
 * @param rowStart - Start row to fetch the data from
 * @param rowEnd -  End row to get data
 * @param repositoryId - id of the repository to get items 
 * @param contentTypeId - id of the content type
 * @param propertyName - The property to sort on
 * @param orderType - The order to sort by (ascending/descending)
 * 
 * @return List of institutional items
 * @see edu.ur.ir.institution.InstitutionalItemDAO#getRepositoryItemsOrderByName(int, int, java.lang.Long, java.lang.Long, edu.ur.order.OrderType)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getRepositoryItemsOrderByName(int rowStart, int maxResults, Long repositoryId,
        Long contentTypeId, OrderType orderType) {

    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getRepositoryItemsContentTypeByNameOrderDesc");
    } else {
        q = session.getNamedQuery("getRepositoryItemsContentTypeByNameOrderAsc");
    }

    q.setParameter("repositoryId", repositoryId);
    q.setParameter("contentTypeId", contentTypeId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return q.list();

}