Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

In this page you can find the example usage for org.hibernate Criteria setProjection.

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

From source file:com.hmsinc.epicenter.model.AbstractJPARepository.java

License:Open Source License

public <L extends T> long count(final Class<L> type) {
    Validate.notNull(type, "Type must be specified.");
    final Criteria c = ModelUtils.criteriaQuery(entityManager, type);
    c.setProjection(Projections.rowCount());
    return ((Integer) c.uniqueResult()).longValue();
}

From source file:com.hmsinc.epicenter.model.surveillance.impl.SurveillanceRepositoryImpl.java

License:Open Source License

public Integer getAnomalyCount(final DateTime startDate, final DateTime endDate, final boolean includeAll,
        final Geometry filter, final Geometry excludeFacilityEventsFilter) {

    final Criteria c = criteriaQuery(entityManager, Anomaly.class);
    c.setCacheable(true);//from w ww .j  a  v a 2  s  .  c o m

    applyAnomalyCriteria(c, startDate, endDate, includeAll, filter, excludeFacilityEventsFilter);

    return (Integer) c.setProjection(Projections.rowCount()).uniqueResult();
}

From source file:com.hmsinc.epicenter.model.surveillance.impl.SurveillanceRepositoryImpl.java

License:Open Source License

public DateTime getDateOfOldestAnomaly(final Geometry filter, final Geometry excludeFacilityEventsFilter) {

    final Criteria c = criteriaQuery(entityManager, Anomaly.class);

    applyAnomalyCriteria(c, null, null, false, filter, excludeFacilityEventsFilter);

    c.setProjection(Projections.min("analysisTimestamp"));

    final Object min = c.uniqueResult();
    return (min == null ? null : (DateTime) min);

}

From source file:com.hmsinc.epicenter.model.util.ModelUtils.java

License:Open Source License

/**
 * @param <T>/* w w  w . j  a va  2  s  . c  o  m*/
 * @param entityManager
 * @param c
 * @param returnType
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> List<T> listUsingCache(final EntityManager entityManager, final Criteria c,
        final Class<T> returnType) {

    final List<T> resultList = new ArrayList<T>();
    final List<Long> idList = c.setProjection(Projections.id()).list();
    for (Long id : idList) {
        resultList.add(entityManager.getReference(returnType, id));
    }
    return resultList;
}

From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java

License:Open Source License

public Integer getInvestigationCount(DateTime startDate, DateTime endDate, Geometry geometry,
        Collection<Organization> organizations, boolean showAll) {

    final Criteria c = criteriaQuery(entityManager, Investigation.class, "investigation");
    applyInvestigationCriteria(c, startDate, endDate, geometry, organizations, showAll);

    c.setProjection(Projections.rowCount());

    return (Integer) c.uniqueResult();
}

From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java

License:Open Source License

public DateTime getDateOfOldestInvestigation(Geometry geometry, Collection<Organization> organizations) {

    final Criteria c = criteriaQuery(entityManager, Investigation.class, "investigation");
    applyInvestigationCriteria(c, null, null, geometry, organizations, false);

    c.setProjection(Projections.min("timestamp"));

    final Object min = c.uniqueResult();
    return (min == null ? null : (DateTime) min);
}

From source file:com.hrms.manager.DeductionRuleManager.java

public List<String> getGradeList() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    List<String> le = new ArrayList<>();
    Criteria c = session.createCriteria(EmployeeProfile.class);
    c.setProjection(Projections.distinct(Projections.property("empGrade")));
    List emp = c.list();// w ww . j a  v  a  2s . c  o  m
    System.out.println("--------------->" + emp);
    return emp;
}

From source file:com.hrms.manager.HRMSManager.java

public List<String> getQuarters()

{
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    Criteria c = session.createCriteria(ResidentialQuarters.class);
    c.setProjection(Projections.distinct(Projections.property("quarterType")));
    List emp = c.list();/*from  w w  w  .j  a  v a2  s .c o m*/
    return emp;
}

From source file:com.hrms.manager.LoanAppManager.java

public List<String> getLoanEligibilityList() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    List<String> le = new ArrayList<>();
    Criteria c = session.createCriteria(LoanEligibility.class);
    c.setProjection(Projections.property("eligibilityRuleId"));
    List departments = c.list();//ww  w .j  a  v a 2  s.  c  o m
    return departments;
}