1 | |
package liquibase.change.core; |
2 | |
|
3 | |
import liquibase.change.AbstractChange; |
4 | |
import liquibase.change.Change; |
5 | |
import liquibase.change.ChangeMetaData; |
6 | |
import liquibase.database.Database; |
7 | |
import liquibase.statement.SqlStatement; |
8 | |
import liquibase.statement.core.CreateSequenceStatement; |
9 | |
import liquibase.util.StringUtils; |
10 | |
|
11 | |
import java.math.BigInteger; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
public class CreateSequenceChange extends AbstractChange { |
17 | |
|
18 | |
private String schemaName; |
19 | |
private String sequenceName; |
20 | |
private BigInteger startValue; |
21 | |
private BigInteger incrementBy; |
22 | |
private BigInteger maxValue; |
23 | |
private BigInteger minValue; |
24 | |
private Boolean ordered; |
25 | |
private Boolean cycle; |
26 | |
|
27 | |
public CreateSequenceChange() { |
28 | 19 | super("createSequence", "Create Sequence", ChangeMetaData.PRIORITY_DEFAULT); |
29 | 19 | } |
30 | |
|
31 | |
public String getSchemaName() { |
32 | 43 | return schemaName; |
33 | |
} |
34 | |
|
35 | |
public void setSchemaName(String schemaName) { |
36 | 0 | this.schemaName = StringUtils.trimToNull(schemaName); |
37 | 0 | } |
38 | |
|
39 | |
public String getSequenceName() { |
40 | 44 | return sequenceName; |
41 | |
} |
42 | |
|
43 | |
public void setSequenceName(String sequenceName) { |
44 | 5 | this.sequenceName = sequenceName; |
45 | 5 | } |
46 | |
|
47 | |
public BigInteger getStartValue() { |
48 | 43 | return startValue; |
49 | |
} |
50 | |
|
51 | |
public void setStartValue(BigInteger startValue) { |
52 | 4 | this.startValue = startValue; |
53 | 4 | } |
54 | |
|
55 | |
public BigInteger getIncrementBy() { |
56 | 43 | return incrementBy; |
57 | |
} |
58 | |
|
59 | |
public void setIncrementBy(BigInteger incrementBy) { |
60 | 1 | this.incrementBy = incrementBy; |
61 | 1 | } |
62 | |
|
63 | |
public BigInteger getMaxValue() { |
64 | 43 | return maxValue; |
65 | |
} |
66 | |
|
67 | |
public void setMaxValue(BigInteger maxValue) { |
68 | 1 | this.maxValue = maxValue; |
69 | 1 | } |
70 | |
|
71 | |
public BigInteger getMinValue() { |
72 | 43 | return minValue; |
73 | |
} |
74 | |
|
75 | |
public void setMinValue(BigInteger minValue) { |
76 | 1 | this.minValue = minValue; |
77 | 1 | } |
78 | |
|
79 | |
public Boolean isOrdered() { |
80 | 43 | return ordered; |
81 | |
} |
82 | |
|
83 | |
public void setOrdered(Boolean ordered) { |
84 | 1 | this.ordered = ordered; |
85 | 1 | } |
86 | |
|
87 | |
public Boolean getCycle() { |
88 | 43 | return cycle; |
89 | |
} |
90 | |
|
91 | |
public void setCycle(Boolean cycle) { |
92 | 1 | this.cycle = cycle; |
93 | 1 | } |
94 | |
|
95 | |
public SqlStatement[] generateStatements(Database database) { |
96 | 43 | return new SqlStatement[] { new CreateSequenceStatement( |
97 | |
getSchemaName() == null ? database.getDefaultSchemaName() : getSchemaName(), getSequenceName()) |
98 | |
.setIncrementBy(getIncrementBy()).setMaxValue(getMaxValue()).setMinValue(getMinValue()) |
99 | |
.setOrdered(isOrdered()).setStartValue(getStartValue()).setCycle(getCycle()) }; |
100 | |
} |
101 | |
|
102 | |
@Override |
103 | |
protected Change[] createInverses() { |
104 | 0 | DropSequenceChange inverse = new DropSequenceChange(); |
105 | 0 | inverse.setSequenceName(getSequenceName()); |
106 | 0 | inverse.setSchemaName(getSchemaName()); |
107 | |
|
108 | 0 | return new Change[] { inverse }; |
109 | |
} |
110 | |
|
111 | |
public String getConfirmationMessage() { |
112 | 1 | return "Sequence " + getSequenceName() + " created"; |
113 | |
} |
114 | |
} |