Search in sources :

Example 1 with RQueryImpl

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

the class QueryInterpreterTest method test084QueryUserAssignmentTargetRefManagerUnqualified.

@Test
public void test084QueryUserAssignmentTargetRefManagerUnqualified() throws Exception {
    Session session = open();
    try {
        ObjectReferenceType ort = new ObjectReferenceType().oid("123").type(OrgType.COMPLEX_TYPE).relation(QNameUtil.nullNamespace(SchemaConstants.ORG_MANAGER));
        ObjectQuery query = prismContext.queryFor(UserType.class).item(F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(ort.asReferenceValue()).build();
        RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
        String real = rQuery.getQuery().getQueryString();
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  u.oid, u.fullObject\n" + "from\n" + "  RUser u\n" + "    left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + "  (\n" + "    a.targetRef.targetOid = :targetOid and\n" + "    a.targetRef.relation in (:relation) and\n" + "    a.targetRef.targetType = :targetType\n" + "  )\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 2 with RQueryImpl

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

the class QueryInterpreterTest method test082QueryUserAssignmentTargetRefManagerStandardQualified.

@Test
public void test082QueryUserAssignmentTargetRefManagerStandardQualified() throws Exception {
    Session session = open();
    try {
        ObjectReferenceType ort = new ObjectReferenceType().oid("123").type(OrgType.COMPLEX_TYPE).relation(SchemaConstants.ORG_MANAGER);
        ObjectQuery query = prismContext.queryFor(UserType.class).item(F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(ort.asReferenceValue()).build();
        RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
        String real = rQuery.getQuery().getQueryString();
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  u.oid, u.fullObject\n" + "from\n" + "  RUser u\n" + "    left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + "  (\n" + "    a.targetRef.targetOid = :targetOid and\n" + "    a.targetRef.relation in (:relation) and\n" + "    a.targetRef.targetType = :targetType\n" + "  )\n");
        @SuppressWarnings("unchecked") Collection<String> relationParameter = (Collection<String>) rQuery.getQuerySource().getParameters().get("relation").getValue();
        System.out.println("relationParameter: " + relationParameter);
        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 3 with RQueryImpl

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

the class QueryInterpreterTest method test128QueryOrgTreeFindUsersRelationManager.

@Test
public void test128QueryOrgTreeFindUsersRelationManager() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = prismContext.queryFor(UserType.class).isChildOf(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 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<>(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 4 with RQueryImpl

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

the class QueryInterpreterTest method test005QueryOrganizationNorm.

@Test
public void test005QueryOrganizationNorm() throws Exception {
    Session session = open();
    try {
        /*
             *  ### user: Equal (organization, "...", PolyStringNorm)
             */
        ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_ORGANIZATION).eqPoly("guľôčka v jamôčke").matchingNorm().build();
        RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
        String real = rQuery.getQuery().getQueryString();
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  u.oid, u.fullObject\n" + "from\n" + "  RUser u\n" + "    left join u.organization o\n" + "where\n" + "  o.norm = :norm");
        assertEquals("Wrong parameter value", "gulocka v jamocke", rQuery.getQuerySource().getParameters().get("norm").getValue());
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 5 with RQueryImpl

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

the class QueryInterpreterTest method test017QueryGenericLong.

@Test
public void test017QueryGenericLong() throws Exception {
    Session session = open();
    try {
        /*
             *  ### generic: And (Equal (name, "generic object", PolyStringNorm),
             *                    Equal (c:extension/p:intType, 123))
             *  ==> from RGenericObject g
             *        left join g.longs l (l.ownerType = com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType.EXTENSION and l.name = 'http://example.com/p#intType')
             *      where
             *         g.name.norm = 'generic object' and
             *         l.value = 123
             */
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, GenericObjectType.class, getQuery(new File(TEST_DIR, "query-and-generic.xml"), GenericObjectType.class), false, null);
        String real = realQuery.getQuery().getQueryString();
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  g.oid, g.fullObject\n" + "from\n" + "  RGenericObject g\n" + "    left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" + "where\n" + "  ( g.nameCopy.norm = :norm and l.value = :value )\n");
        assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) File(java.io.File) 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