Search in sources :

Example 56 with Query

use of org.hibernate.query.Query in project midpoint by Evolveum.

the class LookupTableHelper method deleteRowByKey.

private void deleteRowByKey(Session session, String tableOid, String key) {
    Query query = session.getNamedQuery("delete.lookupTableDataRowByKey");
    query.setParameter("oid", tableOid);
    query.setParameter("key", key);
    query.executeUpdate();
}
Also used : Query(org.hibernate.query.Query) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery)

Example 57 with Query

use of org.hibernate.query.Query in project midpoint by Evolveum.

the class GeneralHelper method findLastIdInRepo.

public int findLastIdInRepo(Session session, String tableOid, String queryName) {
    Query query = session.getNamedQuery(queryName);
    query.setParameter("oid", tableOid);
    Integer lastId = (Integer) query.uniqueResult();
    if (lastId == null) {
        lastId = 0;
    }
    return lastId;
}
Also used : Query(org.hibernate.query.Query)

Example 58 with Query

use of org.hibernate.query.Query in project midpoint by Evolveum.

the class OrgClosureManager method getChildren.

private List<String> getChildren(String oid, Session session) {
    Query childrenQuery = session.createQuery("select distinct parentRef.ownerOid from RObjectReference as parentRef" + " join parentRef.owner as owner where parentRef.targetOid=:oid and parentRef.referenceType=0" + " and owner.objectTypeClass = :orgType");
    // TODO eliminate use of parameter here
    childrenQuery.setParameter("orgType", RObjectType.ORG);
    childrenQuery.setParameter("oid", oid);
    return childrenQuery.list();
}
Also used : NativeQuery(org.hibernate.query.NativeQuery) Query(org.hibernate.query.Query)

Example 59 with Query

use of org.hibernate.query.Query in project midpoint by Evolveum.

the class OrgStructTest method test005deleteOrg.

@Test
public void test005deleteOrg() throws Exception {
    OperationResult opResult = new OperationResult("test005deleteOrg");
    repositoryService.deleteObject(OrgType.class, DELETE_ORG_OID, opResult);
    Session session = open();
    try {
        Query sqlOrgClosure = session.createQuery("select count(*) from ROrgClosure where descendantOid=:oid or ancestorOid=:oid");
        sqlOrgClosure.setParameter("oid", DELETE_ORG_OID);
        Number number = (Number) sqlOrgClosure.uniqueResult();
        AssertJUnit.assertEquals(0, (number != null ? number.intValue() : 0));
    } finally {
        close(session);
    }
}
Also used : Query(org.hibernate.query.Query) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 60 with Query

use of org.hibernate.query.Query in project hibernate-orm by hibernate.

the class ParameterTest method testSetPropertiesMapNotContainingAllTheParameters.

@Test
@TestForIssue(jiraKey = "HHH-10796")
public void testSetPropertiesMapNotContainingAllTheParameters() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    try {
        Human human = new Human();
        human.setNickName("nick");
        human.setIntValue(1);
        s.save(human);
        Map parameters = new HashMap();
        parameters.put("nickNames", "nick");
        List<Integer> intValues = new ArrayList<>();
        intValues.add(1);
        Query q = s.createQuery("from Human h where h.nickName in (:nickNames) and h.intValue in (:intValues)");
        q.setParameterList("intValues", intValues);
        q.setProperties((parameters));
        assertThat(q.list().size(), is(1));
        s.delete(human);
        t.commit();
    } catch (Exception e) {
        if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
            session.getTransaction().rollback();
        }
        throw e;
    } finally {
        s.close();
    }
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.query.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

Query (org.hibernate.query.Query)149 Test (org.junit.Test)46 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 SQLException (java.sql.SQLException)7 Collectors (java.util.stream.Collectors)7 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 Predicate (javax.persistence.criteria.Predicate)6 Root (javax.persistence.criteria.Root)6