Example usage for org.hibernate ScrollableResults first

List of usage examples for org.hibernate ScrollableResults first

Introduction

In this page you can find the example usage for org.hibernate ScrollableResults first.

Prototype

boolean first();

Source Link

Document

Go to the first result.

Usage

From source file:org.sakaiproject.tool.assessment.facade.util.PagingUtilQueries.java

License:Educational Community License

public List getAll(final int pageSize, final int pageNumber, final String queryString, final Integer value) {

    HibernateCallback callback = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            ArrayList page = new ArrayList();
            Query q = session.createQuery(queryString);
            if (value != null) {
                q.setInteger(0, value.intValue());
            }//w ww . j  ava  2  s. com
            ScrollableResults assessmentList = q.scroll();
            if (assessmentList.first()) { // check that result set is not empty
                int first = pageSize * (pageNumber - 1);
                int i = 0;
                assessmentList.setRowNumber(first);
                assessmentList.beforeFirst();
                while ((pageSize > i++) && assessmentList.next()) {
                    log.debug("**** add " + i);
                    page.add(assessmentList.get(0));
                }
            }
            return page;
        }
    };
    List pageList = (List) getHibernateTemplate().execute(callback);
    return pageList;
}

From source file:org.smallmind.persistence.orm.hibernate.ScrollIterator.java

License:Open Source License

public ScrollIterator(ScrollableResults scrollableResults, Class<T> managedClass) {

    this.scrollableResults = scrollableResults;
    this.managedClass = managedClass;

    more = scrollableResults.first();
}

From source file:uit.qabpss.util.dao.orm.hibernate.QueryUtil.java

License:Open Source License

public static List<?> randomList(Query query, Dialect dialect, int total, int num, boolean unmodifiable) {

    if ((total == 0) || (num == 0)) {
        return new ArrayList<Object>();
    }// w  w  w.ja  va  2 s .c  o m

    if (num >= total) {
        return list(query, ALL_POS, ALL_POS);
    }

    int[] scrollIds = Randomizer.getInstance().nextInt(total, num);

    List<Object> list = new ArrayList<Object>();

    ScrollableResults sr = query.scroll();

    for (int i = 0; i < scrollIds.length; i++) {
        if (sr.scroll(scrollIds[i])) {
            Object obj = sr.get(0);

            list.add(obj);

            sr.first();
        }
    }

    return list;

}

From source file:vnpt.media.efinder.model.PaginationResult.java

public PaginationResult(Query query, int page, int maxResult, int maxNavigationPage) {
    final int pageIndex = page - 1 < 0 ? 0 : page - 1;
    int fromRecordIndex = pageIndex * maxResult;
    int maxRecordIndex = fromRecordIndex + maxResult;

    ScrollableResults resultScroll = query.scroll(ScrollMode.SCROLL_INSENSITIVE);

    //resultScroll.g
    List results = new ArrayList<>();
    boolean hasResult = resultScroll.first();
    if (hasResult) {
        // Cuon toi vi tri
        hasResult = resultScroll.scroll(fromRecordIndex);
        if (hasResult) {
            do {/*from  www.  jav  a  2 s . c  om*/
                E record = (E) resultScroll.get(0);
                results.add(record);
            } while (resultScroll.next()//
                    && resultScroll.getRowNumber() >= fromRecordIndex
                    && resultScroll.getRowNumber() < maxRecordIndex);
        }

        // chuyen toi ban ghi cuoi
        resultScroll.last();
    }

    // Tong so ban ghi
    this.totalRecords = resultScroll.getRowNumber() + 1;
    this.currentPage = pageIndex + 1;
    this.list = results;
    this.maxResult = maxResult;
    this.totalPages = (this.totalRecords / this.maxResult);
    if (totalRecords % this.maxResult != 0) {
        this.totalPages = this.totalPages + 1;
    }
    this.maxNavigationPage = totalPages;

    if (maxNavigationPage < totalPages) {
        this.maxNavigationPage = maxNavigationPage;
    }

    this.calcNavigationPages();

}