Example usage for org.hibernate Criteria setFirstResult

List of usage examples for org.hibernate Criteria setFirstResult

Introduction

In this page you can find the example usage for org.hibernate Criteria setFirstResult.

Prototype

public Criteria setFirstResult(int firstResult);

Source Link

Document

Set the first result to be retrieved.

Usage

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();/* w w  w.java2 s .c  o  m*/

    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);//  w ww  .jav a 2s . c om
    return criteria.list();
}

From source file:br.com.itw.commons.persistence.CoreRepository.java

License:Apache License

public Page<T> search(T entity, Pageable pageable) {
    if (pageable == null) {
        pageable = new PageRequest(0, 10);
    }/*from w w w . ja v a2s  . c  om*/

    Session session = (Session) entityManager.getDelegate();
    Criteria criteria = session.createCriteria(entity.getClass());
    // Prepare Example
    Example example = Example.create(entity);
    criteria.add(example.enableLike(MatchMode.ANYWHERE).ignoreCase());

    // Count
    Long totalItems = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();

    // Pageable result Result
    criteria.setProjection(null).setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
    List<T> result = criteria.setFirstResult((pageable.getPageNumber() - 1) * pageable.getPageSize())
            .setMaxResults(pageable.getPageSize()).list();
    return (Page<T>) new PageImpl<T>(result, pageable, totalItems);
}

From source file:br.com.itw.commons.persistence.PageableHelper.java

License:Apache License

public static Page<?> getPage(Criteria criteria, Pageable pageable) {
    // Count/*from   w  w  w  .  ja  v  a 2  s . com*/
    Long totalItems = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();

    // Pageable result Result
    criteria.setProjection(null).setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
    if (pageable.getSort() != null) {
        Iterator<Sort.Order> orders = pageable.getSort().iterator();
        while (orders.hasNext()) {
            Sort.Order order = orders.next();
            if (order.getDirection() == null || Sort.Direction.ASC.equals(order.getDirection())) {
                criteria.addOrder(Order.asc(order.getProperty()));
            } else {
                criteria.addOrder(Order.desc(order.getProperty()));
            }
        }
    }
    List<?> result = criteria.setFirstResult(pageable.getPageNumber() * pageable.getPageSize())
            .setMaxResults(pageable.getPageSize()).list();
    return (Page<?>) new PageImpl<>(result, pageable, totalItems);
}

From source file:br.com.muranodesign.dao.impl.AlunoDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<Aluno> listIntervalo(int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(Aluno.class);

    criteria.add(Restrictions.eq("ativo", "s"));

    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);/*from w w  w  .  j av a  2 s . co m*/

    List<Aluno> result = criteria.list();

    return result;
}

From source file:br.com.muranodesign.dao.impl.AlunoVariavelDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<AlunoVariavel> ListarCicloAno(List<Integer> i, int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(AlunoVariavel.class);
    criteria.createAlias("anoEstudo", "anoEstudo");
    criteria.add(Restrictions.in("anoEstudo.idanoEstudo", i));
    String ano = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
    AnoLetivo anoLetivo = new AnoLetivoService().listarAnoLetivo(ano).get(0);
    criteria.add(Restrictions.eq("anoLetivo", anoLetivo));
    criteria.add(Restrictions.eq("ativo", 1));
    criteria.addOrder(Order.asc("anoEstudo.ano"));
    criteria.createAlias("aluno", "aluno");
    criteria.addOrder(Order.asc("aluno.nome"));
    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);/* w  w w  .  ja  v  a  2s . c om*/
    List<AlunoVariavel> result = criteria.list();
    return result;

}

