Example usage for org.hibernate.criterion Projections min

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

Introduction

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

Prototype

public static AggregateProjection min(String propertyName) 

Source Link

Document

A property minimum value projection

Usage

From source file:org.n52.sos.ds.hibernate.util.HibernateCriteriaQueryUtilities.java

License:Open Source License

/**
 * Get min time from observations for procedure
 * /*  www.  j a va2 s. c o m*/
 * @param procedure
 *            Procedure identifier
 * @param session
 *            Hibernate session
 * @return min time for procedure
 */
@Deprecated
public static DateTime getMinDate4Procedure(String procedure, Session session) {
    Criteria criteria = session.createCriteria(Observation.class)
            .setProjection(Projections.min(Observation.PHENOMENON_TIME_START))
            .add(Restrictions.eq(Observation.DELETED, false)).createCriteria(Observation.PROCEDURE)
            .add(Restrictions.eq(Procedure.IDENTIFIER, procedure));
    Object min = criteria.uniqueResult();
    if (min != null) {
        return new DateTime(min);
    }
    return null;
}

From source file:org.openbravo.advpaymentmngt.process.FIN_PaymentMonitorProcess.java

License:Open Source License

private static Long getDaysTillDue(Invoice invoice) {
    // Calculate days till due
    final OBCriteria<FIN_PaymentSchedule> obc = OBDal.getInstance().createCriteria(FIN_PaymentSchedule.class);
    // For Background process execution at system level
    if (OBContext.getOBContext().isInAdministratorMode()) {
        obc.setFilterOnReadableClients(false);
        obc.setFilterOnReadableOrganization(false);
    }//  ww w . ja v a2s . c o m
    obc.add(Restrictions.eq(FIN_PaymentSchedule.PROPERTY_INVOICE, invoice));
    obc.add(Restrictions.ne(FIN_PaymentSchedule.PROPERTY_OUTSTANDINGAMOUNT, BigDecimal.ZERO));
    obc.setProjection(Projections.min(FIN_PaymentSchedule.PROPERTY_DUEDATE));
    Object o = obc.list().get(0);
    if (o != null) {
        return (FIN_Utility.getDaysToDue((Date) o));
    } else {
        return 0L;
    }
}

From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateIndexDAO.java

License:Open Source License

/**
 * @see IndexDAO#getInitialDate(org.openmrs.Location)
 *///from   w w  w  .ja va2s. co  m
@Override
public Date getInitialDate(final Location location) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Index.class);
    criteria.add(Restrictions.eq("location", location));
    criteria.setProjection(Projections.min("initialDate"));
    return (Date) criteria.uniqueResult();
}

From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public SyncRecord getEarliestRecord(Date afterDate) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SyncRecord.class)
            .setProjection(Projections.min("recordId"));

    if (afterDate != null)
        criteria.add(Restrictions.ge("timestamp", afterDate));

    List<Integer> result = criteria.list();

    if (result.size() < 1) {
        return null;
    } else {/*from ww  w  .java  2  s  .c  o  m*/
        Integer minRecordId = result.get(0);
        return getSyncRecord(minRecordId);
    }
}

From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java

License:Open Source License

/**
 * @see org.openmrs.module.sync.api.SyncService#getNextRecord(SyncRecord)
 *//* w  w  w.  ja  va 2 s  .  c  o  m*/
public SyncRecord getNextRecord(SyncRecord record) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SyncRecord.class);
    criteria.setProjection(Projections.min("recordId"));
    criteria.add(Restrictions.gt("recordId", record.getRecordId()));
    Object nextRecordId = criteria.uniqueResult();
    if (nextRecordId == null) {
        return null;
    }
    return getSyncRecord((Integer) nextRecordId);
}

From source file:org.ourgrid.peer.business.dao.statistics.PeerDAO.java

License:Open Source License

