Example usage for org.hibernate.criterion Projections max

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

Introduction

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

Prototype

public static AggregateProjection max(String propertyName) 

Source Link

Document

A property maximum value projection

Usage

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

License:Open Source License

public Date findLatestLastModifiedTime(final String menuType, final String workingUid) {

    Date latestLastModifiedTime = (Date) super.getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria cri = session.createCriteria(Siteaggregationmenu_temp.class);

            cri.add(Expression.eq("Id.Type", menuType));
            cri.add(Expression.eq("Workinguid", workingUid));

            Projection projection = Projections.projectionList().add(Projections.max("Lastmodified"));
            cri.setProjection(projection);
            try {
                return (Date) cri.uniqueResult();
            } catch (Exception e) {
                logger.error("parsing error", e);
                throw new RuntimeException();
            }/* w  w  w  . j a  v  a  2s .c  om*/
        }

    });

    return latestLastModifiedTime;
}

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

License:Open Source License

/**
 * @param res/*from  w ww  .ja  v a  2 s . co  m*/
 * @return
 */
public Map selectMax() {
    HibernateTemplate templete = super.getHibernateTemplate();
    List staticTabs = templete.findByCriteria(DetachedCriteria.forClass(StaticTab.class)
            .add(Expression.not(Expression.eq("Tabid", StaticTab.COMMANDBAR_TAB_ID)))
            .add(Expression.not(Expression.eq("Tabid", StaticTab.PORTALHEADER_TAB_ID)))
            .setProjection(Projections.projectionList().add(Projections.max("Tabid"))
                    .add(Projections.max(StaticTab.PROP_TABNUMBER))));

    Map resultMap = new HashMap();
    for (int i = 0; i < staticTabs.size(); i++) {
        Object[] tablayout = (Object[]) staticTabs.get(i);
        resultMap.put("tabId", tablayout[0]);
        resultMap.put("tabNumber", tablayout[1]);
    }

    return resultMap;
}

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

License:Open Source License

/**
 * @param res//from   ww  w. ja va2 s.  com
 * @return
 */
public String selectMaxTabId() {
    HibernateTemplate templete = super.getHibernateTemplate();
    List tabIdList = templete.findByCriteria(DetachedCriteria.forClass(StaticTab.class)
            .add(Expression.not(Expression.eq("Tabid", StaticTab.COMMANDBAR_TAB_ID)))
            .add(Expression.not(Expression.eq("Tabid", StaticTab.PORTALHEADER_TAB_ID)))
            .setProjection(Projections.projectionList().add(Projections.max("Tabid"))));

    String tabId = null;
    for (int i = 0; i < tabIdList.size(); i++) {
        tabId = (String) tabIdList.get(i);
    }

    return tabId;
}

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

License:Open Source License

/**
 * @param res/*from  w w  w.  ja  v  a 2  s  .co m*/
 * @return
 */
public Map selectMax() {
    HibernateTemplate templete = super.getHibernateTemplate();
    List tabLayouts = templete.findByCriteria(DetachedCriteria.forClass(TabLayout.class)
            .add(Expression.not(Expression.eq("id.Tabid", "commandbar")))
            .setProjection(Projections.projectionList().add(Projections.max("id.Tabid"))
                    .add(Projections.max(TabLayout.PROP_TABNUMBER))));

    Map resultMap = new HashMap();
    for (int i = 0; i < tabLayouts.size(); i++) {
        Object[] tablayout = (Object[]) tabLayouts.get(i);
        resultMap.put("tabId", tablayout[0]);
        resultMap.put("tabNumber", tablayout[1]);
    }

    return resultMap;
}

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

License:Apache License

