Search in sources :

Example 1 with ArgumentListFunctionExpression

use of org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression in project eclipselink by eclipse-ee4j.

the class CriteriaBuilderImpl method coalesce.

// coalesce, nullif:
/**
 * Create an expression that returns null if all its arguments evaluate to
 * null, and the value of the first non-null argument otherwise.
 *
 * @param x
 *            expression
 * @param y
 *            expression
 * @return expression corresponding to the given coalesce expression
 */
@Override
public <Y> Expression<Y> coalesce(Expression<? extends Y> x, Expression<? extends Y> y) {
    ArgumentListFunctionExpression coalesce = ((InternalSelection) x).getCurrentNode().coalesce();
    org.eclipse.persistence.expressions.Expression expX = ((InternalSelection) x).getCurrentNode();
    expX = org.eclipse.persistence.expressions.Expression.from(expX, coalesce);
    coalesce.addChild(expX);
    org.eclipse.persistence.expressions.Expression expY = ((InternalSelection) y).getCurrentNode();
    expY = org.eclipse.persistence.expressions.Expression.from(expY, coalesce);
    coalesce.addChild(expY);
    return new CoalesceImpl(metamodel, x.getJavaType(), coalesce, buildList(x, y), "coalesce");
}
Also used : ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression)

Example 2 with ArgumentListFunctionExpression

use of org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression in project eclipselink by eclipse-ee4j.

the class Expression method caseStatement.

/**
 * INTERNAL:
 * Creates an ArgumentListFunctionExpression that is capable of creating a case statement of the form:
 * <blockquote><pre>
 * SQL: CASE name WHEN "Robert" THEN "Bob"
 *     WHEN "Susan" THEN "Sue"
 *  ELSE "No-Nickname"
 * </pre></blockquote>
 *
 * This expression must be manipulated to successfully build a case statement by adding appropriate
 * children to it.
 *
 * A child must be added for the "case expression" (name above), a pair of children must be added for
 * each "when then" expression and a child must be added for the else.
 *
 * @see ArgumentListFunctionExpression
 */
public ArgumentListFunctionExpression caseStatement() {
    ListExpressionOperator caseOperator = (ListExpressionOperator) getOperator(ExpressionOperator.Case);
    ListExpressionOperator clonedCaseOperator = new ListExpressionOperator();
    caseOperator.copyTo(clonedCaseOperator);
    ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
    expression.setBaseExpression(this);
    expression.setOperator(clonedCaseOperator);
    return expression;
}
Also used : ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression)

Example 3 with ArgumentListFunctionExpression

use of org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression in project eclipselink by eclipse-ee4j.

the class Expression method caseConditionStatement.

/**
 * INTERNAL:
 * Creates an ArgumentListFunctionExpression that is capable of creating a case statement of the form:
 * <blockquote><pre>
 * SQL: CASE WHEN name = "Robert" THEN "Bob"
 *     WHEN name = "Susan" THEN "Sue"
 *  ELSE "No-Nickname"
 * </pre></blockquote>
 *
 * This expression must be manipulated to successfully build a case statement by adding appropriate
 * children to it.
 *
 * A pair of children must be added for  each "when then" expression and a child must be added for the else.
 *
 * @see ArgumentListFunctionExpression
 */
public ArgumentListFunctionExpression caseConditionStatement() {
    ListExpressionOperator caseOperator = (ListExpressionOperator) getOperator(ExpressionOperator.CaseCondition);
    ListExpressionOperator clonedCaseOperator = new ListExpressionOperator();
    caseOperator.copyTo(clonedCaseOperator);
    ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
    expression.setBaseExpression(this);
    expression.setOperator(clonedCaseOperator);
    return expression;
}
Also used : ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression)

Example 4 with ArgumentListFunctionExpression

use of org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression in project eclipselink by eclipse-ee4j.

the class Expression method coalesce.

public ArgumentListFunctionExpression coalesce() {
    ListExpressionOperator coalesceOperator = (ListExpressionOperator) getOperator(ExpressionOperator.Coalesce);
    ListExpressionOperator clonedCoalesceOperator = new ListExpressionOperator();
    coalesceOperator.copyTo(clonedCoalesceOperator);
    ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
    expression.setBaseExpression(this);
    expression.setOperator(clonedCoalesceOperator);
    return expression;
}
Also used : ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression)

Example 5 with ArgumentListFunctionExpression

use of org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression in project eclipselink by eclipse-ee4j.

the class Expression method coalesce.

/**
 * PUBLIC:
 * Function Return null if all arguments are null and the first non-null argument otherwise
 * The equivalent of the COALESCE SQL function
 * <p>Example:
 * <blockquote><pre>
 * List list = new ArrayList(3);
 * list.add(builder.get("firstName"));
 * list.add(builder.get("lastName"));
 * list.add(builder.get("nickname"));
 *
 * EclipseLink: expressionBuilder.coalesce(caseTable)
 * Java: NA
 * SQL: COALESCE(firstname, lastname, nickname)
 * </pre></blockquote>
 * @param expressions java.util.Collection
 * A Collection containing the items to check if null
 */
public ArgumentListFunctionExpression coalesce(Collection expressions) {
    ArgumentListFunctionExpression expression = coalesce();
    Iterator iterator = expressions.iterator();
    if (iterator.hasNext()) {
        Expression base = Expression.from(iterator.next(), this);
        expression.addChild(base);
        // base needs to be the same as the first child for reportQuery items.
        expression.setBaseExpression(base);
        while (iterator.hasNext()) {
            expression.addChild(Expression.from(iterator.next(), this));
        }
    }
    return expression;
}
Also used : ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression) MapEntryExpression(org.eclipse.persistence.internal.expressions.MapEntryExpression) ArgumentListFunctionExpression(org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) BaseExpression(org.eclipse.persistence.internal.expressions.BaseExpression) LiteralExpression(org.eclipse.persistence.internal.expressions.LiteralExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression) CollectionExpression(org.eclipse.persistence.internal.expressions.CollectionExpression) Iterator(java.util.Iterator) ExpressionIterator(org.eclipse.persistence.internal.expressions.ExpressionIterator)

Aggregations

ArgumentListFunctionExpression (org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression)6 Iterator (java.util.Iterator)1 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)1 BaseExpression (org.eclipse.persistence.internal.expressions.BaseExpression)1 CollectionExpression (org.eclipse.persistence.internal.expressions.CollectionExpression)1 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)1 ExpressionIterator (org.eclipse.persistence.internal.expressions.ExpressionIterator)1 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)1 LiteralExpression (org.eclipse.persistence.internal.expressions.LiteralExpression)1 MapEntryExpression (org.eclipse.persistence.internal.expressions.MapEntryExpression)1 ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)1 SubSelectExpression (org.eclipse.persistence.internal.expressions.SubSelectExpression)1