Search in sources :

Example 1 with ExpressionPair

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;
}
Also used : CaseExpression(org.datanucleus.query.expression.CaseExpression) ArrayExpression(org.datanucleus.query.expression.ArrayExpression) CreatorExpression(org.datanucleus.query.expression.CreatorExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) Expression(org.datanucleus.query.expression.Expression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) ExpressionPair(org.datanucleus.query.expression.CaseExpression.ExpressionPair)

Aggregations

ArrayExpression (org.datanucleus.query.expression.ArrayExpression)1 CaseExpression (org.datanucleus.query.expression.CaseExpression)1 ExpressionPair (org.datanucleus.query.expression.CaseExpression.ExpressionPair)1 CreatorExpression (org.datanucleus.query.expression.CreatorExpression)1 DyadicExpression (org.datanucleus.query.expression.DyadicExpression)1 Expression (org.datanucleus.query.expression.Expression)1 InvokeExpression (org.datanucleus.query.expression.InvokeExpression)1 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)1 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)1 VariableExpression (org.datanucleus.query.expression.VariableExpression)1