List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final int maxResults, final QueryType type, final NamedParam... params) { Query query = createQuery(queryString, type); if (lockOptions != null) { query.setLockOptions(lockOptions); }//w w w.j a v a 2 s . c o m if (maxResults > 0) { query.setMaxResults(maxResults); } applyParameters(query, params); return query; }
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final boolean cacheable, final int maxResults, final QueryType type) { Query query = createQuery(queryString, type); if (lockOptions != null) { query.setLockOptions(lockOptions); }//w w w. j av a 2s .c om query.setCacheable(cacheable); if (maxResults > 0) { query.setMaxResults(maxResults); } return query; }
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final boolean cacheable, final int maxResults, final QueryType type, final Object... params) { Query query = createQuery(queryString, type); if (lockOptions != null) { query.setLockOptions(lockOptions); }/*w w w .j ava 2 s . c om*/ query.setCacheable(cacheable); if (maxResults > 0) { query.setMaxResults(maxResults); } applyParameters(query, params); return query; }
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final boolean cacheable, final int maxResults, final QueryType type, final NamedParam... params) { Query query = createQuery(queryString, type); if (lockOptions != null) { query.setLockOptions(lockOptions); }/*w w w . j a va 2 s . c o m*/ query.setCacheable(cacheable); if (maxResults > 0) { query.setMaxResults(maxResults); } applyParameters(query, params); return query; }
From source file:ch.tatool.app.service.impl.TrialDAO.java
License:Open Source License
/** Get all trials for a given session. */ @SuppressWarnings("unchecked") public List<Trial> getTrials(final ModuleImpl module, final ModuleSession moduleSession, final String elementNameLike, final String propertyNameLike, final int offset, final int maxResults) { if (elementNameLike == null && propertyNameLike == null) { throw new RuntimeException("Either elementName or propertyName needs to be non-null"); }/*from w w w . j av a 2 s . co m*/ return (List<Trial>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { getHibernateTemplate().update(module); if (moduleSession != null) { getHibernateTemplate().update(moduleSession); } StringBuilder q = new StringBuilder(); q.append("select distinct(trial) from TrialImpl trial "); q.append(" join trial.entriesImpl as entry where "); if (moduleSession != null) { q.append(" trial.session = :session "); } else { q.append(" trial.session.module = :module "); } if (elementNameLike != null) { q.append(" and entry.nodeId like :elementName"); } if (propertyNameLike != null) { q.append(" and entry.name like :propName"); } // sort reverse q.append(" order by trial.id DESC"); // create the query and set the various parameters Query query = session.createQuery(q.toString()); if (moduleSession != null) { query.setParameter("session", moduleSession); } else { query.setParameter("module", module); } if (elementNameLike != null) { query.setParameter("elementName", elementNameLike); } if (propertyNameLike != null) { query.setParameter("propName", propertyNameLike); } // limit results if requested if (offset > 0) { query.setFirstResult(offset); } if (maxResults > -1) { query.setMaxResults(maxResults); } List<Trial> trials = (List<Trial>) query.list(); // make sure we set the moduleSession correctly if (moduleSession != null) { for (Trial t : trials) { t.setSession(moduleSession); } } return trials; } }); }
From source file:classe.restaurantUtil.java
cents() { List<Restaurant> listeResto = null; /*w ww . jav a 2 s.c o m*/ Transaction tx = null; this.session = HibernateUtil.getSessionFactory().openSession(); try { tx = session.beginTransaction(); Query requete = session.createQuery("FROM Restaurant ORDER BY Idresto DESC"); requete.setFirstResult(0); requete.setMaxResults(3); listeResto = requete.list(); } catch (Exception e) { e.printStackTrace(); } this.session.close(); return listeResto; }
From source file:cn.dao.MedicineInfoDao.java
@SuppressWarnings("unchecked") public List<MedicineInfo> query(MedicineInfo vo, PageResult page) { Session session = this.getSessionFactory().getCurrentSession(); Map<String, Object> properties = new HashMap<>(); StringBuffer hql = new StringBuffer(); hql.append("from MedicineInfo"); hql.append(" where 1=1"); if (vo.getMedicineName() != null && !"".equals(vo.getMedicineName())) { hql.append(" and medicineName like :medicineName"); properties.put("medicineName", "%" + vo.getMedicineName() + "%"); }//w w w . j av a 2s.c om int items = getPageCount(session, hql.toString(), properties); page.setItems(items); Query query = session.createQuery(hql.toString()); query.setProperties(properties); if (page != null) { query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }
From source file:cn.dao.MedicineInfoDao.java
public List<MedicineInfo> queryFuzzy(String search) { Session session = this.getSessionFactory().getCurrentSession(); StringBuffer hql = new StringBuffer(); hql.append("from MedicineInfo"); hql.append(" where licenseNumber like :search"); hql.append(" or medicineName like :search"); hql.append(" or medicineENName like :search"); Query query = session.createQuery(hql.toString()); query.setString("search", "%" + search + "%"); query.setMaxResults(10); return query.list(); }
From source file:cn.dao.MedicinePurchaseDao.java
@SuppressWarnings("unchecked") public List<Object> query(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()); query.setProperties(properties);/*from w w w . 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.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);//w ww . j a v a 2s . c o m query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResult()); } return query.list(); }