Search in sources :

Example 6 with JpaEntityDefinition

use of com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition 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 7 with JpaEntityDefinition

use of com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition in project midpoint by Evolveum.

the class ItemPathResolver method findProperDataDefinition.

/**
     * Finds the proper definition for (possibly abstract) entity.
     * Returns the most abstract entity that can be used.
     * Checks for conflicts, such as user.locality vs org.locality.
     *
     * @param path Path to be found (non-empty!)
     * @param itemDefinition Definition of target property, required/used only for "any" properties
     * @param clazz Kind of definition to be looked for
     * @param prismContext
     * @return Entity type definition + item definition, or null if nothing was found
     */
public <T extends JpaDataNodeDefinition> ProperDataSearchResult<T> findProperDataDefinition(JpaEntityDefinition baseEntityDefinition, ItemPath path, ItemDefinition itemDefinition, Class<T> clazz, PrismContext prismContext) throws QueryException {
    QueryDefinitionRegistry2 registry = QueryDefinitionRegistry2.getInstance();
    ProperDataSearchResult<T> candidateResult = null;
    for (JpaEntityDefinition entityDefinition : findPossibleBaseEntities(baseEntityDefinition, registry)) {
        DataSearchResult<T> result = entityDefinition.findDataNodeDefinition(path, itemDefinition, clazz, prismContext);
        if (result != null) {
            if (candidateResult == null) {
                candidateResult = new ProperDataSearchResult<>(entityDefinition, result);
            } else {
                // there is no possibility of false alarm.
                if (!candidateResult.getEntityDefinition().isAssignableFrom(entityDefinition)) {
                    throw new QueryException("Unable to determine root entity for " + path + ": found incompatible candidates: " + candidateResult.getEntityDefinition() + " and " + entityDefinition);
                }
            }
        }
    }
    LOGGER.trace("findProperDataDefinition: base='{}', path='{}', def='{}', class={} -- returning '{}'", baseEntityDefinition, path, itemDefinition, clazz.getSimpleName(), candidateResult);
    return candidateResult;
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QueryDefinitionRegistry2(com.evolveum.midpoint.repo.sql.query2.QueryDefinitionRegistry2) JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)

Example 8 with JpaEntityDefinition

use of com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition in project midpoint by Evolveum.

the class QueryDefinitionRegistry2 method getDirectChildrenOf.

private List<JpaEntityDefinition> getDirectChildrenOf(JpaEntityDefinition parentDefinition) {
    Class parentClass = parentDefinition.getJpaClass();
    List<JpaEntityDefinition> retval = new ArrayList<>();
    for (JpaEntityDefinition definition : definitions.values()) {
        if (parentClass.equals(definition.getJpaClass().getSuperclass())) {
            retval.add(definition);
        }
    }
    return retval;
}
Also used : ArrayList(java.util.ArrayList) JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)

Example 9 with JpaEntityDefinition

use of com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition in project midpoint by Evolveum.

the class QueryDefinitionRegistry2 method debugDump.

@Override
public String debugDump(int indent) {
    StringBuilder builder = new StringBuilder();
    DebugUtil.indentDebugDump(builder, indent);
    Collection<JpaEntityDefinition> defCollection = definitions.values();
    for (JpaEntityDefinition definition : defCollection) {
        builder.append(definition.debugDump(indent)).append('\n');
    }
    return builder.toString();
}
Also used : JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)

Example 10 with JpaEntityDefinition

use of com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition in project midpoint by Evolveum.

the class QueryDefinitionRegistry2 method getChildrenOf.

/**
     * Returns possible "children" of a given definition.
     * More abstract classes are listed first.
     */
public List<JpaEntityDefinition> getChildrenOf(JpaEntityDefinition entityDefinition) {
    List<JpaEntityDefinition> retval = new ArrayList<>();
    List<JpaEntityDefinition> children = getDirectChildrenOf(entityDefinition);
    for (JpaEntityDefinition child : children) {
        retval.add(child);
        retval.addAll(getChildrenOf(child));
    }
    return retval;
}
Also used : ArrayList(java.util.ArrayList) JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)

Aggregations

JpaEntityDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)7 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 QueryDefinitionRegistry2 (com.evolveum.midpoint.repo.sql.query2.QueryDefinitionRegistry2)2 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)2 ArrayList (java.util.ArrayList)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 AllFilter (com.evolveum.midpoint.prism.query.AllFilter)1 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)1 QueryInterpreter2 (com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)1 JpaDataNodeDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaDataNodeDefinition)1 JpaPropertyDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition)1 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)1 ItemPathResolver (com.evolveum.midpoint.repo.sql.query2.resolution.ItemPathResolver)1 ProperDataSearchResult (com.evolveum.midpoint.repo.sql.query2.resolution.ProperDataSearchResult)1