Search in sources :

Example 16 with Expression

use of jakarta.persistence.criteria.Expression in project eclipselink by eclipse-ee4j.

the class CriteriaBuilderImpl method not.

/**
 * Create a negation of the given restriction.
 *
 * @param restriction
 *            restriction expression
 * @return not predicate
 */
@Override
public Predicate not(Expression<Boolean> restriction) {
    if (((InternalExpression) restriction).isPredicate()) {
        return ((Predicate) restriction).not();
    }
    org.eclipse.persistence.expressions.Expression parentNode = null;
    List<Expression<?>> compoundExpressions = null;
    String name = "not";
    if (((InternalExpression) restriction).isCompoundExpression() && ((CompoundExpressionImpl) restriction).getOperation().equals("exists")) {
        FunctionExpression exp = (FunctionExpression) ((InternalSelection) restriction).getCurrentNode();
        SubSelectExpression sub = (SubSelectExpression) exp.getChildren().get(0);
        parentNode = ExpressionOperator.getOperator(ExpressionOperator.NotExists).expressionFor(sub);
        name = "notExists";
        compoundExpressions = ((CompoundExpressionImpl) restriction).getChildExpressions();
    } else {
        parentNode = ((InternalSelection) restriction).getCurrentNode().not();
        compoundExpressions = buildList(restriction);
    }
    CompoundExpressionImpl expr = new CompoundExpressionImpl(this.metamodel, parentNode, compoundExpressions, name);
    expr.setIsNegated(true);
    return expr;
}
Also used : ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) ParameterExpression(jakarta.persistence.criteria.ParameterExpression) Expression(jakarta.persistence.criteria.Expression) ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) Predicate(jakarta.persistence.criteria.Predicate)

Example 17 with Expression

use of jakarta.persistence.criteria.Expression in project eclipselink by eclipse-ee4j.

the class SubQueryImpl method in.

/**
 * Apply a predicate to test whether the expression is a member
 * of the argument list.
 * @return predicate testing for membership
 */
@Override
public Predicate in(Expression<?>... values) {
    List<Expression<?>> list = new ArrayList<>();
    list.add(this);
    for (Expression exp : values) {
        if (!((InternalExpression) exp).isLiteral() && !((InternalExpression) exp).isParameter()) {
            Object[] params = new Object[] { exp };
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage("CRITERIA_NON_LITERAL_PASSED_TO_IN", params));
        }
    }
    return new CompoundExpressionImpl(this.metamodel, this.currentNode.in(values), list, "in");
}
Also used : ParameterExpression(jakarta.persistence.criteria.ParameterExpression) Expression(jakarta.persistence.criteria.Expression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) ArrayList(java.util.ArrayList)

Aggregations

Expression (jakarta.persistence.criteria.Expression)17 EntityManager (jakarta.persistence.EntityManager)9 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)9 Predicate (jakarta.persistence.criteria.Predicate)9 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)6 ParameterExpression (jakarta.persistence.criteria.ParameterExpression)5 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)4 SubSelectExpression (org.eclipse.persistence.internal.expressions.SubSelectExpression)4 Employee (org.eclipse.persistence.testing.models.jpa21.advanced.Employee)4 Employee (org.eclipse.persistence.testing.models.jpa22.advanced.Employee)4 ArrayList (java.util.ArrayList)3 Root (jakarta.persistence.criteria.Root)1 Collection (java.util.Collection)1 ArgumentListFunctionExpression (org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression)1 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)1 MetamodelImpl (org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl)1 TypeImpl (org.eclipse.persistence.internal.jpa.metamodel.TypeImpl)1 CompoundExpressionImpl (org.eclipse.persistence.internal.jpa.querydef.CompoundExpressionImpl)1 JpaCriteriaBuilder (org.eclipse.persistence.jpa.JpaCriteriaBuilder)1 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)1