Search in sources :

Example 1 with RQueryImpl

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

the class QueryInterpreter2Test method test010QueryOrganizationNorm.

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

Example 2 with RQueryImpl

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

the class QueryInterpreter2Test method test070QueryGenericLong.

@Test
public void test070QueryGenericLong() 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) getInterpretedQuery2Whole(session, GenericObjectType.class, getQuery(new File(TEST_DIR, "query-and-generic.xml"), GenericObjectType.class), false, null);
        String real = realQuery.getQuery().getQueryString();
        String expected = "select\n" + "  g.oid, g.fullObject, g.stringsCount, g.longsCount, g.datesCount, g.referencesCount, g.polysCount, g.booleansCount\n" + "from\n" + "  RGenericObject g\n" + "    left join g.longs l with ( l.ownerType = :ownerType and l.name = :name )\n" + "where\n" + "  ( g.name.norm = :norm and l.value = :value )\n";
        assertEqualsIgnoreWhitespace(expected, real);
        assertEquals("Wrong property URI for 'intType'", "http://example.com/p#intType", realQuery.getQuerySource().getParameters().get("name").getValue());
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query2.RQueryImpl) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 3 with RQueryImpl

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

the class QueryInterpreter2Test method test071QueryGenericLongTwice.

@Test
public void test071QueryGenericLongTwice() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext).item(F_NAME).eqPoly("generic object", "generic object").matchingNorm().and().item(F_EXTENSION, new QName("intType")).ge(100).and().item(F_EXTENSION, new QName("intType")).lt(200).and().item(F_EXTENSION, new QName("longType")).eq(335).build();
        RQuery realQuery = getInterpretedQuery2Whole(session, GenericObjectType.class, query, false, null);
        RootHibernateQuery source = ((RQueryImpl) realQuery).getQuerySource();
        String real = ((RQueryImpl) realQuery).getQuery().getQueryString();
        String expected = "select\n" + "  g.oid, g.fullObject, g.stringsCount, g.longsCount, g.datesCount, g.referencesCount, g.polysCount, g.booleansCount\n" + "from\n" + "  RGenericObject g\n" + "    left join g.longs l with ( l.ownerType = :ownerType and l.name = :name )\n" + "    left join g.longs l2 with ( l2.ownerType = :ownerType2 and l2.name = :name2 )\n" + "where\n" + "  (\n" + "    g.name.norm = :norm and\n" + "    l.value >= :value and\n" + "    l.value < :value2 and\n" + "    l2.value = :value3\n" + "  )";
        // note l and l2 cannot be merged as they point to different extension properties (intType, longType)
        assertEqualsIgnoreWhitespace(expected, real);
        assertEquals("Wrong property URI for 'intType'", "http://example.com/p#intType", source.getParameters().get("name").getValue());
        assertEquals("Wrong property URI for 'longType'", "http://example.com/p#longType", source.getParameters().get("name2").getValue());
    } finally {
        close(session);
    }
}
Also used : RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) QName(javax.xml.namespace.QName) RQueryImpl(com.evolveum.midpoint.repo.sql.query2.RQueryImpl) Session(org.hibernate.Session) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) Test(org.testng.annotations.Test)

Example 4 with RQueryImpl

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

the class QueryInterpreter2Test method test630QueryGenericBoolean.

