use of com.evolveum.midpoint.repo.sql.query.QueryEngine in project midpoint by Evolveum.
the class ObjectRetriever method searchObjectsAttempt.
@NotNull
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjectsAttempt(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
LOGGER_PERFORMANCE.debug("> search objects {}", type.getSimpleName());
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);
@SuppressWarnings({ "unchecked", "raw" }) List<GetObjectResult> queryResult = rQuery.list();
LOGGER.trace("Found {} objects, translating to JAXB.", queryResult != null ? queryResult.size() : 0);
List<PrismObject<T>> list = queryResultToPrismObjects(queryResult, type, options, session, result);
session.getTransaction().commit();
return new SearchResultList<>(list);
} catch (QueryException | RuntimeException ex) {
baseHelper.handleGeneralException(ex, session, result);
throw new IllegalStateException("shouldn't get here");
} finally {
baseHelper.cleanupSessionAndResult(session, result);
}
}
use of com.evolveum.midpoint.repo.sql.query.QueryEngine 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 assignments = AssignmentType.class.equals(type);
boolean cases = AccessCertificationCaseType.class.equals(type);
boolean accCertWorkItems = AccessCertificationWorkItemType.class.equals(type);
boolean caseWorkItems = CaseWorkItemType.class.equals(type);
if (!cases && !accCertWorkItems && !caseWorkItems && !assignments) {
throw new UnsupportedOperationException("Only AccessCertificationCaseType or AccessCertificationWorkItemType" + " or CaseWorkItemType or Assignments is supported here now.");
}
LOGGER_PERFORMANCE.debug("> search containers {}", type.getSimpleName());
List<C> list = new ArrayList<>();
Session session = null;
try {
session = baseHelper.beginReadOnlyTransaction();
QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
RQuery rQuery = engine.interpret(query, type, options, false, session);
if (assignments) {
processAssignmentsQuery(list, rQuery);
} else if (cases) {
@SuppressWarnings({ "unchecked", "raw" }) 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) certificationCaseHelper.updateLoadedCertificationCase(item, campaignsCache, options, session, result);
list.add(value);
}
} else if (accCertWorkItems) {
@SuppressWarnings({ "unchecked", "raw" }) 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) {
@SuppressWarnings({ "raw", "unchecked" }) C value = (C) certificationCaseHelper.updateLoadedCertificationWorkItem(item, casesCache, campaignsCache, options, engine, session, result);
list.add(value);
}
} else {
assert caseWorkItems;
@SuppressWarnings({ "unchecked", "raw" }) List<GetContainerableIdOnlyResult> items = rQuery.list();
LOGGER.trace("Found {} items (case work items), translating to JAXB.", items.size());
Map<String, PrismObject<CaseType>> casesCache = new HashMap<>();
for (GetContainerableIdOnlyResult item : items) {
try {
@SuppressWarnings({ "raw", "unchecked" }) C value = (C) caseManagementHelper.updateLoadedCaseWorkItem(item, casesCache, session);
list.add(value);
} catch (ObjectNotFoundException | DtoTranslationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't retrieve case work item for {}", e, item);
}
}
}
nameResolutionHelper.resolveNamesIfRequested(session, PrismContainerValue.asPrismContainerValues(list), options);
session.getTransaction().commit();
} catch (QueryException | DtoTranslationException | RuntimeException ex) {
baseHelper.handleGeneralException(ex, session, result);
} finally {
baseHelper.cleanupSessionAndResult(session, result);
}
list.forEach(c -> ObjectTypeUtil.normalizeAllRelations(c.asPrismContainerValue(), relationRegistry));
return new SearchResultList<>(list);
}
Aggregations