{
// strExpr.indexOf(str1)
funcArgs.add(expr);
funcArgs.add(substrExpr);
SQLExpression oneExpr = ExpressionUtils.getLiteralForOne(stmt);
NumericExpression locateExpr = new NumericExpression(stmt, getMappingForClass(int.class), "STRPOS", funcArgs);
return new NumericExpression(locateExpr, Expression.OP_SUB, oneExpr);
}
else
{
// strExpr.indexOf(str1, pos)
SQLExpression fromExpr = (SQLExpression)args.get(1);
if (!(fromExpr instanceof NumericExpression))
{
throw new NucleusException(LOCALISER.msg("060003", "indexOf", "StringExpression", 1,
"NumericExpression"));
}
// Find the substring starting at this position
ArrayList substrArgs = new ArrayList(1);
substrArgs.add(fromExpr);
SQLExpression strExpr = exprFactory.invokeMethod(stmt, "java.lang.String", "substring", expr, substrArgs);
funcArgs.add(strExpr);
funcArgs.add(substrExpr);
NumericExpression locateExpr = new NumericExpression(stmt, getMappingForClass(int.class), "STRPOS", funcArgs);
SQLExpression[] whenExprs = new SQLExpression[1];
NumericExpression zeroExpr = new IntegerLiteral(stmt, exprFactory.getMappingForType(Integer.class, false), Integer.valueOf(0), null);
whenExprs[0] = locateExpr.gt(zeroExpr);
SQLExpression[] actionExprs = new SQLExpression[1];
SQLExpression oneExpr = ExpressionUtils.getLiteralForOne(stmt);
NumericExpression posExpr1 = new NumericExpression(locateExpr, Expression.OP_SUB, oneExpr);
actionExprs[0] = new NumericExpression(posExpr1, Expression.OP_ADD, fromExpr);
SQLExpression elseExpr = new IntegerLiteral(stmt, exprFactory.getMappingForType(Integer.class, false), Integer.valueOf(-1), null);
return new CaseExpression(whenExprs, actionExprs, elseExpr);
}