List of usage examples for org.hibernate.criterion Projections min
public static AggregateProjection min(String propertyName)
From source file:net.firejack.platform.core.store.statistics.MetricsEntryStore.java
License:Apache License
@Override public List<AggregatedMetricsEntryModel> findAggregatedByTermAndDates(Integer offset, Integer limit, String term, String lookup, Date startDate, Date endDate, String sortColumn, String sortDirection, MetricGroupLevel level, LogEntryType logEntryType) { ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.min("hourPeriod"), "startTime").add(Projections.max("hourPeriod"), "endTime") .add(Projections.groupProperty("lookup"), "lookup") .add(Projections.groupProperty("systemAccountName"), "systemAccountName") .add(Projections.groupProperty("username"), "username") .add(Projections.sum("numberOfInvocations"), "numberOfInvocations") .add(Projections.avg("averageExecutionTime"), "averageExecutionTime") .add(Projections.min("minResponseTime"), "minResponseTime") .add(Projections.max("maxResponseTime"), "maxResponseTime") .add(Projections.avg("successRate"), "successRate"); switch (level) { case HOUR://from w w w . j a va 2 s .co m projectionList.add(Projections.groupProperty("hourPeriod").as("hourPeriod")); break; case DAY: projectionList.add(Projections.groupProperty("dayPeriod").as("dayPeriod")); break; case WEEK: projectionList.add(Projections.groupProperty("weekPeriod").as("weekPeriod")); break; case MONTH: projectionList.add(Projections.groupProperty("monthPeriod").as("monthPeriod")); break; } return findAllByProjection(offset, limit, term, lookup, startDate, endDate, sortColumn, sortDirection, logEntryType, projectionList); }
From source file:net.jforum.core.hibernate.TopicDAO.java
License:Open Source License
/** * @see net.jforum.repository.TopicRepository#getFirstPost(net.jforum.entities.Topic) *///from ww w .j a v a2s . c o m public Post getFirstPost(Topic topic) { DetachedCriteria firstPost = DetachedCriteria.forClass(Post.class).setProjection(Projections.min("id")) .add(Restrictions.eq("topic", topic)).setComment("topicDAO.getFirstPostID"); return (Post) this.session().createCriteria(Post.class).add(Subqueries.propertyEq("id", firstPost)) .setComment("topicDAO.getFirstPost").uniqueResult(); }
From source file:net.jforum.repository.TopicDao.java
License:Open Source License
public Post getFirstPost(Topic topic) { DetachedCriteria firstPost = DetachedCriteria.forClass(Post.class).setProjection(Projections.min("id")) .add(Restrictions.eq("topic", topic)).setComment("topicDAO.getFirstPostID"); return (Post) session.createCriteria(Post.class).add(Subqueries.propertyEq("id", firstPost)) .setComment("topicDAO.getFirstPost").uniqueResult(); }
From source file:org.apache.ode.daohib.bpel.ProcessInstanceDaoImpl.java
License:Apache License
public EventsFirstLastCountTuple getEventsFirstLastCount() { entering("ProcessInstanceDaoImpl.getEventsFirstLastCount"); // Using a criteria, find the min,max, and count of event tstamps. Criteria c = getSession().createCriteria(HBpelEvent.class); c.add(Restrictions.eq("instance", _instance)); c.setProjection(Projections.projectionList().add(Projections.min("tstamp")).add(Projections.max("tstamp")) .add(Projections.count("tstamp"))); Object[] ret = (Object[]) c.uniqueResult(); EventsFirstLastCountTuple flc = new EventsFirstLastCountTuple(); flc.first = (Date) ret[0];// www .j a va2s . co m flc.last = (Date) ret[1]; flc.count = (Integer) ret[2]; return flc; }
From source file:org.apache.usergrid.apm.service.charts.service.NetworkMetricsChartUtil.java
License:Apache License
public static ProjectionList getProjectionList(MetricsChartCriteria cq) { ProjectionList projList = Projections.projectionList(); //Adding GroupBy. We will allow only one groupby so that chart looks cleaner. if (cq.isGroupedByApp()) { projList.add(Projections.groupProperty("this.appId"), "appId"); } else//from www . j a v a 2 s . c om projList.add(Projections.property("this.appId"), "appId"); //projList.add(Projections.groupProperty("appId"),"appId"); if (cq.isGroupedByNetworkType()) { projList.add(Projections.groupProperty("this.networkType"), "networkType"); } else if (cq.isGroupedByNetworkCarrier()) { projList.add(Projections.groupProperty("this.networkCarrier"), "networkCarrier"); } else if (cq.isGroupedByAppVersion()) { projList.add(Projections.groupProperty("this.applicationVersion"), "applicationVersion"); } else if (cq.isGroupedByAppConfigType()) { projList.add(Projections.groupProperty("this.appConfigType"), "appConfigType"); } else if (cq.isGroupedByDeviceModel()) { projList.add(Projections.groupProperty("this.deviceModel"), "deviceModel"); } else if (cq.isGroupedbyDevicePlatform()) { projList.add(Projections.groupProperty("this.devicePlatform"), "devicePlatform"); } switch (cq.getSamplePeriod()) { //see http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections on why "this." is needed //in following lines case MINUTE: projList.add(Projections.groupProperty("this.endMinute"), "endMinute"); break; case HOUR: projList.add(Projections.groupProperty("this.endHour"), "endHour"); break; case DAY_WEEK: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case DAY_MONTH: projList.add(Projections.groupProperty("this.endDay"), "endDay"); break; case MONTH: projList.add(Projections.groupProperty("this.endMonth"), "endMonth"); break; } //Adding Projections projList.add(Projections.sum("numSamples"), "numSamples"); projList.add(Projections.sum("numErrors"), "numErrors"); projList.add(Projections.sum("sumLatency"), "sumLatency"); projList.add(Projections.max("maxLatency"), "maxLatency"); projList.add(Projections.min("minLatency"), "minLatency"); //may run into this bug because of alias http://stackoverflow.com/questions/84644/hibernate-query-by-example-and-projections //And I did run into it. ouch. Fix was to add this.filedName !! return projList; }
From source file:org.balisunrise.daa.hibernate.HQuery.java
License:Open Source License
@Override public <V> V min(String property) { return (V) hcrit.setProjection(Projections.min(property)).uniqueResult(); }
From source file:org.encuestame.persistence.dao.imp.HashTagDao.java
License:Apache License
/** * Get max-min tag frecuency.//from w w w. ja va 2s .c o m * * @param tag * @param filter * @return */ @SuppressWarnings("unchecked") public List<Object[]> getMaxMinTagFrecuency() { final DetachedCriteria criteria = DetachedCriteria.forClass(HashTag.class); ProjectionList projectList = Projections.projectionList(); projectList.add(Projections.max("hits")); projectList.add(Projections.min("hits")); criteria.setProjection(projectList); return (List<Object[]>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.encuestame.persistence.dao.imp.ScheduleDao.java
License:Apache License
@SuppressWarnings("unchecked") public Date retrieveMinimumScheduledDate(final Status status) { final DetachedCriteria criteria = DetachedCriteria.forClass(Schedule.class); criteria.setProjection(Projections.min("scheduleDate")); List<Schedule> results = (List<Schedule>) getHibernateTemplate().findByCriteria(criteria); return (Date) (results.get(0) == null ? new Date() : results.get(0)); }
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())); }//w w w . jav a 2 s .c o m 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.iternine.jeppetto.dao.hibernate.HibernateQueryModelDAO.java
License:Apache License
@Override public Projection buildProjection(String projectionField, ProjectionType projectionType, Iterator argsIterator) {// ww w .ja va 2 s. 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; }