throw new RuntimeException(MessageFormat.format(
Resources.getString("CannotFindSchema"), schemaName,
statement));
}
final PgFunction function = new PgFunction();
function.setName(ParserUtils.getObjectName(functionName));
schema.addFunction(function);
parser.expect("(");
while (!parser.expectOptional(")")) {
final String mode;
if (parser.expectOptional("IN")) {
mode = "IN";
} else if (parser.expectOptional("OUT")) {
mode = "OUT";
} else if (parser.expectOptional("INOUT")) {
mode = "INOUT";
} else if (parser.expectOptional("VARIADIC")) {
mode = "VARIADIC";
} else {
mode = null;
}
final int position = parser.getPosition();
String argumentName = null;
String dataType = parser.parseDataType();
final int position2 = parser.getPosition();
if (!parser.expectOptional(")") && !parser.expectOptional(",")
&& !parser.expectOptional("=")
&& !parser.expectOptional("DEFAULT")) {
parser.setPosition(position);
argumentName =
ParserUtils.getObjectName(parser.parseIdentifier());
dataType = parser.parseDataType();
} else {
parser.setPosition(position2);
}
final String defaultExpression;
if (parser.expectOptional("=")
|| parser.expectOptional("DEFAULT")) {
defaultExpression = parser.getExpression();
} else {
defaultExpression = null;
}
final PgFunction.Argument argument = new PgFunction.Argument();
argument.setDataType(dataType);
argument.setDefaultExpression(defaultExpression);
argument.setMode(mode);
argument.setName(argumentName);
function.addArgument(argument);
if (parser.expectOptional(")")) {
break;
} else {
parser.expect(",");
}
}
function.setBody(parser.getRest());
}