All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.data.model.jpa.criteria.impl.AbstractCriteriaBuilder Maven / Gradle / Ivy

There is a newer version: 4.10.3
Show newest version
/*
 * Copyright 2017-2021 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.data.model.jpa.criteria.impl;

import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.data.model.Association;
import io.micronaut.data.model.DataType;
import io.micronaut.data.model.JsonDataType;
import io.micronaut.data.model.PersistentProperty;
import io.micronaut.data.model.PersistentPropertyPath;
import io.micronaut.data.model.jpa.criteria.PersistentEntityCriteriaBuilder;
import io.micronaut.data.model.jpa.criteria.PersistentEntityCriteriaQuery;
import io.micronaut.data.model.jpa.criteria.impl.predicate.ConjunctionPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.DisjunctionPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.ExpressionBinaryPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.NegatedPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.PersistentPropertyBetweenPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.PersistentPropertyBinaryPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.PersistentPropertyInValuesPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.PersistentPropertyUnaryPredicate;
import io.micronaut.data.model.jpa.criteria.impl.predicate.PredicateBinaryOp;
import io.micronaut.data.model.jpa.criteria.impl.predicate.PredicateUnaryOp;
import io.micronaut.data.model.jpa.criteria.impl.selection.AggregateExpression;
import io.micronaut.data.model.jpa.criteria.impl.selection.AggregateType;
import io.micronaut.data.model.query.builder.QueryParameterBinding;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.CompoundSelection;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.ParameterExpression;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;
import jakarta.persistence.criteria.SetJoin;
import jakarta.persistence.criteria.Subquery;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.notSupportedOperation;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireBoolExpression;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireBoolExpressions;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireBoolProperty;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireComparableProperty;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireComparablePropertyParameterOrLiteral;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireNumericProperty;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireNumericPropertyParameterOrLiteral;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requireProperty;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requirePropertyOrRoot;
import static io.micronaut.data.model.jpa.criteria.impl.CriteriaUtils.requirePropertyParameterOrLiteral;

/**
 * Abstract {@link jakarta.persistence.criteria.CriteriaBuilder} implementation.
 *
 * @author Denis Stepanov
 * @since 3.2
 */
@Internal
public abstract class AbstractCriteriaBuilder implements PersistentEntityCriteriaBuilder {

