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);
}
}
Aggregations