Search in sources :

Example 11 with QueryException

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

the class QueryInterpreter2Test method test610QueryGenericClob.

@Test(expectedExceptions = QueryException.class)
public void test610QueryGenericClob() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext).item(ObjectType.F_EXTENSION, new QName("http://example.com/p", "locations")).isNull().build();
        getInterpretedQuery2(session, GenericObjectType.class, query);
    } catch (QueryException ex) {
        LOGGER.info("Exception", ex);
        throw ex;
    } finally {
        close(session);
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QName(javax.xml.namespace.QName) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 12 with QueryException

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

the class ObjectRetriever method countObjectsAttempt.

public <T extends ObjectType> int countObjectsAttempt(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) {
    LOGGER_PERFORMANCE.debug("> count objects {}", type.getSimpleName());
    int count = 0;
    Session session = null;
    try {
        Class<? extends RObject> hqlType = ClassMapper.getHQLTypeClass(type);
        session = baseHelper.beginReadOnlyTransaction();
        Number longCount;
        if (query == null || query.getFilter() == null) {
            if (GetOperationOptions.isDistinct(SelectorOptions.findRootOptions(options))) {
                // TODO
                throw new UnsupportedOperationException("Distinct option is not supported here");
            }
            // this is 5x faster than count with 3 inner joins, it can probably improved also for queries which
            // filters uses only properties from concrete entities like RUser, RRole by improving interpreter [lazyman]
            SQLQuery sqlQuery = session.createSQLQuery("SELECT COUNT(*) FROM " + RUtil.getTableName(hqlType));
            longCount = (Number) sqlQuery.uniqueResult();
        } else {
            RQuery rQuery;
            QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
            rQuery = engine.interpret(query, type, options, true, session);
            longCount = (Number) rQuery.uniqueResult();
        }
        LOGGER.trace("Found {} objects.", longCount);
        count = longCount != null ? longCount.intValue() : 0;
        session.getTransaction().commit();
    } catch (QueryException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
    }
    return count;
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QueryEngine2(com.evolveum.midpoint.repo.sql.query2.QueryEngine2) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery)

Example 13 with QueryException

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

the class ObjectRetriever method searchObjectsIterativeAttempt.

public <T extends ObjectType> void searchObjectsIterativeAttempt(Class<T> type, ObjectQuery query, ResultHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    Session session = null;
    try {
        session = baseHelper.beginReadOnlyTransaction();
        RQuery rQuery;
        QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
        rQuery = engine.interpret(query, type, options, false, session);
        ScrollableResults results = rQuery.scroll(ScrollMode.FORWARD_ONLY);
        try {
            Iterator<GetObjectResult> iterator = new ScrollableResultsIterator(results);
            while (iterator.hasNext()) {
                GetObjectResult object = iterator.next();
                // TODO treat exceptions encountered within the next call
                PrismObject<T> prismObject = updateLoadedObject(object, type, null, options, null, session, result);
                if (!handler.handle(prismObject, result)) {
                    break;
                }
            }
        } finally {
            if (results != null) {
                results.close();
            }
        }
        session.getTransaction().commit();
    } catch (SchemaException | QueryException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QueryEngine2(com.evolveum.midpoint.repo.sql.query2.QueryEngine2)

Example 14 with QueryException

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

the class RAnyConverter method getAnySetType.

/**
     * This method provides extension type (in real it's table) string for definition and value
     * defined as parameters.
     *
     * @param definition
     * @param prismContext
	 * @return One of "strings", "longs", "dates", "clobs"
     * @throws SchemaException
     */
public static String getAnySetType(ItemDefinition definition, PrismContext prismContext) throws SchemaException, QueryException {
    if (!isIndexed(definition, prismContext)) {
        throw new QueryException("Can't query non-indexed value, definition " + definition);
    }
    QName typeName = definition.getTypeName();
    ValueType valueType = getValueType(typeName);
    switch(valueType) {
        case BOOLEAN:
            return "booleans";
        case DATE:
            return "dates";
        case LONG:
            return "longs";
        case STRING:
        default:
            return "strings";
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QName(javax.xml.namespace.QName)

Example 15 with QueryException

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

the class ObjectRetriever method searchContainersAttempt.

public <C extends Containerable> SearchResultList<C> searchContainersAttempt(Class<C> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    boolean cases = AccessCertificationCaseType.class.equals(type);
    boolean workItems = AccessCertificationWorkItemType.class.equals(type);
    if (!cases && !workItems) {
        throw new UnsupportedOperationException("Only AccessCertificationCaseType or AccessCertificationWorkItemType is supported here now.");
    }
    LOGGER_PERFORMANCE.debug("> search containers {}", type.getSimpleName());
    List<C> list = new ArrayList<>();
    Session session = null;
    try {
        session = baseHelper.beginReadOnlyTransaction();
        QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
        RQuery rQuery = engine.interpret(query, type, options, false, session);
        if (cases) {
            List<GetContainerableResult> items = rQuery.list();
            LOGGER.trace("Found {} items (cases), translating to JAXB.", items.size());
            Map<String, PrismObject<AccessCertificationCampaignType>> campaignsCache = new HashMap<>();
            for (GetContainerableResult item : items) {
                @SuppressWarnings({ "raw", "unchecked" }) C value = (C) caseHelper.updateLoadedCertificationCase(item, campaignsCache, options, session, result);
                list.add(value);
            }
        } else {
            assert workItems;
            List<GetCertificationWorkItemResult> items = rQuery.list();
            LOGGER.trace("Found {} work items, translating to JAXB.", items.size());
            Map<String, PrismContainerValue<AccessCertificationCaseType>> casesCache = new HashMap<>();
            Map<String, PrismObject<AccessCertificationCampaignType>> campaignsCache = new HashMap<>();
            for (GetCertificationWorkItemResult item : items) {
                //LOGGER.trace("- {}", item);
                @SuppressWarnings({ "raw", "unchecked" }) C value = (C) caseHelper.updateLoadedCertificationWorkItem(item, casesCache, campaignsCache, options, engine, session, result);
                list.add(value);
            }
        }
        nameResolutionHelper.resolveNamesIfRequested(session, PrismContainerValue.asPrismContainerValues(list), options);
        session.getTransaction().commit();
    } catch (QueryException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
    }
    list.forEach(c -> ObjectTypeUtil.normalizeAllRelations(c.asPrismContainerValue()));
    return new SearchResultList<>(list);
}
Also used : RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QueryEngine2(com.evolveum.midpoint.repo.sql.query2.QueryEngine2)

Aggregations

QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)26 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)5 QueryEngine2 (com.evolveum.midpoint.repo.sql.query2.QueryEngine2)5 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 QName (javax.xml.namespace.QName)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 JpaEntityDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)3 OrCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)3 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)3 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)2 QueryDefinitionRegistry2 (com.evolveum.midpoint.repo.sql.query2.QueryDefinitionRegistry2)2 JpaPropertyDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition)2 AndCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)2 DataSearchResult (com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)1