Search in sources :

Example 1 with QueryParameterValue

use of com.evolveum.midpoint.repo.sql.query.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) {
            QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
            RQueryImpl rQuery = (RQueryImpl) engine.interpret(request.getQuery(), request.getType(), request.getOptions(), 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.query.hqm.QueryParameterValue) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryParameterValue(com.evolveum.midpoint.repo.sql.query.hqm.QueryParameterValue) QueryEngine(com.evolveum.midpoint.repo.sql.query.QueryEngine) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl)

Aggregations

QueryEngine (com.evolveum.midpoint.repo.sql.query.QueryEngine)1 RQueryImpl (com.evolveum.midpoint.repo.sql.query.RQueryImpl)1 QueryParameterValue (com.evolveum.midpoint.repo.sql.query.hqm.QueryParameterValue)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1