use of org.datanucleus.query.expression.ParameterExpression 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.ParameterExpression 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.ParameterExpression 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.ParameterExpression 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();
}
use of org.datanucleus.query.expression.ParameterExpression in project datanucleus-core by datanucleus.
the class JDOQLCompiler method containsOnlyGroupingOrAggregates.
/**
* Convenience method to check the provided expression for whether it contains only grouping expressions
* or aggregates
* @param expr The expression to check
* @param exprGrouping The grouping expressions
* @return Whether it contains only grouping or aggregates
*/
private static boolean containsOnlyGroupingOrAggregates(Expression expr, Expression[] exprGrouping) {
if (expr == null) {
return true;
} else if (expr instanceof DyadicExpression) {
Expression left = expr.getLeft();
Expression right = expr.getRight();
if (!containsOnlyGroupingOrAggregates(left, exprGrouping)) {
return false;
}
if (!containsOnlyGroupingOrAggregates(right, exprGrouping)) {
return false;
}
return true;
} else if (expr instanceof InvokeExpression) {
InvokeExpression invExpr = (InvokeExpression) expr;
if (isExpressionGroupingOrAggregate(invExpr, exprGrouping)) {
return true;
}
Expression invokedExpr = invExpr.getLeft();
if (invokedExpr != null && !containsOnlyGroupingOrAggregates(invokedExpr, exprGrouping)) {
// Check invoked object
return false;
}
List<Expression> invArgs = invExpr.getArguments();
if (invArgs != null) {
// Check invocation arguments
Iterator<Expression> iter = invArgs.iterator();
while (iter.hasNext()) {
Expression argExpr = iter.next();
if (!containsOnlyGroupingOrAggregates(argExpr, exprGrouping)) {
return false;
}
}
}
return true;
} else if (expr instanceof PrimaryExpression) {
return isExpressionGroupingOrAggregate(expr, exprGrouping);
} else if (expr instanceof Literal) {
return true;
} else if (expr instanceof ParameterExpression) {
return true;
} else if (expr instanceof VariableExpression) {
return true;
}
return false;
}
Aggregations