20
25
* Creates a new instance of PgDiffIndexes.
22
27
private PgDiffIndexes() {
27
* Outputs commands for creation of new indexes.
31
* Outputs statements for creation of new indexes.
29
33
* @param writer writer the output should be written to
30
* @param arguments object containing arguments settings
31
34
* @param oldSchema original schema
32
35
* @param newSchema new schema
34
37
public static void createIndexes(final PrintWriter writer,
35
final PgDiffArguments arguments, final PgSchema oldSchema,
36
final PgSchema newSchema) {
38
final PgSchema oldSchema, final PgSchema newSchema) {
37
39
for (final PgTable newTable : newSchema.getTables()) {
38
40
final String newTableName = newTable.getName();
39
final PgTable oldTable;
41
if (oldSchema == null) {
44
oldTable = oldSchema.getTable(newTableName);
48
43
if (oldSchema == null) {
49
44
for (PgIndex index : newTable.getIndexes()) {
52
index.getCreationSQL(arguments.isQuoteNames()));
46
writer.println(index.getCreationSQL());
55
49
for (PgIndex index : getNewIndexes(
56
50
oldSchema.getTable(newTableName), newTable)) {
59
index.getCreationSQL(arguments.isQuoteNames()));
52
writer.println(index.getCreationSQL());
66
* Outputs commands for dropping indexes that exist no more.
59
* Outputs statements for dropping indexes that exist no more.
68
61
* @param writer writer the output should be written to
69
* @param arguments object containing arguments settings
70
62
* @param oldSchema original schema
71
63
* @param newSchema new schema
73
65
public static void dropIndexes(final PrintWriter writer,
74
final PgDiffArguments arguments, final PgSchema oldSchema,
75
final PgSchema newSchema) {
66
final PgSchema oldSchema, final PgSchema newSchema) {
76
67
for (final PgTable newTable : newSchema.getTables()) {
77
68
final String newTableName = newTable.getName();
78
69
final PgTable oldTable;
86
77
// Drop indexes that do not exist in new schema or are modified
87
78
for (final PgIndex index : getDropIndexes(oldTable, newTable)) {
89
writer.println(index.getDropSQL(arguments.isQuoteNames()));
80
writer.println(index.getDropSQL());
105
96
private static List<PgIndex> getDropIndexes(final PgTable oldTable,
106
97
final PgTable newTable) {
98
@SuppressWarnings("CollectionWithoutInitialCapacity")
107
99
final List<PgIndex> list = new ArrayList<PgIndex>();
109
if ((newTable != null) && (oldTable != null)) {
101
if (newTable != null && oldTable != null) {
110
102
for (final PgIndex index : oldTable.getIndexes()) {
111
103
if (!newTable.containsIndex(index.getName())
112
104
|| !newTable.getIndex(index.getName()).equals(index)) {
129
121
private static List<PgIndex> getNewIndexes(final PgTable oldTable,
130
122
final PgTable newTable) {
123
@SuppressWarnings("CollectionWithoutInitialCapacity")
131
124
final List<PgIndex> list = new ArrayList<PgIndex>();
133
126
if (newTable != null) {