Example usage for org.hibernate.criterion Projections sum

List of usage examples for org.hibernate.criterion Projections sum

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections sum.

Prototype

public static AggregateProjection sum(String propertyName) 

Source Link

Document

A property value sum projection

Usage

From source file:ar.com.zauber.commons.repository.aggregate.ProjectionAggregateFunctionVisitor.java

License:Apache License

/** crea projecciones en base a {@link PropertyAggregateFunction}. */
private static Projection createPropertyProjection(final PropertyAggregateFunction paf) {
    final String propertyName = paf.getProperty();
    final Projection projection;

    if (paf instanceof AveragePropertyAggregateFunction) {
        projection = Projections.avg(propertyName);
    } else if (paf instanceof CountDistinctPropertyAggregateFunction) {
        projection = Projections.countDistinct(propertyName);
    } else if (paf instanceof CountPropertyAggregateFunction) {
        projection = Projections.count(propertyName);
    } else if (paf instanceof MaxPropertyAggregateFunction) {
        projection = Projections.max(propertyName);
    } else if (paf instanceof MinPropertyAggregateFunction) {
        projection = Projections.min(propertyName);
    } else if (paf instanceof SumPropertyAggregateFunction) {
        projection = Projections.sum(propertyName);
    } else if (paf instanceof GroupPropertyAggregateFilter) {
        projection = Projections.groupProperty(propertyName);
    } else {/*from   w w  w  . j  a  va2 s . c  o  m*/
        throw new IllegalArgumentException("don't know how to process " + paf.getClass());
    }

    return projection;
}

From source file:au.org.theark.lims.model.dao.BiospecimenDao.java

License:Open Source License

public Double getQuantityAvailable(Biospecimen biospecimen) {
    Criteria criteria = getSession().createCriteria(BioTransaction.class);
    criteria.add(Restrictions.eq("biospecimen", biospecimen));
    criteria.setProjection(Projections.sum("quantity"));
    Double sum = (Double) criteria.uniqueResult();
    return sum;//www. j  a  v a  2  s .c o m
}

From source file:au.org.theark.report.model.dao.ReportDao.java

License:Open Source License