@Override
public Projection buildProjection(String projectionField, ProjectionType projectionType,
        Iterator argsIterator) {/*from   ww w . j  ava2  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;
}

From source file:org.jtalks.jcommune.model.dao.hibernate.TopicHibernateDao.java

License:Open Source License

/**
 * {@inheritDoc}//from www .  java 2  s. co m
 */
@Override
public Topic getLastUpdatedTopicInBranch(Branch branch) {
    //find the last topic in the branch
    String modificationDateProperty = "modificationDate";
    DetachedCriteria topicMaxModificationDateCriteria = DetachedCriteria.forClass(Topic.class)
            .setProjection(Projections.max(modificationDateProperty)).add(Restrictions.eq(BRANCH, branch));
    //possible that the two topics will be modified at the same time
    @SuppressWarnings(UNCHECKED)
    List<Topic> topics = (List<Topic>) session().createCriteria(Topic.class)
            .add(Restrictions.eq(BRANCH, branch))
            .add(Property.forName(modificationDateProperty).eq(topicMaxModificationDateCriteria)).list();
    return topics.isEmpty() ? null : topics.get(0);
}

From source file:org.n52.sos.ds.hibernate.dao.AbstractObservationDAO.java

License:Open Source License

/**
 * Get max phenomenon time from observations
 *
 * @param session/*w  w  w  .  j av a  2 s  .  c  o m*/
 *            Hibernate session Hibernate session
 *
 * @return max time
 */
public DateTime getMaxPhenomenonTime(Session session) {

    Criteria criteriaStart = session.createCriteria(getObservationTimeClass())
            .setProjection(Projections.max(AbstractObservation.PHENOMENON_TIME_START))
            .add(Restrictions.eq(AbstractObservation.DELETED, false));
    LOGGER.debug("QUERY getMaxPhenomenonTime() start: {}", HibernateHelper.getSqlString(criteriaStart));
    Object maxStart = criteriaStart.uniqueResult();

    Criteria criteriaEnd = session.createCriteria(getObservationTimeClass())
            .setProjection(Projections.max(AbstractObservation.PHENOMENON_TIME_END))
            .add(Restrictions.eq(AbstractObservation.DELETED, false));
    LOGGER.debug("QUERY getMaxPhenomenonTime() end: {}", HibernateHelper.getSqlString(criteriaEnd));
    Object maxEnd = criteriaEnd.uniqueResult();
    if (maxStart == null && maxEnd == null) {
        return null;
    } else {
        DateTime start = new DateTime(maxStart, DateTimeZone.UTC);
        if (maxEnd != null) {
            DateTime end = new DateTime(maxEnd, DateTimeZone.UTC);
            if (end.isAfter(start)) {
                return end;
            }
        }
        return start;
    }
}

From source file:org.n52.sos.ds.hibernate.dao.AbstractObservationDAO.java

License:Open Source License

/**
 * Get max phenomenon time from observations
 *
 * @param session/*from   ww  w.ja  v  a2 s.co  m*/
 *            Hibernate session Hibernate session
 *
 * @return max time
 */
public DateTime getMaxResultTime(Session session) {

    Criteria criteria = session.createCriteria(getObservationTimeClass())
            .setProjection(Projections.max(AbstractObservation.RESULT_TIME))
            .add(Restrictions.eq(AbstractObservation.DELETED, false));
    LOGGER.debug("QUERY getMaxResultTime(): {}", HibernateHelper.getSqlString(criteria));
    Object max = criteria.uniqueResult();
    if (max == null) {
        return null;
    } else {
        return new DateTime(max, DateTimeZone.UTC);
    }
}

From source file:org.n52.sos.ds.hibernate.dao.AbstractObservationDAO.java

License:Open Source License

/**
 * Get global temporal bounding box/*  ww  w  .  j  av a  2 s .c o m*/
 *
 * @param session
 *            Hibernate session the session
 *
 * @return the global getEqualRestiction bounding box over all observations,
 *         or <tt>null</tt>
 */
public TimePeriod getGlobalTemporalBoundingBox(Session session) {
    if (session != null) {
        Criteria criteria = session.createCriteria(getObservationTimeClass());
        criteria.add(Restrictions.eq(AbstractObservation.DELETED, false));
        criteria.setProjection(
                Projections.projectionList().add(Projections.min(AbstractObservation.PHENOMENON_TIME_START))
                        .add(Projections.max(AbstractObservation.PHENOMENON_TIME_START))
                        .add(Projections.max(AbstractObservation.PHENOMENON_TIME_END)));
        LOGGER.debug("QUERY getGlobalTemporalBoundingBox(): {}", HibernateHelper.getSqlString(criteria));
        Object temporalBoundingBox = criteria.uniqueResult();
        if (temporalBoundingBox instanceof Object[]) {
            Object[] record = (Object[]) temporalBoundingBox;
            TimePeriod bBox = createTimePeriod((Timestamp) record[0], (Timestamp) record[1],
                    (Timestamp) record[2]);
            return bBox;
        }
    }
    return null;
}

From source file:org.n52.sos.ds.hibernate.dao.AbstractObservationDAO.java

License:Open Source License

/**
 * Get projection for {@link SosIndeterminateTime} value
 *
 * @param indetTime/*w  w  w.  ja  va2s  .c o  m*/
 *            Value to get projection for
 * @return Projection to use to determine indeterminate time extrema
 */
protected Projection getIndeterminateTimeExtremaProjection(final SosIndeterminateTime indetTime) {
    if (indetTime.equals(SosIndeterminateTime.first)) {
        return Projections.min(AbstractObservation.PHENOMENON_TIME_START);
    } else if (indetTime.equals(SosIndeterminateTime.latest)) {
        return Projections.max(AbstractObservation.PHENOMENON_TIME_END);
    }
    return null;
}