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:org.egov.ptis.actions.reports.BoundaryWisePropUsgeDelegate.java

License:Open Source License

public List getTotPropUsage(Integer bndryNo) {
    LOGGER.debug("Entered into getTotPropUsage method");
    LOGGER.debug("Boundary Number : " + bndryNo);
    List wardList = null;/*from   w  w  w . j  av a  2s . c  o m*/
    Criterion criterion = null;
    Criterion vacantCrit = null;
    Conjunction conjun = Restrictions.conjunction();
    Projection projection = Projections.projectionList().add(Projections.property("propTypeMstrID.id"))
            .add(Projections.count("basicPropertyID")).add(Projections.sum("aggrArrDmd"))
            .add(Projections.sum("aggrCurrDmd")).add(Projections.groupProperty("propTypeMstrID"));
    if (bndryNo != null) {
        criterion = Restrictions.like("zone.id", bndryNo);
        conjun.add(criterion);
    }
    /*
     * Integer vacTypeId = getPropertyIdbyCode("OPEN_PLOT"); vacantCrit =
     * Restrictions.ne("propTypeMstrID", vacTypeId); conjun.add(vacantCrit);
     */
    wardList = propertyDAO.getPropMaterlizeViewList(projection, conjun, null);
    LOGGER.debug("Ward list : " + (wardList != null ? wardList : ZERO));
    LOGGER.debug("Exit from getTotPropUsage method");
    return wardList;
}

From source file:org.egov.ptis.actions.reports.BoundaryWisePropUsgeDelegate.java

License:Open Source License

public List getWardList(Integer zoneNo) {
    LOGGER.debug("Entered into getWardList method");
    LOGGER.debug("Zone Number : " + zoneNo);
    List wardList = null;//ww w . j a  v  a2s .c om
    Conjunction conjun = Restrictions.conjunction();
    if (zoneNo > 0) {
        Criterion criterion = Restrictions.like("zone.id", zoneNo);
        conjun.add(criterion);
        Integer vacTypeId = getPropertyIdbyCode("OPEN_PLOT");
        // Criterion anothercriterion = Restrictions.ne("propTypeMstrID",
        // vacTypeId);
        // conjun.add(anothercriterion);

        Projection projection = Projections.projectionList().add(Projections.property("ward.id"))
                .add(Projections.property("propTypeMstrID.id")).add(Projections.sum("aggrArrDmd"))
                .add(Projections.sum("aggrCurrDmd")).add(Projections.count("basicPropertyID"))
                .add(Projections.groupProperty("ward.id")).add(Projections.groupProperty("propTypeMstrID"));
        Order order = Order.asc("ward.id");
        wardList = propertyDAO.getPropMaterlizeViewList(projection, conjun, order);
    }
    LOGGER.debug("Ward list : " + (wardList != null ? wardList : ZERO));
    LOGGER.debug("Exit from getWardList method");
    return wardList;
}

From source file:org.egov.ptis.actions.reports.ZoneWiseDemandAction.java

License:Open Source License

@Override
public String execute() {
    LOGGER.debug("Entered into execute method");
    String target = "failure";
    List zoneDemandList;//from  w w  w  . ja v a2s  . c  om
    LinkedList<Map<String, Object>> links;
    try {
        HttpServletRequest request = ServletActionContext.getRequest();
        // criterion object consists of statements that needs to done in
        // where clause
        Criterion criterion = null;
        // Projection object consists of the fields that are required in
        // select statements
        Projection projection = Projections.projectionList().add(Projections.property("zone.id"))
                .add(Projections.sum("aggrArrDmd")).add(Projections.sum("aggrCurrDmd"))
                .add(Projections.groupProperty("zone.id"));
        // In Order object we can mention the order in which result needs to
        // displayed.
        Order order = Order.asc("zone.id");
        zoneDemandList = propertyDAO.getPropMaterlizeViewList(projection, criterion, order);
        LOGGER.debug("Zone wise demand list : " + (zoneDemandList != null ? zoneDemandList : ZERO));
        links = prepareDispTagList(zoneDemandList);
        request.setAttribute("links", links);
        target = "success";
    } catch (Exception e) {
        target = "failure";
        LOGGER.error("Error in ZoneWiseDemandAction : " + e.getMessage());
        throw new ApplicationRuntimeException("error in ZoneWiseDemandAction---------------", e);
    }
    LOGGER.debug("Exit from execute method");
    return target;
}

