use of org.datanucleus.query.expression.Expression in project datanucleus-core by datanucleus.
the class InMemoryExpressionEvaluator method processNotInExpression.
/* (non-Javadoc)
* @see org.datanucleus.query.evaluator.AbstractExpressionEvaluator#processNotInExpression(org.datanucleus.query.expression.Expression)
*/
@Override
protected Object processNotInExpression(Expression expr) {
if (expr instanceof DyadicExpression) {
DyadicExpression dyExpr = (DyadicExpression) expr;
Expression left = dyExpr.getLeft();
Expression right = dyExpr.getRight();
Object leftVal = getValueForExpression(left);
Object rightVal = getValueForExpression(right);
if (rightVal instanceof Collection) {
Boolean result = Boolean.TRUE;
Iterator rightValIter = ((Collection) rightVal).iterator();
while (rightValIter.hasNext()) {
Object rightElem = rightValIter.next();
if (leftVal.equals(rightElem)) {
result = Boolean.FALSE;
break;
}
}
stack.push(result);
return result;
}
Boolean result = leftVal.equals(rightVal) ? Boolean.FALSE : Boolean.TRUE;
stack.push(result);
return result;
}
return super.processNotInExpression(expr);
}
use of org.datanucleus.query.expression.Expression in project datanucleus-core by datanucleus.
the class NullIfFunction 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 ignored, InMemoryExpressionEvaluator eval) {
List<Expression> args = expr.getArguments();
if (args == null || args.isEmpty()) {
throw new NucleusException("NULLIF requires two arguments");
} else if (args.size() == 1) {
return getValueForArgExpression(args.get(0), eval);
}
Expression argExpr1 = args.get(0);
Expression argExpr2 = args.get(1);
Object argValue1 = getValueForArgExpression(argExpr1, eval);
Object argValue2 = getValueForArgExpression(argExpr2, eval);
if (argValue1 == argValue2) {
return null;
}
return argValue1;
}
use of org.datanucleus.query.expression.Expression in project datanucleus-core by datanucleus.
the class CoalesceFunction 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 ignored, InMemoryExpressionEvaluator eval) {
List<Expression> args = expr.getArguments();
if (args == null || args.isEmpty()) {
return null;
}
Iterator<Expression> iter = args.iterator();
Object argValue = null;
while (iter.hasNext()) {
Expression argExpr = iter.next();
argValue = getValueForArgExpression(argExpr, eval);
if (argValue != null) {
return argValue;
}
}
return null;
}
use of org.datanucleus.query.expression.Expression in project datanucleus-core by datanucleus.
the class QueryUtils method getParameterExpressionForPosition.
/**
* Convenience method to return the ParameterExpression for the specified position
* if found in the expression tree starting at <pre>rootExpr</pre>
* @param rootExpr The expression
* @param pos The position
* @return The ParameterExpression (if found)
*/
public static ParameterExpression getParameterExpressionForPosition(Expression rootExpr, int pos) {
if (rootExpr instanceof ParameterExpression && ((ParameterExpression) rootExpr).getPosition() == pos) {
return (ParameterExpression) rootExpr;
}
if (rootExpr.getLeft() != null) {
ParameterExpression paramExpr = getParameterExpressionForPosition(rootExpr.getLeft(), pos);
if (paramExpr != null) {
return paramExpr;
}
}
if (rootExpr.getRight() != null) {
ParameterExpression paramExpr = getParameterExpressionForPosition(rootExpr.getRight(), pos);
if (paramExpr != null) {
return paramExpr;
}
}
if (rootExpr instanceof InvokeExpression) {
InvokeExpression invokeExpr = (InvokeExpression) rootExpr;
List<Expression> args = invokeExpr.getArguments();
if (args != null) {
Iterator<Expression> argIter = args.iterator();
while (argIter.hasNext()) {
ParameterExpression paramExpr = getParameterExpressionForPosition(argIter.next(), pos);
if (paramExpr != null) {
return paramExpr;
}
}
}
}
return null;
}
use of org.datanucleus.query.expression.Expression in project datanucleus-core by datanucleus.
the class JavaQueryCompiler method compileHaving.
public Expression compileHaving() {
if (having == null) {
return null;
}
Node node = parser.parse(having);
if (candidateAliasOrig != null) {
swapCandidateAliasNodeName(node);
}
if (parameterSubtitutionMap != null) {
node = swapSubqueryParameters(node);
}
ExpressionCompiler comp = new ExpressionCompiler();
comp.setSymbolTable(symtbl);
comp.setMethodAliases(queryMgr.getQueryMethodAliasesByPrefix());
Expression expr = comp.compileExpression(node);
expr.bind(symtbl);
return expr;
}
Aggregations