List of usage examples for org.hibernate Query setFirstResult
@Override
Query<R> setFirstResult(int startPosition);
From source file:cn.dao.MedicinePurchaseDao.java
public List<Object> queryInfo(MedicinePurchase vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("select t.batch_number,t.purchase_date,u.name"); hql.append(" from medicine_purchase t"); hql.append(" left join user_info u"); hql.append(" on t.user_id = u.id"); hql.append(" group by t.batch_number,t.purchase_date,u.name"); hql.append(" order by t.purchase_date desc"); Query query = session.createSQLQuery(hql.toString()); if (page != null) { int items = getPageCount(session, hql.toString(), properties); page.setItems(items);/*from www. j a v a 2 s .c om*/ query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }
From source file:cn.dao.MedicinePurchaseDao.java
public List<Object> queryByBatchNumber(MedicinePurchase vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("select u.license_number,u.medicine_name,t.cost_price,t.number"); hql.append(" from medicine_purchase t"); hql.append(" left join medicine_info u"); hql.append(" on t.medicine_id = u.id"); hql.append(" where t.batch_number = :batchNumber"); hql.append(" order by t.purchase_date desc"); Query query = session.createSQLQuery(hql.toString()); properties.put("batchNumber", vo.getBatchNumber()); query.setProperties(properties);//from w ww . ja v a 2 s . c o m if (page != null) { int items = getPageCount(session, hql.toString(), properties); page.setItems(items); query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }
From source file:cn.dao.MedicineSalesDao.java
@SuppressWarnings("unchecked") public List<Object> query(MedicineSales vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("select t.sale_batch_number,t.sale_date,u.name"); hql.append(" from medicine_sales t"); hql.append(" left join user_info u"); hql.append(" on t.user_id = u.id"); hql.append(" group by t.sale_batch_number,t.sale_date,u.name"); hql.append(" order by t.sale_date desc"); Query query = session.createSQLQuery(hql.toString()); query.setProperties(properties);//from ww w . ja va 2 s . c o m if (page != null) { int items = getPageCount(session, hql.toString(), properties); page.setItems(items); query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }
From source file:cn.dao.MedicineSalesDao.java
public List<Object> queryByBatchNumber(MedicineSales vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("select u.license_number,u.medicine_name,t.sale_price,t.sale_number"); hql.append(" from medicine_sales t"); hql.append(" left join medicine_storehouse s"); hql.append(" on t.medicine_store_house_id = s.id"); hql.append(" left join medicine_info u"); hql.append(" on s.medicine_id = u.id"); hql.append(" where t.sale_batch_number = :batchNumber"); hql.append(" order by t.sale_date desc"); Query query = session.createSQLQuery(hql.toString()); properties.put("batchNumber", vo.getSaleBatchNumber()); query.setProperties(properties);/*from ww w.j a va 2 s . com*/ if (page != null) { int items = getPageCount(session, hql.toString(), properties); page.setItems(items); query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }
From source file:cn.dayuanzi.dao.BaseDao.java
License:Apache License
/** * //from w ww . java 2 s. c o m * * @param hql * @param current_page * @param max_num * @param map * @return */ public List<T> findForPage(String hql, int current_page, int max_num, Map<String, Object> map) { List<T> result = null; if (current_page <= 0) { current_page = 1; } if (max_num > 20) { max_num = 20; } else if (max_num <= 0) { max_num = 1; } try { if (!hql.contains("where")) { hql = hql.concat(" where 1=1 "); } if (map != null) { Set<String> keys = map.keySet(); for (String key : keys) { hql = hql.concat(" and " + key + " =:" + key); } } Query query = this.getSession().createQuery(hql); Iterator<String> it = map.keySet().iterator(); while (it.hasNext()) { String key = it.next(); query.setParameter(key, map.get(key)); } query.setFirstResult(((current_page - 1)) * max_num); query.setMaxResults(max_num); result = query.list(); } catch (RuntimeException re) { throw re; } return result; }
From source file:cn.hxh.springside.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Query,./*from w ww. j a va2 s . c om*/ */ protected Query setPageParameterToQuery(final Query q, final PageRequest pageRequest) { q.setFirstResult(pageRequest.getOffset()); q.setMaxResults(pageRequest.getPageSize()); return q; }
From source file:cn.newtouch.util.hibernate.HibernateDao.java
License:Apache License
/** * ?Query,.//w ww .j a v a2 s .co m */ protected Query setPageParameterToQuery(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 source file:cn.newtouch.util.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Query,.//from w w w . j a v a2 s . com */ protected Query setPageParameterToQuery(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 source file:cn.zhuqi.mavenssh.dao.impl.GenericDAO.java
@SuppressWarnings("unchecked") protected T queryForTopObject(String hql, Object[] params) { Query query = getSession().createQuery(hql); setQueryParams(query, params);/*from w w w. j a v a2 s . c o m*/ return (T) query.setFirstResult(0).setMaxResults(1).uniqueResult(); }
From source file:cn.zhuqi.mavenssh.dao.impl.GenericDAO.java
@SuppressWarnings("unchecked") protected List<T> queryForList(final String hql, final Object[] params, final int recordNum) { Query query = getSession().createQuery(hql); setQueryParams(query, params);// w w w . j a v a 2 s .c om return query.setFirstResult(0).setMaxResults(recordNum).list(); }