List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:br.ufac.sion.dao.InscricaoFacade.java
@Override public List<Inscricao> findByConcursoAndPNE(FiltroInscritos filtro) { Criteria criteria = criarCriteriaParaFiltro(filtro); criteria.setFirstResult(filtro.getPrimeiroRegistro()); criteria.setMaxResults(filtro.getQuantidadeRegistros()); Criterion portador = Restrictions.eq("necessidadeEspecial.portador", true); Criterion necessitaAtendimento = Restrictions.eq("necessidadeEspecial.necessitaAtendimento", true); criteria.add(Restrictions.or(portador, necessitaAtendimento)); return criteria.list(); }
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())); }/*from ww w . j av a2s .com*/ 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.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); criteria.setMaxResults(pageSize);/*w ww .j av a 2 s . c om*/ 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(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); criteria.setMaxResults(pageSize);//w w w. j ava 2s.c om 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(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); criteria.setMaxResults(pageSize);// ww w. ja va 2s . c o m 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.UsuarioDao.java
@Transactional(readOnly = true) public List<Usuario> listar(int first, int pageSize, String sortField, String sortOrder, Map<String, Object> filters) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Usuario.class); criteria.setFirstResult(first); criteria.setMaxResults(pageSize);//from w ww . j a va 2 s.c o m 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")) { criteria.add(Restrictions.or( Restrictions.like("nome", filters.get(key).toString(), MatchMode.ANYWHERE).ignoreCase(), Restrictions.like("login", filters.get(key).toString(), MatchMode.ANYWHERE) .ignoreCase())); } if (key.equals("perfil")) { PerfilEnum p = (PerfilEnum) filters.get(key); criteria.add(Restrictions.eq("perfil", p)); } } } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Usuario> resultado = criteria.list(); for (Usuario u : resultado) { Hibernate.initialize(u.getPerfil()); } return resultado; }
From source file:ca.myewb.controllers.common.EventList.java
License:Open Source License
private void addPagination(int startPage, int eventsPerPage, Criteria criteria) { if (eventsPerPage > 0) { criteria.setMaxResults(eventsPerPage); }//w ww .j a va 2s.c o m if (startPage > 0) { criteria.setFirstResult(startPage); } }
From source file:ca.myewb.controllers.common.PostList.java
License:Open Source License
private void addPagination(int start, int limit, Criteria criteria) { if (limit > 0) { criteria.setMaxResults(limit);//from w ww .j a va 2 s. co m } if (start > 0) { criteria.setFirstResult(start); } }
From source file:ca.myewb.controllers.common.WhiteboardList.java
License:Open Source License
private void addPagination(int startPage, int whiteboardsPerPage, Criteria criteria) { if (whiteboardsPerPage > 0) { criteria.setMaxResults(whiteboardsPerPage); }//from w ww.j av a 2s. c o m if (startPage > 0) { criteria.setFirstResult(startPage); } }
From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java
License:Open Source License
@Override public PagingLoadResult<UserDetail> getAllUserDetail(PagingLoadConfig config) throws PigeException { PermissionHelper.checkUserManagementPermission(getThreadLocalRequest()); logger.debug("Rcupration des dtails de tous les usagers " + "[Pagination: dpart=" + config.getOffset() + ", max=" + config.getLimit() + "] ..."); BaseFilterPagingLoadConfig xConfig = null; if (config instanceof BaseFilterPagingLoadConfig) { xConfig = (BaseFilterPagingLoadConfig) config; }/*ww w .j a v a 2 s .c o m*/ Session session = null; Transaction tx = null; List<User> users = null; List<UserDetail> userDetailList = null; Integer userCount = 0; Integer start; Integer limit; try { session = PigeHibernateUtil.openSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(User.class); Criterion filterCriterion = PigeHibernateUtil.buildFilterCriterion(xConfig.getFilterConfigs()); if (filterCriterion != null) { criteria.add(filterCriterion); } userCount = (Integer) session.createCriteria(User.class).setProjection(Projections.rowCount()) .uniqueResult(); start = config.getOffset(); limit = userCount; if (limit > 0 && config.getLimit() > 0) { limit = Math.min(config.getLimit(), limit); } logger.debug("Paramtres d'extraction des donnes: dpart=" + start + ", max=" + limit + "] ..."); criteria.setProjection(null); criteria.setResultTransformer(Criteria.ROOT_ENTITY); users = (List) criteria.setFirstResult(start).setMaxResults(limit).list(); tx.commit(); userDetailList = new ArrayList(); for (User u : users) { userDetailList.add(u.getUserDetail()); } logger.debug("Rcupration russie!"); } catch (Exception hex) { logger.error(hex); if (tx != null) { tx.rollback(); } } finally { if (session != null) { session.close(); } } return new BasePagingLoadResult(userDetailList, config.getOffset(), userCount); }