Example usage for org.hibernate Criteria setFirstResult

List of usage examples for org.hibernate Criteria setFirstResult

Introduction

In this page you can find the example usage for org.hibernate Criteria setFirstResult.

Prototype

public Criteria setFirstResult(int firstResult);

Source Link

Document

Set the first result to be retrieved.

Usage

From source file:br.com.muranodesign.dao.impl.AlunoVariavelDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<AlunoVariavel> ListarRangePeriodoSemGrupo(int idPeriodo, int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(AlunoVariavel.class);
    String ano = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
    AnoLetivo anoLetivo = new AnoLetivoService().listarAnoLetivo(ano).get(0);
    criteria.add(Restrictions.eq("anoLetivo", anoLetivo));
    criteria.add(Restrictions.eq("ativo", 1));
    criteria.createAlias("periodo", "periodo");
    criteria.add(Restrictions.eq("periodo.idperiodo", idPeriodo));
    criteria.createAlias("grupo", "grupo", Criteria.LEFT_JOIN);
    criteria.add(Restrictions.or(Restrictions.isNull("grupo"), Restrictions.eq("grupo.status", "1")));
    criteria.createAlias("anoEstudo", "anoEstudo");
    criteria.addOrder(Order.asc("anoEstudo.ano"));
    criteria.createAlias("aluno", "aluno");
    criteria.addOrder(Order.asc("aluno.nome"));
    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);/*  w  ww.j av a2  s  .  c  om*/
    List<AlunoVariavel> result = criteria.list();
    return result;
}

From source file:br.com.muranodesign.dao.impl.MensagensDAOImpl.java

License:Creative Commons License

@SuppressWarnings("unchecked")
public List<Mensagens> listIntervalo(int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(Mensagens.class);
    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);/*from   w ww  .  j  a v a  2s  .  c o  m*/

    criteria.addOrder(Order.asc("lida"));
    criteria.addOrder(Order.desc("data"));
    criteria.addOrder(Order.desc("idmensagens"));

    List<Mensagens> result = criteria.list();

    return result;
}

From source file:br.com.muranodesign.dao.impl.MensagensDAOImpl.java

License:Creative Commons License

@Override
@SuppressWarnings("unchecked")
/*//w  w  w  . j a  v  a 2 s.  c o m
 * (non-Javadoc)
 * @see br.com.muranodesign.dao.MensagensDAO#listarProprietario(br.com.muranodesign.model.Usuario, java.lang.String, int, int)
 */
public List<Mensagens> listarProprietario(Usuario proprietario, String caixa, int primeiro, int ultimo) {
    Criteria criteria = getSession().createCriteria(Mensagens.class);

    criteria.addOrder(Order.asc("lida"));
    criteria.addOrder(Order.desc("data"));
    criteria.addOrder(Order.desc("idmensagens"));

    if (caixa.equals("entrada")) {
        criteria.add(Restrictions.eq("cxEntrada", "S"));

    } else if (caixa.equals("enviado")) {
        criteria.add(Restrictions.eq("cxEnviada", "S"));

    }

    criteria.setFirstResult(primeiro);
    criteria.setMaxResults(ultimo);

    criteria.add(Restrictions.eq("proprietario", proprietario));

    List<Mensagens> 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);
    criteria.setMaxResults(ultimo);/*  www  .  j  a  va2 s  .c  o m*/
    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.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);
    }//from 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.tcc.service.persistence.PaginationHelper.java

/**
 * <p>//from w  w  w.j a  v a 2s.  c o  m
 * Executa o criteria dado retornando o resultado em uma PagedList de T.
 * </p>
 * <p>
 * <b>ATENO:</b> Este mtodo <b>altera permanentemente</b> o objeto {@link Criteria} recebido como parmetro. Qualquer {@link Projection} ou {@link ResultTransformer} configurado no criteria
 * <b>ser substitudo</b>.
 * </p>
 * <p>
 * Use o parmetro <code>distinct</code> para definir se o {@link ResultTransformer} deve ser
 * {@link Criteria.DISTINCT_ROOT_ENTITY} ou apenas {@link Criteria.ROOT_ENTITY}
 * e se deve ser usado <code>distinct count(*)</code> ou apenas <code>count(*)</code>.
 * </p>
 *
 * @param <T> Tipo de Entidade que ser retornada na PagedList
 * @param pagination Paginao utilizada
 * @param criteria criteria
 * @param distinct Se a consulta deve usar <code>SQL DISTINCT</code>.
 * @return pagedList de T
 */
