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();
}
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;
}
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();
}
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();
}
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;
}
Aggregations