Search in sources :

Example 41 with Query

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);
    }
}
Also used : Query(org.hibernate.query.Query)

Example 42 with Query

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;
}
Also used : Program(org.hisp.dhis.program.Program) HashSet(java.util.HashSet) Set(java.util.Set) Query(org.hibernate.query.Query) HashMap(java.util.HashMap) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute)

Example 43 with Query

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;
}
Also used : Query(org.hibernate.query.Query)

Example 44 with Query

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;
}
Also used : Query(org.hibernate.query.Query)

Example 45 with Query

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();
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(org.hibernate.query.Query) Session(org.hibernate.Session)

Aggregations

Query (org.hibernate.query.Query)157 Test (org.junit.Test)44 Session (org.hibernate.Session)39 List (java.util.List)24 ArrayList (java.util.ArrayList)19 TestForIssue (org.hibernate.testing.TestForIssue)19 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)17 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 HashMap (java.util.HashMap)15 Map (java.util.Map)14 NativeQuery (org.hibernate.query.NativeQuery)14 AbstractJPATest (org.hibernate.test.jpa.AbstractJPATest)11 SessionFactory (org.hibernate.SessionFactory)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 Method (java.lang.reflect.Method)7 SQLException (java.sql.SQLException)7 Collectors (java.util.stream.Collectors)7 AbstractQueryFacade (org.jboss.tools.hibernate.runtime.common.AbstractQueryFacade)7 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)6