Example usage for org.hibernate Criteria addOrder

List of usage examples for org.hibernate Criteria addOrder

Introduction

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

Prototype

public Criteria addOrder(Order order);

Source Link

Document

Add an Order ordering to the result set.

Usage

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

License:Open Source License

/**
 *
 * @param isBlocked/*from  w  w  w.  j a va  2  s  .  co  m*/
 * @return
 */
@Override
public List<Card> listByStatus(Boolean isBlocked) {

    final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass());

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

    criteria.addOrder(Order.desc("inclusion"));

    return criteria.list();
}

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

License:Open Source License

/**
 * // w  w  w . j a  v a2  s .c  o  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);
}

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

License:Open Source License

/**
 *
 * @param filter/*from w w  w  .  j av  a  2s  .c o  m*/
 * @param blocked
 * @param pageRequest
 * @return
 */
@Override
public Page<Contact> listLazilyByFilter(String filter, Boolean blocked, PageRequest pageRequest) {

    final Criteria criteria = this.createCriteria();

    if (filter != null) {
        criteria.add(Restrictions.or(Restrictions.ilike("name", "%" + filter + "%"),
                Restrictions.ilike("email", "%" + filter + "%"), Restrictions.eq("document", filter),
                Restrictions.ilike("city", "%" + filter + "%")));
    }

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

    // 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.CostCenterRepository.java

License:Open Source License

/**
 *
 * @param isBlocked/*  www  . ja v a2  s. c  om*/
 * @return
 */
@Override
public List<CostCenter> listByStatus(Boolean isBlocked) {

    final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass());

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

    criteria.addOrder(Order.asc("name"));

    return criteria.list();
}

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

License:Open Source License

/**
 * // w w w. j  a v  a 2 s  .co  m
 * @param isBlocked
 * @param pageRequest
 * @return 
 */
@Override
public Page<CostCenter> listLazilyByStatus(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);
}

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

License:Open Source License

/**
 *
 * @param isBlocked/*from  w ww  .j  a  v a  2 s  .  co  m*/
 * @return
 */
@Override
public List<MovementClass> listByStatus(Boolean isBlocked) {

    final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass());

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

    criteria.addOrder(Order.asc("costCenter"));

    return criteria.list();
}

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

License:Open Source License

/**
 * /*from  w w  w . j  av  a 2 s  .  c o m*/
 * @param isBlocked
 * @param pageRequest
 * @return 
 */
@Override
public Page<MovementClass> listLazilyByStatus(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);
}

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

License:Open Source License

/**
 *
 * @param costCenter//from  w w  w.j  a  v a  2s  .c  o m
 * @return
 */
@Override
public List<MovementClass> listByCostCenterAndType(CostCenter costCenter, MovementClassType type) {

    final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass());

    criteria.createAlias("costCenter", "cc");
    criteria.add(Restrictions.eq("cc.id", costCenter.getId()));

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

    criteria.add(Restrictions.eq("blocked", false));

    criteria.addOrder(Order.asc("name"));

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param isBlocked/*from  w w w.  ja  v a  2 s  .  c  om*/
 * @return
 */
@Override
public List<Vehicle> listByStatus(Boolean isBlocked) {

    final Criteria criteria = this.getSession().createCriteria(this.getPersistentClass());

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

    criteria.addOrder(Order.asc("brand"));

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param isBlocked//from w w w .j  a v  a2 s.c  o  m
 * @param pageRequest
 * @return
 */
@Override
public Page<Vehicle> listLazilyByStatus(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);
}