use of org.datanucleus.store.rdbms.sql.expression.TypeConverterExpression in project datanucleus-rdbms by datanucleus.
the class QueryToSQLMapper method processInExpression.
/* (non-Javadoc)
* @see org.datanucleus.query.evaluator.AbstractExpressionEvaluator#processInExpression(org.datanucleus.query.expression.Expression)
*/
@Override
protected Object processInExpression(Expression expr) {
SQLExpression right = stack.pop();
SQLExpression left = stack.pop();
if (right instanceof CollectionExpression || right instanceof org.datanucleus.store.rdbms.sql.expression.ArrayExpression) {
// myElement IN myCollection
if (right.getParameterName() != null) {
setNotPrecompilable();
}
if (left instanceof TypeConverterExpression && right.getParameterName() != null && right instanceof CollectionLiteral) {
NucleusLogger.GENERAL.debug(">> processInExpression : left=" + left + " right=" + right + " rightParamName=" + right.getParameterName());
// TODO Support this somehow, but would need to split up user collection parameter into multiple single params
throw new NucleusUserException("Query has 'elem IN collectionParam'. We don't currently support this when the element value uses a TypeConverter." + " Suggest that you rewrite it using individual parameters for the elements.");
}
// Use Collection.contains(element)/Array.contains(element)
List<SQLExpression> sqlExprArgs = new ArrayList();
sqlExprArgs.add(left);
SQLExpression sqlExpr = right.invoke("contains", sqlExprArgs);
stack.push(sqlExpr);
return sqlExpr;
} else if (right.getParameterName() != null || left.getParameterName() != null) {
// "expr IN (:param)" or ":param IN (expr)" or ":param1 IN (:param2)"
setNotPrecompilable();
// Replace parameter(s) with equivalent literal of correct type
if (right instanceof ParameterLiteral) {
right = exprFactory.replaceParameterLiteral((ParameterLiteral) right, left);
}
if (left instanceof ParameterLiteral && !Collection.class.isAssignableFrom(right.getJavaTypeMapping().getJavaType())) {
left = exprFactory.replaceParameterLiteral((ParameterLiteral) left, right);
}
// Single valued parameter, so use equality
SQLExpression inExpr = new BooleanExpression(left, Expression.OP_EQ, right);
stack.push(inExpr);
return inExpr;
}
SQLExpression inExpr = left.in(right, false);
stack.push(inExpr);
return inExpr;
}
Aggregations