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:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public Long getTotalEmpCareerHistoryDataByParamReport(ReportEmpMutationParameter searchParameter) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchEmpRotasiByParamReport(searchParameter, criteria);
    DetachedCriteria maxTglPengangkatanQuery = DetachedCriteria.forClass(getEntityClass());
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.max("tglPenganngkatan"));
    proj.add(Projections.groupProperty("nik"));
    maxTglPengangkatanQuery.setProjection(proj);
    criteria.add(Subqueries.propertiesIn(new String[] { "tglPenganngkatan", "nik" }, maxTglPengangkatanQuery));
    return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.LoanCanceledDaoImpl.java

@Override
public Long getCurrentMaxId() {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    return (Long) criteria.setProjection(Projections.max("id")).uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.RecruitmenSelectionSeriesDetailDaoImpl.java

@Override
public Integer getLastIndexBySelectionSeriesId(Long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("recruitmenSelectionSeries.id", id));
    criteria.setProjection(Projections.max("listOrder"));
    return (Integer) criteria.uniqueResult();
}

From source file:com.jaspersoft.jasperserver.search.sorter.ByAccessTimeSorter.java

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    String alias = criteria.getAlias("accessEvents", "ae");
    criteria.addProjection(Projections.projectionList().add(Projections.max(alias + ".eventDate"), "aed")
            .add(Projections.groupProperty("accessEvents")));

    criteria.addOrder(Order.desc("aed"));
}

From source file:com.jubination.model.dao.DataAnalyticsDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Object readPropertyByRecency() {
    List<DataAnalytics> list = new ArrayList<>();

    session = getSessionFactory().getCurrentSession();
    List<String> tempList = session.createCriteria(DataAnalytics.class)
            .setProjection(Projections.projectionList().add(Projections.max("requestedTime"))
            //.add(Projections.groupProperty("type"))
            ).list();//from ww w  . ja  va 2  s  .c  o m

    if (tempList.size() > 0) {
        list = session.createCriteria(DataAnalytics.class)
                .add(Restrictions.like("requestedTime", tempList.get(0))).list();
    }

    return (T) list;

}

From source file:com.klistret.cmdb.utility.hibernate.XPathCriteria.java

License:Open Source License

/**
 * Creates a Hibernate projection from an aggregate expression
 * // ww w  . j  a  va  2  s . co  m
 * @param expression
 */
public Projection aggregate(String expression) {
    logger.debug("Creating projection based on aggregate expression [{}]", expression);

    FunctionCall fc = new FunctionCall(expression);
    RelativePathExpr rpe = fc.getRelativePath();

    HibernateRelativePath hrp = translate(rpe);

    /**
     * Confirm the last Hibernate step is a Hibernate property
     */
    HibernateStep last = hrp.getLastHibernateStep();
    if (last.getType() != Type.Property)
        throw new ApplicationException("Aggregation must act either on a Hibernate property or an XML column");

    /**
     * Property name with alias
     */
    String alias = aliasCache.get(last.getPrevious().getPath());
    String propertyName = alias == null ? last.getName() : String.format("%s.%s", alias, last.getName());

    /**
     * Only sum, avg, max, and min supported
     */
    switch (fc.getFunction()) {
    case sum:
        return last.isXml() ? new XPathAggregation("sum", propertyName, last.getStep())
                : Projections.sum(propertyName);
    case avg:
        return last.isXml() ? new XPathAggregation("avg", propertyName, last.getStep())
                : Projections.avg(propertyName);
    case max:
        return last.isXml() ? new XPathAggregation("max", propertyName, last.getStep())
                : Projections.max(propertyName);
    case min:
        return last.isXml() ? new XPathAggregation("min", propertyName, last.getStep())
                : Projections.min(propertyName);
    default:
        throw new InfrastructureException(String.format("Function call [%s] not handled.", fc.getFunction()));
    }
}

From source file:com.kodemore.hibernate.criteria.KmCriteria.java

License:Open Source License

public void selectMaximum(String name) {
    Projection e;
    e = Projections.max(getFullName(name));
    addProjection(e);
}

From source file:com.liferay.portal.dao.orm.hibernate.ProjectionFactoryImpl.java

License:Open Source License

public Projection max(String propertyName) {
    return new ProjectionImpl(Projections.max(propertyName));
}

From source file:com.liferay.portal.workflow.jbpm.dao.CustomSession.java

License:Open Source License

public List<ProcessDefinition> findProcessDefinitions(String name, boolean latest, int start, int end,
        OrderByComparator orderByComparator) {

    try {//from   ww w.  j a va 2  s  .c  o  m
        Criteria criteria = _session.createCriteria(ProcessDefinition.class);

        if (latest) {
            ProjectionList projectionList = Projections.projectionList();

            projectionList.add(Projections.groupProperty("name"));
            projectionList.add(Projections.max("version"));

            criteria.setProjection(projectionList);

            addOrder(criteria, orderByComparator, "version");
        }

        if (name != null) {
            criteria.add(Restrictions.eq("name", name));

            addOrder(criteria, orderByComparator, "name");
        }

        if (latest == false && name == null) {
            addOrder(criteria, orderByComparator);
        }

        addPagination(criteria, start, end);

        if (latest) {
            List<Object[]> list = criteria.list();

            List<String> names = new ArrayList<String>(list.size());

            for (Object[] array : list) {
                names.add((String) array[0]);
            }

            return findProcessDefinitions(names);
        } else {
            return criteria.list();
        }
    } catch (Exception e) {
        throw new JbpmException(e);
    }
}

From source file:com.lnganalysis.dao.domain.impl.ExplorationDaoImpl.java

@Override
public int getLastRecordNum() throws Exception {
    // TODO Auto-generated method stub
    Session session = null;/*from   w w  w. j av  a  2 s.  c om*/
    Integer count = 0;
    try {
        logger.info("Class - ExplorationDaoImpl - getLastRecordNum()");
        session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        Criteria c = session.createCriteria(Exploration.class);
        c.setProjection(Projections.max("id"));
        count = (Integer) c.uniqueResult();
        if (count == null)
            count = 0;
        tx.commit();
    } catch (Exception e) {
        logger.error("Exception in ExplorationDaoImpl - Method getLastRecordNum():" + e);
        throw e;
    } finally {
        session.close();
    }
    return count;
}