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.huateng.commquery.dao.CommQueryDAO.java

License:Open Source License

public List<TxnModel> findBySQLQueryModel(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).addScalar("TERM_ID", Hibernate.STRING)
                    .addScalar("INST_DATE", Hibernate.STRING).addScalar("TXN_TYPE", Hibernate.STRING)
                    .addScalar("CUP_SSN", Hibernate.STRING).addScalar("REFE_NUM", Hibernate.STRING)
                    .addScalar("ORDER_TRSNUM", Hibernate.STRING).addScalar("TXN_STATE", Hibernate.STRING)
                    .addScalar("PAN", Hibernate.STRING).addScalar("TRS_AMOUNT", Hibernate.STRING)
                    .addScalar("IPS_MERCHT", Hibernate.STRING)

                    .setResultTransformer(Transformers.aliasToBean(TxnModel.class));
            if (begin >= 0) {
                query.setFirstResult(begin);
                query.setMaxResults(count);
            }/*from w  ww.ja v  a 2  s  .c o m*/
            List<TxnModel> list = query.list();

            return list;
        }
    });
}

From source file:com.hyzy.core.orm.hibernate.HibernateDao.java

License:Apache License

protected Query setPageParameterToSqlQuery(final Query q, final Page<T> page) {

    Assert.isTrue(page.getPageSize() > 0, "Page Size must larger than zero");

    //hibernatefirstResult??0
    q.setFirstResult(page.getFirst() - 1);
    q.setMaxResults(page.getPageSize());

    return q;//from   w  w  w.  j  av a 2 s  . c  o m
}

From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java

License:Open Source License

@Override
public List<DverDetail> findAllRejectedDvers(final int start, final int end) throws DataAccessException {

    logger.info("Find All Rejected Dvers....");
    List rejectedDvers = getHibernateTemplate().executeFind(new HibernateCallback<List<DverDetail>>() {
        @Override//from   w ww.j  av  a  2  s .c o m
        public List<DverDetail> doInHibernate(Session session) throws HibernateException, SQLException {
            org.hibernate.Query q = session.createQuery(FIND_REJECTED_DVERS);
            q.setFirstResult(start);
            q.setMaxResults(end);
            return q.list();
        }
    });

    return (!CollectionUtils.isEmpty(rejectedDvers)) ? rejectedDvers : new ArrayList<DverDetail>();
}

From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java

License:Open Source License

@Override
public List<DverNotif> findAllFailNotifications(final int start, final int end) throws DataAccessException {
    List failNotifs = getHibernateTemplate().executeFind(new HibernateCallback<List<DverNotif>>() {
        @Override/*from  w w w  .  j a  va 2 s . co  m*/
        public List<DverNotif> doInHibernate(Session session) throws HibernateException, SQLException {
            logger.info("find All Failed Notifications ....");
            org.hibernate.Query q = session.createQuery(FIND_FAIL_NOTIFICATIONS);
            q.setFirstResult(start);
            q.setMaxResults(end);
            return q.list();
        }
    });

    return (!CollectionUtils.isEmpty(failNotifs)) ? failNotifs : new ArrayList<DverNotif>();

}

From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java

License:Open Source License

@Override
public List<DverDetail> filterRejectedDvers(Map<String, String> filtermap, int start, int end)
        throws DataAccessException {
    logger.info("filter Rejected DVER's By Scac Or Dot.....");
    Session session = SessionFactoryUtils.getSession(this.getSessionFactory(), true);
    String filterQuery = generateQuery(filtermap, Boolean.FALSE);
    logger.info("filter query for Rejected DVER's is :: " + filterQuery);
    Query filters = session.createQuery(filterQuery);
    filters.setFirstResult(start);/*from  w ww .  j a  v a2s.c o m*/
    filters.setMaxResults(end);
    List result = filters.list();
    session.close();
    return result != null ? result : new ArrayList<DverDetail>();
}

From source file:com.iana.dver.dao.impl.DverUsersDaoImpl.java

License:Open Source License

