Search in sources :

Example 21 with QueryException

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

the class PropertyRestriction method createPropertyVsPropertyCondition.

protected Condition createPropertyVsPropertyCondition(String leftPropertyValuePath) throws QueryException {
    HqlDataInstance rightItem = getItemPathResolver().resolveItemPath(filter.getRightHandSidePath(), filter.getRightHandSideDefinition(), getBaseHqlEntityForChildren(), true);
    String rightHqlPath = rightItem.getHqlPath();
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    if (filter instanceof EqualFilter) {
        // left = right OR (left IS NULL AND right IS NULL)
        Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, "=", false);
        OrCondition orCondition = hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
        return orCondition;
    } else if (filter instanceof ComparativeFilter) {
        ItemRestrictionOperation operation = findOperationForFilter(filter);
        Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
        return condition;
    } else {
        throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) ComparativeFilter(com.evolveum.midpoint.prism.query.ComparativeFilter) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition)

Example 22 with QueryException

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

the class PropertyRestriction method interpretInternal.

@Override
public Condition interpretInternal() throws QueryException {
    if (linkDefinition.getTargetDefinition().isLob()) {
        throw new QueryException("Can't query based on clob property value '" + linkDefinition + "'.");
    }
    String propertyValuePath = getHqlDataInstance().getHqlPath();
    if (filter.getRightHandSidePath() != null) {
        return createPropertyVsPropertyCondition(propertyValuePath);
    } else {
        Object value = getValueFromFilter(filter);
        Condition condition = createPropertyVsConstantCondition(propertyValuePath, value, filter);
        return addIsNotNullIfNecessary(condition, propertyValuePath);
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) OrCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.OrCondition) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 23 with QueryException

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

the class PropertyRestriction method getValueFromFilter.

protected Object getValueFromFilter(ValueFilter filter) throws QueryException {
    JpaPropertyDefinition def = linkDefinition.getTargetDefinition();
    Object value;
    if (filter instanceof PropertyValueFilter) {
        value = getValue((PropertyValueFilter) filter);
    } else {
        throw new QueryException("Unknown filter '" + filter + "', can't get value from it.");
    }
    value = checkValueType(value, filter);
    if (def.isEnumerated()) {
        value = getRepoEnumValue((Enum) value, def.getJpaClass());
    }
    return value;
}
Also used : SchemaEnum(com.evolveum.midpoint.repo.sql.data.common.enums.SchemaEnum) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 24 with QueryException

use of com.evolveum.midpoint.repo.sql.query.QueryException 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 25 with QueryException

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

the class ItemValueRestriction method interpret.

@Override
public Condition interpret() throws QueryException {
    ItemPath path = getItemPath();
    if (ItemPath.isNullOrEmpty(path)) {
        throw new QueryException("Null or empty path for ItemValueRestriction in " + filter.debugDump());
    }
    HqlDataInstance dataInstance = getItemPathResolver().resolveItemPath(path, itemDefinition, getBaseHqlEntity(), false);
    setHqlDataInstance(dataInstance);
    Condition condition = interpretInternal();
    return condition;
}
Also used : AndCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.AndCondition) Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) IsNotNullCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNotNullCondition) IsNullCondition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.IsNullCondition) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) HqlDataInstance(com.evolveum.midpoint.repo.sql.query2.resolution.HqlDataInstance) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

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