Search in sources :

Example 1 with NOT

use of com.yahoo.elide.core.filter.Operator.NOT in project elide by yahoo.

the class FilterTranslator method apply.

/**
 * Transforms a filter predicate into a JPQL query fragment.
 * @param filterPredicate The predicate to transform.
 * @param aliasGenerator Function which supplies a HQL fragment which represents the column in the predicate.
 * @return The hql query fragment.
 */
protected String apply(FilterPredicate filterPredicate, Function<Path, String> aliasGenerator) {
    Function<Path, String> removeThisFromAlias = (path) -> {
        String fieldPath = aliasGenerator.apply(path);
        // JPQL doesn't support 'this', but it does support aliases.
        return fieldPath.replaceAll("\\.this", "");
    };
    Path.PathElement last = filterPredicate.getPath().lastElement().get();
    Operator op = filterPredicate.getOperator();
    JPQLPredicateGenerator generator = predicateOverrides.get(Triple.of(op, last.getType(), last.getFieldName()));
    if (generator == null) {
        generator = operatorGenerators.get(op);
    }
    if (generator == null) {
        throw new BadRequestException("Operator not implemented: " + filterPredicate.getOperator());
    }
    return generator.generate(filterPredicate, removeThisFromAlias);
}
Also used : Path(com.yahoo.elide.core.Path) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Path(com.yahoo.elide.core.Path) LE(com.yahoo.elide.core.filter.Operator.LE) FilterOperation(com.yahoo.elide.core.filter.FilterOperation) NOT(com.yahoo.elide.core.filter.Operator.NOT) HashMap(java.util.HashMap) NOTBETWEEN(com.yahoo.elide.core.filter.Operator.NOTBETWEEN) POSTFIX(com.yahoo.elide.core.filter.Operator.POSTFIX) Function(java.util.function.Function) ISNULL(com.yahoo.elide.core.filter.Operator.ISNULL) PREFIX(com.yahoo.elide.core.filter.Operator.PREFIX) BETWEEN(com.yahoo.elide.core.filter.Operator.BETWEEN) IN(com.yahoo.elide.core.filter.Operator.IN) ISEMPTY(com.yahoo.elide.core.filter.Operator.ISEMPTY) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) Map(java.util.Map) GT(com.yahoo.elide.core.filter.Operator.GT) IN_INSENSITIVE(com.yahoo.elide.core.filter.Operator.IN_INSENSITIVE) HASMEMBER(com.yahoo.elide.core.filter.Operator.HASMEMBER) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Triple(org.apache.commons.lang3.tuple.Triple) INFIX_CASE_INSENSITIVE(com.yahoo.elide.core.filter.Operator.INFIX_CASE_INSENSITIVE) FilterParameter(com.yahoo.elide.core.filter.predicates.FilterPredicate.FilterParameter) FilterExpressionVisitor(com.yahoo.elide.core.filter.expression.FilterExpressionVisitor) NOT_INSENSITIVE(com.yahoo.elide.core.filter.Operator.NOT_INSENSITIVE) NOTEMPTY(com.yahoo.elide.core.filter.Operator.NOTEMPTY) TRUE(com.yahoo.elide.core.filter.Operator.TRUE) NotFilterExpression(com.yahoo.elide.core.filter.expression.NotFilterExpression) EnumMap(java.util.EnumMap) TypeHelper.getPathAlias(com.yahoo.elide.core.utils.TypeHelper.getPathAlias) GE(com.yahoo.elide.core.filter.Operator.GE) FALSE(com.yahoo.elide.core.filter.Operator.FALSE) Collectors(java.util.stream.Collectors) NOTNULL(com.yahoo.elide.core.filter.Operator.NOTNULL) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) INFIX(com.yahoo.elide.core.filter.Operator.INFIX) PREFIX_CASE_INSENSITIVE(com.yahoo.elide.core.filter.Operator.PREFIX_CASE_INSENSITIVE) List(java.util.List) BadRequestException(com.yahoo.elide.core.exceptions.BadRequestException) HASNOMEMBER(com.yahoo.elide.core.filter.Operator.HASNOMEMBER) LT(com.yahoo.elide.core.filter.Operator.LT) Type(com.yahoo.elide.core.type.Type) Operator(com.yahoo.elide.core.filter.Operator) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) Preconditions(com.google.common.base.Preconditions) TypeHelper.getFieldAlias(com.yahoo.elide.core.utils.TypeHelper.getFieldAlias) POSTFIX_CASE_INSENSITIVE(com.yahoo.elide.core.filter.Operator.POSTFIX_CASE_INSENSITIVE) Operator(com.yahoo.elide.core.filter.Operator) BadRequestException(com.yahoo.elide.core.exceptions.BadRequestException)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Path (com.yahoo.elide.core.Path)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)1 FilterOperation (com.yahoo.elide.core.filter.FilterOperation)1 Operator (com.yahoo.elide.core.filter.Operator)1 BETWEEN (com.yahoo.elide.core.filter.Operator.BETWEEN)1 FALSE (com.yahoo.elide.core.filter.Operator.FALSE)1 GE (com.yahoo.elide.core.filter.Operator.GE)1 GT (com.yahoo.elide.core.filter.Operator.GT)1 HASMEMBER (com.yahoo.elide.core.filter.Operator.HASMEMBER)1 HASNOMEMBER (com.yahoo.elide.core.filter.Operator.HASNOMEMBER)1 IN (com.yahoo.elide.core.filter.Operator.IN)1 INFIX (com.yahoo.elide.core.filter.Operator.INFIX)1 INFIX_CASE_INSENSITIVE (com.yahoo.elide.core.filter.Operator.INFIX_CASE_INSENSITIVE)1 IN_INSENSITIVE (com.yahoo.elide.core.filter.Operator.IN_INSENSITIVE)1 ISEMPTY (com.yahoo.elide.core.filter.Operator.ISEMPTY)1 ISNULL (com.yahoo.elide.core.filter.Operator.ISNULL)1 LE (com.yahoo.elide.core.filter.Operator.LE)1 LT (com.yahoo.elide.core.filter.Operator.LT)1