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.HbCrudDAO.java

License:Apache License

/**
 * Helper query for find information found 
 * // ww  w . j  a  va 2  s.  c o  m
 * @param queryName - the query to execute
 * @param startRecord - the index to start at 
 * @param numRecords - the number of records to get
 * @return the data found found
 */
@SuppressWarnings("unchecked")
public List<T> getByQuery(final String queryName, final int startRecord, final int numRecords) {
    Query query = sessionFactory.getCurrentSession().getNamedQuery(queryName);
    query.setFirstResult(startRecord);
    query.setMaxResults(numRecords);
    query.setFetchSize(numRecords);
    return query.list();

}

From source file:edu.ur.hibernate.ir.groupspace.db.HbGroupWorkspaceDAO.java

License:Apache License

/**
 * Get the list of group spaces ordered by name.
 * /*from  w w  w . j  a v  a 2s . c  o m*/
 * 
 * @param rowStart - start position
 * @param numberOfResultsToShow - number of rows to grab.
 * @param orderType - Order (Desc/Asc) 
 * 
 * @return list of group spaces found.
 */
@SuppressWarnings("unchecked")
public List<GroupWorkspace> getGroupWorkspacesNameOrder(int rowStart, int numberOfResultsToShow,
        OrderType orderType) {
    Query q = null;
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    if (orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("groupWorkspaceByNameAsc");
    } else {
        q = session.getNamedQuery("groupWorkspaceByNameDesc");
    }

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

From source file:edu.ur.hibernate.ir.groupspace.db.HbGroupWorkspaceDAO.java

License:Apache License

/**
 * Get all group workspaces for a given user - this includes groups they own or belong to a group within the workspace.
 * /*w w  w .j av a2  s. co  m*/
 * @param userId - id of the user to get the group workspaces for
 * 
 * @return - list of all groups the user belongs to.
 */
@SuppressWarnings("unchecked")
public List<GroupWorkspace> getGroupWorkspacesForUser(Long userId, int rowStart, int numberOfResultsToShow,
        OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();
    Query q = null;
    if (orderType.equals(OrderType.ASCENDING_ORDER)) {
        q = session.getNamedQuery("groupWorkspaceByUserIdNameAsc");
    } else {
        q = session.getNamedQuery("groupWorkspaceByUserIdNameDesc");
    }

    q.setParameter("userId", userId);
    q.setFirstResult(rowStart);
    q.setMaxResults(numberOfResultsToShow);
    q.setFetchSize(numberOfResultsToShow);
    return q.list();
}

From source file:edu.ur.hibernate.ir.groupspace.db.HbGroupWorkspaceEmailInviteDAO.java

License:Apache License

/**
 * Get the list of invite infos ordered by inviteor
 * /*from   w  w w. j  ava 2  s .c  o m*/
 * @param rowStart - start position in the list
 * @param maxResults - maximum number of results to retrieve
 * @param orderType - ascending/descending order
 * 
 * @return list of invite infos found
 */
@SuppressWarnings("unchecked")
public List<GroupWorkspaceEmailInvite> getInviteInfosOrderByGroup(int rowStart, int maxResults,
        OrderType orderType) {
    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getGroupWorkspaceEmailInviteOrderByInvitorDesc");
    } else {
        q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("getGroupWorkspaceEmailInviteOrderByInvitorAsc");
    }

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

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

License:Apache License

/**
 * Get the sub or child institutional collections.
 * //w  ww . j  av  a2  s.  c om
 * @see edu.ur.ir.institution.InstitutionalCollectionDAO#getSubInstituionalCollections(java.lang.Long, java.lang.Long, int, int, String)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalCollection> getSubInstituionalCollections(final Long repositoryId,
        final Long parentCollectionId, final int rowStart, final int maxNumToFetch, final String orderType) {
    List<InstitutionalCollection> institutionalCollections = (List<InstitutionalCollection>) hbCrudDAO
            .getHibernateTemplate().execute(new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException, SQLException {
                    Query q = null;
                    if (orderType.equalsIgnoreCase("asc")) {
                        q = session.getNamedQuery("getSubCollectionsByNameAsc");
                    } else {
                        q = session.getNamedQuery("getSubCollectionsByNameDesc");
                    }
                    q.setParameter("repositoryId", repositoryId);
                    q.setParameter("parentCollectionId", parentCollectionId);
                    q.setFirstResult(rowStart);
                    q.setMaxResults(maxNumToFetch);
                    q.setReadOnly(true);
                    q.setFetchSize(maxNumToFetch);
                    return q.list();
                }
            });

    return institutionalCollections;
}

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

License:Apache License

/**
 * Get the root institutional collections.
 * //w w w.  j ava 2s  .  com
 * @see edu.ur.ir.institution.InstitutionalCollectionDAO#getRootInstituionalCollections(java.lang.Long, int, int, String)
 */
@SuppressWarnings("unchecked")
public List<InstitutionalCollection> getRootInstituionalCollections(final Long repositoryId, final int rowStart,
        final int maxNumToFetch, final String orderType) {
    List<InstitutionalCollection> institutionalCollections = (List<InstitutionalCollection>) hbCrudDAO
            .getHibernateTemplate().execute(new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException, SQLException {
                    Query q = null;
                    if (orderType.equalsIgnoreCase("asc")) {
                        q = session.getNamedQuery("getRootCollectionsByNameAsc");
                    } else {
                        q = session.getNamedQuery("getRootCollectionsByNameDesc");
                    }
                    q.setParameter("repositoryId", repositoryId);
                    q.setFirstResult(rowStart);
                    q.setMaxResults(maxNumToFetch);
                    q.setReadOnly(true);
                    q.setFetchSize(maxNumToFetch);
                    return q.list();
                }
            });

    return institutionalCollections;
}

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