public List<ResearcherCostDataRow> getResearcherBillableItemTypeCostData(
        final ResearcherCostResportVO researcherCostResportVO) {
    List<ResearcherCostDataRow> results = new ArrayList<ResearcherCostDataRow>();
    Criteria criteria = getSession().createCriteria(BillableItem.class, "bi");
    criteria.createAlias("workRequest", "wr", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("billableItemType", "bit", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bit.billableItemTypeStatus", "bitst", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("wr.researcher", "re", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("re.id", researcherCostResportVO.getResearcherId()));
    criteria.add(Restrictions.eq("bi.studyId", researcherCostResportVO.getStudyId()));
    criteria.add(Restrictions.eq("bi.invoice", researcherCostResportVO.getInvoice()));
    criteria.add(Restrictions.le("bi.commenceDate", researcherCostResportVO.getToDate()));
    criteria.add(Restrictions.ge("bi.commenceDate", researcherCostResportVO.getFromDate()));
    criteria.add(Restrictions.eq("bitst.name", "ACTIVE"));

    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("bit.id"));
    projectionList.add(Projections.property("bit.itemName"), "costType");
    projectionList.add(Projections.sum("bi.totalCost"), "totalCost");
    projectionList.add(Projections.sum("bi.totalGST"), "totalGST");

    criteria.setProjection(projectionList); // only return fields required for report
    criteria.setResultTransformer(Transformers.aliasToBean(ResearcherCostDataRow.class));

    criteria.addOrder(Order.asc("bit.itemName"));
    results = criteria.list();/*from w  w w. j a v  a 2s  .  com*/
    return results;
}

From source file:bernardo.venda.controle.ProdutoVendaControle.java

public List findAllM(Caixa caixa) {
    Criteria crit = getSession().createCriteria(ProdutoVenda.class, "pv")
            .setProjection(Projections.projectionList().add(Projections.property("produto"))
                    .add(Projections.sum("quantidade")).add(Projections.sum("quantEntrada"))
                    .add(Projections.sum("quantSaida")).add(Projections.groupProperty("produto")))
            .createCriteria("transacao").add(Restrictions.eq("caixa", caixa));

    List results = crit.list();//from  w w w . j  a  va  2s  .c o  m
    return results;
}

From source file:br.com.gerenciapessoal.repository.Lancamentos.java

@SuppressWarnings("UnusedAssignment")
public Map<Date, BigDecimal> valoresTotaisPorData(Integer numeroDeDias, Conta conta) {
    Session session = manager.unwrap(Session.class);

    Calendar dataInicial = Calendar.getInstance();
    dataInicial = DateUtils.truncate(dataInicial, Calendar.DAY_OF_MONTH);
    dataInicial.add(Calendar.DAY_OF_MONTH, numeroDeDias * -1);

    Map<Date, BigDecimal> resultado = criarMapaVazio(numeroDeDias, dataInicial);

    Criteria criteria = session.createCriteria(Lancamento.class).createAlias("conta", "c");

    criteria.setProjection(Projections.projectionList()
            .add(Projections.sqlGroupProjection("date(data_emissao) as data", "date(data_emissao)",
                    new String[] { "data" }, new Type[] { StandardBasicTypes.DATE }))
            .add(Projections.sum("valorLanca").as("valor")))
            .add(Restrictions.ge("dataEmissao", dataInicial.getTime()));

    if (conta != null) {
        criteria.add(Restrictions.eq("c.id", conta.getId()));
    }// ww w . j a  va 2s .co m
    List<DataValor> valoresPorData = criteria.setResultTransformer(Transformers.aliasToBean(DataValor.class))
            .list();

    for (DataValor dataValor : valoresPorData) {
        resultado.put(dataValor.getData(), dataValor.getValor());
    }

    return resultado;
}

From source file:br.com.map.marcelo.dao.VendaDaoImp.java

@Override
public double aputadoMes(Calendar dataInicial, Calendar dataFinal) throws DAOException {
    manager = getEntityManager();//w ww .j  ava2 s . c o m
    double valor = 0;
    try {
        Criteria criteria = getCriteria();
        criteria.add(Restrictions.between("dataVenda", dataInicial, dataFinal));
        criteria.setProjection(Projections.sum("precoTotal"));
        if (criteria.uniqueResult() != null) {
            valor = (double) criteria.uniqueResult();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new DAOException(e.getMessage());
    } finally {
        manager.close();
    }
    return valor;
}

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

License:Open Source License

/**
 *
 * @param movementClass//from w ww.jav a 2 s .  c  om
 * @return
 */
@Override
public BigDecimal totalMovementsPerClass(MovementClass movementClass) {

    final Criteria criteria = this.createCriteria();

    criteria.setProjection(Projections.sum("value"));
    criteria.add(Restrictions.eq("movementClass", movementClass));

    return (BigDecimal) criteria.uniqueResult();
}

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

License:Open Source License

/**
 * /* w  w  w.j  av a2s.  com*/
 * @param period
 * @param movementClass
 * @return 
 */
@Override
public BigDecimal totalMovementsPerClassAndPeriod(FinancialPeriod period, MovementClass movementClass) {

    final Criteria criteria = this.createCriteria();

    criteria.createAlias("movement", "mv");
    criteria.createAlias("mv.financialPeriod", "fp");

    criteria.add(Restrictions.eq("fp.id", period.getId()));
    criteria.add(Restrictions.in("mv.movementStateType",
            new Object[] { MovementStateType.PAID, MovementStateType.CALCULATED }));
    criteria.add(Restrictions.eq("movementClass", movementClass));

    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   w  w  w .  ja v  a2 s.  c  om
 * @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.miscellany.ClosingRepository.java

License:Open Source License

/**
 *
 * @return//  w w  w. ja  va2s. c  om
 */
@Override
public BigDecimal findLastAccumulated() {

    final Criteria criteria = this.createCriteria();

    final DetachedCriteria mostRecent = DetachedCriteria.forClass(Closing.class)
            .setProjection(Projections.max("closingDate"));

    criteria.add(Property.forName("closingDate").eq(mostRecent));
    criteria.setProjection(Projections.sum("accumulated"));

    return (BigDecimal) criteria.uniqueResult();
}