use of org.datanucleus.query.expression.PrimaryExpression 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);
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class MathFunction 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();
Object param = expr.getArguments().get(0);
Object paramValue = null;
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 InvokeExpression) {
InvokeExpression invokeExpr = (InvokeExpression) param;
paramValue = eval.getValueForInvokeExpression(invokeExpr);
} else if (param instanceof Literal) {
paramValue = ((Literal) param).getLiteral();
} else if (param instanceof DyadicExpression) {
DyadicExpression dyExpr = (DyadicExpression) param;
paramValue = dyExpr.evaluate(eval);
} else {
throw new NucleusException(method + "(num) where num is instanceof " + param.getClass().getName() + " not supported");
}
Object result = null;
if (paramValue instanceof Double) {
result = new Double(evaluateMathFunction(((Double) paramValue).doubleValue()));
} else if (paramValue instanceof Float) {
result = new Float(evaluateMathFunction(((Float) paramValue).floatValue()));
} else if (paramValue instanceof BigDecimal) {
result = new BigDecimal(evaluateMathFunction(((BigDecimal) paramValue).doubleValue()));
} else if (paramValue instanceof Integer) {
result = new Double(evaluateMathFunction(((Integer) paramValue).doubleValue()));
} else if (paramValue instanceof Long) {
result = new Double(evaluateMathFunction(((Long) paramValue).doubleValue()));
} else {
throw new NucleusException("Not possible to use " + getFunctionName() + " on value of type " + paramValue.getClass().getName());
}
return result;
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class ObjectGetClassMethod 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) {
Expression argExpr = expr.getArguments().get(0);
if (argExpr instanceof ParameterExpression) {
ParameterExpression paramExpr = (ParameterExpression) argExpr;
Object value = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
return value.getClass();
}
return eval.getValueForPrimaryExpression((PrimaryExpression) argExpr).getClass();
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class StringCharAtMethod 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 Integer.valueOf(-1);
}
if (!(invokedValue instanceof String)) {
throw new NucleusException(Localiser.msg("021011", method, invokedValue.getClass().getName()));
}
// Evaluate the argument
Object arg1Obj = null;
Object param = expr.getArguments().get(0);
if (param instanceof PrimaryExpression) {
PrimaryExpression primExpr = (PrimaryExpression) param;
arg1Obj = eval.getValueForPrimaryExpression(primExpr);
} else if (param instanceof ParameterExpression) {
ParameterExpression paramExpr = (ParameterExpression) param;
arg1Obj = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
} else if (param instanceof Literal) {
arg1Obj = ((Literal) param).getLiteral();
} else if (param instanceof InvokeExpression) {
arg1Obj = eval.getValueForInvokeExpression((InvokeExpression) param);
} else if (param instanceof DyadicExpression) {
arg1Obj = ((DyadicExpression) param).evaluate(eval);
} else {
throw new NucleusException(method + "(param1) where param is instanceof " + param.getClass().getName() + " not supported");
}
if (!(arg1Obj instanceof Number)) {
throw new NucleusException(method + "(param1]) : param1 must be numeric");
}
int arg1 = ((Number) arg1Obj).intValue();
return Integer.valueOf(((String) invokedValue).indexOf(arg1));
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class StringConcatMethod 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 String)) {
throw new NucleusException(Localiser.msg("021011", method, invokedValue.getClass().getName()));
}
Expression arg0Expr = expr.getArguments().get(0);
Object arg0Val = null;
if (arg0Expr instanceof PrimaryExpression) {
arg0Val = eval.getValueForPrimaryExpression((PrimaryExpression) arg0Expr);
} else if (arg0Expr instanceof ParameterExpression) {
arg0Val = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), (ParameterExpression) arg0Expr);
} else if (arg0Expr instanceof Literal) {
arg0Val = ((Literal) arg0Expr).getLiteral();
} else if (arg0Expr instanceof DyadicExpression) {
arg0Val = ((DyadicExpression) arg0Expr).evaluate(eval);
}
if (!(arg0Val instanceof String)) {
throw new NucleusException(method + "(param1) : param1 must be String");
}
return ((String) invokedValue).concat((String) arg0Val);
}
Aggregations