Search in sources :

Example 6 with QueryException

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

the class PolyStringMatcher method match.

@Override
public Condition match(RootHibernateQuery hibernateQuery, ItemRestrictionOperation operation, String propertyName, PolyString value, String matcher) throws QueryException {
    boolean ignoreCase = STRICT_IGNORE_CASE.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher) || NORM_IGNORE_CASE.equals(matcher);
    if (StringUtils.isEmpty(matcher) || DEFAULT.equals(matcher) || STRICT.equals(matcher) || STRICT_IGNORE_CASE.equals(matcher)) {
        AndCondition conjunction = hibernateQuery.createAnd();
        conjunction.add(createOrigMatch(hibernateQuery, operation, propertyName, value, ignoreCase));
        conjunction.add(createNormMatch(hibernateQuery, operation, propertyName, value, ignoreCase));
        return conjunction;
    } else if (ORIG.equals(matcher) || ORIG_IGNORE_CASE.equals(matcher)) {
        return createOrigMatch(hibernateQuery, operation, propertyName, value, ignoreCase);
    } else if (NORM.equals(matcher) || NORM_IGNORE_CASE.equals(matcher)) {
        return createNormMatch(hibernateQuery, operation, propertyName, value, ignoreCase);
    } else {
        throw new QueryException("Unknown matcher '" + matcher + "'.");
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)

Example 7 with QueryException

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

the class ItemPathResolutionState method nextState.

/**
     * Executes transition to next state. Modifies query context by adding joins as necessary.
     *
     * Precondition: !isFinal()
     * Precondition: adequate transition exists
     *
     * @param itemDefinition Target item definition (used/required only for "any" properties)
     * @param singletonOnly Collections are forbidden
     * @return destination state - always not null
     */
public ItemPathResolutionState nextState(ItemDefinition itemDefinition, boolean singletonOnly, PrismContext prismContext) throws QueryException {
    // This is brutal hack, to be thought again.
    if (remainingItemPath.startsWith(ParentPathSegment.class) && hqlDataInstance.getParentItem() != null) {
        return new ItemPathResolutionState(remainingItemPath.tail(), hqlDataInstance.getParentItem(), itemPathResolver);
    }
    DataSearchResult<?> result = hqlDataInstance.getJpaDefinition().nextLinkDefinition(remainingItemPath, itemDefinition, prismContext);
    LOGGER.trace("nextLinkDefinition on '{}' returned '{}'", remainingItemPath, result != null ? result.getLinkDefinition() : "(null)");
    if (result == null) {
        // sorry we failed (however, this should be caught before -> so IllegalStateException)
        throw new IllegalStateException("Couldn't find '" + remainingItemPath + "' in " + hqlDataInstance.getJpaDefinition());
    }
    JpaLinkDefinition linkDefinition = result.getLinkDefinition();
    String newHqlPath = hqlDataInstance.getHqlPath();
    if (linkDefinition.hasJpaRepresentation()) {
        if (singletonOnly && linkDefinition.isMultivalued()) {
            // TODO better message + context
            throw new QueryException("Collections are not allowable for right-side paths");
        }
        if (!linkDefinition.isEmbedded() || linkDefinition.isMultivalued()) {
            LOGGER.trace("Adding join for '{}' to context", linkDefinition);
            newHqlPath = itemPathResolver.addJoin(linkDefinition, hqlDataInstance.getHqlPath());
        } else {
            newHqlPath += "." + linkDefinition.getJpaName();
        }
    }
    HqlDataInstance<?> parentDataInstance;
    if (!remainingItemPath.startsWith(ParentPathSegment.class)) {
        // TODO what about other special cases? (@, ...)
        parentDataInstance = hqlDataInstance;
    } else {
        parentDataInstance = null;
    }
    return new ItemPathResolutionState(result.getRemainder(), new HqlDataInstance<>(newHqlPath, result.getTargetDefinition(), parentDataInstance), itemPathResolver);
}
Also used : JpaLinkDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaLinkDefinition) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) ParentPathSegment(com.evolveum.midpoint.prism.path.ParentPathSegment)

Example 8 with QueryException

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

the class ItemPathResolver method createQueryParamValue.

/**
     * This method provides transformation from {@link String} value defined in
     * {@link com.evolveum.midpoint.repo.sql.query.definition.VirtualQueryParam#value()} to real object. Currently only
     * to simple types and enum values.
     */
private Object createQueryParamValue(VirtualQueryParam param) throws QueryException {
    Class type = param.type();
    String value = param.value();
    try {
        if (type.isPrimitive()) {
            return type.getMethod("valueOf", new Class[] { String.class }).invoke(null, new Object[] { value });
        }
        if (type.isEnum()) {
            return Enum.valueOf(type, value);
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | RuntimeException ex) {
        throw new QueryException("Couldn't transform virtual query parameter '" + param.name() + "' from String to '" + type + "', reason: " + ex.getMessage(), ex);
    }
    throw new QueryException("Couldn't transform virtual query parameter '" + param.name() + "' from String to '" + type + "', it's not yet implemented.");
}
Also used : QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with QueryException

use of com.evolveum.midpoint.repo.sql.query.QueryException 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 {
    QueryDefinitionRegistry2 registry = QueryDefinitionRegistry2.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.sql.query.QueryException) QueryDefinitionRegistry2(com.evolveum.midpoint.repo.sql.query2.QueryDefinitionRegistry2) JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)

Example 10 with QueryException

use of com.evolveum.midpoint.repo.sql.query.QueryException 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);
        QueryInterpreter2 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");
    }
}
Also used : JpaDataNodeDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaDataNodeDefinition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) AllFilter(com.evolveum.midpoint.prism.query.AllFilter) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition) QueryInterpreter2(com.evolveum.midpoint.repo.sql.query2.QueryInterpreter2)

Aggregations

QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)26 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)5 QueryEngine2 (com.evolveum.midpoint.repo.sql.query2.QueryEngine2)5 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 QName (javax.xml.namespace.QName)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 JpaEntityDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition)3 OrCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)3 HqlDataInstance (com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance)3 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)2 QueryDefinitionRegistry2 (com.evolveum.midpoint.repo.sql.query2.QueryDefinitionRegistry2)2 JpaPropertyDefinition (com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition)2 AndCondition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition)2 DataSearchResult (com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)1