use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class ExistsRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
HqlDataInstance dataInstance = getItemPathResolver().resolveItemPath(filter.getFullPath(), filter.getDefinition(), getBaseHqlEntity(), false);
boolean isAll = filter.getFilter() == null || filter.getFilter() instanceof AllFilter;
JpaDataNodeDefinition jpaDefinition = dataInstance.getJpaDefinition();
if (!isAll) {
if (!(jpaDefinition instanceof JpaEntityDefinition)) {
// partially checked already (for non-null-ness)
throw new QueryException("ExistsRestriction with non-empty subfilter points to non-entity node: " + jpaDefinition);
}
setHqlDataInstance(dataInstance);
QueryInterpreter interpreter = context.getInterpreter();
return interpreter.interpretFilter(context, filter.getFilter(), this);
} else if (jpaDefinition instanceof JpaPropertyDefinition && (((JpaPropertyDefinition) jpaDefinition).isCount())) {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
return hibernateQuery.createSimpleComparisonCondition(dataInstance.getHqlPath(), 0, ">");
} else {
// TODO support exists also for other properties (single valued or multi valued)
throw new UnsupportedOperationException("Exists filter with 'all' subfilter is currently not supported");
}
}
use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class QueryEngine method interpret.
public RQuery interpret(ObjectQuery query, Class<? extends Containerable> type, Collection<SelectorOptions<GetOperationOptions>> options, boolean countingObjects, Session session) throws QueryException {
query = refineAssignmentHolderQuery(type, query);
QueryInterpreter interpreter = new QueryInterpreter(repoConfiguration, extItemDictionary);
RootHibernateQuery hibernateQuery = interpreter.interpret(query, type, options, prismContext, relationRegistry, countingObjects, session);
Query<?> hqlQuery = hibernateQuery.getAsHqlQuery(session);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Query interpretation result:\n--- Query:\n{}\n--- with options: {}\n--- resulted in HQL:\n{}", DebugUtil.debugDump(query), options, hqlQuery.getQueryString());
}
return new RQueryImpl(hqlQuery, hibernateQuery);
}
use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery 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.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class ReferenceRestriction method interpretInternal.
@Override
public Condition interpretInternal() throws QueryException {
String hqlPath = hqlDataInstance.getHqlPath();
LOGGER.trace("interpretInternal starting with hqlPath = {}", hqlPath);
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
List<PrismReferenceValue> values = filter.getValues();
if (CollectionUtils.isEmpty(values)) {
return hibernateQuery.createIsNull(hqlDataInstance.getHqlPath());
}
Set<String> oids = new HashSet<>();
Set<QName> relations = new HashSet<>();
Set<QName> targetTypes = new HashSet<>();
boolean valuesWithWildcardOid = false;
boolean valuesWithSpecifiedOid = false;
for (PrismReferenceValue value : values) {
if (value.getOid() != null) {
oids.add(value.getOid());
valuesWithSpecifiedOid = true;
} else {
if (filter.isOidNullAsAny()) {
valuesWithWildcardOid = true;
} else {
throw new QueryException("Null OID is not allowed in the reference query. " + "If you'd like to search for missing reference, use empty list of values.");
}
}
if (value.getRelation() == null) {
relations.add(context.getPrismContext().getDefaultRelation());
} else {
// we intentionally don't normalize relations namespaces, to be able to do namespace-insensitive searches
// so the caller is responsible to unify namespaces if he needs to optimize queries (use IN instead of OR)
relations.add(value.getRelation());
}
targetTypes.add(qualifyTypeName(value.getTargetType()));
}
if (valuesWithWildcardOid && valuesWithSpecifiedOid || relations.size() > 1 || targetTypes.size() > 1) {
// We must use 'OR' clause
OrCondition rootOr = hibernateQuery.createOr();
values.forEach(prv -> rootOr.add(createRefCondition(hibernateQuery, MiscUtil.singletonOrEmptySet(prv.getOid()), prv.getRelation(), prv.getTargetType())));
return rootOr;
} else {
return createRefCondition(hibernateQuery, oids, MiscUtil.extractSingleton(relations), MiscUtil.extractSingleton(targetTypes));
}
}
use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class ItemValueRestriction method addIsNotNullIfNecessary.
/**
* Filter of type NOT(PROPERTY=VALUE) causes problems when there are entities with PROPERTY set to NULL.
* <p>
* Such a filter has to be treated like
* <p>
* NOT (PROPERTY=VALUE & PROPERTY IS NOT NULL)
* <p>
* TODO implement for restrictions other than PropertyRestriction.
*/
Condition addIsNotNullIfNecessary(Condition condition, String propertyPath) {
if (condition instanceof IsNullCondition || condition instanceof IsNotNullCondition) {
return condition;
}
if (!isNegated()) {
return condition;
}
RootHibernateQuery hibernateQuery = getContext().getHibernateQuery();
AndCondition conjunction = hibernateQuery.createAnd();
conjunction.add(condition);
conjunction.add(hibernateQuery.createIsNotNull(propertyPath));
return conjunction;
}
Aggregations