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");
}
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;
}
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;
}
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;
}
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;
}
Aggregations