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:benedict.zhang.addon.persistence.PersistenceManager.java

public AddonDescription loadAddonDescription() {
    session = sessionFactory.openSession();
    session.beginTransaction();//from w  ww .ja  v  a2 s.  c o  m
    Criteria criteria = session.createCriteria(AddonDescription.class);
    criteria.addOrder(Order.desc("version"));
    criteria.setMaxResults(1);
    List addonDescriptions = criteria.list();
    AddonDescription addonDescription = null;
    if (addonDescriptions.isEmpty()) {
        addonDescription = new AddonDescription();
        session.save(addonDescription);
    } else {
        addonDescription = (AddonDescription) addonDescriptions.get(0);
    }
    session.getTransaction().commit();
    session.close();
    return addonDescription;
}

From source file:br.com.arsmachina.dao.hibernate.ReadableDAOImpl.java

License:Apache License

/**
 * Adds <code>sortCriteria</code> to a {@link Criteria} instance.
 * //from ww w  .  j  ava2  s .co  m
 * @param criteria a {@link Criteria}. It cannot be null.
 * @param sortCriteria a {@link SortCriterion}<code>...</code>. It cannot be null.
 * @todo Support for property paths, not just property names.
 */
final public void addSortCriteria(Criteria criteria, SortCriterion... sortCriteria) {

    assert criteria != null;

    if (sortCriteria == null || sortCriteria.length == 0) {
        sortCriteria = getDefaultSortCriteria();
    }

    for (SortCriterion sortingConstraint : sortCriteria) {

        final String property = sortingConstraint.getProperty();
        final boolean ascending = sortingConstraint.isAscending();
        final Order order = ascending ? Order.asc(property) : Order.desc(property);
        criteria.addOrder(order);

    }

}

From source file:br.com.ateliens.repository.ClientesFiltrados.java

@SuppressWarnings("unchecked")
public List<Cliente> filtrados(FiltroCliente filtro) {
    Criteria criteria = criarCriteriaParaFiltro(filtro);

    criteria.setFirstResult(filtro.getPrimeiroRegistro());
    criteria.setMaxResults(filtro.getQuantidadeRegistros());

    if (filtro.isAscendente() && filtro.getPropriedadeOrdenacao() != null) {
        criteria.addOrder(Order.asc(filtro.getPropriedadeOrdenacao()));
    } else if (filtro.getPropriedadeOrdenacao() != null) {
        criteria.addOrder(Order.desc(filtro.getPropriedadeOrdenacao()));
    }//from w w  w  .j  a  v a  2 s. c  om
    return criteria.list();
}

From source file:br.com.bluesoft.pronto.dao.SprintDao.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<Sprint> listar() {
    final Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Sprint.class);
    criteria.addOrder(Order.desc("atual")).addOrder(Order.desc("dataFinal"));
    final List<Sprint> sprints = criteria.list();
    preencheTotaisDeEsforcoEValorDeNegocioDosSprints(sprints);
    return sprints;
}

From source file:br.com.cary.dao.FornecedorDAO.java

public Fornecedor pesquisar(Fornecedor forn) {
    Session s = null;//from   w  w  w  .ja  v a2s . com
    try {
        s = ConectaDB.getSessionFactory().openSession();
        Criteria c = s.createCriteria(Fornecedor.class);
        c.addOrder(Order.asc("nomeFantasia"));
        if (c.uniqueResult() != null) {
            return (Fornecedor) c.uniqueResult();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:br.com.cary.dao.FornecedorDAO.java

public List<Fornecedor> listarOrdenadoPorNomeFantasia() {
    Session s = null;/*  w  ww . ja v a  2 s .  c  o  m*/
    try {
        s = ConectaDB.getSessionFactory().openSession();
        Criteria c = s.createCriteria(Fornecedor.class);
        c.addOrder(Order.asc("nomeFantasia"));
        return c.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:br.com.cary.dao.FornecedorPrecoCustoDAO.java

public List listar(Produto p) {
    List lista = null;//from ww  w  .  j av a 2  s .  com
    Session s = null;
    try {
        s = ConectaDB.getSessionFactory().openSession();
        Criteria crit = s.createCriteria(FornecedorPrecoCusto.class);
        crit.add(Restrictions.eq("produto", p));
        crit.addOrder(Order.asc("preco"));
        lista = crit.list();
    } catch (Exception e) {
        Alertas.mensagemErro(e.getMessage() + "\nErro ao tentar salvar os dados!");
    } finally {
        s.close();
    }
    return lista;
}

From source file:br.com.chamado.dao.DaoGenerico.java

public List carregaTudoOrdernado(Class classe, String ordem) {
    Session session = hibernateConfiguracao.openSession();
    Criteria criterica = session.createCriteria(classe);
    criterica.addOrder(Order.asc(ordem));
    List lista = criterica.list();
    return lista;
}

From source file:br.com.controlehoras.dao.EscalaDao.java

public Escala ultimaDataEscala() {
    sessao = (Session) HibernateUtil.getSessionFactory().openSession();
    try {/*from   w ww  .j a  va2 s .  c om*/
        Criteria criteria = sessao.createCriteria(Escala.class);
        criteria.addOrder(Order.desc("data"));
        return (Escala) criteria.list().get(0);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        sessao.close();
    }
}

From source file:br.com.danese.multitenancy.data.MemberRepository.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Member> findAllOrderedByName() {
    Criteria criteria = session().createCriteria(Member.class);
    criteria.addOrder(Order.asc("name"));

    return criteria.list();
}