use of com.evolveum.midpoint.repo.sql.query2.InterpretationContext in project midpoint by Evolveum.
the class QueryInterpreter2 method interpretPagingAndSorting.
private void interpretPagingAndSorting(InterpretationContext context, ObjectQuery query, boolean countingObjects) throws QueryException {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
String rootAlias = hibernateQuery.getPrimaryEntityAlias();
if (query != null && query.getPaging() instanceof ObjectPagingAfterOid) {
ObjectPagingAfterOid paging = (ObjectPagingAfterOid) query.getPaging();
if (paging.getOidGreaterThan() != null) {
Condition c = hibernateQuery.createSimpleComparisonCondition(rootAlias + ".oid", paging.getOidGreaterThan(), ">");
hibernateQuery.addCondition(c);
}
}
if (!countingObjects && query != null && query.getPaging() != null) {
if (query.getPaging() instanceof ObjectPagingAfterOid) {
// very special case - ascending ordering by OID (nothing more)
updatePagingAndSortingByOid(hibernateQuery, (ObjectPagingAfterOid) query.getPaging());
} else {
updatePagingAndSorting(context, query.getPaging());
}
}
}
use of com.evolveum.midpoint.repo.sql.query2.InterpretationContext in project midpoint by Evolveum.
the class QueryInterpreter2 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<JpaDataNodeDefinition> 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<JpaReferenceDefinition> 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<JpaPropertyDefinition> 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.sql.query2.InterpretationContext in project midpoint by Evolveum.
the class QueryInterpreter2 method interpretQueryFilter.
private void interpretQueryFilter(InterpretationContext context, ObjectQuery query) throws QueryException {
if (query != null && query.getFilter() != null) {
Condition c = interpretFilter(context, query.getFilter(), null);
context.getHibernateQuery().addCondition(c);
}
}
use of com.evolveum.midpoint.repo.sql.query2.InterpretationContext in project midpoint by Evolveum.
the class TypeRestriction method interpret.
@Override
public Condition interpret() throws QueryException {
InterpretationContext context = getContext();
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
String property = getBaseHqlEntity().getHqlPath() + "." + RObject.F_OBJECT_TYPE_CLASS;
Set<RObjectType> values = getValues(filter.getType());
Condition basedOnType;
if (values.size() > 1) {
basedOnType = hibernateQuery.createIn(property, values);
} else {
basedOnType = hibernateQuery.createEq(property, values.iterator().next());
}
if (filter.getFilter() == null) {
return basedOnType;
}
QueryInterpreter2 interpreter = context.getInterpreter();
Condition basedOnFilter = interpreter.interpretFilter(context, filter.getFilter(), this);
return hibernateQuery.createAnd(basedOnType, basedOnFilter);
}
use of com.evolveum.midpoint.repo.sql.query2.InterpretationContext in project midpoint by Evolveum.
the class UnaryLogicalRestriction method interpretChildFilter.
protected Condition interpretChildFilter() throws QueryException {
InterpretationContext context = getContext();
QueryInterpreter2 interpreter = context.getInterpreter();
return interpreter.interpretFilter(context, filter.getFilter(), this);
}
Aggregations