public Long getFirstDBUpdateDate() {

    Criteria criteria = HibernateUtil.getSession().createCriteria(Peer.class);
    criteria.setProjection(Projections.min("lastModified"));
    Long minPeer = (Long) criteria.uniqueResult();

    Criteria criteriaSC = HibernateUtil.getSession().createCriteria(LocalPeerStatusChange.class);
    criteriaSC.setProjection(Projections.min("lastModified"));
    Long minStatusChange = (Long) criteriaSC.uniqueResult();

    return Math.min(minPeer, minStatusChange);
}

From source file:org.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 (ColumnStatRequest<T> column : statRequest) {
        if (column.isFlag(COUNT)) {
            projList.add(Projections.count(column.getColumn().getName()));
        }//from   www .j  av  a2s .  com
        if (column.isFlag(MIN)) {
            projList.add(Projections.min(column.getColumn().getName()));
        }
        if (column.isFlag(MAX)) {
            projList.add(Projections.max(column.getColumn().getName()));
        }
        if (column.isFlag(AVERAGE)) {
            projList.add(Projections.avg(column.getColumn().getName()));
        }
        if (column.isFlag(SUM)) {
            projList.add(Projections.sum(column.getColumn().getName()));
        }
        if (column.isFlag(GROUP_BY_VAL)) {
            projList.add(Projections.groupProperty(column.getColumn().getName()));
        }

        // Time groups
        for (ColumnStatType flag : TIME_GROUPS) {
            if (column.isFlag(flag)) {
                projList.add(makeTimeGroupBy(column, flag, criteria));
            }
        }
    }

    criteria.setProjection(projList);
}

From source file:org.shredzone.cilla.core.repository.impl.PageDaoHibImpl.java

License:Open Source License

@Transactional(readOnly = true)
@Override//from   w  ww .ja  va2  s.  co m
public Date[] fetchMinMaxModification() {
    Date now = new Date();

    Criteria crit = getCurrentSession().createCriteria(Page.class);

    crit.add(Restrictions.and(Restrictions.isNotNull("publication"), Restrictions.le("publication", now)));

    crit.add(Restrictions.or(Restrictions.isNull("expiration"), Restrictions.gt("expiration", now)));

    crit.add(Restrictions.eq("hidden", false));

    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.min(pageOrder.getColumn()));
    proj.add(Projections.max(pageOrder.getColumn()));
    crit.setProjection(proj);
    Object[] row = (Object[]) crit.uniqueResult();

    Date[] result = new Date[2];
    result[0] = (Date) row[0];
    result[1] = (Date) row[1];
    return result;
}

From source file:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public Long getNextStageFileId(FileType fileType, StatusType... statusTypes) {
    Criteria criteria = currentSession().createCriteria(StageFile.class);
    criteria.add(Restrictions.eq("fileType", fileType));
    criteria.add(Restrictions.in("status", statusTypes));
    criteria.setProjection(Projections.min("id"));
    criteria.setCacheable(true);/*  ww w. jav a  2  s. c o m*/
    criteria.setCacheMode(CacheMode.NORMAL);
    return (Long) criteria.uniqueResult();
}

From source file:postgreHibernateClient.postgreCacheClient.java

License:Open Source License

@Override
public HashMap<String, String> getInitialStats() {
    HashMap<String, String> stats = new HashMap<String, String>();
    session = sessionFactory.openSession();
    try {/*from  w  ww.  ja va 2 s  .c om*/
        tx = session.beginTransaction();

        Criteria c = session.createCriteria(USERS.class).setProjection(Projections.count("userid"));

        Long usercount = (Long) c.list().get(0);
        usercount = usercount > 0 ? usercount : 0;
        stats.put("usercount", Long.toString(usercount));

        Criteria c1 = session.createCriteria(USERS.class).setProjection(Projections.min("userid"));

        String offset = (String) c1.list().get(0);
        //get resources per user

        USERS u = new USERS();
        u = (USERS) session.get(USERS.class, offset);
        stats.put("avgfriendsperuser", Integer.toString(u.getConfFriendCnt()));

        stats.put("resourcesperuser", Integer.toString(u.getResCnt()));

        stats.put("avgpendingperuser", Integer.toString(u.getPendFriendCnt()));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
    return stats;
}