2
* $Id: PgSequence.java 80 2007-09-01 20:25:45Z fordfrog $
4
package cz.startnet.utils.pgdiff.schema;
6
import cz.startnet.utils.pgdiff.PgDiffUtils;
10
* Stores sequence information.
13
* @version $Id: PgSequence.java 80 2007-09-01 20:25:45Z fordfrog $
15
public class PgSequence {
17
* Value for CACHE or null if no value is specified.
22
* Value for INCREMENT BY or null if no value is specified.
24
private String increment;
27
* Value for MAXVALUE or null if no value is specified.
29
private String maxValue;
32
* Value for MINVALUE or null if no value is specified.
34
private String minValue;
37
* Name of the sequence.
42
* Value for START WITH or null if no value is specified.
44
private String startWith;
47
* True if CYCLE, false if NO CYCLE.
49
private boolean cycle;
52
* Creates a new PgSequence object.
54
* @param name name of the sequence
56
public PgSequence(final String name) {
61
* Setter for {@link #cache}.
63
* @param cache {@link #cache}
65
public void setCache(final String cache) {
70
* Getter for {@link #cache}.
72
* @return {@link #cache}
74
public String getCache() {
79
* Creates and returns SQL command for creation of the sequence.
81
* @param quoteNames whether names should be quoted
83
* @return created SQL command
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));
90
if (startWith != null) {
91
sbSQL.append("\n\tSTART WITH ");
92
sbSQL.append(startWith);
95
if (increment != null) {
96
sbSQL.append("\n\tINCREMENT BY ");
97
sbSQL.append(increment);
100
sbSQL.append("\n\t");
102
if (maxValue == null) {
103
sbSQL.append("NO MAXVALUE");
105
sbSQL.append("MAXVALUE ");
106
sbSQL.append(maxValue);
109
sbSQL.append("\n\t");
111
if (maxValue == null) {
112
sbSQL.append("NO MINVALUE");
114
sbSQL.append("MINVALUE ");
115
sbSQL.append(maxValue);
119
sbSQL.append("\n\tCACHE ");
124
sbSQL.append("\n\tCYCLE");
129
return sbSQL.toString();
133
* Setter for {@link #cycle}.
135
* @param cycle {@link #cycle}
137
public void setCycle(final boolean cycle) {
142
* Getter for {@link #cycle}.
144
* @return {@link #cycle}
146
public boolean isCycle() {
151
* Creates and returns SQL command for dropping the sequence.
153
* @param quoteNames whether names should be quoted
155
* @return created SQL
157
public String getDropSQL(final boolean quoteNames) {
158
return "DROP SEQUENCE "
159
+ PgDiffUtils.getQuotedName(getName(), quoteNames) + ";";
163
* Setter for {@link #increment}.
165
* @param increment {@link #increment}
167
public void setIncrement(final String increment) {
168
this.increment = increment;
172
* Getter for {@link #increment}.
174
* @return {@link #increment}
176
public String getIncrement() {
181
* Setter for {@link #maxValue}.
183
* @param maxValue {@link #maxValue}
185
public void setMaxValue(final String maxValue) {
186
this.maxValue = maxValue;
190
* Getter for {@link #maxValue}.
192
* @return {@link #maxValue}
194
public String getMaxValue() {
199
* Setter for {@link #minValue}.
201
* @param minValue {@link #minValue}
203
public void setMinValue(final String minValue) {
204
this.minValue = minValue;
208
* Getter for {@link #minValue}.
210
* @return {@link #minValue}
212
public String getMinValue() {
217
* Setter for {@link #name}.
219
* @param name {@link #name}
221
public void setName(final String name) {
226
* Getter for {@link #name}.
228
* @return {@link #name}
230
public String getName() {
235
* Setter for {@link #startWith}.
237
* @param startWith {@link #startWith}
239
public void setStartWith(final String startWith) {
240
this.startWith = startWith;
244
* Getter for {@link #startWith}.
246
* @return {@link #startWith}
248
public String getStartWith() {