License:Apache License

/**
 * Get a list of items for a specified repository by name.
 * //www. j  a v a 2s  .  c o m
 * @param rowStart - Start row to fetch the data from
 * @param maxResulsts - maximum number of results to fetch
 * @param repositoryId - id of the collection to get items 
 * @param orderType - The order to sort by (ascending/descending)
 * 
 * @return List of institutional items
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getRepositoryItemsByName(final int rowStart, final int maxResults,
        final Long repositoryId, final OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();

    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getRepositoryItemsByNameOrderDesc");
    } else {
        q = session.getNamedQuery("getRepositoryItemsByNameOrderAsc");
    }
    q.setLong("repositoryId", repositoryId);
    q.setFirstResult(rowStart);
    q.setMaxResults(maxResults);
    q.setCacheable(false);
    q.setReadOnly(true);
    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
 * //w  w w. j a  v  a 2  s  . com
 * @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 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(final int rowStart, final int maxResults,
        final Long repositoryId, final char firstChar, final OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();

    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getRepositoryItemsByCharOrderDesc");
    } else {
        q = session.getNamedQuery("getRepositoryItemsByCharOrderAsc");
    }
    q.setLong("repositoryId", repositoryId);
    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

/**
 * Get a list of items for a specified repository by between the that have titles
 * that start between the specified characters
 * //from  ww  w.j av a  2  s .  com
 * @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 orderType - The order to sort by (asc/desc)
 * 
 * @return List of institutional items
 */
@SuppressWarnings("unchecked")
public List<InstitutionalItem> getRepositoryItemsBetweenChar(final int rowStart, final int maxResults,
        final Long repositoryId, final char firstChar, final char lastChar, final OrderType orderType) {
    Session session = hbCrudDAO.getSessionFactory().getCurrentSession();

    Query q = null;
    if (orderType.equals(OrderType.DESCENDING_ORDER)) {
        q = session.getNamedQuery("getRepositoryItemsByCharRangeOrderDesc");
    } else {
        q = session.getNamedQuery("getRepositoryItemsByCharRangeOrderAsc");
    }
    q.setLong("repositoryId", repositoryId);
    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

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

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

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

}