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.person.db.HbPersonNameDAO.java

License:Apache License

/**
 * @see edu.ur.ir.person.PersonNameDAO#getCollectionPersonNamesByChar(int, int, edu.ur.ir.institution.InstitutionalCollection, char, edu.ur.order.OrderType)
 *//*from w  ww  . j  av  a2s.c o m*/
@SuppressWarnings("unchecked")
public List<PersonName> getCollectionPersonNamesByChar(final int rowStart, final int maxResults,
        final InstitutionalCollection collection, final char firstChar, final OrderType orderType) {

    List<PersonName> personNames = (List<PersonName>) 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("getCollectionPersonNameByCharOrderDesc");
                    } else {
                        q = session.getNamedQuery("getCollectionPersonNameByCharOrderAsc");
                    }

                    q.setLong(0, collection.getLeftValue());
                    q.setLong(1, collection.getRightValue());
                    q.setLong(2, collection.getTreeRoot().getId());
                    q.setCharacter(3, Character.toLowerCase(firstChar));
                    q.setFirstResult(rowStart);
                    q.setMaxResults(maxResults);
                    q.setFetchSize(maxResults);
                    return q.list();
                }
            });
    return personNames;
}

From source file:edu.ur.hibernate.ir.person.db.HbPersonNameDAO.java

License:Apache License

/**
 * @see edu.ur.ir.person.PersonNameDAO#getCollectionPersonNamesByLastName(int, int, edu.ur.ir.institution.InstitutionalCollection, edu.ur.order.OrderType)
 *//*from  w  w  w  . j a  v a 2s .c  o  m*/
@SuppressWarnings("unchecked")
public List<PersonName> getCollectionPersonNamesByLastName(final int rowStart, final int maxResults,
        final InstitutionalCollection collection, final OrderType orderType) {

    List<PersonName> personNames = (List<PersonName>) 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("getCollectionPersonNameByNameOrderDesc");
                    } else {
                        q = session.getNamedQuery("getCollectionPersonNameByNameOrderAsc");
                    }

                    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 personNames;
}

From source file:edu.ur.hibernate.ir.person.db.HbPersonNameDAO.java

License:Apache License

/**
 * @see edu.ur.ir.person.PersonNameDAO#getPersonNamesBetweenChar(int, int, char, char, edu.ur.order.OrderType)
 *//* www  .  j  a  va  2 s . c o m*/
@SuppressWarnings("unchecked")
public List<PersonName> getPersonNamesBetweenChar(final int rowStart, final int maxResults,
        final char firstChar, final char lastChar, final OrderType orderType) {

    List<PersonName> personNames = (List<PersonName>) 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("getPersonNameByCharRangeOrderDesc");
                    } else {
                        q = session.getNamedQuery("getPersonNameByCharRangeOrderAsc");
                    }
                    q.setCharacter(0, Character.toLowerCase(firstChar));
                    q.setCharacter(1, Character.toLowerCase(lastChar));
                    q.setFirstResult(rowStart);
                    q.setMaxResults(maxResults);
                    q.setFetchSize(maxResults);
                    return q.list();
                }
            });
    return personNames;
}

From source file:edu.ur.hibernate.ir.person.db.HbPersonNameDAO.java

License:Apache License

/**
 * @see edu.ur.ir.person.PersonNameDAO#getPersonNamesByChar(int, int, char, edu.ur.order.OrderType)
 *///from w  w  w .java 2  s. co  m
@SuppressWarnings("unchecked")
public List<PersonName> getPersonNamesByChar(final int rowStart, final int maxResults, final char firstChar,
        final OrderType orderType) {

    List<PersonName> personNames = (List<PersonName>) 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("getPersonNameByCharOrderDesc");
                    } else {
                        q = session.getNamedQuery("getPersonNameByCharOrderAsc");
                    }
                    q.setCharacter(0, Character.toLowerCase(firstChar));
                    q.setFirstResult(rowStart);
                    q.setMaxResults(maxResults);
                    q.setFetchSize(maxResults);
                    return q.list();
                }
            });
    return personNames;
}

From source file:edu.ur.hibernate.ir.person.db.HbPersonNameTitleDAO.java

License:Apache License

/**
 * Returns all person name title with a person name id like the specified value.
 * /*from  www  .  j av a  2 s  . co  m*/
 * @param personNameId
 * @param startRecord
 * @param numRecords
 */
