List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:br.gov.mdarte.controleacesso.cd.PerfilDAOImpl.java
@Override protected Object handleRecuperarSuperPerfil(Session session, String sistema, Integer paginacao, Integer linhas, Integer paginas) throws DAOException { ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("id")); Criteria criterios = session.createCriteria(PerfilImpl.class); criterios.createAlias("sistema", "sistema"); criterios.add(Restrictions.eq("superUsuario", Boolean.TRUE)); criterios.setProjection(projectionList); if (sistema != null) criterios.add(Restrictions.eq("sistema.nome", sistema)); ResultTransformer resultTransformer = new ResultTransformer() { public Object transformTuple(Object[] result, String[] arg1) { return result; }/*from w ww .j a v a 2 s.co m*/ public List transformList(List resultado) { List idPerfis = new ArrayList<Long>(); for (Object[] result : (List<Object[]>) resultado) { Collection rows = Arrays.asList(result); Iterator iteratorRow = rows.iterator(); idPerfis.add((Long) iteratorRow.next()); } return idPerfis; } }; criterios.setResultTransformer(resultTransformer); return criterios; }
From source file:br.ufac.sion.dao.CandidatoFacade.java
private Criteria criarCriteriaParaFiltro(FiltroCandidatos filtro) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(Candidato.class); criteria.createAlias("usuario", "u"); if (StringUtils.isNotEmpty(filtro.getNome())) { criteria.add(Restrictions.ilike("nome", filtro.getNome(), MatchMode.ANYWHERE)); }/*from w ww .j a va2 s . c o m*/ if (StringUtils.isNotEmpty(filtro.getCpf())) { criteria.add(Restrictions.ilike("cpf", filtro.getCpf(), MatchMode.EXACT)); } if (StringUtils.isNotEmpty(filtro.getEmail())) { criteria.add(Restrictions.ilike("u.email", filtro.getEmail(), MatchMode.START)); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria; }
From source file:br.ufac.sion.dao.CidadeFacade.java
private Criteria criarCriteriaParaFiltro(FiltroCidades filtro) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(Cidade.class); if (StringUtils.isNotEmpty(filtro.getNome())) { criteria.add(Restrictions.ilike("nome", filtro.getNome(), MatchMode.ANYWHERE)); }//from w w w . j a v a2 s. com if (filtro.getEstado() != null && filtro.getEstado().getId() != null) { criteria.add(Restrictions.eq("estado", filtro.getEstado())); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria; }
From source file:br.ufac.sion.dao.InscricaoFacade.java
@Override public Map<Date, Long> inscricoesPorData(Concurso concurso, SituacaoInscricao situacao) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(Inscricao.class); LocalDateTime dataInicial = concurso.getDataInicioInscricao(); Integer dias = Period.between(concurso.getDataInicioInscricao().toLocalDate(), concurso.getDataTerminoIncricao().toLocalDate()).getDays(); Map<Date, Long> resultado = criaMapaVazio(dias, dataInicial); criteria.createAlias("cargoConcurso", "cc") .setProjection(Projections.projectionList() .add(Projections.sqlGroupProjection("date(data_inscricao) as data", "date(data_inscricao)", new String[] { "data" }, new Type[] { StandardBasicTypes.DATE })) .add(Projections.count("id").as("quantidade"))) .add(Restrictions.ge("dataInscricao", dataInicial)).add(Restrictions.eq("cc.concurso", concurso)); if (situacao != null) { criteria.add(Restrictions.eq("status", situacao.CONFIRMADA)); }//w w w . jav a2s . com List<DataQuantidade> quantidadesPorData = criteria .setResultTransformer(Transformers.aliasToBean(DataQuantidade.class)).list(); for (DataQuantidade quantidadeData : quantidadesPorData) { resultado.put(quantidadeData.getData(), quantidadeData.getQuantidade()); } return resultado; }
From source file:br.ufac.sion.dao.InscricaoFacade.java
private Criteria criarCriteriaParaFiltro(FiltroInscritos filtro) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(Inscricao.class); criteria.createAlias("cargoConcurso", "cc").add(Restrictions.eq("cc.concurso", filtro.getConcurso())); criteria.createAlias("candidato", "c"); if (filtro.getCargo() != null && filtro.getCargo().getId() != null) { criteria.add(Restrictions.eq("cargoConcurso", filtro.getCargo())); }/*ww w.j a v a 2 s. co m*/ if (StringUtils.isNotEmpty(filtro.getNome())) { criteria.add(Restrictions.ilike("c.nome", filtro.getNome(), MatchMode.ANYWHERE)); } if (StringUtils.isNotEmpty(filtro.getCpf())) { criteria.add(Restrictions.ilike("c.cpf", filtro.getCpf(), MatchMode.EXACT)); } if (StringUtils.isNotEmpty(filtro.getNumeroInscricao())) { criteria.add(Restrictions.ilike("numero", filtro.getNumeroInscricao(), MatchMode.START)); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria; }
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)); }//from ww w . j a v a 2 s . c o 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 List<Inscricao> findByCargoAndLocalidade(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 v a 2 s . c o m criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(filtroRelatorio.getPrimeiroRegistro()); criteria.setMaxResults(filtroRelatorio.getQuantidadeRegistros()); Criterion confirmada = Restrictions.eq("status", SituacaoInscricao.CONFIRMADA); Criterion judice = Restrictions.eq("status", SituacaoInscricao.SUB_JUDICE); criteria.add(Restrictions.or(confirmada, judice)); //criteria.addOrder(Order.asc("c.nome")); return criteria.list(); }
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())); }//ww w .j a va 2 s . c om 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.EventoDao.java
@Transactional(readOnly = true) public List<Evento> listar(int first, int pageSize, String sortField, String sortOrder, Map<String, Object> filters) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Evento.class); criteria.setFirstResult(first);/* w w w .ja v a2 s.c o m*/ criteria.setMaxResults(pageSize); if ((sortField != null && !sortField.isEmpty()) && (sortOrder != null && !sortOrder.isEmpty())) { if (sortOrder.equals("ASCENDING")) { criteria.addOrder(Order.asc(sortField)); } if (sortOrder.equals("DESCENDING")) { criteria.addOrder(Order.desc(sortField)); } } else { criteria.addOrder(Order.asc("id")); } if (filters != null && !filters.isEmpty()) { for (String key : filters.keySet()) { if (key.equals("termo")) { List foundList = buscarTermo(session, filters.get("termo").toString()); if (foundList.size() > 0) { criteria.add(Restrictions.in("id", foundList)); } else { 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")) { Interessado interessado = (Interessado) filters.get(key); System.out.println("interessado: " + interessado.getNome()); criteria.createCriteria("interessado").add(Restrictions.eq("id", interessado.getId())); } if (key.equals("regional")) { Regional regional = (Regional) filters.get(key); System.out.println("regional: " + regional.getNome()); criteria.createCriteria("regional").add(Restrictions.eq("id", regional.getId())); } if (key.equals("periodo")) { Map periodo = (Map) filters.get(key); criteria.add(Restrictions .or(Restrictions.between("inicio", periodo.get("inicio"), periodo.get("termino"))) .add(Restrictions.between("termino", periodo.get("inicio"), periodo.get("termino")))); } if (key.equals("calendario")) { criteria.createAlias("calendario", "c"); criteria.add(Restrictions.eq("c.ano", ((Calendario) filters.get(key)).getAno())); } } } if (filters == null || !filters.containsKey("calendario")) { criteria.createAlias("calendario", "c"); criteria.add(Restrictions.eq("c.ativo", true)); } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Evento> resultado = criteria.list(); for (Evento evt : resultado) { Hibernate.initialize(evt.getInteressado()); Hibernate.initialize(evt.getRegional()); } return resultado; }
From source file:br.ufg.calendario.dao.UsuarioDao.java
@Transactional(readOnly = true) public Usuario buscarPorLogin(String login) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Usuario.class); criteria.add(Restrictions.eq("login", login)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Usuario usuario = (Usuario) criteria.uniqueResult(); if (usuario != null) { Hibernate.initialize(usuario.getPerfil()); }//from w w w . j a v a 2s. co m return usuario; }