Search in sources :

Example 1 with QueryDefinitionRegistry

use of com.evolveum.midpoint.repo.sql.query.QueryDefinitionRegistry in project midpoint by Evolveum.

the class ItemPathResolver method findRestrictedEntityDefinition.

/**
 * Given existing entity definition and a request for narrowing it, tries to find refined definition.
 */
public JpaEntityDefinition findRestrictedEntityDefinition(JpaEntityDefinition baseEntityDefinition, QName specificTypeName) throws QueryException {
    QueryDefinitionRegistry registry = QueryDefinitionRegistry.getInstance();
    JpaEntityDefinition specificEntityDefinition = registry.findEntityDefinition(specificTypeName);
    if (!baseEntityDefinition.isAssignableFrom(specificEntityDefinition)) {
        throw new QueryException("Entity " + baseEntityDefinition + " cannot be restricted to " + specificEntityDefinition);
    }
    return specificEntityDefinition;
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) QueryDefinitionRegistry(com.evolveum.midpoint.repo.sql.query.QueryDefinitionRegistry)

Example 2 with QueryDefinitionRegistry

use of com.evolveum.midpoint.repo.sql.query.QueryDefinitionRegistry 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
 * @return Entity type definition + item definition, or null if nothing was found
 */
public <T extends JpaDataNodeDefinition<T>> ProperDataSearchResult<T> findProperDataDefinition(JpaEntityDefinition baseEntityDefinition, ItemPath path, ItemDefinition itemDefinition, Class<T> clazz, PrismContext prismContext) throws QueryException {
    QueryDefinitionRegistry registry = QueryDefinitionRegistry.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.sqlbase.QueryException) QueryDefinitionRegistry(com.evolveum.midpoint.repo.sql.query.QueryDefinitionRegistry)

Aggregations

QueryDefinitionRegistry (com.evolveum.midpoint.repo.sql.query.QueryDefinitionRegistry)2 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)2