//    @Test(enabled = false)
//    public void atest100() throws Exception {
//        Session session = open();
//
//        try {
//            String expected = null;//HibernateToSqlTranslator.toSql(main);
//
//            List<EqualFilter> secondaryEquals = new ArrayList<>();
//            EqualFilter eq = EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, SchemaConstantsGenerated.ICF_S_UID),
//                    new PrismPropertyDefinitionImpl(SchemaConstantsGenerated.ICF_S_UID, DOMUtil.XSD_STRING, prismContext),
//                    "8daaeeae-f0c7-41c9-b258-2a3351aa8876");
//            secondaryEquals.add(eq);
//            eq = EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, SchemaConstantsGenerated.ICF_S_NAME),
//                    new PrismPropertyDefinitionImpl(SchemaConstantsGenerated.ICF_S_NAME, DOMUtil.XSD_STRING, prismContext),
//                    "some-name");
//            secondaryEquals.add(eq);
//
//            OrFilter secondaryIdentifierFilter = OrFilter.createOr((List) secondaryEquals);
//            RefFilter ref = RefFilter.createReferenceEqual(ShadowType.F_RESOURCE_REF, ShadowType.class,
//                    prismContext, "ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2");
//
//            AndFilter filter = AndFilter.createAnd(ref, secondaryIdentifierFilter);
//            ObjectQuery query = ObjectQuery.createObjectQuery(filter);
//            LOGGER.debug("Query\n{}", query);
//
//            QueryEngine engine = new QueryEngine(repositoryService.getConfiguration(), prismContext);
//            RQuery rQuery = engine.interpret(query, ShadowType.class, null, false, session);
//            RQueryCriteriaImpl rci = (RQueryCriteriaImpl) rQuery;
//            System.out.println(rci);
//            System.out.println(rci.getCriteria());
//            //just test if DB will handle it or throws some exception
//            List l = rQuery.list();
//            LOGGER.info(">>>>>>>>asdfasdfasdfasdf{}",l.size());
//
//            String real = getInterpretedQuery2(session, ShadowType.class, query);
//
//            LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[]{expected, real});
//            AssertJUnit.assertEquals(expected, real);
//        } finally {
//            close(session);
//        }
//    }
@Test
public void test630QueryGenericBoolean() throws Exception {
    Session session = open();
    try {
        ObjectQuery objectQuery = QueryBuilder.queryFor(GenericObjectType.class, prismContext).item(ObjectType.F_EXTENSION, SKIP_AUTOGENERATION).eq(true).build();
        objectQuery.setUseNewQueryInterpreter(true);
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQuery2Whole(session, GenericObjectType.class, objectQuery, false, null);
        String expected = "select\n" + "  g.oid, g.fullObject,\n" + "  g.stringsCount,\n" + "  g.longsCount,\n" + "  g.datesCount,\n" + "  g.referencesCount,\n" + "  g.polysCount,\n" + "  g.booleansCount\n" + "from\n" + "  RGenericObject g\n" + "    left join g.booleans b with ( b.ownerType = :ownerType and b.name = :name )\n" + "where\n" + "  b.value = :value\n";
        assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString());
        assertEquals("Wrong property URI for 'skipAutogeneration'", "http://example.com/p#skipAutogeneration", realQuery.getQuerySource().getParameters().get("name").getValue());
        OperationResult result = new OperationResult("search");
        List<PrismObject<GenericObjectType>> objects = repositoryService.searchObjects(GenericObjectType.class, objectQuery, null, result);
        result.computeStatus();
        AssertJUnit.assertTrue(result.isSuccess());
        AssertJUnit.assertNotNull(objects);
        assertEquals(1, objects.size());
        PrismObject<GenericObjectType> obj = objects.get(0);
        AssertJUnit.assertTrue(obj.getCompileTimeClass().equals(GenericObjectType.class));
        result = new OperationResult("count");
        long count = repositoryService.countObjects(GenericObjectType.class, objectQuery, result);
        result.computeStatus();
        AssertJUnit.assertTrue(result.isSuccess());
        assertEquals(1, count);
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query2.RQueryImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 5 with RQueryImpl

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

the class QueryInterpreter2Test method test074QueryAccountByAttributeAndExtensionValue.

@Test
public void test074QueryAccountByAttributeAndExtensionValue() throws Exception {
    Session session = open();
    try {
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQuery2Whole(session, ShadowType.class, getQuery(new File(TEST_DIR, "query-account-by-attribute-and-extension-value.xml"), ShadowType.class), false, null);
        String expected = "select\n" + "  s.oid, s.fullObject, s.stringsCount, s.longsCount, s.datesCount, s.referencesCount, s.polysCount, s.booleansCount\n" + "from\n" + "  RShadow s\n" + "    left join s.strings s2 with ( s2.ownerType = :ownerType and s2.name = :name )\n" + "    left join s.longs l with ( l.ownerType = :ownerType2 and l.name = :name2 )\n" + "where\n" + "  (\n" + "    s2.value = :value and\n" + "    l.value = :value2\n" + "  )";
        assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString());
        assertEquals("Wrong property URI for 'a1'", "#a1", realQuery.getQuerySource().getParameters().get("name").getValue());
        assertEquals("Wrong property URI for 'shoeSize'", "http://example.com/xml/ns/mySchema#shoeSize", realQuery.getQuerySource().getParameters().get("name2").getValue());
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query2.RQueryImpl) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

RQueryImpl (com.evolveum.midpoint.repo.sql.query2.RQueryImpl)8 Session (org.hibernate.Session)7 Test (org.testng.annotations.Test)7 File (java.io.File)3 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)2 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)2 QName (javax.xml.namespace.QName)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)1 QueryEngine2 (com.evolveum.midpoint.repo.sql.query2.QueryEngine2)1 QueryParameterValue (com.evolveum.midpoint.repo.sql.query2.hqm.QueryParameterValue)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