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