Example usage for org.hibernate Query setFirstResult

List of usage examples for org.hibernate Query setFirstResult

Introduction

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

Prototype

@Override
    Query<R> setFirstResult(int startPosition);

Source Link

Usage

From source file:com.algoTrader.entity.TransactionDaoBase.java

/**
 * {@inheritDoc}//w  w w. j av  a2s .  c  o  m
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findAllTrades(final int transform, final String queryString, int pageNumber, int pageSize) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        if (pageNumber > 0 && pageSize > 0) {
            queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize));
            queryObject.setMaxResults(pageSize);
        }
        List results = queryObject.list();
        transformEntities(transform, results);
        return results;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.algoTrader.entity.TransactionDaoBase.java

/**
 * {@inheritDoc}/*  w ww  .j av a  2  s .  c  om*/
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findAllCashflows(final int transform, final String queryString, int pageNumber, int pageSize) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        if (pageNumber > 0 && pageSize > 0) {
            queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize));
            queryObject.setMaxResults(pageSize);
        }
        List results = queryObject.list();
        transformEntities(transform, results);
        return results;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.alibaba.intl.bcds.goldroom.dao.impl.LendingDaoImpl.java

License:Open Source License

public List<Lending> listLendingByLoginId(String loginId, int page, int pageSize) {
    Query q = this.createNamedQuery("listLendingByLoginId");
    q.setParameter("loginId", loginId);
    return q.setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list();
}

From source file:com.alibaba.intl.bcds.goldroom.dao.impl.LendingDaoImpl.java

License:Open Source License

public List<Lending> listByLoginId(String loginId, int page, int pageSize) {
    Query q = this.createNamedQuery("listLendingByLoginId");
    q.setParameter("loginId", loginId);
    return q.setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list();
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findByHQLQuery(final String hql, final int begin, final int count) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createQuery(hql);
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }/*from  w w  w  .j a  v a2 s  .  c  om*/
            return query.list();
        }
    });
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findByNamedQuery(final String name, final int begin, final int count) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.getNamedQuery(name);
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }/*w ww  . ja va  2 s . com*/
            return query.list();
        }
    });
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findByNamedQuery(final String name, final Map params, final int begin, final int count) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.getNamedQuery(name);
            if (null != params) {
                for (Iterator i = params.entrySet().iterator(); i.hasNext();) {
                    Map.Entry entry = (Map.Entry) i.next();
                    query.setParameter((String) entry.getKey(), entry.getValue());
                }/*from ww  w. j  a v a 2s  .  c o  m*/
            }
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }
            return query.list();
        }
    });
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findByNamedQuery(final String name, final Serializable[] params, final int begin, final int count) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.getNamedQuery(name);
            if (null != params) {
                for (int i = 0; i < params.length; i++) {
                    query.setParameter(i, params[i]);
                }/*from ww  w. j a va 2s.  c om*/
            }
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }
            return query.list();
        }
    });
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findBySQLQuery(final String sql, final int begin, final int count) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createSQLQuery(sql);
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }/*from w ww. ja va 2  s  . co m*/
            return query.list();
        }
    });
}

From source file:com.allinfinance.commquery.dao.CommQueryDAO.java

License:Open Source License

public List findBySQLQuery(final String sql, final int begin, final int count, final Map map) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createSQLQuery(sql);
            Iterator iter = map.keySet().iterator();
            while (iter.hasNext()) {
                String key = iter.next().toString();
                Object obj = map.get(key);
                String[] keys = query.getNamedParameters();
                for (int i = 0; i < keys.length; i++) {
                    if (key != null && key.equals(keys[i])) {
                        if (obj instanceof String) {
                            query.setString(key, obj.toString());
                        }//from w  w  w.  j a  v  a  2 s .  com
                        if (obj instanceof Number) {
                            query.setInteger(key, Integer.parseInt(obj.toString()));
                        }
                        if (obj instanceof BigDecimal) {
                            query.setBigDecimal(key, (BigDecimal) obj);
                        }
                        if (obj instanceof List) {
                            query.setParameterList(key, (List) obj);
                        }
                    }
                }
            }
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }
            return query.list();
        }
    });
}