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:com.algaworks.repository.Clientes.java

public List<Cliente> filtrados(ClienteFilter filtro) {
    Session session = manager.unwrap(Session.class);

    Criteria criteria = session.createCriteria(Cliente.class);

    if (StringUtils.isNotBlank(filtro.getDocumentoReceitaFederal()))
        criteria.add(Restrictions.ilike("documentoReceitaFederal", filtro.getDocumentoReceitaFederal(),
                MatchMode.ANYWHERE));/*from   w ww. j a  va2 s  .c  o  m*/

    if (StringUtils.isNotBlank(filtro.getNome()))
        criteria.add(Restrictions.ilike("nome", filtro.getNome(), MatchMode.ANYWHERE));

    return criteria.addOrder(Order.asc("nome")).list();
}

From source file:com.algaworks.repository.Produtos.java

public List<Produto> filtrados(ProdutoFilter filtro) {
    Session session = manager.unwrap(Session.class);

    Criteria criteria = session.createCriteria(Produto.class);

    if (StringUtils.isNotBlank(filtro.getSku()))
        criteria.add(Restrictions.eq("sku", filtro.getSku()));

    if (StringUtils.isNotBlank(filtro.getNome()))
        criteria.add(Restrictions.ilike("nome", filtro.getNome(), MatchMode.ANYWHERE));

    return criteria.addOrder(Order.asc("nome")).list();
}

From source file:com.algaworks.repository.Usuarios.java

public List<Usuario> filtrados(String nome) {
    Session session = manager.unwrap(Session.class);

    Criteria criteria = session.createCriteria(Usuario.class);

    if (StringUtils.isNotBlank(nome))
        criteria.add(Restrictions.ilike("nome", nome, MatchMode.ANYWHERE));

    return criteria.addOrder(Order.asc("nome")).list();
}

From source file:com.app.inventario.dao.FamiliaDAOImpl.java

public List<Familia> obtenerTodosAGrid(String ordenarPor, String ordenarAsc) {
    List<Familia> result = null;
    try {/*from  w w  w .  j a  va  2  s  . c  om*/
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Familia.class);
        if (ordenarAsc.equalsIgnoreCase("asc")) {
            criteria.addOrder(Order.asc(ordenarPor));
        } else if (ordenarAsc.equalsIgnoreCase("desc")) {
            criteria.addOrder(Order.desc(ordenarPor));
        }
        result = criteria.list();
    } catch (HibernateException he) {
        Logger.getLogger(FamiliaDAOImpl.class.getName()).log(Level.SEVERE, null, he);
        tx.rollback();
        throw he;
    } finally {
        // Cerrar la session
    }
    return result;
}

From source file:com.app.inventario.dao.ProveedorDAOImpl.java

public List<Proveedor> obtenerTodosAGrid(String ordenarPor, String ordenarAsc) {
    List<Proveedor> result = null;
    try {/*from   ww  w .  j  av  a  2 s  .  c o m*/
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Proveedor.class);
        if (ordenarAsc.equalsIgnoreCase("asc")) {
            criteria.addOrder(Order.asc(ordenarPor));
        } else if (ordenarAsc.equalsIgnoreCase("desc")) {
            criteria.addOrder(Order.desc(ordenarPor));
        }
        result = criteria.list();
    } catch (HibernateException he) {
        Logger.getLogger(ProveedorDAOImpl.class.getName()).log(Level.SEVERE, null, he);
        tx.rollback();
        throw he;
    } finally {
        // Cerrar la session
    }
    return result;
}

From source file:com.app.inventario.dao.UsuarioDAOImpl.java

public List<Usuario> obtenerTodosAGrid(String ordenarPor, String ordenarAsc) {
    List<Usuario> result = null;
    try {//  w  w w.j a  v a  2  s  . co m
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Usuario.class);
        if (ordenarAsc.equalsIgnoreCase("asc")) {
            criteria.addOrder(Order.asc(ordenarPor));
        } else if (ordenarAsc.equalsIgnoreCase("desc")) {
            criteria.addOrder(Order.desc(ordenarPor));
        }
        result = criteria.list();
    } catch (HibernateException he) {
        this.manejaExcepcion(he);
    } finally {
        // Cerrar la session
    }
    return result;
}

From source file:com.ar.dev.tierra.api.dao.impl.CategoriaDAOImpl.java

@SuppressWarnings("unchecked")
@Override//  ww w  . ja  v a 2s .  c o  m
public List<Categoria> getAll() {
    Criteria criteria = getSession().createCriteria(Categoria.class);
    criteria.add(Restrictions.eq("estado", true));
    criteria.addOrder(Order.asc("idCategoria"));
    List<Categoria> list = criteria.list();
    return list;
}

From source file:com.ar.dev.tierra.api.dao.impl.ClienteDAOImpl.java

@SuppressWarnings("unchecked")
@Override/*  w ww  . j av  a2  s  .  co m*/
public List<Cliente> getAll() {
    Criteria criteria = getSession().createCriteria(Cliente.class);
    criteria.addOrder(Order.asc("idCliente"));
    List<Cliente> list = criteria.list();
    return list;
}

From source file:com.ar.dev.tierra.api.dao.impl.DetalleFacturaDAOImpl.java

@SuppressWarnings("unchecked")
@Override//from w w w  .  j ava2  s.  c  om
public List<DetalleFactura> getAll() {
    Criteria criteria = getSession().createCriteria(DetalleFactura.class);
    criteria.add(Restrictions.eq("estadoDetalle", true));
    criteria.addOrder(Order.asc("idDetalleFactura"));
    List<DetalleFactura> list = criteria.list();
    return list;
}

From source file:com.ar.dev.tierra.api.dao.impl.DetalleFacturaDAOImpl.java

@Override
public List<DetalleFactura> getDay() {
    Criteria criteria = getSession().createCriteria(DetalleFactura.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.asc("idDetalleFactura"));
    List<DetalleFactura> list = criteria.list();
    return list;/* ww w  .ja v  a2s  .  c  om*/
}