use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class LowerFunction 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 Literal) {
paramValue = ((Literal) param).getLiteral();
} else {
throw new NucleusException(method + "(param) where param is instanceof " + param.getClass().getName() + " not supported");
}
if (paramValue == null) {
return null;
}
if (!(paramValue instanceof String)) {
throw new NucleusException(Localiser.msg("021011", method, paramValue.getClass().getName()));
}
return ((String) paramValue).toLowerCase();
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class CoalesceFunction method getValueForArgExpression.
protected Object getValueForArgExpression(Expression argExpr, InMemoryExpressionEvaluator eval) {
Object argValue = null;
if (argExpr instanceof PrimaryExpression) {
PrimaryExpression primExpr = (PrimaryExpression) argExpr;
argValue = eval.getValueForPrimaryExpression(primExpr);
} else if (argExpr instanceof ParameterExpression) {
ParameterExpression paramExpr = (ParameterExpression) argExpr;
argValue = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), paramExpr);
} else if (argExpr instanceof Literal) {
argValue = ((Literal) argExpr).getLiteral();
} else {
throw new NucleusException("Don't support COALESCE with argument of type " + argExpr.getClass().getName());
}
return argValue;
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class ConcatFunction 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 Literal) {
paramValue = ((Literal) param).getLiteral();
} else {
throw new NucleusException(method + "(param) where param is instanceof " + param.getClass().getName() + " not supported");
}
Object param2 = expr.getArguments().get(1);
Object param2Value = null;
if (param2 instanceof PrimaryExpression) {
PrimaryExpression primExpr = (PrimaryExpression) param;
param2Value = eval.getValueForPrimaryExpression(primExpr);
} else if (param2 instanceof ParameterExpression) {
ParameterExpression param2Expr = (ParameterExpression) param2;
param2Value = QueryUtils.getValueForParameterExpression(eval.getParameterValues(), param2Expr);
} else if (param2 instanceof Literal) {
param2Value = ((Literal) param).getLiteral();
} else {
throw new NucleusException(method + "(param, param2) where param2 is instanceof " + param2.getClass().getName() + " not supported");
}
if (paramValue == null) {
return null;
}
return ((String) paramValue).concat((String) param2Value);
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class LengthFunction 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 Literal) {
paramValue = ((Literal) param).getLiteral();
} else {
throw new NucleusException(method + "(param) where param is instanceof " + param.getClass().getName() + " not supported");
}
if (paramValue == null) {
return Integer.valueOf(0);
}
if (!(paramValue instanceof String)) {
throw new NucleusException(Localiser.msg("021011", method, paramValue.getClass().getName()));
}
return Integer.valueOf(((String) paramValue).length());
}
use of org.datanucleus.query.expression.PrimaryExpression in project datanucleus-core by datanucleus.
the class UpperFunction 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 Literal) {
paramValue = ((Literal) param).getLiteral();
} else {
throw new NucleusException(method + "(param) where param is instanceof " + param.getClass().getName() + " not supported");
}
if (paramValue == null) {
return null;
}
if (!(paramValue instanceof String)) {
throw new NucleusException(Localiser.msg("021011", method, paramValue.getClass().getName()));
}
return ((String) paramValue).toUpperCase();
}
Aggregations