~ubuntu-branches/ubuntu/raring/apgdiff/raring

« back to all changes in this revision

Viewing changes to src/main/java/cz/startnet/utils/pgdiff/schema/PgConstraint.java

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2010-10-11 09:08:18 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20101011090818-sdw8yfemrnxo328k
Tags: 2.2.2-1
* New upstream version.
* Using changelog included in zipfile, thanks Miroslav for providing this.
* Update manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2006 StartNet s.r.o.
 
3
 *
 
4
 * Distributed under MIT license
 
5
 */
1
6
package cz.startnet.utils.pgdiff.schema;
2
7
 
3
8
import cz.startnet.utils.pgdiff.PgDiffUtils;
42
47
    /**
43
48
     * Creates and returns SQL for creation of the constraint.
44
49
     *
45
 
     * @param quoteNames whether names should be quoted
46
 
     *
47
50
     * @return created SQL
48
51
     */
49
 
    public String getCreationSQL(final boolean quoteNames) {
50
 
        final StringBuilder sbSQL = new StringBuilder();
 
52
    public String getCreationSQL() {
 
53
        final StringBuilder sbSQL = new StringBuilder(100);
51
54
        sbSQL.append("ALTER TABLE ");
52
 
        sbSQL.append(PgDiffUtils.getQuotedName(getTableName(), quoteNames));
 
55
        sbSQL.append(PgDiffUtils.getQuotedName(getTableName()));
53
56
        sbSQL.append("\n\tADD CONSTRAINT ");
54
 
        sbSQL.append(PgDiffUtils.getQuotedName(getName(), quoteNames));
 
57
        sbSQL.append(PgDiffUtils.getQuotedName(getName()));
55
58
        sbSQL.append(' ');
56
59
        sbSQL.append(getDefinition());
57
60
        sbSQL.append(';');
80
83
    /**
81
84
     * Creates and returns SQL for dropping the constraint.
82
85
     *
83
 
     * @param quoteNames whether names should be quoted
84
 
     *
85
86
     * @return created SQL
86
87
     */
87
 
    public String getDropSQL(final boolean quoteNames) {
88
 
        final StringBuilder sbSQL = new StringBuilder();
 
88
    public String getDropSQL() {
 
89
        final StringBuilder sbSQL = new StringBuilder(100);
89
90
        sbSQL.append("ALTER TABLE ");
90
 
        sbSQL.append(PgDiffUtils.getQuotedName(getTableName(), quoteNames));
 
91
        sbSQL.append(PgDiffUtils.getQuotedName(getTableName()));
91
92
        sbSQL.append("\n\tDROP CONSTRAINT ");
92
 
        sbSQL.append(PgDiffUtils.getQuotedName(getName(), quoteNames));
 
93
        sbSQL.append(PgDiffUtils.getQuotedName(getName()));
93
94
        sbSQL.append(';');
94
95
 
95
96
        return sbSQL.toString();
156
157
            equals = true;
157
158
        } else if (object instanceof PgConstraint) {
158
159
            final PgConstraint constraint = (PgConstraint) object;
159
 
            equals = definition.equals(constraint.definition)
160
 
                    && name.equals(constraint.name)
161
 
                    && tableName.equals(constraint.tableName);
 
160
            equals = definition.equals(constraint.getDefinition())
 
161
                    && name.equals(constraint.getName())
 
162
                    && tableName.equals(constraint.getTableName());
162
163
        }
163
164
 
164
165
        return equals;