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.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());
                        }/*w  w w  . ja  v a2s.c om*/
                        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();
        }
    });
}

From source file:com.app.usercenter.dao.impl.SysFunctionDaoImpl.java

License:Open Source License

@SuppressWarnings("rawtypes")
@Override/*from  w  w w  . j a v a  2 s. c om*/
public Wrapper getAllFunctionsByCataLogId(Long id, PageExtNative page) {
    String hqlCount = "select count(*) from SysFunction sf ";
    String hql = "select sf.sfunId,sf.sfunName,sf.sfunDesc,sf.sfunUrl,"
            + "sf.sfunIndex,sf.sfunCode,sf.sfunIsHidden from SysFunction sf where sf.parentCatalog.scatId=" + id
            + " or sf.parentCatalog.parentCatalog.scatId=" + id;
    List listCount = super.getSession().createQuery(hqlCount).list();
    Query q = super.getSession().createQuery(hql);
    if (page != null && page.getLimit() != 0) {
        q.setFirstResult(page.getStart());
        q.setMaxResults(page.getLimit());
    }
    List list = q.list();
    if (list == null || list.size() == 0) {
        list = super.getSession()
                .createQuery(hql.substring(0, hql.indexOf("where")) + "   where sf.sfunId=" + id).list();
    }
    return new Wrapper(list, listCount.get(0).toString());
}

From source file:com.appeligo.search.entity.Favorite.java

License:Apache License

public static Favorite getTopFavoriteShow(User user) {
    Permissions.checkUser(user);/*from w  w w.java  2s . c o m*/
    Session session = getSession();
    Query query = session.getNamedQuery("Favorite.getFavoriteNonEpisodes");
    query.setMaxResults(1);
    query.setEntity("user", user);
    return (Favorite) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Favorite.java

License:Apache License

public static Favorite getTopFavoriteEpisode(User user) {
    Permissions.checkUser(user);/*from   www .  ja v a  2s .  c  om*/
    Session session = getSession();
    Query query = session.getNamedQuery("Favorite.getFavoriteEpisodes");
    query.setMaxResults(1);
    query.setEntity("user", user);
    return (Favorite) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Message.java

License:Apache License

/**
 * /*from  w  w  w .j a va  2 s  .c om*/
 * @param max
 * @return
 */
@SuppressWarnings("unchecked")
public static List<Message> getUnsentMessages(int maxResults, int maxAttempts) {
    Session session = getSession();
    Query query = session.getNamedQuery("Message.getUnsent");
    query.setTimestamp("now", new Timestamp(System.currentTimeMillis()));
    query.setInteger("maxAttempts", maxAttempts);
    query.setMaxResults(maxResults);
    return query.list();
}

From source file:com.appeligo.search.util.ChunkedResults.java

License:Apache License

public ChunkedResults(Query query, int chunkSize) {
    this.query = query;
    this.chunkSize = chunkSize;
    query.setMaxResults(chunkSize);
    beforeFirst();/*from  www . j  a  va  2s . c o  m*/
}

From source file:com.aprotrain.sl.dal.dao.impl.EmployeeServiceImpl.java

public Employee checkLogin(String internalEmail, String password) {
    Session session = this.getSession();

    Query query = session.createQuery("FROM Employee WHERE internalEmail=:mail AND password=:password");
    query.setString("mail", internalEmail);
    query.setString("password", password);
    query.setMaxResults(1);

    List<Employee> list = query.list();
    Employee e = null;/*from w  w w . j av  a2s  . c om*/
    if (!list.isEmpty()) {
        e = list.get(0);
    }

    session.close();

    return e;
}

From source file:com.aptech.model.AbstractDao.java

public List paging(Class clazz, Integer pageNumber, Integer perPage) {
    List objects = null;/* w  ww.ja  va2 s .c o  m*/
    try {
        startOperation();
        Query query = session.createQuery("from " + clazz.getName());
        query.setMaxResults(perPage);
        query.setFirstResult(pageNumber);
        objects = query.list();
        tx.commit();
    } catch (HibernateException e) {
        handleException(e);
    } finally {
        HibernateFactory.close(session);
    }
    return objects;
}

From source file:com.aptech.model.OrderDao.java

public List findLatest() {
    List objects = null;/*  w  ww  .j a  v a 2  s .  c o m*/
    try {
        startOperation2();
        Query query = session.createQuery("from " + Order.class.getName() + " o ORDER BY o.id DESC");
        query.setMaxResults(8);
        objects = query.list();
        tx.commit();
    } catch (HibernateException e) {
        handleException(e);
    } finally {
        HibernateFactory.close(session);
    }
    return objects;
}

From source file:com.aptech.model.ProductDao.java

public List paging(Integer pageNumber, Integer perPage) {
    List objects = null;/*from w w  w  .  j  a  va 2 s . com*/
    try {
        startOperation2();
        Query query = session.createQuery("from " + Product.class.getName());
        query.setMaxResults(perPage);
        query.setFirstResult(pageNumber);
        objects = query.list();
        tx.commit();
    } catch (HibernateException e) {
        handleException(e);
    } finally {
        HibernateFactory.close(session);
    }
    return objects;
}