use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ObjectRetriever method searchObjectsIterativeAttempt.
public <T extends ObjectType> void searchObjectsIterativeAttempt(Class<T> type, ObjectQuery query, ResultHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result, Set<String> retrievedOids) {
Set<String> newlyRetrievedOids = new HashSet<>();
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);
try (ScrollableResults results = rQuery.scroll(ScrollMode.FORWARD_ONLY)) {
Iterator<GetObjectResult> iterator = new ScrollableResultsIterator<>(results);
while (iterator.hasNext()) {
GetObjectResult object = iterator.next();
if (retrievedOids.contains(object.getOid())) {
continue;
}
// TODO treat exceptions encountered within the next call
PrismObject<T> prismObject = updateLoadedObject(object, type, null, options, null, session);
/*
* We DO NOT store OIDs directly into retrievedOids, because this would mean that any duplicated results
* would get eliminated from processing. While this is basically OK, it would break existing behavior,
* and would lead to inconsistencies between e.g. "estimated total" vs "progress" in iterative tasks.
* Such inconsistencies could happen also in the current approach with retrievedOids/newlyRetrievedOids,
* but are much less likely.
* TODO reconsider this in the future - i.e. if it would not be beneficial to skip duplicate processing of objects
* TODO what about memory requirements of this data structure (consider e.g. millions of objects)
*/
newlyRetrievedOids.add(object.getOid());
if (!handler.handle(prismObject, result)) {
break;
}
}
}
session.getTransaction().commit();
} catch (SchemaException | QueryException | RuntimeException | ObjectNotFoundException ex) {
baseHelper.handleGeneralException(ex, session, result);
} finally {
baseHelper.cleanupSessionAndResult(session, result);
retrievedOids.addAll(newlyRetrievedOids);
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ObjectRetriever method countObjectsAttempt.
public <T extends ObjectType> int countObjectsAttempt(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) {
LOGGER_PERFORMANCE.debug("> count objects {}", type.getSimpleName());
int count = 0;
Session session = null;
try {
Class<? extends RObject> hqlType = ClassMapper.getHQLTypeClass(type);
session = baseHelper.beginReadOnlyTransaction();
Number longCount;
query = refineAssignmentHolderQuery(type, query);
if (query == null || query.getFilter() == null) {
// this is 5x faster than count with 3 inner joins, it can probably improved also for queries which
// filters uses only properties from concrete entities like RUser, RRole by improving interpreter [lazyman]
// note: distinct can be ignored here, as there is no filter, so no joins
NativeQuery sqlQuery = session.createNativeQuery("SELECT COUNT(*) FROM " + RUtil.getTableName(hqlType, session));
longCount = (Number) sqlQuery.uniqueResult();
} else {
RQuery rQuery;
QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
rQuery = engine.interpret(query, type, options, true, session);
longCount = rQuery.uniqueResult();
}
LOGGER.trace("Found {} objects.", longCount);
count = longCount != null ? longCount.intValue() : 0;
session.getTransaction().commit();
} catch (QueryException | RuntimeException ex) {
baseHelper.handleGeneralException(ex, session, result);
} finally {
baseHelper.cleanupSessionAndResult(session, result);
}
return count;
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ObjectRetriever method countContainersAttempt.
public <C extends Containerable> int countContainersAttempt(Class<C> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) {
boolean cases = AccessCertificationCaseType.class.equals(type);
boolean workItems = AccessCertificationWorkItemType.class.equals(type);
boolean caseWorkItems = CaseWorkItemType.class.equals(type);
if (!cases && !workItems && !caseWorkItems) {
throw new UnsupportedOperationException("Only AccessCertificationCaseType or AccessCertificationWorkItemType or CaseWorkItemType is supported here now.");
}
LOGGER_PERFORMANCE.debug("> count containers {}", type.getSimpleName());
Session session = null;
try {
session = baseHelper.beginReadOnlyTransaction();
QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
RQuery rQuery = engine.interpret(query, type, options, true, session);
Number longCount = rQuery.uniqueResult();
LOGGER.trace("Found {} objects.", longCount);
session.getTransaction().commit();
return longCount != null ? longCount.intValue() : 0;
} catch (QueryException | RuntimeException ex) {
baseHelper.handleGeneralException(ex, session, result);
throw new AssertionError("Shouldn't get here; previous method call should throw an exception.");
} finally {
baseHelper.cleanupSessionAndResult(session, result);
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class ExtensionItemSqlMapper method primaryPath.
@Override
@Nullable
public Expression<?> primaryPath(Q entityPath, ItemDefinition<?> definition) throws QueryException {
Objects.requireNonNull(definition, "Null definition provided for extension/attributes item.");
JsonbPath path = rootToExtensionPath.apply(entityPath);
ExtItemInfo info = new ExtensionProcessor(repositoryContext).findExtensionItem(definition, holderType);
if (info == null) {
throw new QueryException("Extension property " + definition + " is not indexed and cannot be used for ordering.");
}
MExtItem extItem = info.item;
if (extItem.valueType.equals(STRING_TYPE) || ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition) || extItem.valueType.equals(DATETIME_TYPE)) {
return stringTemplate("{0}->>'{1s}'", path, info.getId());
} else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
return stringTemplate("{0}->'{1s}'->>'" + JsonbUtils.JSONB_POLY_ORIG_KEY + "'", path, info.getId());
} else {
return stringTemplate("{0}->'{1s}'", path, info.getId());
}
}
use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.
the class QueryInterpreterTest method test178QueryGenericClob.
@Test(expectedExceptions = QueryException.class)
public void test178QueryGenericClob() throws Exception {
Session session = open();
try {
ObjectQuery query = prismContext.queryFor(GenericObjectType.class).item(ObjectType.F_EXTENSION, new QName("http://example.com/p", "locations")).isNull().build();
getInterpretedQuery(session, GenericObjectType.class, query);
} catch (QueryException ex) {
logger.info("Exception", ex);
throw ex;
} finally {
close(session);
}
}
Aggregations