12
9
import java.util.regex.Matcher;
13
10
import java.util.regex.Pattern;
17
13
* Parses CREATE FUNCTION and CREATE OR REPLACE FUNCTION commands.
20
* @version $Id: CreateFunctionParser.java 80 2007-09-01 20:25:45Z fordfrog $
22
17
public class CreateFunctionParser {
24
20
* Pattern for parsing CREATE FUNCTION and CREATE OR REPLACE
25
21
* FUNCTION command.
27
private static final Pattern PATTERN =
29
"^CREATE[\\s]+(?:OR[\\s]+REPLACE[\\s]+)?FUNCTION[\\s]+"
30
+ "([^\\s(]+)\\(([^)]*)\\).*$",
31
Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
23
private static final Pattern PATTERN = Pattern.compile(
24
"^CREATE[\\s]+(?:OR[\\s]+REPLACE[\\s]+)?FUNCTION[\\s]+"
25
+ "([^\\s(]+)\\(([^)]*)\\).*$",
26
Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
34
28
* Pattern for parsing function arguments.
36
private static final Pattern PATTERN_ARGUMENT =
38
"^(?:(?:IN|OUT|INOUT)[\\s]+)?(?:\"?[^\\s\"]+\"?[\\s]+)?(.+)$",
39
Pattern.CASE_INSENSITIVE);
30
private static final Pattern PATTERN_ARGUMENT = Pattern.compile(
31
"^(?:(?:IN|OUT|INOUT)[\\s]+)?(?:\"?[^\\s\"]+\"?[\\s]+)?(.+)$",
32
Pattern.CASE_INSENSITIVE);
42
35
* Creates a new instance of CreateFunctionParser.
65
58
getFunctionDeclaration(functionName, arguments));
66
59
function.setDefinition(command);
67
60
function.setName(ParserUtils.getObjectName(functionName));
69
ParserUtils.getSchemaName(functionName, database))
70
.addFunction(function);
61
database.getSchema(ParserUtils.getSchemaName(
62
functionName, database)).addFunction(function);
72
64
throw new ParserException(
73
65
ParserException.CANNOT_PARSE_COMMAND + command);
87
79
* @throws ParserException Thrown if cannot parse function arguments.
89
private static String getFunctionDeclaration(
90
final String functionName,
91
final String arguments) {
81
private static String getFunctionDeclaration(final String functionName,
82
final String arguments) {
92
83
final String result;
94
85
if ((arguments == null) || (arguments.trim().length() == 0)) {