Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

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

Prototype

public Criteria createAlias(String associationPath, String alias) throws HibernateException;

Source Link

Document

Join an association, assigning an alias to the joined association.

Usage

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

License:Open Source License

/**
 *
 * @param period/*www .  j  ava2s . c  o  m*/
 * @param state
 * @param type
 * @param direction
 * @return
 */
@Override
public List<Movement> listByPeriodAndStateAndTypeAndDirection(FinancialPeriod period, MovementStateType state,
        MovementType type, MovementClassType direction) {

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

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

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

    criteria.createAlias("financialPeriod", "fp");
    criteria.add(Restrictions.eq("fp.id", period.getId()));

    if (direction != null) {
        criteria.createAlias("apportionments", "ap");
        criteria.createAlias("ap.movementClass", "mc");
        criteria.add(Restrictions.eq("mc.movementClassType", direction));
    }

    return criteria.list();
}

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

License:Open Source License

/**
 * // w ww.j  a va2  s.  c o m
 * @param user
 * @return 
 */
@Override
public List<Permission> listByUser(User user) {

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

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

    return criteria.list();
}

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

License:Open Source License

/**
 * //from   w w w  .ja v  a2s  .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  v a2  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.user.UserPrivateMessageRepository.java

License:Open Source License

@Override
public List<UserPrivateMessage> listReceipts(PrivateMessage privateMessage) {

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

    criteria.createAlias("privateMessage", "pm");
    criteria.add(Restrictions.eq("pm.id", privateMessage.getId()));

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    return criteria.list();
}

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

License:Open Source License

/**
 * /*from www.j  ava  2 s.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  v a  2s  .  c om*/
 * @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.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);/*ww w .j a  va2 s. c o  m*/
    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;
}

From source file:br.gov.jfrj.siga.hibernate.ExDao.java

License:Open Source License

public ExModelo consultarExModelo(String sForma, String sModelo) {
    final Criteria crit = getSessao().createCriteria(ExModelo.class);
    crit.add(Restrictions.eq("nmMod", sModelo));
    crit.add(Restrictions.eq("hisAtivo", 1));

    if (sForma != null) {
        crit.createAlias("exFormaDocumento", "f");
        crit.add(Restrictions.eq("f.descrFormaDoc", sForma));
    }//from w w w  .j a  v  a2 s . co m
    return (ExModelo) crit.uniqueResult();
}

From source file:br.gov.mdarte.controleacesso.cd.PerfilDAOImpl.java

protected Object handleFilter(DataObject vo) throws br.gov.mdarte.controleacesso.cd.DAOException {

    Session session = AbstractDAO.currentSession();
    Criteria criterios = session.createCriteria(PerfilImpl.class);

    if (vo instanceof PerfilVO) {
        PerfilVO perfilVO = (PerfilVO) vo;

        if (!Util.checkEmpty(perfilVO.getNome())) {
            criterios.add(Restrictions.eq("nome", perfilVO.getNome()));
        }/*from ww w.ja  v a  2s. co  m*/

        if (!Util.checkEmpty(perfilVO.getSistema())) {
            criterios.createAlias("sistema", "sistema");
            criterios.add(Restrictions.eq("sistema.nome", perfilVO.getSistema()));
        }
    }

    return criterios;
}