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

License:Open Source License

/**
 *
 * @param contact//w ww. j a v a 2s .c  o  m
 * @return
 */
@Override
public List<Movement> listByContact(Contact contact) {

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

    criteria.createAlias("contact", "ct");
    criteria.add(Restrictions.eq("ct.id", contact.getId()));

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

    return criteria.list();
}

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

License:Open Source License

/**
 * //  w  w w .j  a  v  a  2s  .c  om
 * @param period
 * @return 
 */
@Override
public List<Movement> listByPeriod(FinancialPeriod period) {

    final Criteria criteria = this.createCriteria();

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

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param cardInvoice//from w  ww.  ja v a2  s  . com
 * @return
 */
@Override
public List<Movement> listByCardInvoice(CardInvoice cardInvoice) {

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

    criteria.createAlias("cardInvoice", "ci");
    criteria.add(Restrictions.eq("ci.id", cardInvoice.getId()));

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

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param financialPeriod/*from ww  w  . j  av a  2  s .  c om*/
 * @param type
 * @return
 */
@Override
public List<Movement> listByPeriodAndCardType(FinancialPeriod financialPeriod, CardType type) {

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

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

    criteria.createAlias("payment", "py").createAlias("py.card", "cc");
    criteria.add(Restrictions.eq("cc.cardType", type));

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param period/*  www  .j a  v  a2s .  c  o  m*/
 * @param direction
 * @return
 */
@Override
public List<Movement> listByPeriodAndDirection(FinancialPeriod period, MovementClassType direction) {

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

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

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

License:Open Source License

/**
 *
 * @param financialPeriod//from  w  w  w. j av a 2s  .c o  m
 * @param state
 * @return
 */
@Override
public List<Movement> listByPeriodAndState(FinancialPeriod financialPeriod, MovementStateType state) {

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

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

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

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param financialPeriod//from   ww w  . jav a  2s.  co  m
 * @param card
 * @return
 */
@Override
public List<Movement> listPaidWithoutInvoiceByPeriodAndCard(FinancialPeriod financialPeriod, Card card) {

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

    criteria.add(Restrictions.isNull("cardInvoice"));
    criteria.add(Restrictions.eq("cardInvoicePaid", Boolean.FALSE));
    criteria.add(Restrictions.eq("movementStateType", MovementStateType.PAID));

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

    criteria.createAlias("payment", "py").createAlias("py.card", "cc");
    criteria.add(Restrictions.eq("cc.id", card.getId()));

    criteria.addOrder(Order.asc("py.paymentDate"));

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param period/*from  w w w  . java 2s  . com*/
 * @param movementClass
 * @return
 */
@Override
public BigDecimal countTotalByPeriodAndMovementClass(FinancialPeriod period, MovementClass movementClass) {

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

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

    criteria.createAlias("apportionments", "ap");
    criteria.createAlias("ap.movementClass", "mc");
    criteria.add(Restrictions.eq("mc.id", movementClass.getId()));

    criteria.setProjection(Projections.sum("value"));

    return (BigDecimal) criteria.uniqueResult();
}

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

License:Open Source License

/**
 *
 * @param period//from   www  .  j a v  a  2s  .c  o m
 * @param costCenter
 * @return
 */
@Override
public List<Movement> listByPeriodAndCostCenterAndDirection(FinancialPeriod period, CostCenter costCenter,
        MovementClassType direction) {

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

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

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

    criteria.add(Restrictions.eq("mc.movementClassType", direction));
    criteria.add(Restrictions.eq("cc.id", costCenter.getId()));

    return criteria.list();
}

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

License:Open Source License

/**
 *
 * @param period/*w  w  w  . ja  v a  2 s  .co  m*/
 * @param state
 * @param type
 * @param direction
 * @return
 */
@Override
public List<Movement> listByPeriodAndStateAndTypeAndDirection(FinancialPeriod period, MovementStateType state,
        MovementType type, MovementClassType direction) {

    if (period == null) {
        throw new NullPointerException("Period can't be null");
    }

    final Criteria criteria = this.createCriteria();

    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();
}