List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
From source file:br.com.muranodesign.dao.impl.TutoriaDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<Tutoria> listarAno(String ano) { Criteria criteria = getSession().createCriteria(Tutoria.class); criteria.createAlias("anoLetivo", "anoLetivo"); criteria.add(Restrictions.eq("anoLetivo.ano", ano)); criteria.addOrder(Order.asc("tutoria")); List<Tutoria> result = criteria.list(); return result; }
From source file:br.com.muranodesign.dao.impl.TutoriaDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<Tutoria> listarAnoid(int id) { Criteria criteria = getSession().createCriteria(Tutoria.class); criteria.createAlias("anoLetivo", "anoLetivo"); criteria.add(Restrictions.eq("anoLetivo.idanoLetivo", id)); criteria.addOrder(Order.asc("tutoria")); List<Tutoria> result = criteria.list(); return result; }
From source file:br.com.muranodesign.dao.impl.TutoriaDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<Tutoria> listarPeriodo(int id) { Criteria criteria = getSession().createCriteria(Tutoria.class); criteria.createAlias("periodo", "periodo"); criteria.add(Restrictions.eq("periodo.idperiodo", id)); criteria.addOrder(Order.asc("tutoria")); List<Tutoria> result = criteria.list(); return result; }
From source file:br.com.nfsconsultoria.radiologic.dao.GenericDAO.java
public List<Entidade> listar(String campoOrdenacao) { Session sessao = HBUtil.getSessionFactory().openSession(); try {/* w w w. ja va2 s .c o m*/ Criteria consulta = sessao.createCriteria(classe); consulta.addOrder(Order.asc(campoOrdenacao)); List<Entidade> resultado = consulta.list(); return resultado; } catch (RuntimeException ex) { throw ex; } finally { sessao.close(); } }
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 2 s . c o 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.pfood.dao.imp.GenericDAOImp.java
/** * No obrigatrio passar o ORDER, caso receba null vai buscar pelo padro * do banco de dados/*from w ww.java 2 s .c o m*/ * * @param <T> * @param obj * @param order * @return List<T> podendo ser null */ @Override public <T extends Object> List<T> getPorAtributosIguais(T obj, Order order) { Criteria c = session.createCriteria(obj.getClass()); Field[] fields = obj.getClass().getDeclaredFields(); for (Field f : fields) { f.setAccessible(true); if ((f.isAnnotationPresent(Column.class) || f.isAnnotationPresent(ManyToOne.class) || f.isAnnotationPresent(OneToOne.class)) && !f.getType().isPrimitive()) { try { Object valor = f.get(obj); if (valor != null) { c.add(Restrictions.eq(f.getName(), valor)); } } catch (IllegalAccessException ex) { ex.printStackTrace(); } } } c.setResultTransformer(c.DISTINCT_ROOT_ENTITY); if (order != null) { c.addOrder(order); } return (ArrayList<T>) c.list(); }
From source file:br.com.pfood.dao.imp.GenericDAOImp.java
/** * Metodo criado inicialmente para busca de item_tabela_preco. Voce deve * preencher o objeto com os atributos a ser buscado. Vai executar uma busca * apartir de todos os atributos COM VALOR, onde on valor for igual ao * informado ou entao esta null no banco. A busca apenas pelos atributos * que possuem valor, nao em todo os atributos do objeto. * * @param <T>//from ww w . j a v a 2 s. com * @param obj * @param order * @return * @throws Exception */ @Override public <T> List<T> getPorAtributosIguaisOuNull(T obj, Order order) throws Exception { Criteria c = session.createCriteria(obj.getClass()); Field[] fields = obj.getClass().getDeclaredFields(); for (Field f : fields) { f.setAccessible(true); if ((f.isAnnotationPresent(Column.class) || f.isAnnotationPresent(ManyToOne.class) || f.isAnnotationPresent(OneToOne.class)) && !f.getType().isPrimitive()) { try { Object valor = f.get(obj); if (valor != null) { c.add(Restrictions.or(Restrictions.eq(f.getName(), valor), Restrictions.isNull(f.getName()))); } } catch (IllegalAccessException ex) { ex.printStackTrace(); } } } c.setResultTransformer(c.DISTINCT_ROOT_ENTITY); if (order != null) { c.addOrder(order); } return (ArrayList<T>) c.list(); }
From source file:br.com.prototipo.dao.CursoDao.java
public List<String> getListParaTurmas() { if (sessao.isConnected()) { sessao.close();//from ww w . ja va 2s .co m } sessao = HibernateUtil.getSessionFactory().openSession(); Criteria cri = sessao.createCriteria(Curso.class); Criteria cri2 = sessao.createCriteria(Curso.class); cri.addOrder(Order.asc("codigo")); cri2.addOrder(Order.asc("codigo")); ProjectionList projection = Projections.projectionList(); projection.add(Projections.property("codigo")); ProjectionList projection2 = Projections.projectionList(); projection2.add(Projections.property("nome")); cri.setProjection(projection); cri2.setProjection(projection2); List<String> l1 = cri.list(); List<String> l2 = cri2.list(); List<String> l3 = new ArrayList<>(); Iterator<String> it1 = l1.iterator(); Iterator<String> it2 = l2.iterator(); while (it1.hasNext()) { String aux1 = it1.next(); String aux2 = it2.next(); String aux3 = aux1 + " - " + aux2; l3.add(aux3); } return l3; }
From source file:br.com.prototipo.dao.CursoDao.java
public List<Curso> getList(String c) { if (sessao.isConnected()) { sessao.close();//from ww w . j a v a 2s . com } sessao = HibernateUtil.getSessionFactory().openSession(); trans = sessao.beginTransaction(); Criteria cri = sessao.createCriteria(Curso.class); Criterion _nome = Restrictions.like("nome", c, MatchMode.ANYWHERE); cri.add(_nome); cri.addOrder(Order.asc("nome")); this.list = cri.list(); return list; }
From source file:br.com.prototipo.dao.DisciplinaDao.java
public List<String> getListParaTurmas() { if (sessao.isConnected()) { sessao.close();/* www . ja v a2 s . c o m*/ } sessao = HibernateUtil.getSessionFactory().openSession(); Criteria cri = sessao.createCriteria(Disciplina.class); cri.addOrder(Order.asc("codigo")); ProjectionList projection = Projections.projectionList(); projection.add(Projections.property("codigo")); cri.setProjection(projection); listaParaTurmas = cri.list(); return listaParaTurmas; }