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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2008-09-09 15:42:54 UTC
  • Revision ID: james.westby@ubuntu.com-20080909154254-458sv7ew1rczdal1
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: PgSequence.java 80 2007-09-01 20:25:45Z fordfrog $
 
3
 */
 
4
package cz.startnet.utils.pgdiff.schema;
 
5
 
 
6
import cz.startnet.utils.pgdiff.PgDiffUtils;
 
7
 
 
8
 
 
9
/**
 
10
 * Stores sequence information.
 
11
 *
 
12
 * @author fordfrog
 
13
 * @version $Id: PgSequence.java 80 2007-09-01 20:25:45Z fordfrog $
 
14
 */
 
15
public class PgSequence {
 
16
    /**
 
17
     * Value for CACHE or null if no value is specified.
 
18
     */
 
19
    private String cache;
 
20
 
 
21
    /**
 
22
     * Value for INCREMENT BY or null if no value is specified.
 
23
     */
 
24
    private String increment;
 
25
 
 
26
    /**
 
27
     * Value for MAXVALUE or null if no value is specified.
 
28
     */
 
29
    private String maxValue;
 
30
 
 
31
    /**
 
32
     * Value for MINVALUE or null if no value is specified.
 
33
     */
 
34
    private String minValue;
 
35
 
 
36
    /**
 
37
     * Name of the sequence.
 
38
     */
 
39
    private String name;
 
40
 
 
41
    /**
 
42
     * Value for START WITH or null if no value is specified.
 
43
     */
 
44
    private String startWith;
 
45
 
 
46
    /**
 
47
     * True if CYCLE, false if NO CYCLE.
 
48
     */
 
49
    private boolean cycle;
 
50
 
 
51
    /**
 
52
     * Creates a new PgSequence object.
 
53
     *
 
54
     * @param name name of the sequence
 
55
     */
 
56
    public PgSequence(final String name) {
 
57
        this.name = name;
 
58
    }
 
59
 
 
60
    /**
 
61
     * Setter for {@link #cache}.
 
62
     *
 
63
     * @param cache {@link #cache}
 
64
     */
 
65
    public void setCache(final String cache) {
 
66
        this.cache = cache;
 
67
    }
 
68
 
 
69
    /**
 
70
     * Getter for {@link #cache}.
 
71
     *
 
72
     * @return {@link #cache}
 
73
     */
 
74
    public String getCache() {
 
75
        return cache;
 
76
    }
 
77
 
 
78
    /**
 
79
     * Creates and returns SQL command for creation of the sequence.
 
80
     *
 
81
     * @param quoteNames whether names should be quoted
 
82
     *
 
83
     * @return created SQL command
 
84
     */
 
85
    public String getCreationSQL(final boolean quoteNames) {
 
86
        final StringBuilder sbSQL = new StringBuilder();
 
87
        sbSQL.append("CREATE SEQUENCE ");
 
88
        sbSQL.append(PgDiffUtils.getQuotedName(name, quoteNames));
 
89
 
 
90
        if (startWith != null) {
 
91
            sbSQL.append("\n\tSTART WITH ");
 
92
            sbSQL.append(startWith);
 
93
        }
 
94
 
 
95
        if (increment != null) {
 
96
            sbSQL.append("\n\tINCREMENT BY ");
 
97
            sbSQL.append(increment);
 
98
        }
 
99
 
 
100
        sbSQL.append("\n\t");
 
101
 
 
102
        if (maxValue == null) {
 
103
            sbSQL.append("NO MAXVALUE");
 
104
        } else {
 
105
            sbSQL.append("MAXVALUE ");
 
106
            sbSQL.append(maxValue);
 
107
        }
 
108
 
 
109
        sbSQL.append("\n\t");
 
110
 
 
111
        if (maxValue == null) {
 
112
            sbSQL.append("NO MINVALUE");
 
113
        } else {
 
114
            sbSQL.append("MINVALUE ");
 
115
            sbSQL.append(maxValue);
 
116
        }
 
117
 
 
118
        if (cache != null) {
 
119
            sbSQL.append("\n\tCACHE ");
 
120
            sbSQL.append(cache);
 
121
        }
 
122
 
 
123
        if (cycle) {
 
124
            sbSQL.append("\n\tCYCLE");
 
125
        }
 
126
 
 
127
        sbSQL.append(';');
 
128
 
 
129
        return sbSQL.toString();
 
130
    }
 
131
 
 
132
    /**
 
133
     * Setter for {@link #cycle}.
 
134
     *
 
135
     * @param cycle {@link #cycle}
 
136
     */
 
137
    public void setCycle(final boolean cycle) {
 
138
        this.cycle = cycle;
 
139
    }
 
140
 
 
141
    /**
 
142
     * Getter for {@link #cycle}.
 
143
     *
 
144
     * @return {@link #cycle}
 
145
     */
 
146
    public boolean isCycle() {
 
147
        return cycle;
 
148
    }
 
149
 
 
150
    /**
 
151
     * Creates and returns SQL command for dropping the sequence.
 
152
     *
 
153
     * @param quoteNames whether names should be quoted
 
154
     *
 
155
     * @return created SQL
 
156
     */
 
157
    public String getDropSQL(final boolean quoteNames) {
 
158
        return "DROP SEQUENCE "
 
159
        + PgDiffUtils.getQuotedName(getName(), quoteNames) + ";";
 
160
    }
 
161
 
 
162
    /**
 
163
     * Setter for {@link #increment}.
 
164
     *
 
165
     * @param increment {@link #increment}
 
166
     */
 
167
    public void setIncrement(final String increment) {
 
168
        this.increment = increment;
 
169
    }
 
170
 
 
171
    /**
 
172
     * Getter for {@link #increment}.
 
173
     *
 
174
     * @return {@link #increment}
 
175
     */
 
176
    public String getIncrement() {
 
177
        return increment;
 
178
    }
 
179
 
 
180
    /**
 
181
     * Setter for {@link #maxValue}.
 
182
     *
 
183
     * @param maxValue {@link #maxValue}
 
184
     */
 
185
    public void setMaxValue(final String maxValue) {
 
186
        this.maxValue = maxValue;
 
187
    }
 
188
 
 
189
    /**
 
190
     * Getter for {@link #maxValue}.
 
191
     *
 
192
     * @return {@link #maxValue}
 
193
     */
 
194
    public String getMaxValue() {
 
195
        return maxValue;
 
196
    }
 
197
 
 
198
    /**
 
199
     * Setter for {@link #minValue}.
 
200
     *
 
201
     * @param minValue {@link #minValue}
 
202
     */
 
203
    public void setMinValue(final String minValue) {
 
204
        this.minValue = minValue;
 
205
    }
 
206
 
 
207
    /**
 
208
     * Getter for {@link #minValue}.
 
209
     *
 
210
     * @return {@link #minValue}
 
211
     */
 
212
    public String getMinValue() {
 
213
        return minValue;
 
214
    }
 
215
 
 
216
    /**
 
217
     * Setter for {@link #name}.
 
218
     *
 
219
     * @param name {@link #name}
 
220
     */
 
221
    public void setName(final String name) {
 
222
        this.name = name;
 
223
    }
 
224
 
 
225
    /**
 
226
     * Getter for {@link #name}.
 
227
     *
 
228
     * @return {@link #name}
 
229
     */
 
230
    public String getName() {
 
231
        return name;
 
232
    }
 
233
 
 
234
    /**
 
235
     * Setter for {@link #startWith}.
 
236
     *
 
237
     * @param startWith {@link #startWith}
 
238
     */
 
239
    public void setStartWith(final String startWith) {
 
240
        this.startWith = startWith;
 
241
    }
 
242
 
 
243
    /**
 
244
     * Getter for {@link #startWith}.
 
245
     *
 
246
     * @return {@link #startWith}
 
247
     */
 
248
    public String getStartWith() {
 
249
        return startWith;
 
250
    }
 
251
}