From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionStatAccessImpl.java

License:Apache License

private void addStatProjection(Criteria criteria) throws PersistenceException {
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.rowCount());
    for (ColumnStat<T> column : statResult) {
        if (column.isCountNotNullFlag()) {
            projList.add(Projections.count(column.getColumn().getName()));
        }/*from   w ww  .  java2s.c om*/
        if (column.isMinFlag()) {
            projList.add(Projections.min(column.getColumn().getName()));
        }
        if (column.isMaxFlag()) {
            projList.add(Projections.max(column.getColumn().getName()));
        }
        if (column.isAverageFlag()) {
            projList.add(Projections.avg(column.getColumn().getName()));
        }
        if (column.isSumFlag()) {
            projList.add(Projections.sum(column.getColumn().getName()));
        }
    }

    criteria.setProjection(projList);
}

From source file:org.generationcp.middleware.dao.ims.LotDAO.java

License:Open Source License

public Double getActualLotBalance(Integer lotId) throws MiddlewareQueryException {
    try {/*from w  w  w. jav  a2 s.  co m*/
        if (lotId != null) {
            Lot lot = this.getById(lotId, false);
            Criteria criteria = this.getSession().createCriteria(Transaction.class);
            criteria.setProjection(Projections.sum("quantity"));
            criteria.add(Restrictions.eq("lot", lot));
            // get only committed transactions
            criteria.add(Restrictions.eq("status", 1));
            return (Double) criteria.uniqueResult();
        }
    } catch (HibernateException e) {
        this.logAndThrowException(
                "Error with getActualLotBalance(lotId=" + lotId + QUERY_FROM_LOT + e.getMessage(), e);
    }
    return 0d;
}

From source file:org.generationcp.middleware.dao.ims.LotDAO.java

License:Open Source License

public Double getAvailableLotBalance(Integer lotId) throws MiddlewareQueryException {
    try {/*from ww  w .  jav a 2 s. co  m*/
        if (lotId != null) {
            Lot lot = this.getById(lotId, false);
            Criteria criteria = this.getSession().createCriteria(Transaction.class);
            criteria.setProjection(Projections.sum("quantity"));
            criteria.add(Restrictions.eq("lot", lot));
            // get all non-cancelled transactions
            criteria.add(Restrictions.ne("status", 9));
            return (Double) criteria.uniqueResult();
        }
    } catch (HibernateException e) {
        this.logAndThrowException(
                "Error with getAvailableLotBalance(lotId=" + lotId + QUERY_FROM_LOT + e.getMessage(), e);
    }
    return 0d;
}

From source file:org.generationcp.middleware.dao.LotDAO.java

License:Open Source License

public Long getActualLotBalance(Integer lotId) throws MiddlewareQueryException {
    try {//from  ww w  .  ja  v  a  2  s.  c om
        Lot lot = getById(lotId, false);
        Criteria criteria = getSession().createCriteria(Transaction.class);
        criteria.setProjection(Projections.sum("quantity"));
        criteria.add(Restrictions.eq("lot", lot));
        // get only committed transactions
        criteria.add(Restrictions.eq("status", 1));
        return (Long) criteria.uniqueResult();
    } catch (HibernateException e) {
        throw new MiddlewareQueryException(
                "Error with getActualLotBalance(lotId=" + lotId + ") query from Lot: " + e.getMessage(), e);
    }
}

From source file:org.generationcp.middleware.dao.LotDAO.java

License:Open Source License

public Long getAvailableLotBalance(Integer lotId) throws MiddlewareQueryException {
    try {//w  ww  . j av a2 s  . co  m
        Lot lot = getById(lotId, false);
        Criteria criteria = getSession().createCriteria(Transaction.class);
        criteria.setProjection(Projections.sum("quantity"));
        criteria.add(Restrictions.eq("lot", lot));
        // get all non-cancelled transactions
        criteria.add(Restrictions.ne("status", 9));
        return (Long) criteria.uniqueResult();
    } catch (HibernateException e) {
        throw new MiddlewareQueryException(
                "Error with getAvailableLotBalance(lotId=" + lotId + ") query from Lot: " + e.getMessage(), e);
    }
}