@Override
public List<DverUsers> findAllUsersByType(final Integer userTypeId, final Integer start, final Integer end,
        final String sortColumnIndex, final String sSortDirection) throws DataAccessException {
    List result = getHibernateTemplate().executeFind(new HibernateCallback<List<DverUsers>>() {
        @Override/*from  ww w. j  a v a2s  .c o m*/
        public List<DverUsers> doInHibernate(Session session) throws HibernateException, SQLException {
            logger.info("find AllUsers By Type ");
            StringBuilder query = new StringBuilder(
                    "FROM DverUsers DU WHERE DU.dverUserType.dverUserTypeId in (2,3) ");
            if (sortColumnIndex.equalsIgnoreCase("0")) {
                query.append("order by DU.companyName ");
            } else if (sortColumnIndex.equalsIgnoreCase("2")) {
                query.append("order by DU.fname ");
            } else if (sortColumnIndex.equalsIgnoreCase("3")) {
                query.append("order by DU.lname ");
            }
            query.append(sSortDirection);

            logger.info("All user listing query is :: " + query.toString());

            Query q = session.createQuery(query.toString());
            q.setFirstResult(start);
            q.setMaxResults(end);
            return q.list();
        }
    });
    return result != null ? result : new ArrayList<DverUsers>();
}

From source file:com.iana.dver.dao.impl.DverUsersDaoImpl.java

License:Open Source License

@Override
public List<DverUsers> filterUserByScacOrDot(Integer userTypeId, Map<String, String> filtermap, Integer start,
        Integer end) throws DataAccessException {
    logger.info("filter User By Scac Or Dot.....");
    Session session = SessionFactoryUtils.getSession(this.getSessionFactory(), true);

    String filterQuery = generateQuery(userTypeId, filtermap, Boolean.FALSE);
    logger.info("user filter query is :: " + filterQuery);

    Query filters = session.createQuery(filterQuery);
    filters.setFirstResult(start);//from w w w. ja  va2 s .c  o  m
    filters.setMaxResults(end);

    List result = filters.list();
    session.close();
    return result != null ? result : new ArrayList<DverUsers>();
}

From source file:com.ikon.dao.ActivityDAO.java

License:Open Source License

/**
 * Get activity date/*from  w  w w.  ja  v  a  2 s .com*/
 */
public static Calendar getActivityDate(String user, String action, String item) throws DatabaseException {
    log.debug("getActivityDate({}, {}, {})", new Object[] { user, action, item });
    String qsAct = "select max(a.date) from Activity a "
            + "where a.user=:user and a.action=:action and a.item=:item";
    String qsNoAct = "select max(a.date) from Activity a "
            + "where (a.action='CREATE_DOCUMENT' or a.action='CHECKIN_DOCUMENT') and a.item=:item";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = null;

        if (action != null) {
            q = session.createQuery(qsAct);
            q.setString("user", user);
            q.setString("action", action);
            q.setString("item", item);
        } else {
            q = session.createQuery(qsNoAct);
            q.setString("item", item);
        }

        Calendar ret = (Calendar) q.setMaxResults(1).uniqueResult();

        if (ret == null) {
            // May be the document has been moved or renamed? 
            ret = Calendar.getInstance();
        }

        log.debug("getActivityDate: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}

From source file:com.ikon.dao.AuthDAO.java

License:Open Source License

/**
 * Update user in database/*from ww  w.j ava2  s . c om*/
 */
public static void updateUser(User user) throws DatabaseException {
    log.debug("updateUser({})", user);
    String qs = "select u.password from User u where u.id=:id";
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        tx = session.beginTransaction();
        Query q = session.createQuery(qs);
        q.setParameter("id", user.getId());
        String password = (String) q.setMaxResults(1).uniqueResult();
        user.setPassword(password);
        session.update(user);
        HibernateUtil.commit(tx);
    } catch (HibernateException e) {
        HibernateUtil.rollback(tx);
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }

    log.debug("updateUser: void");
}

From source file:com.ikon.dao.AuthDAO.java

License:Open Source License

/**
 * Get user from database// w  w  w. ja  v  a  2  s  .  co  m
 */
public static User findUserByPk(String usrId) throws DatabaseException {
    log.debug("findUserByPk({})", usrId);
    String qs = "from User u where u.id=:id";
    Session session = null;

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        Query q = session.createQuery(qs);
        q.setString("id", usrId);
        User ret = (User) q.setMaxResults(1).uniqueResult();
        log.debug("findUserByPk: {}", ret);
        return ret;
    } catch (HibernateException e) {
        throw new DatabaseException(e.getMessage(), e);
    } finally {
        HibernateUtil.close(session);
    }
}