@SuppressWarnings("unchecked")
public List<PersonNameTitle> findPersonNameTitleForPersonNameID(final int personNameId, final int startRecord,
        final int numRecords) {

    return (List<PersonNameTitle>) hibernateTemplate.executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            Query query = session.getNamedQuery("findPersonNameTitleForPersonNameID");
            query.setFirstResult(startRecord);
            query.setMaxResults(numRecords);
            query.setInteger(0, personNameId);
            query.setFetchSize(numRecords);
            return query.list();
        }
    });
}

From source file:edu.ur.hibernate.ir.researcher.db.HbFieldDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Field> getFields(final int rowStart, final int numberOfResultsToShow, final String sortType) {

    Query q = null;
    if (sortType.equalsIgnoreCase("asc")) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getFieldsOrderByNameAsc");
    } else {/*from w  w  w. j  a  v  a 2  s . co m*/
        q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("getFieldsOrderByNameDesc");
    }

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

From source file:edu.ur.hibernate.ir.researcher.db.HbResearcherDAO.java

License:Apache License

/**
 * This will return all researchers including those who have set their researcher pages to private.
 * //from  w  w  w.ja v a 2s .  co m
 * Get researchers starting from the specified row and end at specified row.
  * The rows will be sorted by the specified parameter in given order.
 *  
  * @return List of researchers 
  */
@SuppressWarnings("unchecked")
public List<Researcher> getResearchersByLastFirstName(final int rowStart, final int maxResults,
        final OrderType orderType) {

    log.debug("order type = " + orderType);

    Query q = null;
    if (orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getAllResearcherByLastFirstNameAsc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getAllResearcherByLastFirstNameDesc");
    }

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

}

From source file:edu.ur.hibernate.ir.researcher.db.HbResearcherDAO.java

License:Apache License

/**
 * This returns only researchers who have set their page to public.
 * //from  w  w  w .  j  a  v a2  s .c o m
 * Get researchers starting from the specified row and end at specified row.
  * The rows will be sorted by the specified parameter in given order.
 *  
  * @return List of researchers 
  */
@SuppressWarnings("unchecked")
public List<Researcher> getPublicResearchersByLastFirstName(final int rowStart, final int maxResults,
        final OrderType orderType) {
    Query q = null;
    if (orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getAllPublicResearcherByLastFirstNameAsc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getAllPublicResearcherByLastFirstNameDesc");
    }

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

}

From source file:edu.ur.hibernate.ir.statistics.db.HbFileDownloadInfoDAO.java

License:Apache License

/**
 * This retrieves all file download info objects that are currently in the ignore
 * ip ranges./*from  w  w  w.  j a v  a2  s  . c  o m*/
 * 
 * @return the list of file download info objects that are ignored.
 * @see edu.ur.ir.statistics.FileDownloadInfoDAO#getAllDownloadInfoIgnored()
 */
@SuppressWarnings("unchecked")
public List<FileDownloadInfo> getDownloadInfoIgnored(final int rowStart, final int maxResults) {

    List<FileDownloadInfo> foundItems = (List<FileDownloadInfo>) hbCrudDAO.getHibernateTemplate()
            .execute(new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException, SQLException {
                    Query q = session.getNamedQuery("getFileDownloadsIgnored");
                    q.setFirstResult(rowStart);
                    q.setMaxResults(maxResults);
                    q.setCacheable(false);
                    q.setReadOnly(true);
                    q.setFetchSize(maxResults);
                    return q.list();
                }
            });
    return foundItems;
}

From source file:edu.ur.hibernate.ir.statistics.db.HbFileDownloadInfoDAO.java

License:Apache License

/**
 * Get a sum of downlod coungs grouped by IP address order by download count.
 * /*w w  w  . j  a v  a 2 s .co  m*/
 * @see edu.ur.ir.statistics.FileDownloadInfoDAO#getIpOrderByDownloadCount(int, int, edu.ur.order.OrderType)
 */
@SuppressWarnings("unchecked")
public List<IpDownloadCount> getIpOrderByDownloadCount(int rowStart, int maxResults, OrderType orderType) {

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

    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setFetchSize(maxResults);
    return (List<IpDownloadCount>) q.list();
}