Search in sources :

Example 1 with VariableNotSetException

use of org.datanucleus.query.inmemory.VariableNotSetException in project datanucleus-core by datanucleus.

the class MapContainsEntryMethod method evaluate.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.memory.InvocationEvaluator#evaluate(org.datanucleus.query.expression.InvokeExpression, org.datanucleus.query.evaluator.memory.InMemoryExpressionEvaluator)
     */
public Object evaluate(InvokeExpression expr, Object invokedValue, InMemoryExpressionEvaluator eval) {
    String method = expr.getOperation();
    if (invokedValue == null) {
        return Boolean.FALSE;
    }
    if (!(invokedValue instanceof Map)) {
        throw new NucleusException(Localiser.msg("021011", method, invokedValue.getClass().getName()));
    }
    Object keyParam = expr.getArguments().get(0);
    Object valParam = expr.getArguments().get(1);
    Object keyValue = null;
    if (keyParam instanceof Literal) {
        keyValue = ((Literal) keyParam).getLiteral();
    } else if (keyParam instanceof PrimaryExpression) {
        PrimaryExpression primExpr = (PrimaryExpression) keyParam;
        keyValue = eval.getValueForPrimaryExpression(primExpr);
    } else if (keyParam instanceof ParameterExpression) {
        ParameterExpression paramExpr = (ParameterExpression) keyParam;
        keyValue = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
    } else if (keyParam instanceof VariableExpression) {
        VariableExpression varExpr = (VariableExpression) keyParam;
        try {
            keyValue = eval.getValueForVariableExpression(varExpr);
        } catch (VariableNotSetException vnse) {
            // Throw an exception with the possible values of values
            throw new VariableNotSetException(varExpr, ((Map) invokedValue).values().toArray());
        }
    } else {
        throw new NucleusException("Dont currently support use of containsEntry(" + keyParam.getClass().getName() + ",?)");
    }
    Object valValue = null;
    if (valParam instanceof Literal) {
        valValue = ((Literal) valParam).getLiteral();
    } else if (keyParam instanceof PrimaryExpression) {
        PrimaryExpression primExpr = (PrimaryExpression) valParam;
        valValue = eval.getValueForPrimaryExpression(primExpr);
    } else if (keyParam instanceof ParameterExpression) {
        ParameterExpression paramExpr = (ParameterExpression) valParam;
        valValue = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
    } else if (keyParam instanceof VariableExpression) {
        VariableExpression varExpr = (VariableExpression) valParam;
        try {
            valValue = eval.getValueForVariableExpression(varExpr);
        } catch (VariableNotSetException vnse) {
            // Throw an exception with the possible values of values
            throw new VariableNotSetException(varExpr, ((Map) invokedValue).values().toArray());
        }
    } else {
        throw new NucleusException("Dont currently support use of containsEntry(?," + valParam.getClass().getName() + ")");
    }
    Map invokedMap = (Map) invokedValue;
    if (invokedMap.containsKey(keyValue)) {
        Object currentValForKey = invokedMap.get(keyValue);
        if (currentValForKey.equals(valValue)) {
            return Boolean.TRUE;
        }
    }
    return Boolean.FALSE;
}
Also used : PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) VariableNotSetException(org.datanucleus.query.inmemory.VariableNotSetException) Literal(org.datanucleus.query.expression.Literal) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) NucleusException(org.datanucleus.exceptions.NucleusException) Map(java.util.Map)

Example 2 with VariableNotSetException

use of org.datanucleus.query.inmemory.VariableNotSetException in project datanucleus-core by datanucleus.

the class MapGetMethod method evaluate.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.memory.InvocationEvaluator#evaluate(org.datanucleus.query.expression.InvokeExpression, org.datanucleus.query.evaluator.memory.InMemoryExpressionEvaluator)
     */
