use of org.eclipse.persistence.jpa.jpql.parser.CaseExpression in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method visit.
@Override
public void visit(CaseExpressionStateObject stateObject) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
CaseExpression expression = stateObject.getExpression();
// 'CASE'
appendIdentifier((expression != null) ? expression.getActualCaseIdentifier() : CASE, CASE);
if (shouldOutput(expression) || expression.hasSpaceAfterCase()) {
writer.append(SPACE);
}
// Case operand
if (stateObject.hasCaseOperand()) {
stateObject.getCaseOperand().accept(this);
if (shouldOutput(expression) || expression.hasSpaceAfterCaseOperand()) {
writer.append(SPACE);
}
}
// WHEN clauses
if (stateObject.hasItems()) {
toStringChildren(stateObject, false);
}
if (shouldOutput(expression) || expression.hasSpaceAfterWhenClauses()) {
writer.append(SPACE);
}
// 'ELSE'
if (shouldOutput(expression) || expression.hasElse()) {
appendIdentifier((expression != null) ? expression.getActualElseIdentifier() : ELSE, ELSE);
}
if (shouldOutput(expression) || expression.hasSpaceAfterElse()) {
writer.append(SPACE);
}
// Else expression
if (stateObject.hasElse()) {
stateObject.getElse().accept(this);
}
if (shouldOutput(expression) || expression.hasSpaceAfterElseExpression()) {
writer.append(SPACE);
}
// END
if (shouldOutput(expression) || expression.hasEnd()) {
appendIdentifier((expression != null) ? expression.getActualEndIdentifier() : END, END);
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.CaseExpression in project eclipselink by eclipse-ee4j.
the class ReportItemBuilder method visit.
@Override
public void visit(CaseExpression expression) {
Expression queryExpression = queryContext.buildExpression(expression, type);
addAttribute("Case", queryExpression, type[0]);
}
use of org.eclipse.persistence.jpa.jpql.parser.CaseExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(CaseExpression expression) {
Expression caseBaseExpression = queryExpression;
Expression caseOperandExpression = null;
// Create the case operand expression
if (expression.hasCaseOperand()) {
expression.getCaseOperand().accept(this);
caseOperandExpression = queryExpression;
}
WhenClauseExpressionVisitor visitor = whenClauseExpressionVisitor();
try {
// Create the WHEN clauses
expression.getWhenClauses().accept(visitor);
// Create the ELSE clause
expression.getElseExpression().accept(this);
Expression elseExpression = queryExpression;
visitor.types.add(type[0]);
// Create the CASE expression
if (caseOperandExpression != null) {
queryExpression = caseOperandExpression.caseStatement(visitor.whenClauses, elseExpression);
// After we build the caseStatement, we need to retroactively fix the THEN/ELSE children's base
if (queryExpression.isFunctionExpression()) {
Vector<Expression> children = ((org.eclipse.persistence.internal.expressions.FunctionExpression) queryExpression).getChildren();
int index = 1;
while (index < children.size()) {
Expression when_else = children.get(index);
if (index + 1 < children.size()) {
// Not at end, must be a THEN
children.get(index + 1).setLocalBase(caseBaseExpression);
} else {
// At end, must be an ELSE
when_else.setLocalBase(caseBaseExpression);
}
index = index + 2;
}
}
} else {
queryExpression = queryContext.getBaseExpression();
queryExpression = queryExpression.caseStatement(visitor.whenClauses, elseExpression);
}
// Set the expression type
type[0] = queryContext.typeResolver().compareCollectionEquivalentTypes(visitor.types);
} finally {
visitor.dispose();
}
}
Aggregations