Example usage for org.hibernate Query setMaxResults

List of usage examples for org.hibernate Query setMaxResults

Introduction

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

Prototype

@Override
    Query<R> setMaxResults(int maxResult);

Source Link

Usage

From source file:com.algoTrader.entity.security.SecurityDaoBase.java

/**
 * {@inheritDoc}/*  www .  ja  va2  s .  c o  m*/
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findSecuritiesOnActiveWatchlist(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.StrategyDaoBase.java

/**
 * {@inheritDoc}/*from w w  w . ja v a2  s .c om*/
 */
@Override
@SuppressWarnings("unchecked")
public List<?> findAutoActivateStrategies(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 w w  .  j  av  a 2  s  .c  om
 */
@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}//from   www  . jav a2  s.  co  m
 */
@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.all.rds.service.impl.TopHundredServiceImpl.java

License:Apache License

@Override
public TopPlaylist getRandomTopPlaylist() {
    return hibernateTemplate.execute(new HibernateCallback<TopPlaylist>() {
        @Override/*from ww w .  j a  v a 2  s.c om*/
        public TopPlaylist doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createQuery("From TopPlaylist order by rand()");
            query.setMaxResults(1);
            TopPlaylist topPlaylist = (TopPlaylist) query.uniqueResult();
            query = session.createQuery(
                    "Select ct From CachedTrack ct, TopPlaylistTrack tpt where tpt.playlist=:topPlaylistId and tpt.track=ct.hashcode order by tpt.numTrack");
            query.setParameter("topPlaylistId", topPlaylist.getHashcode());
            @SuppressWarnings("unchecked")
            List<CachedTrack> tracks = query.list();
            topPlaylist.setTracks(tracks);
            return topPlaylist;
        }
    });
}

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  ww  w  .j a v  a  2  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);
            }/*from   ww w. j  a  va 2  s .c o m*/
            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 w w w  .  ja  v  a2  s.  co  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]);
                }//w  ww  .j  a v  a  2 s .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  v  a 2  s  .  c o m
            return query.list();
        }
    });
}