Search in sources :

Example 86 with Criteria

use of org.hibernate.Criteria in project dhis2-core by dhis2.

the class HibernateTrackedEntityAttributeValueAuditStore method getTrackedEntityAttributeValueAudits.

@Override
@SuppressWarnings("unchecked")
public List<TrackedEntityAttributeValueAudit> getTrackedEntityAttributeValueAudits(List<TrackedEntityAttribute> trackedEntityAttributes, List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType, int first, int max) {
    Criteria criteria = getTrackedEntityAttributeValueAuditCriteria(trackedEntityAttributes, trackedEntityInstances, auditType);
    criteria.addOrder(Order.desc("created"));
    criteria.setFirstResult(first);
    criteria.setMaxResults(max);
    return criteria.list();
}
Also used : Criteria(org.hibernate.Criteria)

Example 87 with Criteria

use of org.hibernate.Criteria in project dhis2-core by dhis2.

the class HibernateTrackedEntityDataValueAuditStore method getTrackedEntityDataValueAuditCriteria.

private Criteria getTrackedEntityDataValueAuditCriteria(List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(TrackedEntityDataValueAudit.class);
    if (!dataElements.isEmpty()) {
        criteria.add(Restrictions.in("dataElement", dataElements));
    }
    if (!programStageInstances.isEmpty()) {
        criteria.add(Restrictions.in("programStageInstance", programStageInstances));
    }
    if (auditType != null) {
        criteria.add(Restrictions.eq("auditType", auditType));
    }
    return criteria;
}
Also used : Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 88 with Criteria

use of org.hibernate.Criteria in project dhis2-core by dhis2.

the class HibernateTrackedEntityDataValueAuditStore method getTrackedEntityDataValueAudits.

@Override
@SuppressWarnings("unchecked")
public List<TrackedEntityDataValueAudit> getTrackedEntityDataValueAudits(List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType, int first, int max) {
    Criteria criteria = getTrackedEntityDataValueAuditCriteria(dataElements, programStageInstances, auditType);
    criteria.addOrder(Order.desc("created"));
    criteria.setFirstResult(first);
    criteria.setMaxResults(max);
    return criteria.list();
}
Also used : Criteria(org.hibernate.Criteria)

Example 89 with Criteria

use of org.hibernate.Criteria in project dhis2-core by dhis2.

the class HibernateTrackedEntityDataValueStore method get.

@Override
@SuppressWarnings("unchecked")
public List<TrackedEntityDataValue> get(TrackedEntityInstance entityInstance, Collection<DataElement> dataElements, Date startDate, Date endDate) {
    if (dataElements == null || dataElements.isEmpty()) {
        return new ArrayList<>();
    }
    Criteria criteria = getCriteria();
    criteria.createAlias("programStageInstance", "programStageInstance");
    criteria.createAlias("programStageInstance.programInstance", "programInstance");
    criteria.add(Restrictions.in("dataElement", dataElements));
    criteria.add(Restrictions.eq("programInstance.entityInstance", entityInstance));
    criteria.add(Restrictions.between("programStageInstance.executionDate", startDate, endDate));
    return criteria.list();
}
Also used : ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria)

Example 90 with Criteria

use of org.hibernate.Criteria in project dhis2-core by dhis2.

the class HibernateGenericStore method getCriteria.

/**
     * Creates a Criteria for the implementation Class type restricted by the
     * given Criterions.
     *
     * @param expressions the Criterions for the Criteria.
     * @return a Criteria instance.
     */
protected final Criteria getCriteria(Criterion... expressions) {
    Criteria criteria = getCriteria();
    for (Criterion expression : expressions) {
        criteria.add(expression);
    }
    criteria.setCacheable(cacheable);
    return criteria;
}
Also used : Criterion(org.hibernate.criterion.Criterion) Criteria(org.hibernate.Criteria) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Aggregations

Criteria (org.hibernate.Criteria)180 Session (org.hibernate.Session)95 Test (org.junit.Test)69 List (java.util.List)39 Transaction (org.hibernate.Transaction)39 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)27 ArrayList (java.util.ArrayList)15 TestForIssue (org.hibernate.testing.TestForIssue)12 Iterator (java.util.Iterator)9 Period (org.hisp.dhis.period.Period)8 Map (java.util.Map)6 State (org.hibernate.test.cache.infinispan.functional.entities.State)5 OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)5 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)5 HashSet (java.util.HashSet)3 Criterion (org.hibernate.criterion.Criterion)3 Statistics (org.hibernate.stat.Statistics)3 Pager (org.hisp.dhis.common.Pager)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 HashMap (java.util.HashMap)2