use of org.hibernate.query.Query in project dhis2-core by dhis2.
the class TrackedEntityDataElementDimensionDeletionHandler method deleteLegendSet.
@SuppressWarnings("unchecked")
private void deleteLegendSet(LegendSet legendSet) {
// TODO Move this get-method to service layer
Query query = sessionFactory.getCurrentSession().createQuery("FROM TrackedEntityDataElementDimension WHERE legendSet=:legendSet");
query.setParameter("legendSet", legendSet);
List<TrackedEntityDataElementDimension> dataElementDimensions = query.list();
for (TrackedEntityDataElementDimension dataElementDimension : dataElementDimensions) {
dataElementDimension.setLegendSet(null);
sessionFactory.getCurrentSession().update(dataElementDimension);
}
}
use of org.hibernate.query.Query in project dhis2-core by dhis2.
the class HibernateTrackedEntityAttributeStore method getTrackedEntityAttributesByProgram.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<Program, Set<TrackedEntityAttribute>> getTrackedEntityAttributesByProgram() {
Map<Program, Set<TrackedEntityAttribute>> result = new HashMap<>();
Query query = sessionFactory.getCurrentSession().createQuery("select p.programAttributes from Program p");
List<ProgramTrackedEntityAttribute> programTrackedEntityAttributes = query.list();
for (ProgramTrackedEntityAttribute programTrackedEntityAttribute : programTrackedEntityAttributes) {
if (!result.containsKey(programTrackedEntityAttribute.getProgram())) {
result.put(programTrackedEntityAttribute.getProgram(), Sets.newHashSet(programTrackedEntityAttribute.getAttribute()));
} else {
result.get(programTrackedEntityAttribute.getProgram()).add(programTrackedEntityAttribute.getAttribute());
}
}
return result;
}
use of org.hibernate.query.Query in project dhis2-core by dhis2.
the class HibernateTrackedEntityInstanceStore method existsIncludingDeleted.
@Override
public boolean existsIncludingDeleted(String uid) {
Query query = getSession().createNativeQuery("select count(*) from trackedentityinstance where uid=:uid");
query.setParameter("uid", uid);
int count = ((Number) query.getSingleResult()).intValue();
return count > 0;
}
use of org.hibernate.query.Query in project dhis2-core by dhis2.
the class HibernateTrackedEntityInstanceStore method exists.
@Override
public boolean exists(String uid) {
Query query = getSession().createNativeQuery("select count(*) from trackedentityinstance where uid=:uid and deleted is false");
query.setParameter("uid", uid);
int count = ((Number) query.getSingleResult()).intValue();
return count > 0;
}
use of org.hibernate.query.Query in project dhis2-core by dhis2.
the class HibernateTrackedEntityAttributeValueAuditStore method deleteTrackedEntityAttributeValueAudits.
@Override
public void deleteTrackedEntityAttributeValueAudits(TrackedEntityInstance entityInstance) {
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("delete TrackedEntityAttributeValueAudit where entityInstance = :entityInstance");
query.setParameter("entityInstance", entityInstance);
query.executeUpdate();
}
Aggregations