Search in sources :

Example 6 with InterpretationContext

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());
        }
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) ObjectPagingAfterOid(com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)

Example 7 with InterpretationContext

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());
    }
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) ProperDataSearchResult(com.evolveum.midpoint.repo.sql.query2.resolution.ProperDataSearchResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 8 with InterpretationContext

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);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)

Example 9 with InterpretationContext

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);
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Example 10 with InterpretationContext

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);
}
Also used : InterpretationContext(com.evolveum.midpoint.repo.sql.query2.InterpretationContext) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Aggregations

InterpretationContext (com.evolveum.midpoint.repo.sql.query2.InterpretationContext)4 QueryInterpreter2 (com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)4 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)4 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectPagingAfterOid (com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid)1 RObjectType (com.evolveum.midpoint.repo.sql.data.common.other.RObjectType)1 CountProjectionElement (com.evolveum.midpoint.repo.sql.query2.hqm.CountProjectionElement)1 JunctionCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.JunctionCondition)1 Matcher (com.evolveum.midpoint.repo.sql.query2.matcher.Matcher)1 ItemPathResolver (com.evolveum.midpoint.repo.sql.query2.resolution.ItemPathResolver)1 ProperDataSearchResult (com.evolveum.midpoint.repo.sql.query2.resolution.ProperDataSearchResult)1 ResultStyle (com.evolveum.midpoint.repo.sql.util.ResultStyle)1