use of org.datanucleus.store.rdbms.sql.expression.CaseExpression in project datanucleus-rdbms by datanucleus.
the class OptionalOrElseMethod method getExpression.
/* (non-Javadoc)
* @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
*/
public SQLExpression getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args) {
if (args == null || args.size() != 1) {
throw new NucleusException("Optional.orElse should be passed 1 argument");
}
SQLExpression elseExpr = args.get(0);
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
OptionalMapping opMapping = (OptionalMapping) ((OptionalExpression) expr).getJavaTypeMapping();
JavaTypeMapping javaMapping = opMapping.getWrappedMapping();
SQLExpression getExpr = exprFactory.newExpression(stmt, expr.getSQLTable(), javaMapping);
SQLExpression isNotNullExpr = exprFactory.newExpression(stmt, expr.getSQLTable(), javaMapping).ne(new NullLiteral(stmt, javaMapping, null, null));
if (javaMapping instanceof StringMapping) {
return new CaseStringExpression(new SQLExpression[] { isNotNullExpr }, new SQLExpression[] { getExpr }, elseExpr);
} else if (javaMapping instanceof IntegerMapping || javaMapping instanceof LongMapping || javaMapping instanceof ShortMapping || javaMapping instanceof FloatMapping || javaMapping instanceof DoubleMapping || javaMapping instanceof BigIntegerMapping || javaMapping instanceof BigDecimalMapping) // TODO Maybe use javaMapping.getJavaType compared to Number to avoid the check above
{
return new CaseNumericExpression(new SQLExpression[] { isNotNullExpr }, new SQLExpression[] { getExpr }, elseExpr);
} else if (javaMapping instanceof BooleanMapping) {
return new CaseBooleanExpression(new SQLExpression[] { isNotNullExpr }, new SQLExpression[] { getExpr }, elseExpr);
}
return new CaseExpression(new SQLExpression[] { isNotNullExpr }, new SQLExpression[] { getExpr }, elseExpr);
}
Aggregations