use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test018QueryGenericLongTwice.
@Test
public void test018QueryGenericLongTwice() throws Exception {
Session session = open();
try {
ObjectQuery query = prismContext.queryFor(GenericObjectType.class).item(F_NAME).eqPoly("generic object", "generic object").matchingNorm().and().item(F_EXTENSION, new QName("intType")).ge(100).and().item(F_EXTENSION, new QName("intType")).lt(200).and().item(F_EXTENSION, new QName("longType")).eq(335).build();
RQuery realQuery = getInterpretedQueryWhole(session, GenericObjectType.class, query, false, null);
RootHibernateQuery source = ((RQueryImpl) realQuery).getQuerySource();
String real = ((RQueryImpl) realQuery).getQuery().getQueryString();
// note l and l2 cannot be merged as they point to different extension properties (intType, longType)
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " g.oid, g.fullObject\n" + "from\n" + " RGenericObject g\n" + " left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" + " left join g.longs l2 with ( l2.ownerType = :ownerType2 and l2.itemId = :itemId2 )\n" + "where\n" + " (\n" + " g.nameCopy.norm = :norm and\n" + " l.value >= :value and\n" + " l.value < :value2 and\n" + " l2.value = :value3\n" + " )");
assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), source.getParameters().get("itemId").getValue());
assertEquals("Wrong property ID for 'longType'", longTypeDefinition.getId(), source.getParameters().get("itemId2").getValue());
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test120QueryOrgTreeFindUsersRelationDefault.
@Test
public void test120QueryOrgTreeFindUsersRelationDefault() throws Exception {
Session session = open();
try {
ObjectQuery query = prismContext.queryFor(UserType.class).isDirectChildOf(itemFactory().createReferenceValue("some oid").relation(SchemaConstants.ORG_DEFAULT)).build();
RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
String real = rQuery.getQuery().getQueryString();
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid = :orgOid)\n");
@SuppressWarnings("unchecked") Collection<String> relationParameter = (Collection<String>) rQuery.getQuerySource().getParameters().get("relation").getValue();
assertEquals("Wrong relation parameter value", new HashSet<>(getVariantsOfDefaultRelation()), new HashSet<>(relationParameter));
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.RQueryImpl 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) {
QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
RQueryImpl rQuery = (RQueryImpl) engine.interpret(request.getQuery(), request.getType(), request.getOptions(), 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