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.repository.movement.MovementRepository.java

License:Open Source License

/**
 *
 * @param filter// ww w. j av a 2 s . c o  m
 * @param paid
 * @return
 */
@Override
public List<Movement> listByFilter(String filter, Boolean paid) {

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

    if (paid != null && paid.equals(Boolean.TRUE)) {
        criteria.add(Restrictions.isNotNull("payment"));
    }

    criteria.createAlias("apportionments", "ap");
    criteria.createAlias("ap.movementClass", "mc");
    criteria.createAlias("ap.costCenter", "cc");
    criteria.createAlias("financialPeriod", "fp");

    // se conseguir castar para bigdecimal trata como um filtro
    try {
        final BigDecimal value = new BigDecimal(filter);
        criteria.add(Restrictions.or(Restrictions.eq("code", filter), Restrictions.eq("value", value),
                Restrictions.ilike("description", filter + "%"), Restrictions.ilike("mc.name", filter + "%"),
                Restrictions.ilike("cc.name", filter + "%"),
                Restrictions.ilike("fp.identification", filter + "%")));
    } catch (NumberFormatException ex) {
        criteria.add(Restrictions.or(Restrictions.eq("code", filter),
                Restrictions.ilike("description", filter + "%"), Restrictions.ilike("mc.name", filter + "%"),
                Restrictions.ilike("cc.name", filter + "%"),
                Restrictions.ilike("fp.identification", filter + "%")));
    }

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

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    return criteria.list();
}

From source file:br.com.webbudget.domain.repository.movement.MovementRepository.java

License:Open Source License

/**
 *
 * @param dueDate//from   w w w  . j  a va  2 s  . c  o m
 * @param showOverdue
 * @return
 */
@Override
public List<Movement> listByDueDate(Date dueDate, boolean showOverdue) {

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

    if (showOverdue) {
        criteria.add(Restrictions.le("dueDate", dueDate));
        criteria.add(Restrictions.eq("movementStateType", MovementStateType.OPEN));
    } else {
        criteria.add(Restrictions.eq("dueDate", dueDate));
    }

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

    return criteria.list();
}

From source file:br.com.webbudget.domain.repository.user.PrivateMessageRepository.java

License:Open Source License

/**
 * //from  w  ww  .  ja va2  s . c  om
 * @param user
 * @return 
 */
@Override
public List<PrivateMessage> listSent(User user) {

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

    criteria.createAlias("sender", "ow");

    criteria.add(Restrictions.eq("ow.id", user.getId()));

    // nao mostra mensagens deletadas nunca
    criteria.add(Restrictions.eq("deleted", false));

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

    return criteria.list();
}

From source file:br.com.webbudget.domain.repository.user.UserPrivateMessageRepository.java

License:Open Source License

/**
 * //w w w.j a va  2  s. c o  m
 * @param user
 * @param showUnread
 * @return 
 */
@Override
public List<UserPrivateMessage> listByUser(User user, Boolean showUnread) {

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

    criteria.createAlias("recipient", "u");
    criteria.add(Restrictions.eq("u.id", user.getId()));

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

    // nao mostra mensagens deletadas nunca
    criteria.add(Restrictions.eq("deleted", false));

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

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    return criteria.list();
}

From source file:br.com.webbudget.domain.repository.wallet.WalletBalanceRepository.java

License:Open Source License

/**
 * /*  w ww. jav  a 2s . c  o m*/
 * @param wallet
 * @param walletBalanceTypes
 * @return 
 */
@Override
public List<WalletBalance> listByWallet(Wallet wallet, WalletBalanceType... walletBalanceTypes) {

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

    criteria.createAlias("targetWallet", "wl");
    criteria.add(Restrictions.eq("wl.id", wallet.getId()));

    if (walletBalanceTypes != null) {
        for (WalletBalanceType type : walletBalanceTypes) {
            criteria.add(Restrictions.eq("walletBalanceType", type));
        }
    }

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

    return criteria.list();
}