    @NotNull
    private Predicate predicate(Expression x, Expression y, PredicateBinaryOp op) {
        if (x instanceof IdExpression) {
            return new ExpressionBinaryPredicate(x, y, op);
        }
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), op);
    }

    @NotNull
    private Predicate predicate(Expression x, Object y, PredicateBinaryOp op) {
        if (x instanceof IdExpression) {
            return new ExpressionBinaryPredicate(x, Objects.requireNonNull(literal(y)), op);
        }
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), Objects.requireNonNull(literal(y)), op);
    }

    @NotNull
    private Predicate comparable(Expression x, Expression y, PredicateBinaryOp op) {
        if (x instanceof IdExpression) {
            return new ExpressionBinaryPredicate(x, y, op);
        }
        return new PersistentPropertyBinaryPredicate<>(requireComparableProperty(x), requireComparablePropertyParameterOrLiteral(y), op);
    }

    @NotNull
    private Predicate comparable(Expression x, Object y, PredicateBinaryOp op) {
        if (x instanceof IdExpression) {
            return new ExpressionBinaryPredicate(x, Objects.requireNonNull(literal(y)), op);
        }
        return new PersistentPropertyBinaryPredicate<>(requireComparableProperty(x), Objects.requireNonNull(literal(y)), op);
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public PersistentEntityCriteriaQuery createTupleQuery() {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  CompoundSelection construct(@NonNull Class resultClass, @NonNull Selection... selections) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public CompoundSelection tuple(@NonNull Selection... selections) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public CompoundSelection array(@NonNull Selection... selections) {
        throw notSupportedOperation();
    }

    @Override
    @NonNull
    public Order asc(@NonNull Expression x) {
        return new PersistentPropertyOrder<>(requireProperty(x), true);
    }

    @Override
    @NonNull
    public Order desc(@NonNull Expression x) {
        return new PersistentPropertyOrder<>(requireProperty(x), false);
    }

    @Override
    @NonNull
    public  Expression avg(@NonNull Expression x) {
        return new AggregateExpression<>(requireNumericProperty(x), AggregateType.AVG);
    }

    @Override
    @NonNull
    public  Expression sum(@NonNull Expression x) {
        return new AggregateExpression<>(requireNumericProperty(x), AggregateType.SUM);
    }

    @Override
    @NonNull
    public Expression sumAsLong(@NonNull Expression x) {
        return new AggregateExpression<>(requireNumericProperty(x), AggregateType.SUM, Long.class);
    }

    @Override
    @NonNull
    public Expression sumAsDouble(@NonNull Expression x) {
        return new AggregateExpression<>(requireNumericProperty(x), AggregateType.SUM, Double.class);
    }

    @Override
    @NonNull
    public  Expression max(@NonNull Expression x) {
        return new AggregateExpression<>(requireNumericProperty(x), AggregateType.MAX);
    }

    @Override
    @NonNull
    public  Expression min(@NonNull Expression x) {
        return new AggregateExpression<>(requireNumericProperty(x), AggregateType.MIN);
    }

    @Override
    @NonNull
    public > Expression greatest(@NonNull Expression x) {
        return new AggregateExpression<>(requireComparableProperty(x), AggregateType.MAX);
    }

    @Override
    @NonNull
    public > Expression least(@NonNull Expression x) {
        return new AggregateExpression<>(requireComparableProperty(x), AggregateType.MIN);
    }

    @Override
    @NonNull
    public Expression count(@NonNull Expression x) {
        return new AggregateExpression<>(requirePropertyOrRoot(x), AggregateType.COUNT, Long.class);
    }

    @Override
    @NonNull
    public Expression countDistinct(@NonNull Expression x) {
        return new AggregateExpression<>(requirePropertyOrRoot(x), AggregateType.COUNT_DISTINCT, Long.class);
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate exists(@NonNull Subquery subquery) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression all(@NonNull Subquery subquery) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression some(@NonNull Subquery subquery) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression any(@NonNull Subquery subquery) {
        throw notSupportedOperation();
    }

    @Override
    @NonNull
    public Predicate and(@NonNull Expression x, @NonNull Expression y) {
        return new ConjunctionPredicate(Arrays.asList(requireBoolExpression(x), requireBoolExpression(y)));
    }

    @Override
    @NonNull
    public Predicate and(@NonNull Predicate... restrictions) {
        return and(Arrays.asList(restrictions));
    }

    @Override
    @NonNull
    public Predicate and(@NonNull Iterable restrictions) {
        return new ConjunctionPredicate(requireBoolExpressions(restrictions));
    }

    @Override
    @NonNull
    public Predicate isEmptyString(@NonNull Expression expression) {
        return new PersistentPropertyUnaryPredicate<>(requireProperty(expression), PredicateUnaryOp.IS_EMPTY);
    }

    @Override
    @NonNull
    public Predicate isNotEmptyString(@NonNull Expression expression) {
        return new PersistentPropertyUnaryPredicate<>(requireProperty(expression), PredicateUnaryOp.IS_NOT_EMPTY);
    }

    @Override
    @NonNull
    public Predicate rlikeString(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.RLIKE);
    }

    @Override
    @NonNull
    public Predicate ilikeString(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.ILIKE);
    }

    @Override
    public Predicate endingWithString(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.ENDS_WITH);
    }

    @Override
    @NonNull
    public Predicate startsWithString(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.STARTS_WITH);
    }

    @Override
    @NonNull
    public Predicate containsString(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.CONTAINS);
    }

    @Override
    public Predicate containsStringIgnoreCase(Expression x, Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.CONTAINS_IGNORE_CASE);
    }

    @Override
    @NonNull
    public Predicate equalStringIgnoreCase(@NonNull Expression x, @NonNull String y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), literal(y), PredicateBinaryOp.EQUALS_IGNORE_CASE);
    }

    @Override
    @NonNull
    public Predicate equalStringIgnoreCase(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.EQUALS_IGNORE_CASE);
    }

    @Override
    @NonNull
    public Predicate notEqualStringIgnoreCase(@NonNull Expression x, @NonNull String y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), literal(y), PredicateBinaryOp.NOT_EQUALS_IGNORE_CASE);
    }

    @Override
    @NonNull
    public Predicate notEqualStringIgnoreCase(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.NOT_EQUALS_IGNORE_CASE);
    }

    @Override
    @NonNull
    public Predicate startsWithStringIgnoreCase(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.STARTS_WITH_IGNORE_CASE);
    }

    @Override
    @NonNull
    public Predicate endingWithStringIgnoreCase(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(y), PredicateBinaryOp.ENDS_WITH_IGNORE_CASE);
    }

    @Override
    @NonNull
    public Predicate or(@NonNull Expression x, @NonNull Expression y) {
        return new DisjunctionPredicate(Arrays.asList(requireBoolExpression(x), requireBoolExpression(y)));
    }

    @Override
    @NonNull
    public Predicate or(@NonNull Predicate... restrictions) {
        return or(Arrays.asList(restrictions));
    }

    @Override
    @NonNull
    public Predicate or(@NonNull Iterable restrictions) {
        return new DisjunctionPredicate(requireBoolExpressions(restrictions));
    }

    @Override
    @NonNull
    public Predicate not(@NonNull Expression restriction) {
        return new NegatedPredicate(requireBoolExpression(restriction));
    }

    @Override
    @NonNull
    public Predicate conjunction() {
        return new ConjunctionPredicate(Collections.emptyList());
    }

    @Override
    @NonNull
    public Predicate disjunction() {
        return new DisjunctionPredicate(Collections.emptyList());
    }

    @Override
    @NonNull
    public Predicate isTrue(@NonNull Expression x) {
        return new PersistentPropertyUnaryPredicate<>(requireBoolProperty(x), PredicateUnaryOp.IS_TRUE);
    }

    @Override
    @NonNull
    public Predicate isFalse(@NonNull Expression x) {
        return new PersistentPropertyUnaryPredicate<>(requireProperty(x), PredicateUnaryOp.IS_FALSE);
    }

    @Override
    @NonNull
    public Predicate isNull(@NonNull Expression x) {
        return new PersistentPropertyUnaryPredicate<>(requireProperty(x), PredicateUnaryOp.IS_NULL);
    }

    @Override
    @NonNull
    public Predicate isNotNull(@NonNull Expression x) {
        return new PersistentPropertyUnaryPredicate<>(requireProperty(x), PredicateUnaryOp.IS_NON_NULL);
    }

    @Override
    @NonNull
    public Predicate equal(@NonNull Expression x, @NonNull Expression y) {
        return predicate(x, y, PredicateBinaryOp.EQUALS);
    }

    @Override
    @NonNull
    public Predicate equal(@NonNull Expression x, @Nullable Object y) {
        return predicate(x, y, PredicateBinaryOp.EQUALS);
    }

    @Override
    @NonNull
    public Predicate notEqual(@NonNull Expression x, @NonNull Expression y) {
        return predicate(x, y, PredicateBinaryOp.NOT_EQUALS);
    }

    @Override
    @NonNull
    public Predicate notEqual(@NonNull Expression x, @Nullable Object y) {
        return predicate(x, y, PredicateBinaryOp.NOT_EQUALS);
    }

    @Override
    @NonNull
    public > Predicate greaterThan(@NonNull Expression x, @NonNull Expression y) {
        return comparable(x, y, PredicateBinaryOp.GREATER_THAN);
    }

    @Override
    @NonNull
    public > Predicate greaterThan(@NonNull Expression x, @NonNull Y y) {
        return comparable(x, y, PredicateBinaryOp.GREATER_THAN);
    }

    @Override
    @NonNull
    public > Predicate greaterThanOrEqualTo(@NonNull Expression x, @NonNull Expression y) {
        return comparable(x, y, PredicateBinaryOp.GREATER_THAN_OR_EQUALS);
    }

    @Override
    @NonNull
    public > Predicate greaterThanOrEqualTo(@NonNull Expression x, @NonNull Y y) {
        return comparable(x, y, PredicateBinaryOp.GREATER_THAN_OR_EQUALS);
    }

    @Override
    @NonNull
    public > Predicate lessThan(@NonNull Expression x, @NonNull Expression y) {
        return comparable(x, y, PredicateBinaryOp.LESS_THAN);
    }

    @Override
    @NonNull
    public > Predicate lessThan(@NonNull Expression x, @NonNull Y y) {
        return comparable(x, y, PredicateBinaryOp.LESS_THAN);
    }

    @Override
    @NonNull
    public > Predicate lessThanOrEqualTo(@NonNull Expression x, @NonNull Expression y) {
        return comparable(x, y, PredicateBinaryOp.LESS_THAN_OR_EQUALS);
    }

    @Override
    @NonNull
    public > Predicate lessThanOrEqualTo(@NonNull Expression x, Y y) {
        return comparable(x, y, PredicateBinaryOp.LESS_THAN_OR_EQUALS);
    }

    @Override
    @NonNull
    public > Predicate between(@NonNull Expression v, @NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBetweenPredicate<>(requireComparableProperty(v), requireComparablePropertyParameterOrLiteral(x), requireComparablePropertyParameterOrLiteral(y));
    }

    @Override
    @NonNull
    public > Predicate between(@NonNull Expression v, @NonNull Y x, @NonNull Y y) {
        return new PersistentPropertyBetweenPredicate<>(requireComparableProperty(v), Objects.requireNonNull(x), Objects.requireNonNull(y));
    }

    @Override
    @NonNull
    public Predicate gt(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), requireNumericPropertyParameterOrLiteral(y), PredicateBinaryOp.GREATER_THAN);
    }

    @Override
    @NonNull
    public Predicate gt(@NonNull Expression x, @NonNull Number y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), Objects.requireNonNull(literal(y)), PredicateBinaryOp.GREATER_THAN);
    }

    @Override
    @NonNull
    public Predicate ge(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), requireNumericPropertyParameterOrLiteral(y), PredicateBinaryOp.GREATER_THAN_OR_EQUALS);
    }

    @Override
    @NonNull
    public Predicate ge(@NonNull Expression x, @NonNull Number y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), Objects.requireNonNull(literal(y)), PredicateBinaryOp.GREATER_THAN_OR_EQUALS);
    }

    @Override
    @NonNull
    public Predicate lt(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), requireNumericPropertyParameterOrLiteral(y), PredicateBinaryOp.LESS_THAN);
    }

    @Override
    @NonNull
    public Predicate lt(@NonNull Expression x, @NonNull Number y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), Objects.requireNonNull(literal(y)), PredicateBinaryOp.LESS_THAN);
    }

    @Override
    @NonNull
    public Predicate le(@NonNull Expression x, @NonNull Expression y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), requireNumericPropertyParameterOrLiteral(y), PredicateBinaryOp.LESS_THAN_OR_EQUALS);
    }

    @Override
    @NonNull
    public Predicate le(@NonNull Expression x, @NonNull Number y) {
        return new PersistentPropertyBinaryPredicate<>(requireNumericProperty(x), Objects.requireNonNull(literal(y)), PredicateBinaryOp.LESS_THAN_OR_EQUALS);
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression neg(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression abs(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression sum(@NonNull Expression x, Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression sum(@NonNull Expression x, @NonNull N y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression sum(@NonNull N x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression prod(@NonNull Expression x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression prod(@NonNull Expression x, @NonNull N y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression prod(@NonNull N x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression diff(@NonNull Expression x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression diff(@NonNull Expression x, @NonNull N y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public  Expression diff(@NonNull N x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression quot(@NonNull Expression x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression quot(@NonNull Expression x, @NonNull Number y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression quot(@NonNull Number x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression mod(@NonNull Expression x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    public Expression mod(@NonNull Expression x, @NonNull Integer y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression mod(@NonNull Integer x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression sqrt(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression toLong(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression toInteger(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression toFloat(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression toDouble(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression toBigDecimal(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression toBigInteger(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression toString(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    @Override
    @NonNull
    public  Expression literal(@Nullable T value) {
        return new LiteralExpression<>(value);
    }

    @Override
    @NonNull
    public  Expression nullLiteral(@NonNull Class x) {
        return new LiteralExpression<>(null);
    }

    @Override
    @NonNull
    public  ParameterExpression parameter(@NonNull Class paramClass) {
        return parameter(paramClass, null, null);
    }

    private String[] asStringPath(List associations, PersistentProperty property) {
        if (associations.isEmpty()) {
            return new String[]{property.getName()};
        }
        List path = new ArrayList<>(associations.size() + 1);
        for (Association association : associations) {
            path.add(association.getName());
        }
        path.add(property.getName());
        return path.toArray(new String[0]);
    }

    @Override
    public  ParameterExpression parameter(@NonNull Class paramClass, @NonNull String name) {
        return parameter(paramClass, name, null);
    }

    /**
     * Create a new parameter with possible constant value.
     *
     * @param paramClass The param calss
     * @param name       The param name
     * @param value      The param value
     * @param         The param type
     * @return the parameter expression
     */
    @NonNull
    public  ParameterExpression parameter(@NonNull Class paramClass, @Nullable String name, @Nullable Object value) {
        return new ParameterExpressionImpl(paramClass, name) {

            @Override
            public QueryParameterBinding bind(BindingContext bindingContext) {
                String name = bindingContext.getName() == null ? String.valueOf(bindingContext.getIndex()) : bindingContext.getName();
                PersistentPropertyPath outgoingQueryParameterProperty = bindingContext.getOutgoingQueryParameterProperty();
                return new QueryParameterBinding() {
                    @Override
                    public String getKey() {
                        return name;
                    }

                    @Override
                    public DataType getDataType() {
                        return outgoingQueryParameterProperty.getProperty().getDataType();
                    }

                    @Override
                    public JsonDataType getJsonDataType() {
                        return outgoingQueryParameterProperty.getProperty().getJsonDataType();
                    }

                    @Override
                    public String[] getPropertyPath() {
                        return asStringPath(outgoingQueryParameterProperty.getAssociations(), outgoingQueryParameterProperty.getProperty());
                    }

                    @Override
                    public boolean isExpandable() {
                        return bindingContext.isExpandable();
                    }

                    @Override
                    public Object getValue() {
                        return value;
                    }
                };
            }
        };
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Predicate isEmpty(@NonNull Expression collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Predicate isNotEmpty(@NonNull Expression collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Expression size(@NonNull Expression collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Expression size(@NonNull C collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Predicate isMember(@NonNull Expression elem, @NonNull Expression collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Predicate isMember(@NonNull E elem, @NonNull Expression collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Predicate isNotMember(@NonNull Expression elem, @NonNull Expression collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Predicate isNotMember(@NonNull E elem, @NonNull Expression collection) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Expression> values(@NonNull M map) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public > Expression> keys(@NonNull M map) {
        throw notSupportedOperation();
    }

    @Override
    @NonNull
    public Predicate like(@NonNull Expression x, @NonNull Expression pattern) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(pattern), PredicateBinaryOp.LIKE);
    }

    @Override
    @NonNull
    public Predicate regex(@NonNull Expression x, @NonNull Expression pattern) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), requirePropertyParameterOrLiteral(pattern), PredicateBinaryOp.REGEX);
    }

    @Override
    @NonNull
    public Predicate like(@NonNull Expression x, @NonNull String pattern) {
        return new PersistentPropertyBinaryPredicate<>(requireProperty(x), literal(pattern), PredicateBinaryOp.LIKE);
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate like(@NonNull Expression x, @NonNull Expression pattern, @NonNull Expression escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate like(@NonNull Expression x, @NonNull Expression pattern, char escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate like(@NonNull Expression x, @NonNull String pattern, @NonNull Expression escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate like(@NonNull Expression x, @NonNull String pattern, char escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate notLike(@NonNull Expression x, @NonNull Expression pattern) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate notLike(@NonNull Expression x, @NonNull String pattern) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate notLike(@NonNull Expression x, @NonNull Expression pattern, @NonNull Expression escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate notLike(@NonNull Expression x, @NonNull Expression pattern, char escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate notLike(@NonNull Expression x, @NonNull String pattern, @NonNull Expression escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Predicate notLike(@NonNull Expression x, @NonNull String pattern, char escapeChar) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression concat(@NonNull Expression x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression concat(@NonNull Expression x, @NonNull String y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression concat(@NonNull String x, @NonNull Expression y) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression substring(@NonNull Expression x, @NonNull Expression from) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression substring(@NonNull Expression x, int from) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression substring(@NonNull Expression x, @NonNull Expression from, @NonNull Expression len) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression substring(@NonNull Expression x, int from, int len) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression trim(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression trim(@NonNull Trimspec ts, @NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression trim(@NonNull Expression t, @NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression trim(@NonNull Trimspec ts, @NonNull Expression t, @NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression trim(char t, @NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression trim(@NonNull Trimspec ts, char t, @NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression lower(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression upper(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression length(@NonNull Expression x) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression locate(@NonNull Expression x, @NonNull Expression pattern) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression locate(@NonNull Expression x, @NonNull String pattern) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression locate(@NonNull Expression x, @NonNull Expression pattern, @NonNull Expression from) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression locate(@NonNull Expression x, @NonNull String pattern, int from) {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression currentDate() {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression currentTimestamp() {
        throw notSupportedOperation();
    }

    /**
     * Not supported yet.
     *
     * {@inheritDoc}
     */
    @Override
    @NonNull
    public Expression




© 2015 - 2025 Weber Informatics LLC | Privacy Policy