use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class QueryInterpreter2Test method test610QueryGenericClob.
@Test(expectedExceptions = QueryException.class)
public void test610QueryGenericClob() throws Exception {
Session session = open();
try {
ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext).item(ObjectType.F_EXTENSION, new QName("http://example.com/p", "locations")).isNull().build();
getInterpretedQuery2(session, GenericObjectType.class, query);
} catch (QueryException ex) {
LOGGER.info("Exception", ex);
throw ex;
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.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;
if (query == null || query.getFilter() == null) {
if (GetOperationOptions.isDistinct(SelectorOptions.findRootOptions(options))) {
// TODO
throw new UnsupportedOperationException("Distinct option is not supported here");
}
// 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]
SQLQuery sqlQuery = session.createSQLQuery("SELECT COUNT(*) FROM " + RUtil.getTableName(hqlType));
longCount = (Number) sqlQuery.uniqueResult();
} else {
RQuery rQuery;
QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
rQuery = engine.interpret(query, type, options, true, session);
longCount = (Number) 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.sql.query.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) throws SchemaException {
Session session = null;
try {
session = baseHelper.beginReadOnlyTransaction();
RQuery rQuery;
QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
rQuery = engine.interpret(query, type, options, false, session);
ScrollableResults results = rQuery.scroll(ScrollMode.FORWARD_ONLY);
try {
Iterator<GetObjectResult> iterator = new ScrollableResultsIterator(results);
while (iterator.hasNext()) {
GetObjectResult object = iterator.next();
// TODO treat exceptions encountered within the next call
PrismObject<T> prismObject = updateLoadedObject(object, type, null, options, null, session, result);
if (!handler.handle(prismObject, result)) {
break;
}
}
} finally {
if (results != null) {
results.close();
}
}
session.getTransaction().commit();
} catch (SchemaException | QueryException | RuntimeException ex) {
baseHelper.handleGeneralException(ex, session, result);
} finally {
baseHelper.cleanupSessionAndResult(session, result);
}
}
use of com.evolveum.midpoint.repo.sql.query.QueryException in project midpoint by Evolveum.
the class RAnyConverter method getAnySetType.
/**
* This method provides extension type (in real it's table) string for definition and value
* defined as parameters.
*
* @param definition
* @param prismContext
* @return One of "strings", "longs", "dates", "clobs"
* @throws SchemaException
*/
public static String getAnySetType(ItemDefinition definition, PrismContext prismContext) throws SchemaException, QueryException {
if (!isIndexed(definition, prismContext)) {
throw new QueryException("Can't query non-indexed value, definition " + definition);
}
QName typeName = definition.getTypeName();
ValueType valueType = getValueType(typeName);
switch(valueType) {
case BOOLEAN:
return "booleans";
case DATE:
return "dates";
case LONG:
return "longs";
case STRING:
default:
return "strings";
}
}
use of com.evolveum.midpoint.repo.sql.query.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 cases = AccessCertificationCaseType.class.equals(type);
boolean workItems = AccessCertificationWorkItemType.class.equals(type);
if (!cases && !workItems) {
throw new UnsupportedOperationException("Only AccessCertificationCaseType or AccessCertificationWorkItemType is supported here now.");
}
LOGGER_PERFORMANCE.debug("> search containers {}", type.getSimpleName());
List<C> list = new ArrayList<>();
Session session = null;
try {
session = baseHelper.beginReadOnlyTransaction();
QueryEngine2 engine = new QueryEngine2(getConfiguration(), prismContext);
RQuery rQuery = engine.interpret(query, type, options, false, session);
if (cases) {
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) caseHelper.updateLoadedCertificationCase(item, campaignsCache, options, session, result);
list.add(value);
}
} else {
assert workItems;
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) {
//LOGGER.trace("- {}", item);
@SuppressWarnings({ "raw", "unchecked" }) C value = (C) caseHelper.updateLoadedCertificationWorkItem(item, casesCache, campaignsCache, options, engine, session, result);
list.add(value);
}
}
nameResolutionHelper.resolveNamesIfRequested(session, PrismContainerValue.asPrismContainerValues(list), options);
session.getTransaction().commit();
} catch (QueryException | RuntimeException ex) {
baseHelper.handleGeneralException(ex, session, result);
} finally {
baseHelper.cleanupSessionAndResult(session, result);
}
list.forEach(c -> ObjectTypeUtil.normalizeAllRelations(c.asPrismContainerValue()));
return new SearchResultList<>(list);
}
Aggregations