Search in sources :

Example 1 with QueryParameterValue

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

the class ObjectRetriever method executeQueryDiagnosticsRequest.

public RepositoryQueryDiagResponse executeQueryDiagnosticsRequest(RepositoryQueryDiagRequest request, OperationResult result) {
    LOGGER_PERFORMANCE.debug("> execute query diagnostics {}", request);
    Session session = null;
    try {
        // beware, not all databases support read-only transactions!
        session = baseHelper.beginReadOnlyTransaction();
        final String implementationLevelQuery;
        final Map<String, RepositoryQueryDiagResponse.ParameterValue> implementationLevelQueryParameters;
        final Query query;
        final boolean isMidpointQuery = request.getImplementationLevelQuery() == null;
        if (isMidpointQuery) {
            QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
            RQueryImpl rQuery = (RQueryImpl) engine.interpret(request.getQuery(), request.getType(), null, false, session);
            query = rQuery.getQuery();
            implementationLevelQuery = query.getQueryString();
            implementationLevelQueryParameters = new HashMap<>();
            for (Map.Entry<String, QueryParameterValue> entry : rQuery.getQuerySource().getParameters().entrySet()) {
                implementationLevelQueryParameters.put(entry.getKey(), new RepositoryQueryDiagResponse.ParameterValue(entry.getValue().getValue(), entry.getValue().toString()));
            }
        } else {
            implementationLevelQuery = (String) request.getImplementationLevelQuery();
            implementationLevelQueryParameters = new HashMap<>();
            query = session.createQuery(implementationLevelQuery);
        }
        List<?> objects = request.isTranslateOnly() ? null : query.list();
        if (isMidpointQuery && objects != null) {
            // raw GetObjectResult instances are useless outside repo-sql-impl module, so we'll convert them to objects
            @SuppressWarnings("unchecked") List<GetObjectResult> listOfGetObjectResults = (List<GetObjectResult>) objects;
            objects = queryResultToPrismObjects(listOfGetObjectResults, request.getType(), null, session, result);
        }
        RepositoryQueryDiagResponse response = new RepositoryQueryDiagResponse(objects, implementationLevelQuery, implementationLevelQueryParameters);
        session.getTransaction().rollback();
        return response;
    } catch (SchemaException | QueryException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
        throw new IllegalStateException("shouldn't get here");
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
    }
}
Also used : QueryParameterValue(com.evolveum.midpoint.repo.sql.query2.hqm.QueryParameterValue) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryParameterValue(com.evolveum.midpoint.repo.sql.query2.hqm.QueryParameterValue) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QueryEngine2(com.evolveum.midpoint.repo.sql.query2.QueryEngine2) RQueryImpl(com.evolveum.midpoint.repo.sql.query2.RQueryImpl)

Aggregations

ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)1 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)1 QueryEngine2 (com.evolveum.midpoint.repo.sql.query2.QueryEngine2)1 RQueryImpl (com.evolveum.midpoint.repo.sql.query2.RQueryImpl)1 QueryParameterValue (com.evolveum.midpoint.repo.sql.query2.hqm.QueryParameterValue)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1