Search in sources :

Example 11 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test126QueryOrgTreeFindUsersRelationDefault.

@Test
public void test126QueryOrgTreeFindUsersRelationDefault() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = prismContext.queryFor(UserType.class).isChildOf(itemFactory().createReferenceValue("some oid").relation(SchemaConstants.ORG_DEFAULT)).build();
        RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
        String real = rQuery.getQuery().getQueryString();
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  u.oid,\n" + "  u.fullObject\n" + "from\n" + "  RUser u\n" + "where\n" + "  u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n");
        @SuppressWarnings("unchecked") Collection<String> relationParameter = (Collection<String>) rQuery.getQuerySource().getParameters().get("relation").getValue();
        assertEquals("Wrong relation parameter value", new HashSet<>(getVariantsOfDefaultRelation()), new HashSet<>(relationParameter));
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) SelectorOptions.createCollection(com.evolveum.midpoint.schema.SelectorOptions.createCollection) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 12 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test122QueryOrgTreeFindUsersRelationManager.

@Test
public void test122QueryOrgTreeFindUsersRelationManager() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = prismContext.queryFor(UserType.class).isDirectChildOf(itemFactory().createReferenceValue("some oid").relation(SchemaConstants.ORG_MANAGER)).build();
        RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
        String real = rQuery.getQuery().getQueryString();
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  u.oid,\n" + "  u.fullObject\n" + "from\n" + "  RUser u\n" + "where\n" + "  u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid = :orgOid)\n");
        @SuppressWarnings("unchecked") Collection<String> relationParameter = (Collection<String>) rQuery.getQuerySource().getParameters().get("relation").getValue();
        assertEquals("Wrong relation parameter value", new HashSet<>(Arrays.asList(RUtil.qnameToString(QNameUtil.nullNamespace(SchemaConstants.ORG_MANAGER)), RUtil.qnameToString(SchemaConstants.ORG_MANAGER))), new HashSet<>(relationParameter));
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) SelectorOptions.createCollection(com.evolveum.midpoint.schema.SelectorOptions.createCollection) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 13 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test164QueryObjectTypeByTypeAndExtensionAttribute.

@Test
public void test164QueryObjectTypeByTypeAndExtensionAttribute() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = prismContext.queryFor(ObjectType.class).type(UserType.class).item(UserType.F_EXTENSION, new QName("http://example.com/p", "weapon")).eq("some weapon name").build();
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, ObjectType.class, query, false, null);
        assertThat(realQuery.getQuery().getQueryString()).isEqualToIgnoringWhitespace("select\n" + "  o.oid, o.fullObject\n" + "from\n" + "  RObject o\n" + "    left join o.strings s with ( s.ownerType = :ownerType and s.itemId = :itemId )\n" + "where\n" + "  (\n" + "    o.objectTypeClass = :objectTypeClass and\n" + "    s.value = :value\n" + "  )\n");
        assertEquals("Wrong property ID for 'weapon'", weaponDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
    } finally {
        close(session);
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) QName(javax.xml.namespace.QName) RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 14 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test182QueryGenericBoolean.

@Test
public void test182QueryGenericBoolean() throws Exception {
    Session session = open();
    try {
        ObjectQuery objectQuery = prismContext.queryFor(GenericObjectType.class).item(ObjectType.F_EXTENSION, SKIP_AUTOGENERATION_QNAME).eq(true).build();
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, GenericObjectType.class, objectQuery, false, null);
        assertThat(realQuery.getQuery().getQueryString()).isEqualToIgnoringWhitespace("select\n" + "  g.oid, g.fullObject\n" + "from\n" + "  RGenericObject g\n" + "    left join g.booleans b with ( b.ownerType = :ownerType and b.itemId = :itemId )\n" + "where\n" + "  b.value = :value\n");
        assertEquals("Wrong property ID for 'skipAutogeneration'", skipAutogenerationDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
        OperationResult result = new OperationResult("search");
        List<PrismObject<GenericObjectType>> objects = repositoryService.searchObjects(GenericObjectType.class, objectQuery, null, result);
        result.computeStatus();
        assertTrue(result.isSuccess());
        AssertJUnit.assertNotNull(objects);
        assertEquals(1, objects.size());
        PrismObject<GenericObjectType> obj = objects.get(0);
        assertEquals(GenericObjectType.class, obj.getCompileTimeClass());
        result = new OperationResult("count");
        long count = repositoryService.countObjects(GenericObjectType.class, objectQuery, null, result);
        result.computeStatus();
        assertTrue(result.isSuccess());
        assertEquals(1, count);
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 15 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test708QuerySearchForAssignmentHolderType.

@Test
public void test708QuerySearchForAssignmentHolderType() throws Exception {
    Session session = open();
    try {
        RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, AssignmentHolderType.class, null, false, null);
        String real = rQuery.getQuery().getQueryString();
        System.out.println("Query parameters:\n" + rQuery.getQuerySource().getParameters());
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  o.oid,\n" + "  o.fullObject\n" + "from\n" + "  RObject o\n" + "where\n" + "  o.objectTypeClass in (:objectTypeClass)");
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

RQueryImpl (com.evolveum.midpoint.repo.sql.query.RQueryImpl)18 Session (org.hibernate.Session)17 Test (org.testng.annotations.Test)17 SelectorOptions.createCollection (com.evolveum.midpoint.schema.SelectorOptions.createCollection)7 QName (javax.xml.namespace.QName)4 File (java.io.File)3 QueryEngine (com.evolveum.midpoint.repo.sql.query.QueryEngine)1 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)1 QueryParameterValue (com.evolveum.midpoint.repo.sql.query.hqm.QueryParameterValue)1 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1