use of com.evolveum.midpoint.repo.sqlbase.QueryException 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.sqlbase.QueryException 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);
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class QLookupTableMapping method appendLookupTableRows.
private void appendLookupTableRows(UUID ownerOid, LookupTableType base, GetOperationOptions rowOptions, JdbcSession session) {
try {
RelationalValueSearchQuery queryDef = rowOptions == null ? null : rowOptions.getRelationalValueSearchQuery();
QLookupTableRowMapping rowMapping = QLookupTableRowMapping.get();
QLookupTableRow alias = rowMapping.defaultAlias();
BooleanExpression whereQuery = appendConditions(alias, alias.ownerOid.eq(ownerOid), queryDef);
SQLQuery<MLookupTableRow> query = session.newQuery().from(alias).select(alias).where(whereQuery);
query = pagingAndOrdering(query, queryDef, rowMapping, alias);
List<MLookupTableRow> result = query.fetch();
for (MLookupTableRow r : result) {
LookupTableRowType lookupRow = new LookupTableRowType().key(r.key);
if (r.labelOrig != null || r.labelNorm != null) {
lookupRow.label(PolyString.toPolyStringType(new PolyString(r.labelOrig, r.labelNorm)));
}
lookupRow.lastChangeTimestamp(MiscUtil.asXMLGregorianCalendar(r.lastChangeTimestamp));
lookupRow.value(r.value);
lookupRow.asPrismContainerValue().setId(r.cid);
base.getRow().add(lookupRow);
}
} catch (QueryException e) {
throw new SystemException("Unable to fetch nested table rows", e);
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class QueryInterpreter method findAndCreateRestrictionInternal.
private <T extends ObjectFilter> Restriction findAndCreateRestrictionInternal(T filter, InterpretationContext context, Restriction parent, ItemPathResolver resolver, JpaEntityDefinition baseEntityDefinition) throws QueryException {
if (filter instanceof AndFilter) {
return new AndRestriction(context, (AndFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof OrFilter) {
return new OrRestriction(context, (OrFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof NotFilter) {
return new NotRestriction(context, (NotFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof FullTextFilter) {
return new FullTextRestriction(context, (FullTextFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof InOidFilter) {
return new InOidRestriction(context, (InOidFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof OrgFilter) {
return new OrgRestriction(context, (OrgFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof TypeFilter) {
TypeFilter typeFilter = (TypeFilter) filter;
JpaEntityDefinition refinedEntityDefinition = resolver.findRestrictedEntityDefinition(baseEntityDefinition, typeFilter.getType());
return new TypeRestriction(context, typeFilter, refinedEntityDefinition, parent);
} else if (filter instanceof ExistsFilter) {
ExistsFilter existsFilter = (ExistsFilter) filter;
ItemPath path = existsFilter.getFullPath();
ItemDefinition<?> definition = existsFilter.getDefinition();
ProperDataSearchResult<?> searchResult = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaDataNodeDefinition.class, context.getPrismContext());
if (searchResult == null) {
throw new QueryException("Path for ExistsFilter (" + path + ") doesn't point to a hibernate entity or property within " + baseEntityDefinition);
}
return new ExistsRestriction(context, existsFilter, searchResult.getEntityDefinition(), parent);
} else if (filter instanceof RefFilter) {
RefFilter refFilter = (RefFilter) filter;
ItemPath path = refFilter.getFullPath();
ItemDefinition<?> definition = refFilter.getDefinition();
ProperDataSearchResult searchResult = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaReferenceDefinition.class, context.getPrismContext());
if (searchResult == null) {
throw new QueryException("Path for RefFilter (" + path + ") doesn't point to a reference item within " + baseEntityDefinition);
}
return new ReferenceRestriction(context, refFilter, searchResult.getEntityDefinition(), parent, searchResult.getLinkDefinition());
} else if (filter instanceof PropertyValueFilter) {
PropertyValueFilter valFilter = (PropertyValueFilter) filter;
ItemPath path = valFilter.getFullPath();
ItemDefinition definition = valFilter.getDefinition();
ProperDataSearchResult propDefRes = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaPropertyDefinition.class, context.getPrismContext());
if (propDefRes == null) {
throw new QueryException("Couldn't find a proper data item to query, given base entity " + baseEntityDefinition + " and this filter: " + valFilter.debugDump());
}
// TODO can't be unified?
if (propDefRes.getTargetDefinition() instanceof JpaAnyPropertyDefinition) {
return new AnyPropertyRestriction(context, valFilter, propDefRes.getEntityDefinition(), parent, propDefRes.getLinkDefinition());
} else {
return new PropertyRestriction(context, valFilter, propDefRes.getEntityDefinition(), parent, propDefRes.getLinkDefinition());
}
} else if (filter instanceof NoneFilter || filter instanceof AllFilter || filter instanceof UndefinedFilter) {
// these should be filtered out by the client
throw new IllegalStateException("Trivial filters are not supported by QueryInterpreter: " + filter.debugDump());
} else {
throw new IllegalStateException("Unknown filter: " + filter.debugDump());
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class QueryInterpreter method addGrouping.
private void addGrouping(InterpretationContext context, ObjectGrouping grouping) throws QueryException {
ItemPath groupByPath = grouping.getGroupBy();
// TODO if we'd like to have group-by extension properties, we'd need to provide itemDefinition for them
ProperDataSearchResult<?> result = context.getItemPathResolver().findProperDataDefinition(context.getRootEntityDefinition(), groupByPath, null, JpaDataNodeDefinition.class, context.getPrismContext());
if (result == null) {
LOGGER.error("Unknown path '" + groupByPath + "', couldn't find definition for it, " + "list will not be grouped by it.");
return;
}
JpaDataNodeDefinition targetDefinition = result.getLinkDefinition().getTargetDefinition();
if (targetDefinition instanceof JpaAnyContainerDefinition) {
throw new QueryException("Grouping based on extension item or attribute is not supported yet: " + groupByPath);
} else if (targetDefinition instanceof JpaReferenceDefinition) {
throw new QueryException("Grouping based on reference is not supported: " + groupByPath);
} else if (result.getLinkDefinition().isMultivalued()) {
throw new QueryException("Grouping based on multi-valued item is not supported: " + groupByPath);
} else if (targetDefinition instanceof JpaEntityDefinition) {
throw new QueryException("Grouping based on entity is not supported: " + groupByPath);
} else if (!(targetDefinition instanceof JpaPropertyDefinition)) {
throw new IllegalStateException("Unknown item definition type: " + result.getClass());
}
JpaEntityDefinition baseEntityDefinition = result.getEntityDefinition();
JpaPropertyDefinition groupByDefinition = (JpaPropertyDefinition) targetDefinition;
String hqlPropertyPath = context.getItemPathResolver().resolveItemPath(groupByPath, null, context.getPrimaryEntityAlias(), baseEntityDefinition, true).getHqlPath();
if (RPolyString.class.equals(groupByDefinition.getJpaClass())) {
hqlPropertyPath += ".orig";
}
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
hibernateQuery.addGrouping(hqlPropertyPath);
}
Aggregations