27
* Outputs commands for differences in sequences.
29
* @param writer writer the output should be written to
30
* @param arguments object containing arguments settings
31
* @param oldSchema original schema
32
* @param newSchema new schema
34
public static void diffSequences(
35
final PrintWriter writer,
36
final PgDiffArguments arguments,
37
final PgSchema oldSchema,
38
final PgSchema newSchema) {
23
* Outputs commands for creation of new sequences.
25
* @param writer writer the output should be written to
26
* @param arguments object containing arguments settings
27
* @param oldSchema original schema
28
* @param newSchema new schema
30
public static void createSequences(final PrintWriter writer,
31
final PgDiffArguments arguments, final PgSchema oldSchema,
32
final PgSchema newSchema) {
34
for (final PgSequence sequence : newSchema.getSequences()) {
36
|| !oldSchema.containsSequence(sequence.getName())) {
39
sequence.getCreationSQL(arguments.isQuoteNames()));
45
* Outputs commands for dropping of sequences that do not exist anymore.
47
* @param writer writer the output should be written to
48
* @param arguments object containing arguments settings
49
* @param oldSchema original schema
50
* @param newSchema new schema
52
public static void dropSequences(final PrintWriter writer,
53
final PgDiffArguments arguments, final PgSchema oldSchema,
54
final PgSchema newSchema) {
39
55
// Drop sequences that do not exist in new schema
40
56
if (oldSchema != null) {
41
for (PgSequence sequence : oldSchema.getSequences()) {
57
for (final PgSequence sequence : oldSchema.getSequences()) {
42
58
if (!newSchema.containsSequence(sequence.getName())) {
51
for (PgSequence sequence : newSchema.getSequences()) {
54
|| !oldSchema.containsSequence(sequence.getName())) {
57
sequence.getCreationSQL(arguments.isQuoteNames()));
61
// Alter modified sequences
62
addModifiedSequences(writer, arguments, oldSchema, newSchema);
66
* Returns list of modified sequences.
68
* Outputs command for modified sequences.
68
70
* @param writer writer the output should be written to
69
71
* @param arguments object containing arguments settings
70
72
* @param oldSchema original schema
71
73
* @param newSchema new schema
73
private static void addModifiedSequences(
74
final PrintWriter writer,
75
final PgDiffArguments arguments,
76
final PgSchema oldSchema,
77
final PgSchema newSchema) {
75
public static void alterSequences(final PrintWriter writer,
76
final PgDiffArguments arguments, final PgSchema oldSchema,
77
final PgSchema newSchema) {
78
78
final StringBuilder sbSQL = new StringBuilder();
80
80
for (final PgSequence newSequence : newSchema.getSequences()) {
83
82
&& oldSchema.containsSequence(newSequence.getName())) {
84
83
final PgSequence oldSequence =
85
oldSchema.getSequence(newSequence.getName());
84
oldSchema.getSequence(newSequence.getName());
86
85
sbSQL.setLength(0);
88
87
final String oldIncrement = oldSequence.getIncrement();
89
88
final String newIncrement = newSequence.getIncrement();
92
(newIncrement != null)
90
if (newIncrement != null
93
91
&& !newIncrement.equals(oldIncrement)) {
94
92
sbSQL.append("\n\tINCREMENT BY ");
95
93
sbSQL.append(newIncrement);
101
99
if ((newMinValue == null) && (oldMinValue != null)) {
102
100
sbSQL.append("\n\tNO MINVALUE");
104
(newMinValue != null)
101
} else if (newMinValue != null
105
102
&& !newMinValue.equals(oldMinValue)) {
106
103
sbSQL.append("\n\tMINVALUE ");
107
104
sbSQL.append(newMinValue);
113
110
if ((newMaxValue == null) && (oldMaxValue != null)) {
114
111
sbSQL.append("\n\tNO MAXVALUE");
116
(newMaxValue != null)
112
} else if (newMaxValue != null
117
113
&& !newMaxValue.equals(oldMaxValue)) {
118
114
sbSQL.append("\n\tMAXVALUE ");
119
115
sbSQL.append(newMaxValue);
149
145
if (sbSQL.length() > 0) {
150
146
writer.println();
153
+ PgDiffUtils.getQuotedName(
154
newSequence.getName(),
155
arguments.isQuoteNames()));
147
writer.print("ALTER SEQUENCE "
148
+ PgDiffUtils.getQuotedName(newSequence.getName(),
149
arguments.isQuoteNames()));
156
150
writer.print(sbSQL.toString());
157
151
writer.println(';');