Example usage for org.hibernate.criterion Projections count

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

Introduction

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

Prototype

public static CountProjection count(String propertyName) 

Source Link

Document

A property value count projection

Usage

From source file:org.gaixie.micrite.patrolRiverSummary.dao.hibernate.PatrolRiverSummaryDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List findCSGroupByTelVague(SearchBean[] queryBean) {
    DetachedCriteria criteria = SearchFactory.generateCriteria(PatrolRiverSummary.class, queryBean);
    criteria.add(Expression.eq("approveStatus", IPatrolRiverSummaryService.STATUS_NORMAL));
    criteria.addOrder(Order.desc("editDate"));
    criteria.createAlias("carType", "cs");
    criteria.setProjection(Projections.projectionList().add(Projections.count("cs.name"))
            .add(Projections.groupProperty("cs.name")));
    List<PatrolRiverSummary> list = getHibernateTemplate().findByCriteria(criteria);
    //        desidedExpiredFlag(list);
    return list;//from   ww  w.  j  a  v a  2  s  .c o m
}

From source file:org.gaixie.micrite.river.dao.hibernate.RiverDAOImpl.java

@SuppressWarnings("unchecked")
public List findCSGroupByTelVague(SearchBean[] queryBean) {
    DetachedCriteria criteria = SearchFactory.generateCriteria(River.class, queryBean);
    criteria.add(Restrictions.ne("id", SYS_RECORD_ID));
    criteria.createAlias("village", "cs");
    criteria.setProjection(Projections.projectionList().add(Projections.count("cs.vname"))
            .add(Projections.groupProperty("cs.vname")));
    return getHibernateTemplate().findByCriteria(criteria);
}

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  w ww  .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.goobi.production.flow.statistics.hibernate.StatQuestProjectAssociations.java

License:Open Source License

@Override
public List<DataTable> getDataTables(List<? extends BaseDTO> dataSource) {
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.count("id"));
    proj.add(Projections.groupProperty("project.title"));

    Criteria crit;/*from   www  .  j  av  a2s  .  co m*/

    //TODO: fix it
    /*if (originalFilter instanceof UserDefinedFilter) {
    crit = new UserDefinedFilter(originalFilter.getIDList()).getCriteria();
    crit.createCriteria("project", "project");
    } else {
    crit = originalFilter.clone().getCriteria();
    }
    // use a clone on the filter and apply the projection on the clone
    crit.setProjection(proj);*/

    String title = StatisticsMode.getByClassName(this.getClass()).getTitle();

    DataTable dtbl = new DataTable(title);
    dtbl.setShowableInPieChart(true);
    DataRow dRow = new DataRow(Helper.getTranslation("count"));

    //TODO: replace empty list with result list
    for (Object obj : new ArrayList<>()) {
        Object[] objArr = (Object[]) obj;
        dRow.addValue(new Converter(objArr[1]).getString(),
                new Converter(new Converter(objArr[0]).getInteger()).getDouble());
    }
    dtbl.addDataRow(dRow);

    List<DataTable> allTables = new ArrayList<>();

    dtbl.setUnitLabel(Helper.getTranslation("project"));
    allTables.add(dtbl);
    return allTables;
}

From source file:org.headsupdev.agile.storage.issues.IssueHelper.java

License:Open Source License

public static int getIssueCountForProject(Project project) {
    if (project == null) {
        return 0;
    }//w  w  w .jav a 2 s.co  m
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();
    Criteria criteria = session.createCriteria(Issue.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.add(Restrictions.eq("id.project", project));
    criteria.setProjection(Projections.count("id.project"));
    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:org.headsupdev.agile.storage.issues.IssueHelper.java

License:Open Source License

public static int getIssueOpenCountForProject(Project project) {
    if (project == null) {
        return 0;
    }//  w  w  w  .java 2 s  . c o  m
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();
    Criteria criteria = session.createCriteria(Issue.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.add(Restrictions.lt("status", Issue.STATUS_RESOLVED));
    criteria.add(Restrictions.eq("id.project", project));
    criteria.setProjection(Projections.count("id.project"));
    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:org.headsupdev.agile.storage.issues.IssueHelper.java

License:Open Source License

public static int getIssueReOpenedCountForProject(Project project) {
    if (project == null) {
        return 0;
    }/*www.j  a  v a  2 s. c om*/
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();
    Criteria criteria = session.createCriteria(Issue.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.add(Restrictions.ge("reopened", 1));
    criteria.add(Restrictions.eq("id.project", project));
    criteria.setProjection(Projections.count("id.project"));
    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:org.headsupdev.agile.web.wicket.SortableEntityProvider.java

License:Open Source License

public int size() {
    Criteria criteria = createCriteria();
    criteria.setProjection(Projections.count(getCountProperty()));
    return ((Number) criteria.uniqueResult()).intValue();
}

From source file:org.infoscoop.dao.KeywordLogDAO.java

License:Open Source License

/**
 * Get the map to add up keyword-ranking.
 * /*  w  ww . j a  va  2  s  .com*/
 * @param startDate
 * @param endDate
 * @param keywordLogType
 * @return
 */
public Map getCountMap(final String startDate, final String endDate, final Integer keywordLogType) {

    Map countMap = (Map) super.getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Map countMap = new SequencedHashMap();

            Criteria cri = session.createCriteria(Keyword.class);

            SimpleExpression se = Expression.eq("Type", keywordLogType);
            LogicalExpression le = Expression.and(Expression.ge("Date", startDate),
                    Expression.le("Date", endDate));
            LogicalExpression le2 = Expression.and(se, le);
            cri.add(le2);

            Projection projection = Projections.projectionList().add(Projections.property("Keyword"))
                    .add(Projections.count("Keyword").as("KwdCount")).add(Projections.groupProperty("Keyword"));

            cri.setProjection(projection);
            cri.addOrder(Order.desc("KwdCount"));

            try {
                Object[] resultObjs;
                for (Iterator ite = cri.list().iterator(); ite.hasNext();) {
                    resultObjs = (Object[]) ite.next();
                    String keyword = (String) resultObjs[0];
                    Integer count = (Integer) resultObjs[1];

                    countMap.put(keyword, count);
                }

            } catch (Exception e) {
                logger.error("parsing error", e);
                throw new RuntimeException();
            }

            if (log.isInfoEnabled())
                log.info("getCountMap successfully. : startDate=" + startDate + ", endDate=" + endDate
                        + ", keywordLogType=" + keywordLogType);

            return countMap;
        }

    });

    return countMap;
}

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

License:Apache License

@Override
public Projection buildProjection(String projectionField, ProjectionType projectionType,
        Iterator argsIterator) {/*w  w w .  ja v a 2  s. c  o m*/
    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;
}