public Object evaluate(InvokeExpression expr, Object invokedValue, InMemoryExpressionEvaluator eval) {
    String method = expr.getOperation();
    if (invokedValue == null) {
        return null;
    }
    if (!(invokedValue instanceof Map)) {
        throw new NucleusException(Localiser.msg("021011", method, invokedValue.getClass().getName()));
    }
    Object param = expr.getArguments().get(0);
    Object paramValue = null;
    if (param instanceof Literal) {
        paramValue = ((Literal) param).getLiteral();
    } else if (param instanceof PrimaryExpression) {
        PrimaryExpression primExpr = (PrimaryExpression) param;
        paramValue = eval.getValueForPrimaryExpression(primExpr);
    } else if (param instanceof ParameterExpression) {
        ParameterExpression paramExpr = (ParameterExpression) param;
        paramValue = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
    } else if (param instanceof VariableExpression) {
        VariableExpression varExpr = (VariableExpression) param;
        try {
            paramValue = eval.getValueForVariableExpression(varExpr);
        } catch (VariableNotSetException vnse) {
            // Throw an exception with the possible values of values
            throw new VariableNotSetException(varExpr, ((Map) invokedValue).values().toArray());
        }
    } else {
        throw new NucleusException("Dont currently support use of get(" + param.getClass().getName() + ")");
    }
    return ((Map) invokedValue).get(paramValue);
}
Also used : PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) VariableNotSetException(org.datanucleus.query.inmemory.VariableNotSetException) Literal(org.datanucleus.query.expression.Literal) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) NucleusException(org.datanucleus.exceptions.NucleusException) Map(java.util.Map)

Example 3 with VariableNotSetException

use of org.datanucleus.query.inmemory.VariableNotSetException in project datanucleus-core by datanucleus.

the class MapContainsKeyMethod method evaluate.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.memory.InvocationEvaluator#evaluate(org.datanucleus.query.expression.InvokeExpression, org.datanucleus.query.evaluator.memory.InMemoryExpressionEvaluator)
     */
public Object evaluate(InvokeExpression expr, Object invokedValue, InMemoryExpressionEvaluator eval) {
    String method = expr.getOperation();
    if (invokedValue == null) {
        return Boolean.FALSE;
    }
    if (!(invokedValue instanceof Map)) {
        throw new NucleusException(Localiser.msg("021011", method, invokedValue.getClass().getName()));
    }
    Object param = expr.getArguments().get(0);
    Object paramValue = null;
    if (param instanceof Literal) {
        paramValue = ((Literal) param).getLiteral();
    } else if (param instanceof PrimaryExpression) {
        PrimaryExpression primExpr = (PrimaryExpression) param;
        paramValue = eval.getValueForPrimaryExpression(primExpr);
    } else if (param instanceof ParameterExpression) {
        ParameterExpression paramExpr = (ParameterExpression) param;
        paramValue = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
    } else if (param instanceof VariableExpression) {
        VariableExpression varExpr = (VariableExpression) param;
        try {
            paramValue = eval.getValueForVariableExpression(varExpr);
        } catch (VariableNotSetException vnse) {
            // Throw an exception with the possible values of keys
            throw new VariableNotSetException(varExpr, ((Map) invokedValue).keySet().toArray());
        }
    } else {
        throw new NucleusException("Dont currently support use of containsKey(" + param.getClass().getName() + ")");
    }
    return ((Map) invokedValue).containsKey(paramValue) ? Boolean.TRUE : Boolean.FALSE;
}
Also used : PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) VariableNotSetException(org.datanucleus.query.inmemory.VariableNotSetException) Literal(org.datanucleus.query.expression.Literal) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) NucleusException(org.datanucleus.exceptions.NucleusException) Map(java.util.Map)

Example 4 with VariableNotSetException

use of org.datanucleus.query.inmemory.VariableNotSetException in project datanucleus-core by datanucleus.

the class MapContainsValueMethod method evaluate.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.memory.InvocationEvaluator#evaluate(org.datanucleus.query.expression.InvokeExpression, org.datanucleus.query.evaluator.memory.InMemoryExpressionEvaluator)
     */
