use of org.datanucleus.query.expression.CaseExpression.ExpressionPair in project datanucleus-core by datanucleus.
the class InMemoryExpressionEvaluator method processCaseExpression.
/* (non-Javadoc)
* @see org.datanucleus.query.evaluator.AbstractExpressionEvaluator#processCaseExpression(org.datanucleus.query.expression.CaseExpression)
*/
@Override
protected Object processCaseExpression(CaseExpression expr) {
List<ExpressionPair> exprs = expr.getConditions();
Iterator<ExpressionPair> exprCondIter = exprs.iterator();
while (exprCondIter.hasNext()) {
ExpressionPair pair = exprCondIter.next();
Expression whenExpr = pair.getWhenExpression();
Expression actionExpr = pair.getActionExpression();
Object keyResult = whenExpr.evaluate(this);
if (keyResult instanceof Boolean) {
if ((Boolean) keyResult) {
// This case clause resolves to true, so return its result
Object value = actionExpr.evaluate(this);
stack.push(value);
return value;
}
} else {
NucleusLogger.QUERY.error("Case expression " + expr + " clause " + whenExpr + " did not return boolean");
Object value = new InMemoryFailure();
stack.push(value);
return value;
}
}
// No case clause resolves to true, so return the else result
Object value = expr.getElseExpression().evaluate(this);
stack.push(value);
return value;
}
Aggregations