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

« back to all changes in this revision

Viewing changes to src/main/java/cz/startnet/utils/pgdiff/parsers/CreateIndexParser.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: CreateIndexParser.java 93 2008-08-03 12:31:08Z fordfrog $
3
 
 */
4
1
package cz.startnet.utils.pgdiff.parsers;
5
2
 
6
3
import cz.startnet.utils.pgdiff.schema.PgDatabase;
14
11
 * Parses CREATE INDEX commands.
15
12
 *
16
13
 * @author fordfrog
17
 
 * @version $Id: CreateIndexParser.java 93 2008-08-03 12:31:08Z fordfrog $
18
14
 */
19
15
public class CreateIndexParser {
20
16
 
21
17
    /**
22
18
     * Pattern for parsing CREATE INDEX definition.
23
19
     */
24
 
    private static final Pattern PATTERN =
25
 
        Pattern.compile(
26
 
        "CREATE[\\s](UNIQUE[\\s]+)?+INDEX[\\s]+\"?([^\\s\"]+)\"?[\\s]+" +
27
 
        "ON[\\s]+\"?([^\\s\"(]+)\"?[\\s]*([^;]+)[;]?",
28
 
        Pattern.CASE_INSENSITIVE);
 
20
    private static final Pattern PATTERN = Pattern.compile(
 
21
            "CREATE[\\s](UNIQUE[\\s]+)?+INDEX[\\s]+\"?([^\\s\"]+)\"?[\\s]+"
 
22
            + "ON[\\s]+\"?([^\\s\"(]+)\"?[\\s]*([^;]+)[;]?",
 
23
            Pattern.CASE_INSENSITIVE);
29
24
 
30
25
    /**
31
26
     * Creates a new instance of CreateIndexParser.
54
49
 
55
50
            if ((indexName == null) || (tableName == null) || (def == null)) {
56
51
                throw new ParserException(
57
 
                    ParserException.CANNOT_PARSE_COMMAND + command);
 
52
                        ParserException.CANNOT_PARSE_COMMAND + command);
58
53
            }
59
54
 
60
 
            final PgTable table =
61
 
                database.getSchema(
62
 
                ParserUtils.getSchemaName(tableName.trim(), database)).getTable(
63
 
                tableName.trim());
 
55
            final PgTable table = database.getSchema(
 
56
                    ParserUtils.getSchemaName(
 
57
                    tableName.trim(), database)).getTable(tableName.trim());
64
58
            final PgIndex index = new PgIndex(indexName);
65
59
            table.addIndex(index);
66
60
            index.setDefinition(def.trim());
68
62
            index.setUnique(unique);
69
63
        } else {
70
64
            throw new ParserException(
71
 
                ParserException.CANNOT_PARSE_COMMAND + command);
 
65
                    ParserException.CANNOT_PARSE_COMMAND + command);
72
66
        }
73
67
    }
74
68
}