Search in sources :

Example 1 with JpaPropertyDefinition

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

the class PropertyRestriction method getValueFromFilter.

private 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.");
    }
    Object adaptedValue = adaptValueType(value, filter);
    if (def.isEnumerated()) {
        return getRepoEnumValue((Enum) adaptedValue, def.getJpaClass());
    } else {
        return adaptedValue;
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 2 with JpaPropertyDefinition

use of com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition 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);
        QueryInterpreter 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.query.definition.JpaDataNodeDefinition) HqlDataInstance(com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) AllFilter(com.evolveum.midpoint.prism.query.AllFilter) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery) JpaEntityDefinition(com.evolveum.midpoint.repo.sql.query.definition.JpaEntityDefinition) QueryInterpreter(com.evolveum.midpoint.repo.sql.query.QueryInterpreter) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition)

Example 3 with JpaPropertyDefinition

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

the class PropertyRestriction method interpretInternal.

@Override
public Condition interpretInternal() throws QueryException {
    JpaPropertyDefinition propertyDefinition = linkDefinition.getTargetDefinition();
    if (propertyDefinition.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);
        if (value == null && propertyDefinition.isNeverNull()) {
            LOGGER.warn("Checking nullity of non-null property {} (filter = {})", propertyDefinition, filter);
            return new ConstantCondition(context.getHibernateQuery(), false);
        } else {
            Condition condition = createPropertyVsConstantCondition(propertyValuePath, value, filter);
            return addIsNotNullIfNecessary(condition, propertyValuePath);
        }
    }
}
Also used : ConstantCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition) Condition(com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) ConstantCondition(com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

JpaPropertyDefinition (com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition)3 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 AllFilter (com.evolveum.midpoint.prism.query.AllFilter)1 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)1 QueryInterpreter (com.evolveum.midpoint.repo.sql.query.QueryInterpreter)1 JpaDataNodeDefinition (com.evolveum.midpoint.repo.sql.query.definition.JpaDataNodeDefinition)1 JpaEntityDefinition (com.evolveum.midpoint.repo.sql.query.definition.JpaEntityDefinition)1 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)1 Condition (com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition)1 ConstantCondition (com.evolveum.midpoint.repo.sql.query.hqm.condition.ConstantCondition)1 HqlDataInstance (com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance)1