Example usage for org.hibernate Criteria setMaxResults

List of usage examples for org.hibernate Criteria setMaxResults

Introduction

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

Prototype

public Criteria setMaxResults(int maxResults);

Source Link

Document

Set a limit upon the number of objects to be retrieved.

Usage

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

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<Grupo> listarUltimo(String ano, String periodo) {
    Criteria criteria = getSession().createCriteria(Grupo.class);
    criteria.add(Restrictions.eq("status", "0"));
    criteria.add(Restrictions.like("nomeGrupo", ano, MatchMode.START));
    criteria.add(Restrictions.like("nomeGrupo", periodo, MatchMode.ANYWHERE));
    criteria.addOrder(Order.desc("nomeGrupo"));
    criteria.setMaxResults(1);
    List<Grupo> result = criteria.list();
    return result;
}

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

License:Creative Commons License

@SuppressWarnings("unchecked")
/*/*from  ww  w. ja v a2s  . co  m*/
 * (non-Javadoc)
 * @see br.com.muranodesign.dao.GrupoDAO#ListarUltimoCiclo(java.lang.String)
 */
public List<Grupo> ListarUltimoCiclo(String ciclo, String periodo) {
    Criteria criteria = getSession().createCriteria(Grupo.class);
    criteria.add(Restrictions.eq("ciclo", ciclo));
    criteria.add(Restrictions.eq("status", "0"));
    criteria.add(Restrictions.like("nomeGrupo", periodo, MatchMode.ANYWHERE));

    criteria.addOrder(Order.desc("idgrupo"));
    criteria.setMaxResults(1);
    List<Grupo> result = criteria.list();
    return result;
}

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

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<Mensagens> listIntervalo(int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(Mensagens.class);
    criteria.setFirstResult(primeiro);/*from   w  w w . jav  a  2 s  .c  o m*/
    criteria.setMaxResults(ultimo);

    criteria.addOrder(Order.asc("lida"));
    criteria.addOrder(Order.desc("data"));
    criteria.addOrder(Order.desc("idmensagens"));

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

    return result;
}

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

License:Creative Commons License

@Override
@SuppressWarnings("unchecked")
/*//from w  w w  .j av  a  2 s .  c  o  m
 * (non-Javadoc)
 * @see br.com.muranodesign.dao.MensagensDAO#listarProprietario(br.com.muranodesign.model.Usuario, java.lang.String, int, int)
 */
public List<Mensagens> listarProprietario(Usuario proprietario, String caixa, int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(Mensagens.class);

    criteria.addOrder(Order.asc("lida"));
    criteria.addOrder(Order.desc("data"));
    criteria.addOrder(Order.desc("idmensagens"));

    if (caixa.equals("entrada")) {
        criteria.add(Restrictions.eq("cxEntrada", "S"));

    } else if (caixa.equals("enviado")) {
        criteria.add(Restrictions.eq("cxEnviada", "S"));

    }

    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);

    criteria.add(Restrictions.eq("proprietario", proprietario));

    List<Mensagens> result = criteria.list();
    return result;
}

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

License:Creative Commons License

@Override
public List<ProducaoAluno> listaUltimasAluno(int idAluno) {
    Criteria criteria = getSession().createCriteria(ProducaoAluno.class);

    String ano = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
    criteria.createAlias("anoLetivo", "anoLetivo");
    criteria.add(Restrictions.eq("anoLetivo.ano", ano));

    criteria.createAlias("aluno", "aluno");
    criteria.add(Restrictions.eq("aluno.idAluno", idAluno));
    criteria.addOrder(Order.desc("data"));
    criteria.addOrder(Order.desc("idproducaoAluno"));

    criteria.setMaxResults(8);

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

    return result;
}

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

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<Roteiro> listRoteiroRange(int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(Roteiro.class);
    ProjectionList projList = Projections.projectionList();

    criteria.setFirstResult(primeiro);//from   ww  w .ja v a 2s  . c  o m
    criteria.setMaxResults(ultimo);
    projList.add(Projections.property("idroteiro"), "idroteiro");
    projList.add(Projections.property("nome"), "nome");

    criteria.setProjection(projList).setCacheable(true);
    criteria.setResultTransformer(Transformers.aliasToBean(Roteiro.class));

    criteria.addOrder(Order.asc("nome"));
    List<Roteiro> result = criteria.list();

    return result;
}

From source file:br.com.pfood.dao.imp.GenericDAOImp.java

@Override
public <T extends Object> List<T> getAllLimit(Class<T> classe, Order order, Integer inicio, Integer fim) {
    Criteria c = session.createCriteria(classe);
    if (inicio != null) {
        c.setFirstResult(inicio);//w  w w  .j  a  va 2s . co  m
    }
    if (fim != null) {
        c.setMaxResults(fim);
    }
    if (order != null) {
        c.addOrder(order);
    }

    c.setResultTransformer(c.DISTINCT_ROOT_ENTITY);

    return (List<T>) c.list();
}

From source file:br.com.prototipo.dao.CursoDao.java

public Curso getCursoEscolhido(String cod) {
    if (sessao.isConnected()) {
        sessao.close();//  w  ww  .  j a  v a  2s . com
    }
    sessao = HibernateUtil.getSessionFactory().openSession();

    Criteria cri = sessao.createCriteria(Curso.class);
    Criterion _cod = Restrictions.like("codigo", cod, MatchMode.EXACT);
    cri.add(_cod);

    cri.setMaxResults(1);
    Object result = cri.uniqueResult();
    Curso c = new Curso();
    if (result != null) {
        c = (Curso) result;
    }
    return c;
}

From source file:br.com.prototipo.dao.DisciplinaDao.java

public Disciplina getDisciplina(String codigo) { //codigo usado para retornar a disciplina cujo codigo e passado por parametro
    if (sessao.isConnected()) {
        sessao.close();//from  w w w  .jav  a 2 s.  co  m
    }
    sessao = HibernateUtil.getSessionFactory().openSession();

    Criteria cri = sessao.createCriteria(Disciplina.class);
    Criterion _cod = Restrictions.like("codigo", codigo, MatchMode.EXACT);
    cri.add(_cod);
    cri.setMaxResults(1);
    Object result = cri.uniqueResult();
    Disciplina d = new Disciplina();
    if (result != null) {
        d = (Disciplina) result;
    }
    return d;
}

From source file:br.com.prototipo.dao.ProfessorDao.java

public Professor getProfessor(String codigo) { //codigo usado para retornar a disciplina cujo codigo e passado por parametro
    if (sessao.isConnected()) {
        sessao.close();//from  w  ww .j av a2s . co  m
    }
    sessao = HibernateUtil.getSessionFactory().openSession();

    Criteria cri = sessao.createCriteria(Professor.class);
    Criterion _cod = Restrictions.like("registro", codigo, MatchMode.EXACT);
    cri.add(_cod);
    cri.setMaxResults(1);
    Object result = cri.uniqueResult();
    Professor p = new Professor();
    if (result != null) {
        p = (Professor) result;
    }
    return p;
}