List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
From source file:br.com.prototipo.dao.DisciplinaDao.java
public List<String> getListDisciplinasString() { if (sessao.isConnected()) { sessao.close();/* ww w . j a va 2 s . c o m*/ } sessao = HibernateUtil.getSessionFactory().openSession(); Criteria cri = sessao.createCriteria(Disciplina.class); Criteria cri2 = sessao.createCriteria(Disciplina.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.DisciplinaDao.java
public List<Disciplina> getList(Disciplina d) { if (sessao.isConnected()) { sessao.close();/*from w w w. j a va 2s. c o m*/ } sessao = HibernateUtil.getSessionFactory().openSession(); Criteria cri = sessao.createCriteria(Disciplina.class); Criterion _nome = Restrictions.like("nome", d.getNome(), MatchMode.ANYWHERE); cri.add(_nome); cri.addOrder(Order.asc("nome")); this.list = cri.list(); return list; }
From source file:br.com.prototipo.dao.ProfessorDao.java
public List<Professor> getList(String p) { if (sessao.isConnected()) { sessao.close();/*from w w w .j ava 2 s . com*/ } sessao = HibernateUtil.getSessionFactory().openSession(); trans = sessao.beginTransaction(); Criteria cri = sessao.createCriteria(Professor.class); Criterion _nome = Restrictions.like("nome", p, MatchMode.ANYWHERE); cri.add(_nome); cri.addOrder(Order.asc("nome")); this.list = cri.list(); return this.list; }
From source file:br.com.prototipo.dao.ProfessorDao.java
public List<String> getListProfessoresString() { if (sessao.isConnected()) { sessao.close();//from www .jav a2 s . co m } sessao = HibernateUtil.getSessionFactory().openSession(); Criteria cri = sessao.createCriteria(Professor.class); Criteria cri2 = sessao.createCriteria(Professor.class); cri.addOrder(Order.asc("registro")); cri2.addOrder(Order.asc("registro")); ProjectionList projection = Projections.projectionList(); projection.add(Projections.property("registro")); 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.TurmaDao.java
public List<String> getListTurmasString() { if (sessao.isConnected()) { sessao.close();//from www . j ava 2 s.c o m } sessao = HibernateUtil.getSessionFactory().openSession(); Criteria cri = sessao.createCriteria(Turma.class); cri.addOrder(Order.asc("codigo")); Criteria cri2 = sessao.createCriteria(Turma.class); cri2.addOrder(Order.asc("codigo")); ProjectionList projection = Projections.projectionList(); projection.add(Projections.property("codigo")); cri.setProjection(projection); ProjectionList projection2 = Projections.projectionList(); projection2.add(Projections.property("nomeDisciplina")); 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.TurmaDao.java
public List<Turma> getList(String busca) { if (sessao.isConnected()) { sessao.close();// ww w. ja v a 2s. c o m } sessao = HibernateUtil.getSessionFactory().openSession(); Criteria cri = sessao.createCriteria(Turma.class); Criterion _codigo = Restrictions.like("codigo", busca, MatchMode.START); cri.add(_codigo); cri.addOrder(Order.asc("codigo")); this.lista = cri.list(); return this.lista; }
From source file:br.com.railsos.os.dao.FuncionarioDAO.java
public List<Funcionario> buscaPorTecnico(int ordemServicoId) { Session sessao = HibernateUtil.getSessionFactory().openSession(); try {/*from w ww .j a v a2s .co m*/ Criteria consulta = sessao.createCriteria(Funcionario.class); consulta.add(Restrictions.eq("ordemservico.id", ordemServicoId)); consulta.addOrder(Order.asc("nome")); List<Funcionario> resultado = consulta.list(); return resultado; } catch (RuntimeException erro) { throw erro; } finally { sessao.close(); } }
From source file:br.com.railsos.os.dao.GenericDAO.java
/** * Mtodo Genrico Listar Lista o Conteudo da tabela * * @author Rafael//ww w . j a v a 2 s.com */ public List<Entidade> listar(String campoOrdenacao) { Session sessao = HibernateUtil.getSessionFactory().openSession(); try { Criteria consulta = sessao.createCriteria(classe); consulta.addOrder(Order.asc(campoOrdenacao)); List<Entidade> resultado = consulta.list(); return resultado; } catch (RuntimeException erro) { throw erro; } finally { sessao.close(); } }
From source file:br.com.registro.modelo.ControleDAO.java
public List<Controle> listaControle() { List<Controle> listaControle = new ArrayList<>(); sessao = HibernateUtil.getSessionFactory().openSession(); sessao.beginTransaction();//from w ww .j av a 2s . c o m Criteria criterio = sessao.createCriteria(Controle.class); criterio.addOrder(Order.asc("data")); listaControle = criterio.list(); return listaControle; }
From source file:br.com.reindex.suri.framework.dao.DaoSupport.java
License:Open Source License
/** * Metodo Responsavel por recuperar todos os objeto de uma tabela da base de dados de forma ordenada * /*from w w w. j a v a 2s . c o m*/ * @param sort asc - ascending or desc - descending * @param propertyName property to be ordered * @return todos os objetos da classe */ public List<T> retrieveAll(SearchSort sort, String... propertiesName) { Criteria criteria = getSession().createCriteria(tipo); if (SearchSort.ASCENDING.equals(sort)) { for (String property : propertiesName) { criteria.addOrder(Order.asc(property)); } } else if (SearchSort.DESCENDING.equals(sort)) { for (String property : propertiesName) { criteria.addOrder(Order.desc(property)); } } return criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); }