From source file:br.com.muranodesign.dao.impl.AlunoVariavelDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<AlunoVariavel> ListarCicloAnoPeriodo(List<Integer> i, int periodo, int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(AlunoVariavel.class);
    criteria.createAlias("anoEstudo", "anoEstudo");
    criteria.add(Restrictions.in("anoEstudo.idanoEstudo", i));
    String ano = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
    AnoLetivo anoLetivo = new AnoLetivoService().listarAnoLetivo(ano).get(0);
    criteria.add(Restrictions.eq("anoLetivo", anoLetivo));
    criteria.add(Restrictions.eq("ativo", 1));
    criteria.createAlias("periodo", "periodo");
    criteria.add(Restrictions.eq("periodo.idperiodo", periodo));
    criteria.addOrder(Order.asc("anoEstudo.ano"));
    criteria.createAlias("aluno", "aluno");
    criteria.addOrder(Order.asc("aluno.nome"));
    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);/*from  w  w w.  j  a  va2  s . co  m*/
    List<AlunoVariavel> result = criteria.list();
    return result;

}

From source file:br.com.muranodesign.dao.impl.AlunoVariavelDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<AlunoVariavel> ListarRangePeriodo(int id, int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(AlunoVariavel.class);
    criteria.createAlias("periodo", "periodo");
    criteria.add(Restrictions.eq("periodo.idperiodo", id));
    String ano = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
    AnoLetivo anoLetivo = new AnoLetivoService().listarAnoLetivo(ano).get(0);
    criteria.add(Restrictions.eq("anoLetivo", anoLetivo));
    criteria.add(Restrictions.eq("ativo", 1));
    criteria.addOrder(Order.asc("anoEstudo.ano"));
    criteria.createAlias("aluno", "aluno");
    criteria.addOrder(Order.asc("aluno.nome"));
    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);//from ww  w. j  a  v a  2s .  co  m
    List<AlunoVariavel> result = criteria.list();
    return result;
}

From source file:br.com.muranodesign.dao.impl.AlunoVariavelDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<AlunoVariavel> ListarCicloAnoPeriodoSemGrupo(List<Integer> anos, int idPeriodo, int primeiro,
        int ultimo) {
    Criteria criteria = getSession().createCriteria(AlunoVariavel.class);
    String ano = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
    AnoLetivo anoLetivo = new AnoLetivoService().listarAnoLetivo(ano).get(0);
    criteria.add(Restrictions.eq("anoLetivo", anoLetivo));
    criteria.add(Restrictions.eq("ativo", 1));
    criteria.createAlias("anoEstudo", "anoEstudo");
    criteria.add(Restrictions.in("anoEstudo.idanoEstudo", anos));
    criteria.createAlias("periodo", "periodo");
    criteria.add(Restrictions.eq("periodo.idperiodo", idPeriodo));
    criteria.createAlias("grupo", "grupo", Criteria.LEFT_JOIN);
    criteria.add(Restrictions.or(Restrictions.isNull("grupo"), Restrictions.eq("grupo.status", "1")));
    criteria.addOrder(Order.asc("anoEstudo.ano"));
    criteria.createAlias("aluno", "aluno");
    criteria.addOrder(Order.asc("aluno.nome"));
    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);//w ww .j  a v  a2  s.  c o  m
    List<AlunoVariavel> result = criteria.list();
    return result;
}

From source file:br.com.muranodesign.dao.impl.AlunoVariavelDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<AlunoVariavel> ListarCicloAnoSemGrupo(List<Integer> anos, int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(AlunoVariavel.class);
    String ano = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
    AnoLetivo anoLetivo = new AnoLetivoService().listarAnoLetivo(ano).get(0);
    criteria.add(Restrictions.eq("anoLetivo", anoLetivo));
    criteria.add(Restrictions.eq("ativo", 1));
    criteria.createAlias("anoEstudo", "anoEstudo");
    criteria.add(Restrictions.in("anoEstudo.idanoEstudo", anos));
    criteria.createAlias("grupo", "grupo", Criteria.LEFT_JOIN);
    criteria.add(Restrictions.or(Restrictions.isNull("grupo"), Restrictions.eq("grupo.status", "1")));
    criteria.addOrder(Order.asc("anoEstudo.ano"));
    criteria.createAlias("aluno", "aluno");
    criteria.addOrder(Order.asc("aluno.nome"));
    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);//from  w  w  w.  ja  v a 2 s.c o m
    List<AlunoVariavel> result = criteria.list();
    return result;
}