Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

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

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

From source file:br.ufac.sion.dao.CidadeFacade.java

@Override
public int contaCidades(FiltroCidades filtro) {
    Criteria criteria = criarCriteriaParaFiltro(filtro);

    criteria.setProjection(Projections.rowCount());

    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:br.ufac.sion.dao.InscricaoFacade.java

@Override
public int contaInscricoesConfirmadasESubJudice(FiltroInscritos filtro) {
    Criteria criteria = criarCriteriaParaFiltro(filtro);
    Criterion confirmada = Restrictions.eq("status", SituacaoInscricao.CONFIRMADA);
    Criterion judice = Restrictions.eq("status", SituacaoInscricao.SUB_JUDICE);
    criteria.add(Restrictions.or(confirmada, judice));

    criteria.setProjection(Projections.rowCount());

    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:br.ufac.sion.dao.InscricaoFacade.java

@Override
public int contaInscricoes(FiltroInscritos filtro) {
    Criteria criteria = criarCriteriaParaFiltro(filtro);

    criteria.setProjection(Projections.rowCount());

    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:br.ufac.sion.dao.InscricaoFacade.java

@Override
public int contaInscricoesPNE(FiltroInscritos filtro) {
    Criteria criteria = criarCriteriaParaFiltro(filtro);

    Criterion portador = Restrictions.eq("necessidadeEspecial.portador", true);
    Criterion necessitaAtendimento = Restrictions.eq("necessidadeEspecial.necessitaAtendimento", true);
    criteria.add(Restrictions.or(portador, necessitaAtendimento));

    criteria.setProjection(Projections.rowCount());

    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:br.ufac.sion.dao.InscricaoFacade.java

@Override
public Long encontrarQuatidadeDeInscricoesPorCargo(CargoConcurso cargoConcurso, String status) {

    Session session = em.unwrap(Session.class);
    Criteria criteria = session.createCriteria(Inscricao.class);

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

    if (StringUtils.isNotEmpty(status) && status.equals("CONFIRMADA")) {
        Criterion confirmada = Restrictions.eq("status", SituacaoInscricao.CONFIRMADA);
        Criterion judice = Restrictions.eq("status", SituacaoInscricao.SUB_JUDICE);
        criteria.add(Restrictions.or(confirmada, judice));
    }/* ww w.  j av a 2 s  . co m*/

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.setProjection(Projections.rowCount());

    return ((Number) criteria.uniqueResult()).longValue();
}

From source file:br.ufac.sion.dao.InscricaoFacade.java

@Override
public int contaInscricoesByCargoAndLocalidade(FiltroInscritosRelatorio filtroRelatorio) {
    Session session = em.unwrap(Session.class);
    Criteria criteria = session.createCriteria(Inscricao.class);

    criteria.createAlias("cargoConcurso", "cc")
            .add(Restrictions.eq("cc.concurso", filtroRelatorio.getConcurso()));
    criteria.createAlias("candidato", "c");

    if (filtroRelatorio.getCargo() != null && filtroRelatorio.getCargo().getId() != null) {
        criteria.add(Restrictions.eq("cargoConcurso", filtroRelatorio.getCargo()));
    }//from ww  w  .j  a va  2  s.c o  m

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    Criterion confirmada = Restrictions.eq("status", SituacaoInscricao.CONFIRMADA);
    Criterion judice = Restrictions.eq("status", SituacaoInscricao.SUB_JUDICE);
    criteria.add(Restrictions.or(confirmada, judice));

    criteria.setProjection(Projections.rowCount());

    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:br.ufg.calendario.dao.CalendarioDao.java

@Transactional(readOnly = true)
public int rowCount() {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Calendario.class);
    return ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
}

From source file:br.ufg.calendario.dao.EventoDao.java

@Transactional(readOnly = true)
public int rowCount() {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Evento.class);
    return ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
}

From source file:br.ufg.calendario.dao.EventoDao.java

@Transactional(readOnly = true)
public int rowCount(Map<String, Object> filters) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Evento.class);
    for (String key : filters.keySet()) {
        if (key.equals("assunto")) {
            criteria.add(Restrictions.like(key, filters.get(key).toString(), MatchMode.ANYWHERE).ignoreCase());
        }/* ww  w . j a v  a2  s  .  co  m*/
        if (key.equals("periodo")) {
            Map periodo = (Map) filters.get(key);
            criteria.add(Restrictions.and(Restrictions.ge("inicio", periodo.get("inicio")))
                    .add(Restrictions.le("termino", periodo.get("termino"))));
        }

        if (key.equals("calendario")) {
            criteria.createAlias("calendario", "c");
            criteria.add(Restrictions.eq("c.ano", ((Calendario) filters.get(key)).getAno()));
        }
        if (key.equals("termo")) {
            criteria.add(Restrictions.or(
                    Restrictions.like("assunto", filters.get(key).toString(), MatchMode.ANYWHERE).ignoreCase(),
                    Restrictions.like("descricao", filters.get(key).toString(), MatchMode.ANYWHERE)
                            .ignoreCase()));
        }
        if (key.equals("interessado")) {
            System.out.println("implementar filtro interessado");
        }
        if (key.equals("regional")) {
            System.out.println("implementar filtro regional");
        }
    }
    return ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
}

From source file:br.ufg.calendario.dao.InteressadoDao.java

@Transactional(readOnly = true)
public int rowCount() {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Interessado.class);
    return ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
}