~ubuntu-branches/ubuntu/wily/apgdiff/wily

« back to all changes in this revision

Viewing changes to src/main/java/cz/startnet/utils/pgdiff/parsers/CreateFunctionParser.java

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2009-12-02 11:11:33 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091202111133-k5wrh3zb2pzmbv8c
Tags: 1.4-1
* New upstream version. (Without changelog, I am afraid.)
* Test suite still not enabled as it needs network access. (The junit
  version in Debian needs upgrading.)
* Optimize rules files a bit so debhelper doesn't clean twice, and quilt's
  patch target doesn't prevent build-stamp from working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: CreateFunctionParser.java 80 2007-09-01 20:25:45Z fordfrog $
3
 
 */
4
1
package cz.startnet.utils.pgdiff.parsers;
5
2
 
6
3
import cz.startnet.utils.pgdiff.schema.PgDatabase;
12
9
import java.util.regex.Matcher;
13
10
import java.util.regex.Pattern;
14
11
 
15
 
 
16
12
/**
17
13
 * Parses CREATE FUNCTION and CREATE OR REPLACE FUNCTION commands.
18
14
 *
19
15
 * @author fordfrog
20
 
 * @version $Id: CreateFunctionParser.java 80 2007-09-01 20:25:45Z fordfrog $
21
16
 */
22
17
public class CreateFunctionParser {
 
18
 
23
19
    /**
24
20
     * Pattern for parsing CREATE FUNCTION and CREATE OR REPLACE
25
21
     * FUNCTION command.
26
22
     */
27
 
    private static final Pattern PATTERN =
28
 
        Pattern.compile(
29
 
                "^CREATE[\\s]+(?:OR[\\s]+REPLACE[\\s]+)?FUNCTION[\\s]+"
30
 
                + "([^\\s(]+)\\(([^)]*)\\).*$",
31
 
                Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
32
 
 
 
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);
33
27
    /**
34
28
     * Pattern for parsing function arguments.
35
29
     */
36
 
    private static final Pattern PATTERN_ARGUMENT =
37
 
        Pattern.compile(
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);
40
33
 
41
34
    /**
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));
68
 
            database.getSchema(
69
 
                    ParserUtils.getSchemaName(functionName, database))
70
 
                    .addFunction(function);
 
61
            database.getSchema(ParserUtils.getSchemaName(
 
62
                    functionName, database)).addFunction(function);
71
63
        } else {
72
64
            throw new ParserException(
73
65
                    ParserException.CANNOT_PARSE_COMMAND + command);
86
78
     *
87
79
     * @throws ParserException Thrown if cannot parse function arguments.
88
80
     */
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;
93
84
 
94
85
        if ((arguments == null) || (arguments.trim().length() == 0)) {