List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.globalsight.everest.costing.CostingEngineLocal.java
License:Apache License
private float getCurrencyFactorByName(String targetName, String companyId) { StringBuilder sb = new StringBuilder(); sb.append("select new Currency(c.conversionFactor) "); sb.append("from Currency c "); sb.append("where c.isoCurrency.name like :targetName "); sb.append("and c.companyId = :companyId"); Session session = HibernateUtil.getSession(); Transaction transaction = session.beginTransaction(); Query query = session.createQuery(sb.toString()); query.setString("targetName", targetName + "%"); query.setString("companyId", companyId); query.setMaxResults(1); Currency currency = (Currency) query.uniqueResult(); transaction.commit();/* w w w.j a v a 2 s . c om*/ return currency.getConversionFactor(); }
From source file:com.globalsight.everest.costing.CostingEngineLocal.java
License:Apache License
public Currency getCurrencyByName(String targetName, String companyId) throws RemoteException, CostingException, GeneralException { StringBuilder sb = new StringBuilder(); sb.append("from Currency c "); sb.append("where c.isoCurrency.name like :targetName "); sb.append("and c.companyId = :companyId"); Session session = HibernateUtil.getSession(); Transaction transaction = session.beginTransaction(); Query query = session.createQuery(sb.toString()); query.setString("targetName", targetName + "%"); query.setString("companyId", companyId); query.setMaxResults(1); Currency currency = (Currency) query.uniqueResult(); transaction.commit();/*from ww w. j av a 2s . co m*/ return currency; }
From source file:com.globalsight.everest.tuv.TuvManagerLocal.java
License:Apache License
/** * Gets the TaskTuvs from the end of each of the previous stages of the * workflow in reverse chronological order. The parameter p_maxResultNum is * ignored.//from w w w . j a v a 2 s .c o m * * @param p_tuvId * unique identifier of a Tuv object. * @param p_maxResultNum * maximum number of TaskTuvs to return. * @return reverse chronological ordered List of TaskTuvs. * @throws TuvException * when an error occurs. * @throws RemoteException * when a communication-related error occurs. */ public List getPreviousTaskTuvs(long p_tuvId, int p_maxResultNum) throws TuvException, RemoteException { String hql = " from TaskTuv t where t.currentTuvId= :tuvId order by t.version desc"; Session session = HibernateUtil.getSession(); Query query = session.createQuery(hql); query.setMaxResults(p_maxResultNum); query.setLong("tuvId", p_tuvId); List taskTuvs = query.list(); // session.close(); if (CATEGORY.isDebugEnabled()) { CATEGORY.debug("getPreviousTaskTuvs" + " p_tuvId=" + p_tuvId + " returned " + taskTuvs.size() + " TaskTuvs=" + taskTuvs.toString()); } return taskTuvs; }
From source file:com.globalsight.persistence.hibernate.HibernateUtil.java
License:Apache License
/** * Execute the hql, return the result.// ww w.j a v a 2s. c o m * * @param hql * the hql to execute. * @param values * @return * @throws Exception */ public static List<?> search(String hql, Map<String, ?> map, int first, int max) { List<?> result = new ArrayList<Object>(); if (hql != null) { Session session = getSession(); Query query = session.createQuery(hql); if (map != null) { Iterator<String> iterator = map.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); query.setParameter(key, map.get(key)); } } if (first > 0) { query.setFirstResult(first); } if (max > 0) { query.setMaxResults(max); } result = query.list(); } return result; }
From source file:com.gmvc.server.impl.CRUDImpl.java
License:LGPL
/** * Model listesi/*from w ww . j a v a 2 s . c om*/ * * Simdilik numeric ve string sahalar icin, esit ve yakin aramalar yapiyor * * TODO: Gelistirilecek! * * @param filter kayit eleme yapilacaksa bu parametre kullanilacak * * @return List client model listesi */ public List<C> getModelList(FilterItem masterFilter, FilterItem filter) { Session session = DBUtils.getSession(); try { session.beginTransaction(); StringBuilder querySB = new StringBuilder("from "); querySB.append(serverClass.getSimpleName()); if (masterFilter != null && masterFilter.getValue() != null && !masterFilter.getValue().equals("")) { querySB.append(" where "); querySB.append(masterFilter.getFieldName()); if (masterFilter.getSearchType().equals(SearchType.EQUAL)) { querySB.append(" = "); querySB.append(masterFilter.getValue()); } else { querySB.append(" like '"); querySB.append(masterFilter.getValue()); querySB.append("%'"); } } if (filter != null && filter.getValue() != null && !filter.getValue().equals("")) { if (masterFilter != null) querySB.append(" and "); else querySB.append(" where "); querySB.append(filter.getFieldName()); if (filter.getSearchType().equals(SearchType.EQUAL)) { querySB.append(" = "); querySB.append(filter.getValue()); } else { querySB.append(" like '"); querySB.append(filter.getValue()); querySB.append("%'"); } } Query query = session.createQuery(querySB.toString()); if (getMaxResultSize() > 0) query.setMaxResults(getMaxResultSize()); List<S> serverModelList = query.list(); List<C> result = new ArrayList<C>(serverModelList.size()); for (S serverModel : serverModelList) { result.add(DBUtils.getMapper().map(serverModel, clientClass)); } session.getTransaction().commit(); return result; } catch (Exception e) { session.getTransaction().rollback(); return null; } }
From source file:com.googlecode.fahweb.dao.TeamDao.java
License:Open Source License
/** * <p>listTeam.</p>/*from w w w .j ava 2 s . c o m*/ * * @param firstResult a int. * @param maxResults a int. * @return a {@link java.util.List} object. */ @Transactional public List<Team> listTeam(int firstResult, int maxResults) { Query query = sessionFactory.getCurrentSession().createQuery("FROM Team ORDER BY score DESC"); query.setFirstResult(firstResult); query.setMaxResults(maxResults); return query.list(); }
From source file:com.googlecode.fahweb.dao.UserDao.java
License:Open Source License
/** * <p>listUser.</p>/*from w w w. ja va 2s. co m*/ * * @param firstResult a int. * @param maxResults a int. * @return a {@link java.util.List} object. */ @Transactional public List<User> listUser(int firstResult, int maxResults) { Query query = sessionFactory.getCurrentSession().createQuery("FROM User ORDER BY newCredit DESC"); query.setFirstResult(firstResult); query.setMaxResults(maxResults); return query.list(); }
From source file:com.googlecode.fahweb.dao.UserDao.java
License:Open Source License
/** * <p>listUserForTeam.</p>/*from www . j a v a2s. c o m*/ * * @param team a int. * @param firstResult a int. * @param maxResults a int. * @return a {@link java.util.List} object. */ @Transactional public List<User> listUserForTeam(int team, int firstResult, int maxResults) { Query query = sessionFactory.getCurrentSession() .createQuery("FROM User WHERE team=:team ORDER BY newCredit DESC"); query.setFirstResult(firstResult); query.setMaxResults(maxResults); query.setInteger("team", team); return query.list(); }
From source file:com.googlecode.osde.internal.db.PersonTest.java
License:Apache License
@Test public void testCreatePerson() throws Exception { Transaction tx = session.beginTransaction(); Person person = new PersonImpl(); person.setId("john.doe"); person.setAboutMe("aboutMe1"); person.setAge(33);/*from w ww . j a v a 2 s .co m*/ session.save(person); tx.commit(); session.clear(); // tx = session.beginTransaction(); Query query = session.getNamedQuery(PersonImpl.FINDBY_PERSONID); query.setParameter(PersonImpl.PARAM_PERSONID, "john.doe"); query.setFirstResult(0); query.setMaxResults(1); List<?> plist = query.list(); person = null; if (plist != null && plist.size() > 0) { person = (Person) plist.get(0); } Assert.assertEquals("id", "john.doe", person.getId()); Assert.assertEquals("aboutMe", "aboutMe1", person.getAboutMe()); Assert.assertEquals("Age", new Integer(33), person.getAge()); tx.commit(); }
From source file:com.gotour.daos.ReviewDaoImpl.java
public List<Review> getLast(int n) { String hql = "from Review r order by r.id desc"; Query query = getSession().createQuery(hql); query.setMaxResults(n); return query.list(); }