List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
From source file:br.ufac.sion.dao.CargoFacade.java
@Override public List<Cargo> findByDescricaoAndNivel(Cargo filtro) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(Cargo.class); if (StringUtils.isNotBlank(filtro.getDescricao())) { criteria.add(Restrictions.ilike("descricao", filtro.getDescricao(), MatchMode.ANYWHERE)); }//from w w w . j a v a 2 s . com if (filtro.getNivel() != null) { criteria.add(Restrictions.eq("nivel", filtro.getNivel())); } return criteria.addOrder(Order.asc("descricao")).list(); }
From source file:br.ufac.sion.dao.CargoFacade.java
@Override public List<Cargo> findByNivel(Nivel nivel) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(Cargo.class).add(Restrictions.eq("nivel", nivel)); return criteria.addOrder(Order.asc("descricao")).list(); }
From source file:br.ufac.sion.dao.OrgaoExpedidorFacade.java
@Override public List<OrgaoExpedidor> findByNomeAndSigla(FiltroOrgaoExpedidor filtro) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(OrgaoExpedidor.class); if (StringUtils.isNotBlank(filtro.getNome())) { criteria.add(Restrictions.ilike("nome", filtro.getNome(), MatchMode.ANYWHERE)); }/*www . ja v a 2s . c o m*/ if (StringUtils.isNotBlank(filtro.getSigla())) { criteria.add(Restrictions.ilike("sigla", filtro.getSigla(), MatchMode.ANYWHERE)); } return criteria.addOrder(Order.asc("nome")).list(); }
From source file:br.ufc.ivela.commons.dao.GenericDaoImpl.java
License:Open Source License
public List<T> getLastRecords(final String fieldToOrder, final int orderType, final int number) { HibernateCallback callback = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria criteria = session.createCriteria(clazz); if (number != 0) { criteria.setMaxResults(number); }/*from www. j av a2s . c om*/ if (orderType == ORDER_DESC) { return criteria.addOrder(Order.desc(fieldToOrder)).list(); } else if (orderType == ORDER_ASC) { return criteria.addOrder(Order.asc(fieldToOrder)).list(); } else { return criteria.list(); } } }; return (List<T>) getHibernateTemplate().execute(callback); }
From source file:br.ufg.calendario.dao.CalendarioDao.java
@Transactional(readOnly = true) public List<Calendario> listar() { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Calendario.class); criteria.addOrder(Order.asc("ano")); return criteria.list(); }
From source file:br.ufg.calendario.dao.CalendarioDao.java
@Transactional(readOnly = true) public List<Calendario> listar(int first, int pageSize, String sortField, String sortOrder, Map<String, Object> filters) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Calendario.class); criteria.setFirstResult(first);// ww 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)); } } if (filters != null && !filters.isEmpty()) { for (Entry<String, Object> filter : filters.entrySet()) { criteria.add(Restrictions.eq(filter.getKey(), filter.getValue())); } } return criteria.list(); }
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);/* w ww. java 2s. 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.InteressadoDao.java
@Transactional(readOnly = true) public List<Interessado> listar() { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Interessado.class); criteria.addOrder(Order.asc("nome")); return criteria.list(); }
From source file:br.ufg.calendario.dao.InteressadoDao.java
@Transactional(readOnly = true) public List<Interessado> listar(int first, int pageSize, String sortField, String sortOrder, Map<String, Object> filters) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Interessado.class); criteria.setFirstResult(first);/* w w w . j av a2s .com*/ 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)); } } if (filters != null && !filters.isEmpty()) { for (Entry<String, Object> filter : filters.entrySet()) { criteria.add(Restrictions.eq(filter.getKey(), filter.getValue())); } } return criteria.list(); }