List of usage examples for org.hibernate Criteria setProjection
public Criteria setProjection(Projection projection);
From source file:br.com.muranodesign.dao.impl.PlanejamentoRoteiroDAOImpl.java
License:Creative Commons License
public /*List<PlanejamentoRoteiro>*/long listarAlunoCompletos(int id) { Criteria criteria = getSession().createCriteria(PlanejamentoRoteiro.class); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); criteria.add(Restrictions.ge("dataStatusPlanejado", cal.getTime())); criteria.add(Restrictions.eq("idAluno", id)); criteria.add(Restrictions.isNotNull("objetivo")); criteria.add(Restrictions.eq("status", "2")); criteria.setProjection(Projections.count("idAluno")); //List<PlanejamentoRoteiro> result = criteria.list(); long result = (Long) criteria.list().get(0); return result; }
From source file:br.com.muranodesign.dao.impl.PlanejamentoRoteiroDAOImpl.java
License:Creative Commons License
public /*List<PlanejamentoRoteiro>*/long listarAlunoCorrigidos(int id) { Criteria criteria = getSession().createCriteria(PlanejamentoRoteiro.class); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); criteria.add(Restrictions.ge("dataStatusPlanejado", cal.getTime())); criteria.add(Restrictions.eq("idAluno", id)); criteria.add(Restrictions.isNotNull("objetivo")); criteria.add(Restrictions.eq("status", "3")); criteria.setProjection(Projections.count("idAluno")); //List<PlanejamentoRoteiro> result = criteria.list(); long result = (Long) criteria.list().get(0); return result; }
From source file:br.com.muranodesign.dao.impl.PlanoEstudoDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<PlanoEstudo> utimoPlanoEstudos(int idAluno) { Criteria criteria = getSession().createCriteria(PlanoEstudo.class); criteria.createAlias("aluno", "aluno"); Criteria criteria2 = getSession().createCriteria(PlanoEstudo.class); criteria2.createAlias("aluno", "aluno"); criteria2.add(Restrictions.eq("aluno.idAluno", idAluno)); criteria2.setProjection(Projections.max("dataInicio")); criteria.add(Restrictions.eq("aluno.idAluno", idAluno)); criteria.add(Restrictions.eq("dataInicio", criteria2.uniqueResult())); List<PlanoEstudo> result = criteria.list(); return result; }
From source file:br.com.muranodesign.dao.impl.ProfessorFuncionarioDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<ProfessorFuncionario> listAll() { Criteria criteria = getSession().createCriteria(ProfessorFuncionario.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("idprofessorFuncionario"), "idprofessorFuncionario"); projList.add(Projections.property("nome"), "nome"); criteria.setProjection(projList); criteria.setResultTransformer(Transformers.aliasToBean(ProfessorFuncionario.class)); List<ProfessorFuncionario> results = criteria.list(); return results; }
From source file:br.com.muranodesign.dao.impl.ProfessorFuncionarioDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<ProfessorFuncionario> listarIdNome() { Criteria criteria = getSession().createCriteria(ProfessorFuncionario.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("idprofessorFuncionario"), "idprofessorFuncionario"); projList.add(Projections.property("nome"), "nome"); criteria.add(Restrictions.eq("ativo", "s")); criteria.setProjection(projList); criteria.setResultTransformer(Transformers.aliasToBean(ProfessorFuncionario.class)); List<ProfessorFuncionario> results = criteria.list(); return results; }
From source file:br.com.muranodesign.dao.impl.RegistroDiarioDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<RegistroDiario> listarUltimo() { Criteria criteria = getSession().createCriteria(RegistroDiario.class); criteria.setProjection(Projections.max("data")); List<RegistroDiario> 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 w w w .j a v a 2 s. 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.muranodesign.dao.impl.RoteiroDAOImpl.java
License:Creative Commons License
@Override @SuppressWarnings("unchecked") public List<Roteiro> listarAnoEstudoLazy(int anoEstudo) { Criteria criteria = getSession().createCriteria(Roteiro.class); ProjectionList projList = Projections.projectionList(); criteria.createAlias("anoEstudo", "anoEstudo"); criteria.add(Restrictions.eq("anoEstudo.idanoEstudo", anoEstudo)); criteria.add(Restrictions.eqOrIsNull("ativo", 1)); projList.add(Projections.property("idroteiro"), "idroteiro"); projList.add(Projections.property("nome"), "nome"); criteria.setProjection(projList).setCacheable(true); criteria.setResultTransformer(Transformers.aliasToBean(Roteiro.class)); List<Roteiro> result = criteria.list(); return result; }
From source file:br.com.muranodesign.dao.impl.TutoriaDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<Tutoria> listarDadosPertinentes() { Criteria criteria = getSession().createCriteria(Tutoria.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("idtutoria"), "idtutoria"); projList.add(Projections.property("tutoria"), "tutoria"); criteria.setProjection(projList).setCacheable(true); criteria.setResultTransformer(Transformers.aliasToBean(Tutoria.class)); List<Tutoria> results = criteria.list(); return results; }
From source file:br.com.pfood.dao.imp.GenericDAOImp.java
@Override public int buscaProximoCodigo(Class classe) throws Exception { Field[] fields = classe.getDeclaredFields(); Criteria c = getSession().createCriteria(classe); for (Field f : fields) { f.setAccessible(true);/*from w w w . j a va 2 s .c o m*/ if (f.isAnnotationPresent(Id.class)) { c.setProjection(Projections.max(f.getName())); break; } } c.setResultTransformer(c.DISTINCT_ROOT_ENTITY); Integer maximo = (Integer) c.uniqueResult(); if (maximo == null || maximo == 0) { return 1; } else { return maximo + 1; } }