List of usage examples for org.hibernate Criteria setMaxResults
public Criteria setMaxResults(int maxResults);
From source file:br.com.arsmachina.dao.hibernate.ReadableDAOImpl.java
License:Apache License
/** * If <code>sortingConstraints</code> is <code>null</code> or empty, this implementation * sort the results by the {@link SortCriterion}s returned by * {@link #getDefaultSortCriterions()}./*from w ww . j av a2s .c om*/ * * @see br.com.arsmachina.dao.ReadableDAO#findAll(int, int, * br.com.arsmachina.dao.SortCriterion[]) */ @SuppressWarnings("unchecked") public List<T> findAll(int firstResult, int maximumResults, SortCriterion... sortingConstraints) { Criteria criteria = createCriteria(); criteria.setFirstResult(firstResult); criteria.setMaxResults(maximumResults); if (sortingConstraints == null || sortingConstraints.length == 0) { sortingConstraints = getDefaultSortCriteria(); } addSortCriteria(criteria, sortingConstraints); return criteria.list(); }
From source file:br.com.arsmachina.dao.hibernate.ReadableDAOImpl.java
License:Apache License
/** * Creates a {@link Criteria} for this entity class with given sort criteria, * first result index and maximum number of results. * /*from w w w . ja v a 2s .co m*/ * @return a {@link Criteria}. */ public Criteria createCriteria(int firstIndex, int maximumResults, SortCriterion... sortCriteria) { Criteria criteria = createCriteria(sortCriteria); criteria.setFirstResult(firstIndex); criteria.setMaxResults(maximumResults); return criteria; }
From source file:br.com.ateliens.repository.ClientesFiltrados.java
@SuppressWarnings("unchecked") public List<Cliente> filtrados(FiltroCliente filtro) { Criteria criteria = criarCriteriaParaFiltro(filtro); criteria.setFirstResult(filtro.getPrimeiroRegistro()); criteria.setMaxResults(filtro.getQuantidadeRegistros()); if (filtro.isAscendente() && filtro.getPropriedadeOrdenacao() != null) { criteria.addOrder(Order.asc(filtro.getPropriedadeOrdenacao())); } else if (filtro.getPropriedadeOrdenacao() != null) { criteria.addOrder(Order.desc(filtro.getPropriedadeOrdenacao())); }// w w w . j a v a 2 s . co m return criteria.list(); }
From source file:br.com.cary.dao.SetorDAO.java
public Setor verificaSetor() { Session s = ConectaDB.getSessionFactory().openSession(); try {// w ww . j a va2s . c om Criteria c = s.createCriteria(Setor.class); c.setMaxResults(1); if (c.list().size() != 0) { return (Setor) c.uniqueResult(); } } catch (Exception e) { e.printStackTrace(); } finally { s.close(); } return null; }
From source file:br.com.gartech.nfse.integrador.dao.GenericDAOImpl.java
@SuppressWarnings("unchecked") public List<T> findByExample(T entity, int firstResult, int maxResults) { Session session = getSession();/*from ww w. j a va 2s . co m*/ log.debug("findByExample on " + getEntityClass()); Criteria criteria = session.createCriteria(getEntityClass()).add(Example.create(entity)); criteria.setFirstResult(firstResult); if (maxResults > 0) { criteria.setMaxResults(maxResults); criteria.addOrder(Order.asc("dataRecebimento")); } log.debug("findByExample result " + criteria.list().size()); return (List<T>) criteria.list(); }
From source file:br.com.gartech.nfse.integrador.dao.GenericDAOImpl.java
@SuppressWarnings("unchecked") public List<T> findByCriteria(DetachedCriteria detachedCriteria, int firstResult, int maxResults) { Session session = getSession();//from www . j a va2 s . c om session.doWork(new Work() { @Override public void execute(Connection cnctn) throws SQLException { cnctn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } }); Criteria criteria = detachedCriteria.getExecutableCriteria(session); criteria.setFirstResult(firstResult); if (maxResults > 0) { criteria.setMaxResults(maxResults); } // criteria.setLockMode(LockMode.READ); //linha adicionada para no fazer LOCK nas consulta j que apenas consulta. List<T> result = criteria.list(); return result; }
From source file:br.com.hslife.imobiliaria.dao.impl.HibernateGenericDao.java
License:Open Source License
@Override public List list(Class clazz, int firstResult, int maxResults) { HibernateUtility.getSession().clear(); Criteria criteria = HibernateUtility.getSession().createCriteria(clazz); criteria.setFirstResult(firstResult); criteria.setMaxResults(maxResults); return criteria.list(); }
From source file:br.com.hslife.orcamento.repository.IdentidadeRepository.java
License:Open Source License
public Identidade findByUsuarioAndTipoIdentidade(Usuario usuario, TipoIdentidade tipoIdentidade) { Criteria criteria = getSession().createCriteria(Identidade.class); criteria.add(Restrictions.eq("usuario.id", usuario.getId())); criteria.add(Restrictions.eq("tipoIdentidade", tipoIdentidade)); return criteria.setMaxResults(1).uniqueResult() == null ? null : (Identidade) criteria.setMaxResults(1).uniqueResult(); }
From source file:br.com.hslife.orcamento.repository.LancamentoContaRepository.java
License:Open Source License
@SuppressWarnings("unchecked") public List<LancamentoConta> findByCriterioBusca(CriterioBuscaLancamentoConta criterioBusca) { Criteria criteria = getSession().createCriteria(LancamentoConta.class, "lancamento") .createAlias("lancamento.conta", "con"); for (Criterion criterion : criterioBusca.buildCriteria()) { criteria.add(criterion);/*from w w w . j a v a2 s. c om*/ } return criteria.setMaxResults(criterioBusca.getLimiteResultado()).addOrder(Order.asc("dataPagamento")) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); }
From source file:br.com.hslife.orcamento.repository.LancamentoImportadoRepository.java
License:Open Source License
public LancamentoImportado findByHash(String hash) { Criteria criteria = getSession().createCriteria(LancamentoImportado.class); criteria.add(Restrictions.eq("hash", hash)); return (LancamentoImportado) criteria.setMaxResults(1).uniqueResult(); }