public Object evaluate(InvokeExpression expr, Object invokedValue, InMemoryExpressionEvaluator eval) {
    String method = expr.getOperation();
    if (invokedValue == null) {
        return Boolean.FALSE;
    }
    if (!(invokedValue instanceof Map)) {
        throw new NucleusException(Localiser.msg("021011", method, invokedValue.getClass().getName()));
    }
    Object param = expr.getArguments().get(0);
    Object paramValue = null;
    if (param instanceof Literal) {
        paramValue = ((Literal) param).getLiteral();
    } else if (param instanceof PrimaryExpression) {
        PrimaryExpression primExpr = (PrimaryExpression) param;
        paramValue = eval.getValueForPrimaryExpression(primExpr);
    } else if (param instanceof ParameterExpression) {
        ParameterExpression paramExpr = (ParameterExpression) param;
        paramValue = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
    } else if (param instanceof VariableExpression) {
        VariableExpression varExpr = (VariableExpression) param;
        try {
            paramValue = eval.getValueForVariableExpression(varExpr);
        } catch (VariableNotSetException vnse) {
            // Throw an exception with the possible values of values
            throw new VariableNotSetException(varExpr, ((Map) invokedValue).values().toArray());
        }
    } else {
        throw new NucleusException("Dont currently support use of containsValue(" + param.getClass().getName() + ")");
    }
    return ((Map) invokedValue).containsValue(paramValue) ? Boolean.TRUE : Boolean.FALSE;
}
Also used : PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) VariableNotSetException(org.datanucleus.query.inmemory.VariableNotSetException) Literal(org.datanucleus.query.expression.Literal) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) NucleusException(org.datanucleus.exceptions.NucleusException) Map(java.util.Map)

Example 5 with VariableNotSetException

use of org.datanucleus.query.inmemory.VariableNotSetException in project datanucleus-core by datanucleus.

the class CollectionContainsMethod method evaluate.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.memory.InvocationEvaluator#evaluate(org.datanucleus.query.expression.InvokeExpression, org.datanucleus.query.evaluator.memory.InMemoryExpressionEvaluator)
     */
public Object evaluate(InvokeExpression expr, Object invokedValue, InMemoryExpressionEvaluator eval) {
    String method = expr.getOperation();
    if (invokedValue == null) {
        return Boolean.FALSE;
    }
    if (!(invokedValue instanceof Collection)) {
        throw new NucleusException(Localiser.msg("021011", method, invokedValue.getClass().getName()));
    }
    Object param = expr.getArguments().get(0);
    Object paramValue = null;
    if (param instanceof Literal) {
        paramValue = ((Literal) param).getLiteral();
    } else if (param instanceof PrimaryExpression) {
        PrimaryExpression primExpr = (PrimaryExpression) param;
        paramValue = eval.getValueForPrimaryExpression(primExpr);
    } else if (param instanceof ParameterExpression) {
        ParameterExpression paramExpr = (ParameterExpression) param;
        paramValue = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
    } else if (param instanceof VariableExpression) {
        VariableExpression varExpr = (VariableExpression) param;
        try {
            paramValue = eval.getValueForVariableExpression(varExpr);
        } catch (VariableNotSetException vnse) {
            // Throw an exception with the possible values
            throw new VariableNotSetException(varExpr, ((Collection) invokedValue).toArray());
        }
    } else {
        // TODO Implement this
        throw new NucleusException("Dont currently support use of contains(" + param.getClass().getName() + ")");
    }
    return ((Collection) invokedValue).contains(paramValue) ? Boolean.TRUE : Boolean.FALSE;
}
Also used : PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) VariableNotSetException(org.datanucleus.query.inmemory.VariableNotSetException) Literal(org.datanucleus.query.expression.Literal) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) Collection(java.util.Collection) VariableExpression(org.datanucleus.query.expression.VariableExpression) NucleusException(org.datanucleus.exceptions.NucleusException)

Aggregations

NucleusException (org.datanucleus.exceptions.NucleusException)7 Literal (org.datanucleus.query.expression.Literal)7 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)7 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)7 VariableExpression (org.datanucleus.query.expression.VariableExpression)7 VariableNotSetException (org.datanucleus.query.inmemory.VariableNotSetException)7 Map (java.util.Map)4 Collection (java.util.Collection)1 List (java.util.List)1