16
21
* Creates a new instance of PgDiffSequences.
18
23
private PgDiffSequences() {
23
* Outputs commands for creation of new sequences.
27
* Outputs statements for creation of new sequences.
25
29
* @param writer writer the output should be written to
26
* @param arguments object containing arguments settings
27
30
* @param oldSchema original schema
28
31
* @param newSchema new schema
30
33
public static void createSequences(final PrintWriter writer,
31
final PgDiffArguments arguments, final PgSchema oldSchema,
32
final PgSchema newSchema) {
34
final PgSchema oldSchema, final PgSchema newSchema) {
33
35
// Add new sequences
34
36
for (final PgSequence sequence : newSchema.getSequences()) {
35
37
if (oldSchema == null
36
38
|| !oldSchema.containsSequence(sequence.getName())) {
39
sequence.getCreationSQL(arguments.isQuoteNames()));
40
writer.println(sequence.getCreationSQL());
45
* Outputs commands for dropping of sequences that do not exist anymore.
46
* Outputs statements for dropping of sequences that do not exist anymore.
47
48
* @param writer writer the output should be written to
48
* @param arguments object containing arguments settings
49
49
* @param oldSchema original schema
50
50
* @param newSchema new schema
52
52
public static void dropSequences(final PrintWriter writer,
53
final PgDiffArguments arguments, final PgSchema oldSchema,
54
final PgSchema newSchema) {
53
final PgSchema oldSchema, final PgSchema newSchema) {
55
54
// Drop sequences that do not exist in new schema
56
55
if (oldSchema != null) {
57
56
for (final PgSequence sequence : oldSchema.getSequences()) {
58
57
if (!newSchema.containsSequence(sequence.getName())) {
61
sequence.getDropSQL(arguments.isQuoteNames()));
59
writer.println(sequence.getDropSQL());
68
* Outputs command for modified sequences.
66
* Outputs statement for modified sequences.
70
68
* @param writer writer the output should be written to
71
69
* @param arguments object containing arguments settings
75
73
public static void alterSequences(final PrintWriter writer,
76
74
final PgDiffArguments arguments, final PgSchema oldSchema,
77
75
final PgSchema newSchema) {
78
final StringBuilder sbSQL = new StringBuilder();
76
final StringBuilder sbSQL = new StringBuilder(100);
80
78
for (final PgSequence newSequence : newSchema.getSequences()) {
81
79
if (oldSchema != null
96
94
final String oldMinValue = oldSequence.getMinValue();
97
95
final String newMinValue = newSequence.getMinValue();
99
if ((newMinValue == null) && (oldMinValue != null)) {
97
if (newMinValue == null && oldMinValue != null) {
100
98
sbSQL.append("\n\tNO MINVALUE");
101
99
} else if (newMinValue != null
102
100
&& !newMinValue.equals(oldMinValue)) {
107
105
final String oldMaxValue = oldSequence.getMaxValue();
108
106
final String newMaxValue = newSequence.getMaxValue();
110
if ((newMaxValue == null) && (oldMaxValue != null)) {
108
if (newMaxValue == null && oldMaxValue != null) {
111
109
sbSQL.append("\n\tNO MAXVALUE");
112
110
} else if (newMaxValue != null
113
111
&& !newMaxValue.equals(oldMaxValue)) {
119
117
final String oldStart = oldSequence.getStartWith();
120
118
final String newStart = newSequence.getStartWith();
122
if ((newStart != null) && !newStart.equals(oldStart)) {
120
if (newStart != null && !newStart.equals(oldStart)) {
123
121
sbSQL.append("\n\tRESTART WITH ");
124
122
sbSQL.append(newStart);
128
126
final String oldCache = oldSequence.getCache();
129
127
final String newCache = newSequence.getCache();
131
if ((newCache != null) && !newCache.equals(oldCache)) {
129
if (newCache != null && !newCache.equals(oldCache)) {
132
130
sbSQL.append("\n\tCACHE ");
133
131
sbSQL.append(newCache);
145
143
if (sbSQL.length() > 0) {
146
144
writer.println();
147
145
writer.print("ALTER SEQUENCE "
148
+ PgDiffUtils.getQuotedName(newSequence.getName(),
149
arguments.isQuoteNames()));
146
+ PgDiffUtils.getQuotedName(newSequence.getName()));
150
147
writer.print(sbSQL.toString());
151
148
writer.println(';');