public static <T> PagedList<T> executeCriteriaForPagination(final Pagination pagination,
        final Criteria criteria, boolean distinct) {

    criteria.setFirstResult(0);
    Pagination paginationToReturn = getTotalItemsForCriteria(criteria, pagination, distinct);
    CriteriaHelper.addOrderCriteria(criteria, pagination.getOrdering());
    final List<T> list = criteria.setFirstResult(pagination.getFirstItemIndex())
            .setMaxResults(pagination.getPageSize()).list();

    return new PagedList<T>(list, paginationToReturn);
}

From source file:br.com.tesouro.controll.facade.AbstractFacade.java

public List<T> findRange(int[] range) {
    Criteria q = getSession().createCriteria(entityClass);
    q.setMaxResults(range[1] - range[0] + 1);
    q.setFirstResult(range[0]);
    return q.list();
}

From source file:br.com.thiaguten.persistence.spi.provider.hibernate.HibernatePersistenceProvider.java

License:Apache License

private Criteria criteriaRange(Criteria criteria, int firstResult, int maxResults) {
    if (criteria != null) {
        if (maxResults >= 0) {
            criteria.setMaxResults(maxResults);
        }//from  w  ww.  j  a va 2s .c o  m
        if (firstResult >= 0) {
            criteria.setFirstResult(firstResult);
        }
    }
    return criteria;
}

From source file:br.com.webbudget.domain.model.repository.entries.CardInvoiceRepository.java

License:Open Source License

/**
 *
 * @param card// w  w w  .  j  a v  a  2  s.  c o  m
 * @param pageRequest
 * @return
 */
@Override
public Page<CardInvoice> listByCard(Card card, PageRequest pageRequest) {

    final Criteria criteria = this.createCriteria();

    // filtra
    if (card != null) {
        criteria.createAlias("card", "ca");
        criteria.add(Restrictions.eq("ca.id", card.getId()));
    }

    // projetamos para pegar o total de paginas possiveis
    criteria.setProjection(Projections.count("id"));

    final Long totalRows = (Long) criteria.uniqueResult();

    // limpamos a projection para que a criteria seja reusada
    criteria.setProjection(null);
    criteria.setResultTransformer(Criteria.ROOT_ENTITY);

    // paginamos
    criteria.setFirstResult(pageRequest.getFirstResult());
    criteria.setMaxResults(pageRequest.getPageSize());

    if (pageRequest.getSortDirection() == PageRequest.SortDirection.ASC) {
        criteria.addOrder(Order.asc(pageRequest.getSortField()));
    } else if (pageRequest.getSortDirection() == PageRequest.SortDirection.DESC) {
        criteria.addOrder(Order.desc(pageRequest.getSortField()));
    }

    // montamos o resultado paginado
    return new Page<>(criteria.list(), totalRows);
}

From source file:br.com.webbudget.domain.model.repository.entries.CardRepository.java

License:Open Source License

/**
 * /*  w w w.ja  va  2  s  .co m*/
 * @param isBlocked
 * @param pageRequest
 * @return 
 */
@Override
public Page<Card> listByStatus(Boolean isBlocked, PageRequest pageRequest) {

    final Criteria criteria = this.createCriteria();

    if (isBlocked != null) {
        criteria.add(Restrictions.eq("blocked", isBlocked));
    }

    // projetamos para pegar o total de paginas possiveis
    criteria.setProjection(Projections.count("id"));

    final Long totalRows = (Long) criteria.uniqueResult();

    // limpamos a projection para que a criteria seja reusada
    criteria.setProjection(null);
    criteria.setResultTransformer(Criteria.ROOT_ENTITY);

    // paginamos
    criteria.setFirstResult(pageRequest.getFirstResult());
    criteria.setMaxResults(pageRequest.getPageSize());

    if (pageRequest.getSortDirection() == PageRequest.SortDirection.ASC) {
        criteria.addOrder(Order.asc(pageRequest.getSortField()));
    } else if (pageRequest.getSortDirection() == PageRequest.SortDirection.DESC) {
        criteria.addOrder(Order.desc(pageRequest.getSortField()));
    }

    // montamos o resultado paginado
    return new Page<>(criteria.list(), totalRows);
}