From source file:org.goobi.production.chart.HibernateProjectionProjectTaskList.java

License:Open Source License

@SuppressWarnings("rawtypes")
private synchronized void calculate(Project inProject, List<IProjectTask> myTaskList, Boolean countImages,
        Integer inMax) {/*from   ww w  .j  a v  a2  s . c  o  m*/

    Session session = Helper.getHibernateSession();
    Criteria crit = session.createCriteria(Task.class);

    crit.createCriteria("process", "proc");

    crit.addOrder(Order.asc("ordering"));

    crit.add(Restrictions.eq("proc.template", Boolean.FALSE));
    crit.add(Restrictions.eq("proc.project", inProject));

    ProjectionList proList = Projections.projectionList();

    proList.add(Projections.property("title"));
    proList.add(Projections.property("processingStatus"));
    proList.add(Projections.sum("proc.sortHelperImages"));
    proList.add(Projections.count("id"));
    // proList.add(Projections.groupProperty(("reihenfolge")));

    proList.add(Projections.groupProperty(("title")));
    proList.add(Projections.groupProperty(("processingStatus")));

    crit.setProjection(proList);

    List list = crit.list();

    Iterator it = list.iterator();
    if (!it.hasNext()) {
        logger.debug("No any data!");
    } else {
        Integer rowCount = 0;
        while (it.hasNext()) {
            Object[] row = (Object[]) it.next();
            rowCount++;
            StringBuilder message = new StringBuilder();

            String shorttitle;
            if (((String) row[FieldList.stepName.getFieldLocation()]).length() > 60) {
                shorttitle = ((String) row[FieldList.stepName.getFieldLocation()]).substring(0, 60) + "...";
            } else {
                shorttitle = (String) row[FieldList.stepName.getFieldLocation()];
            }

            IProjectTask pt = null;
            for (IProjectTask task : myTaskList) {
                if (task.getTitle().equals(shorttitle)) {
                    pt = task;
                    break;
                }
            }

            if (pt == null) {
                pt = new ProjectTask(shorttitle, 0, 0);
                myTaskList.add(pt);
            }

            if (TaskStatus.DONE.getValue().equals(row[FieldList.stepStatus.getFieldLocation()])) {
                if (countImages) {
                    pt.setStepsCompleted((Integer) row[FieldList.pageCount.getFieldLocation()]);
                } else {
                    pt.setStepsCompleted((Integer) row[FieldList.processCount.getFieldLocation()]);
                }
            }

            if (countImages) {
                pt.setStepsMax(pt.getStepsMax() + (Integer) row[FieldList.pageCount.getFieldLocation()]);
            } else {
                pt.setStepsMax(pt.getStepsMax() + (Integer) row[FieldList.processCount.getFieldLocation()]);
            }

            // TODO remove following lines all the way to system.out
            for (int i = 0; i < row.length; i++) {
                message.append("|");
                message.append(row[i]);
            }
            logger.debug(Integer.toString(rowCount) + message);

        }
    }

}

From source file:org.iternine.jeppetto.dao.hibernate.HibernateQueryModelDAO.java

License:Apache License

@Override
public Projection buildProjection(String projectionField, ProjectionType projectionType,
        Iterator argsIterator) {//from   www.j  a  v  a 2s. c  om
    Projection projection = new Projection();

    projection.setField(projectionField);

    switch (projectionType) {
    case RowCount:
        projection.setDetails(Projections.rowCount());
        break;

    case Count:
        projection.setDetails(Projections.count(projectionField));
        break;

    case CountDistinct:
        projection.setDetails(Projections.countDistinct(projectionField));
        break;

    case Maximum:
        projection.setDetails(Projections.max(projectionField));
        break;

    case Minimum:
        projection.setDetails(Projections.min(projectionField));
        break;

    case Average:
        projection.setDetails(Projections.avg(projectionField));
        break;

    case Sum:
        projection.setDetails(Projections.sum(projectionField));
        break;

    default:
        throw new RuntimeException("Unexpected projection type: " + projectionType);
    }

    return projection;
}