From source file:br.com.webbudget.domain.repository.wallet.WalletBalanceRepository.java

License:Open Source License

/**
 * //from w ww. j a va  2s.  c o m
 * @param source
 * @param target
 * @param walletBalanceTypes
 * @return 
 */
@Override
public List<WalletBalance> listByWallet(Wallet source, Wallet target, WalletBalanceType... walletBalanceTypes) {

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

    if (target != null) {
        criteria.createAlias("targetWallet", "tgt");
        criteria.add(Restrictions.eq("tgt.id", target.getId()));
    }

    if (source != null) {
        criteria.createAlias("sourceWallet", "src");
        criteria.add(Restrictions.eq("src.id", source.getId()));
    }

    if (walletBalanceTypes != null) {
        for (WalletBalanceType type : walletBalanceTypes) {
            criteria.add(Restrictions.eq("walletBalanceType", type));
        }
    }

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

    return criteria.list();
}

From source file:br.edu.pazin.dao.TipoUsuarioDAO.java

public List<TipoUsuario> getTodosTipoUsuarios() {
    try {//www. j a va2  s  . c o  m
        Criteria c = getSessao().createCriteria(TipoUsuario.class);
        c.addOrder(Order.asc("papel"));
        return c.list();
    } catch (Exception ex) {
        System.out.println("TipoUsuarioDAO.getTodosTipoUsuarios()");
        return null;
    }
}

From source file:br.eti.sw.pontocerto.dao.impl.SalarioDAOHibernate.java

@Override
public List<Salario> listar() {
    Criteria criteria = this.session.createCriteria(Salario.class);
    criteria.addOrder(Order.asc("salarioBase"));
    return criteria.list();
}

From source file:br.eti.sw.pontocerto.dao.impl.UsuarioDAOHibernate.java

@Override
public List<Usuario> listar() {
    Criteria criteria = this.session.createCriteria(Usuario.class);
    criteria.addOrder(Order.asc("nome"));
    return criteria.list();
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public List<DpPessoa> pessoasPorLotacao(Long id, Boolean incluirSublotacoes, Boolean somenteServidor,
        SituacaoFuncionalEnum situacoesFuncionais) throws AplicacaoException {
    if (id == null || id == 0)
        return null;

    DpLotacao lotacao = consultar(id, DpLotacao.class, false);

    List<DpLotacao> sublotacoes = new ArrayList<DpLotacao>();
    sublotacoes.add(lotacao);/* w ww.j  a va  2 s . com*/
    if (incluirSublotacoes) {
        List<DpLotacao> lotacoes = listarLotacoes();
        boolean continuar = true;
        while (continuar) {
            continuar = false;
            for (DpLotacao lot : lotacoes) {
                if (sublotacoes.contains(lot))
                    continue;
                if (sublotacoes.contains(lot.getLotacaoPai())) {
                    if (!lot.isSubsecretaria()) {
                        sublotacoes.add(lot);
                        continuar = true;
                    }
                }
            }
        }
    }

    List<DpPessoa> lstCompleta = new ArrayList<DpPessoa>();
    for (DpLotacao lot : sublotacoes) {

        Criteria c = HibernateUtil.getSessao().createCriteria(DpPessoa.class);
        c.createAlias("cargo", "c");

        c.add(Restrictions.eq("lotacao.id", lot.getId()));
        if (somenteServidor) {
            c.add(Restrictions.not(Restrictions.in("c.nomeCargo",
                    new String[] { "ESTAGIARIO", "JUIZ SUBSTITUTO", "JUIZ FEDERAL" })));
        }

        c.add(Restrictions.in("situacaoFuncionalPessoa", situacoesFuncionais.getValor()));

        c.add(Restrictions.isNull("dataFimPessoa"));

        c.addOrder(Order.asc("nomePessoa"));

        lstCompleta.addAll((List<DpPessoa>) c.list());

    }
    return lstCompleta;
}