List of usage examples for org.hibernate Criteria createAlias
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
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; }//w ww.j a v a 2 s . c o 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 w w . j a v a2 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.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)); }//from w w w . j av a 2 s.c o m 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())); }//from ww w . ja v a 2 s. com 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 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())); }//ww w . j a va2 s.c om 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())); }/*from w w w. j ava2 s . com*/ 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(Date inicio, Date termino, Calendario calendario) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Evento.class); criteria.createAlias("calendario", "c"); criteria.add(Restrictions.between("inicio", inicio, termino)); criteria.add(Restrictions.between("termino", inicio, termino)); criteria.add(Restrictions.eq("c.ano", calendario.getAno())); criteria.addOrder(Order.asc("inicio")); return criteria.list(); }
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);//from w w w . j a v a 2 s . c om 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.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()); }//from w ww .j av a2s. 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.reqweb.dao.RequerimentoDao.java
@Transactional(readOnly = true) public List<Requerimento> find(String sortField, String sortOrder, Map<String, Object> filters) { if (filters == null) { filters = new HashMap(); }/* w w w.j av a 2 s . c om*/ try { Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(Requerimento.class); for (String field : filters.keySet()) { /** * login eq / tipoRequerimento eq / termo like / dataCriacao * between */ if (field.equals("login")) { criteria.createAlias("discente", "d"); criteria.add(Restrictions.and(Restrictions.eq("d.login", filters.get(field)))); } if (field.equals("turmas")) { criteria.createAlias("itemRequerimentoList", "i"); List<Turma> turmas = (List<Turma>) filters.get(field); criteria.add(Restrictions.and(Restrictions.in("i.turma", turmas))); } if (field.equals("tipoRequerimento")) { criteria.add(Restrictions.and(Restrictions.eq(field, filters.get(field)))); } if (field.equals("termo")) { criteria.createAlias("discente", "d"); criteria.add(Restrictions.or(Restrictions.eq("d.matricula", filters.get("termo")), Restrictions .like("d.nome", filters.get("termo").toString(), MatchMode.ANYWHERE).ignoreCase())); } if (field.equals("curso")) { criteria.createAlias("discente.perfilList", "p"); criteria.add(Restrictions.and(Restrictions.eq("p.curso", filters.get(field)))); } if (field.equals("dataCriacao")) { Date[] arrayDate = (Date[]) filters.get("dataCriacao"); criteria.add(Restrictions.and(Restrictions.between("dataCriacao", arrayDate[0], arrayDate[1]))); } } if ((sortField != null && !sortField.isEmpty()) && (sortOrder != null && !sortOrder.isEmpty())) { if (sortOrder.toLowerCase().equals("asc")) { criteria.addOrder(Property.forName(sortField).asc()); } if (sortOrder.toLowerCase().equals("desc")) { criteria.addOrder(Property.forName(sortField).desc()); } } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return criteria.list(); } catch (HibernateException e) { System.out.println("query error: " + e.getMessage()); return new ArrayList<>(); } }