List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:br.luck.dal.LotofacilModelDAO.java
@Override public List<LotofacilModel> listarModalidade(int first, int pageSize) { Query query; query = getSession().createQuery(Queries.RETORNA_TODOS_CONCURSOS_LOTOFACIL); query.setFirstResult(first);//from w ww . jav a 2s . c o m query.setMaxResults(pageSize); return query.list(); }
From source file:br.luck.dal.LotomaniaModelDAO.java
@Override public List<LotomaniaModel> listarModalidade(int first, int pageSize) { Query query; query = getSession().createQuery(Queries.RETORNA_TODOS_CONCURSOS_LOTOMANIA); query.setFirstResult(first);/*from w ww . j a va2 s.com*/ query.setMaxResults(pageSize); return query.list(); }
From source file:br.luck.dal.MegasenaModelDAO.java
@Override public List<MegasenaModel> listarModalidade(int first, int pageSize) { Query query; query = getSession().createQuery(Queries.RETORNA_TODOS_CONCURSOS_MEGASENA); query.setFirstResult(first);//from w w w .j av a2s . c o m query.setMaxResults(pageSize); return query.list(); }
From source file:br.sp.telesul.dao.FuncionarioDAOImpl.java
@Override public FilterReturn searchPage(int pageNumber, int pageSize, String filter) { String countQ = "Select count (f.id) from Funcionario f"; Session session = this.sessionFactory.getCurrentSession(); Query countQuery = session.createQuery(countQ); Long countResults = (Long) countQuery.uniqueResult(); int lastPageNumber = (int) ((countResults / pageSize) + 1); FilterReturn filterReturn = new FilterReturn(); filterReturn.setTotalEntities(countResults); Query selectQuery = session.createQuery("From Funcionario f Where nome LIKE :filter"); selectQuery.setParameter("filter", "%" + filter + "%"); selectQuery.setFirstResult((pageNumber - 1) * pageSize); selectQuery.setMaxResults(pageSize); List<Funcionario> funcionarios = selectQuery.list(); filterReturn.setEmployees(funcionarios); return filterReturn; }
From source file:br.ufg.inf.es.fs.contpatri.persistencia.dao.InventarioDAO.java
License:GNU General Public License
/** * * @return ltimo inventario emitido/*from w ww. ja va2s . c om*/ */ public Inventario findUltimoInventarioEmitido() { String hql = "from Inventario order by dataEmissao desc"; Session session = HibernateUtil.beginTransaction(); Query query = session.createQuery(hql); query.setMaxResults(1); Inventario inventario = findOne(query); HibernateUtil.commitTransaction(); return inventario; }
From source file:br.ufg.inf.es.fs.contpatri.web.controller.BemPatrimonialDataModel.java
License:GNU General Public License
/** * * @param first primeiro elemento da lista * @param pageSize tamanho da pgina// w w w . j a va 2s . com * @param sortField campo de ordenao * @param sortOrder ordem (decrescente, ascendente) * @param filters filtros * @return lista com os bens patrimoniais */ @Override public List<BemPatrimonial> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { StringBuilder sb = new StringBuilder("from BemPatrimonial "); // Filtros if (!filters.isEmpty()) { sb.append("where "); } for (Iterator<String> it = filters.keySet().iterator(); it.hasNext();) { String filterProperty = it.next(); String filterValue = filters.get(filterProperty); sb.append(filterProperty); sb.append(" like "); sb.append('\''); sb.append(filterValue); sb.append("%"); sb.append('\'').append(' '); if (it.hasNext()) { sb.append(" and "); } } // Ordenao if (sortField != null) { if (sortOrder == SortOrder.ASCENDING) { sb.append("order by ").append(sortField).append(" asc"); } else if (sortOrder == SortOrder.DESCENDING) { sb.append("order by ").append(sortField).append(" desc"); } } // Obtendo dados String hql = sb.toString(); HibernateUtil.beginTransaction(); Query query = HibernateUtil.getSession().createQuery(hql); query.setFirstResult(first); query.setMaxResults(pageSize); List<BemPatrimonial> dados = bemPatrimonialDAO.findMany(query); HibernateUtil.commitTransaction(); // Contagem das linhas na tabela HibernateUtil.beginTransaction(); String hqlRowCount = "select count (*) ".concat(hql); query = HibernateUtil.getSession().createQuery(hqlRowCount); int rows = ((Long) query.list().get(0)).intValue(); HibernateUtil.commitTransaction(); setRowCount(rows); return dados; }
From source file:cc.cnfc.core.orm.hibernate.HibernateDao.java
License:Open Source License
/** * ??HQL??/*from w w w. ja va2s .c om*/ * * 1?? a)?(MySQL,Oracle,SQL * Server2005)?limit n,m b)?(informix,Sybase 12.5.3,SQL * Server)?top n c)???? 2? * 3?order bygroup by,having Query q= session.createQuery( * "select new A(M.a,N.b) from M as M,N as N where M.id=N.id"); * * @param hql * HQL??Where???select???? select * a,b,(select c from table1) as d from table2 ... * 1)(select *)??from TUser * 2)select userName,password from TUser; * @param propertyNames * ??? * @param operators * ????=???null * ???=, >=, <=, <>, !=, like * @param values * ? * @param offset * 0??-1 * @param size * ??-1 * @param isTotalSize * ??true * @param orderBy * ?,??order byorderBy="a desc,b asc",??order by a * desc,b asc * @param groupBy * ,??group by groupBy="a desc,b asc",??group by a * desc,b asc * @param otherCause * where????(order by),(group by)??(having) * @param isCache * ?cache "group by name order by name desc" * @return Object[] List list = (List)Object[0] * int count = ((Integer)Object[1]).intValue; * @throws com.rwy.base.core.exception.GenericException * */ public Object[] query(final String hql, final String[] propertyNames, final String[] operators, final Object[] values, final int offset, final int size, final boolean isTotalSize, final String orderBy, final String groupBy, final String otherCause, final boolean isCache) throws DataAccessException { Assert.hasText(hql, "hql?"); Query query; String countSql; String fullSql; Integer count = 0; Map map = new HashMap(); String where = ""; if (propertyNames != null && propertyNames.length > 0 && values != null && values.length > 0) { if (propertyNames.length != values.length) { throw new GenericException(); } if (operators != null && propertyNames.length != operators.length) { logger.error(""); throw new GenericException(); } for (int i = 0; i <= propertyNames.length - 1; i++) { if ("".equals(where)) { where = " where "; } else { where += "and "; } if (operators != null && operators[i].equalsIgnoreCase("isnull")) { where += propertyNames[i] + " is null "; } else if (operators != null && operators[i].equalsIgnoreCase("isnotnull")) { where += propertyNames[i] + " is not null "; } else if (operators != null && operators[i].equalsIgnoreCase("isempty")) { where += propertyNames[i] + " = '' "; } else if (operators != null && operators[i].equalsIgnoreCase("isnotempty")) { where += propertyNames[i] + " <> '' "; } else if (operators != null && operators[i].equalsIgnoreCase("in")) { where += propertyNames[i] + " in "; } else { where += propertyNames[i] + (operators == null || operators[i] == null ? "=" : " " + operators[i]) + " ? "; } } fullSql = hql + where; fullSql += otherCause == null || otherCause.trim().equals("") ? "" : " " + otherCause; fullSql += groupBy == null || groupBy.trim().equals("") ? "" : " group by " + groupBy; fullSql += orderBy == null || orderBy.trim().equals("") ? "" : " order by " + orderBy; query = isCache ? this.createQuery(fullSql).setCacheable(true) : this.createQuery(fullSql); int paramIndex = 0; for (int i = 0; i <= values.length - 1; i++) { if (operators != null && operators[i].equalsIgnoreCase("isnull")) continue; if (operators != null && operators[i].equalsIgnoreCase("isnotnull")) continue; if (operators != null && operators[i].equalsIgnoreCase("isempty")) continue; if (operators != null && operators[i].equalsIgnoreCase("isnotempty")) continue; // IN? if (operators != null && operators[i].equalsIgnoreCase("in")) { values[i] = StringUtil.getInString(values[i]); } query.setParameter(paramIndex++, values[i]); } } else { if ("".equals(where) && hql.indexOf("where") == -1) { where = " where 1=1 "; } else if (!"".equals(where)) { where += " and "; } fullSql = hql + where; fullSql += otherCause == null || otherCause.trim().equals("") ? "" : " " + otherCause; fullSql += groupBy == null || groupBy.trim().equals("") ? "" : " group by " + groupBy; fullSql += orderBy == null || orderBy.trim().equals("") ? "" : " order by " + orderBy; query = this.createQuery(fullSql); } // ? if (isTotalSize) { // ???order by ??? countSql = hql + where; // modi by hongdj countSql += groupBy == null || groupBy.trim().equals("") ? "" : " group by " + groupBy; countSql += otherCause == null || otherCause.trim().equals("") ? "" : " " + otherCause; // ?hql?hql??select???? // select a,b,(select c from table1) as d from table2 ... countSql = "select count(*) from " + countSql.substring(countSql.toLowerCase().indexOf("from") + 5); Query query2 = this.createQuery(countSql); int paramIndex = 0; if (values != null) { for (int i = 0; i <= values.length - 1; i++) { if (operators != null && operators[i].equalsIgnoreCase("isnull")) continue; if (operators != null && operators[i].equalsIgnoreCase("isnotnull")) continue; if (operators != null && operators[i].equalsIgnoreCase("isempty")) continue; if (operators != null && operators[i].equalsIgnoreCase("isnotempty")) continue; query2.setParameter(paramIndex++, values[i]); } } // modi by denny Long res = (Long) query2.uniqueResult(); if (res != null) { count = res.intValue(); } } if (offset > 0) { query.setFirstResult(offset); } if (size > 0) { query.setMaxResults(size); } // ?log // logger.debug("fullSql=" + query.getQueryString()); map.put("list", query.list()); map.put("count", count); return new Object[] { map.get("list"), map.get("count") }; }
From source file:cgi.lemans.portail.domaine.gamaweb.impl.AbsenceDao.java
@Override public Absence findAbsenceByPremierJourAbsence(String idRessource) { String hql = "from Absence a " + "where a.premierJourAbsence >= :dateToday " + "and a.refRessource.idRessource = :idRessource " + "order by a.premierJourAbsence"; Query query = getSession().createQuery(hql); query.setParameter("idRessource", idRessource); query.setDate("dateToday", new java.util.Date()); query.setMaxResults(1); Absence results = (Absence) query.uniqueResult(); return results; }
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) { Query query = createQuery(queryString, type); if (lockOptions != null) { query.setLockOptions(lockOptions); }/*from w w w .ja v a 2s . c o m*/ 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 int maxResults, final QueryType type, final Object... params) { Query query = createQuery(queryString, type); if (lockOptions != null) { query.setLockOptions(lockOptions); }//w w w .j a va 2 s. co m if (maxResults > 0) { query.setMaxResults(maxResults); } applyParameters(query, params); return query; }