Search in sources :

Example 11 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.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, Set<String> retrievedOids) {
    Set<String> newlyRetrievedOids = new HashSet<>();
    Session session = null;
    try {
        session = baseHelper.beginReadOnlyTransaction();
        RQuery rQuery;
        QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
        rQuery = engine.interpret(query, type, options, false, session);
        try (ScrollableResults results = rQuery.scroll(ScrollMode.FORWARD_ONLY)) {
            Iterator<GetObjectResult> iterator = new ScrollableResultsIterator<>(results);
            while (iterator.hasNext()) {
                GetObjectResult object = iterator.next();
                if (retrievedOids.contains(object.getOid())) {
                    continue;
                }
                // TODO treat exceptions encountered within the next call
                PrismObject<T> prismObject = updateLoadedObject(object, type, null, options, null, session);
                /*
                     *  We DO NOT store OIDs directly into retrievedOids, because this would mean that any duplicated results
                     *  would get eliminated from processing. While this is basically OK, it would break existing behavior,
                     *  and would lead to inconsistencies between e.g. "estimated total" vs "progress" in iterative tasks.
                     *  Such inconsistencies could happen also in the current approach with retrievedOids/newlyRetrievedOids,
                     *  but are much less likely.
                     *  TODO reconsider this in the future - i.e. if it would not be beneficial to skip duplicate processing of objects
                     *  TODO what about memory requirements of this data structure (consider e.g. millions of objects)
                     */
                newlyRetrievedOids.add(object.getOid());
                if (!handler.handle(prismObject, result)) {
                    break;
                }
            }
        }
        session.getTransaction().commit();
    } catch (SchemaException | QueryException | RuntimeException | ObjectNotFoundException ex) {
        baseHelper.handleGeneralException(ex, session, result);
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
        retrievedOids.addAll(newlyRetrievedOids);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryEngine(com.evolveum.midpoint.repo.sql.query.QueryEngine) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 12 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.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;
        query = refineAssignmentHolderQuery(type, query);
        if (query == null || query.getFilter() == null) {
            // 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]
            // note: distinct can be ignored here, as there is no filter, so no joins
            NativeQuery sqlQuery = session.createNativeQuery("SELECT COUNT(*) FROM " + RUtil.getTableName(hqlType, session));
            longCount = (Number) sqlQuery.uniqueResult();
        } else {
            RQuery rQuery;
            QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
            rQuery = engine.interpret(query, type, options, true, session);
            longCount = 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.sqlbase.QueryException) NativeQuery(org.hibernate.query.NativeQuery) QueryEngine(com.evolveum.midpoint.repo.sql.query.QueryEngine) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery)

Example 13 with QueryException

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

the class ObjectRetriever method countContainersAttempt.

public <C extends Containerable> int countContainersAttempt(Class<C> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) {
    boolean cases = AccessCertificationCaseType.class.equals(type);
    boolean workItems = AccessCertificationWorkItemType.class.equals(type);
    boolean caseWorkItems = CaseWorkItemType.class.equals(type);
    if (!cases && !workItems && !caseWorkItems) {
        throw new UnsupportedOperationException("Only AccessCertificationCaseType or AccessCertificationWorkItemType or CaseWorkItemType is supported here now.");
    }
    LOGGER_PERFORMANCE.debug("> count containers {}", type.getSimpleName());
    Session session = null;
    try {
        session = baseHelper.beginReadOnlyTransaction();
        QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
        RQuery rQuery = engine.interpret(query, type, options, true, session);
        Number longCount = rQuery.uniqueResult();
        LOGGER.trace("Found {} objects.", longCount);
        session.getTransaction().commit();
        return longCount != null ? longCount.intValue() : 0;
    } catch (QueryException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
        throw new AssertionError("Shouldn't get here; previous method call should throw an exception.");
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) QueryEngine(com.evolveum.midpoint.repo.sql.query.QueryEngine) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery)

Example 14 with QueryException

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

the class ExtensionItemSqlMapper method primaryPath.

@Override
@Nullable
public Expression<?> primaryPath(Q entityPath, ItemDefinition<?> definition) throws QueryException {
    Objects.requireNonNull(definition, "Null definition provided for extension/attributes item.");
    JsonbPath path = rootToExtensionPath.apply(entityPath);
    ExtItemInfo info = new ExtensionProcessor(repositoryContext).findExtensionItem(definition, holderType);
    if (info == null) {
        throw new QueryException("Extension property " + definition + " is not indexed and cannot be used for ordering.");
    }
    MExtItem extItem = info.item;
    if (extItem.valueType.equals(STRING_TYPE) || ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition) || extItem.valueType.equals(DATETIME_TYPE)) {
        return stringTemplate("{0}->>'{1s}'", path, info.getId());
    } else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
        return stringTemplate("{0}->'{1s}'->>'" + JsonbUtils.JSONB_POLY_ORIG_KEY + "'", path, info.getId());
    } else {
        return stringTemplate("{0}->'{1s}'", path, info.getId());
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) ExtensionProcessor(com.evolveum.midpoint.repo.sqale.ExtensionProcessor) ExtItemInfo(com.evolveum.midpoint.repo.sqale.ExtensionProcessor.ExtItemInfo) JsonbPath(com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with QueryException

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

the class QueryInterpreterTest method test178QueryGenericClob.

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

Aggregations

QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)46 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 QName (javax.xml.namespace.QName)9 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)8 Predicate (com.querydsl.core.types.Predicate)8 QueryEngine (com.evolveum.midpoint.repo.sql.query.QueryEngine)6 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)5 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 Condition (com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition)4 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)3 HqlDataInstance (com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance)3 RepositoryException (com.evolveum.midpoint.repo.sqlbase.RepositoryException)3 ItemRelationResolver (com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver)3 NotNull (org.jetbrains.annotations.NotNull)3 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)2 ValueFilter (com.evolveum.midpoint.prism.query.ValueFilter)2 ExtensionProcessor (com.evolveum.midpoint.repo.sqale.ExtensionProcessor)2