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
36
* @param searchPathHelper search path helper
34
38
public static void createIndexes(final PrintWriter writer,
35
final PgDiffArguments arguments, final PgSchema oldSchema,
36
final PgSchema newSchema) {
39
final PgSchema oldSchema, final PgSchema newSchema,
40
final SearchPathHelper searchPathHelper) {
37
41
for (final PgTable newTable : newSchema.getTables()) {
38
42
final String newTableName = newTable.getName();
39
final PgTable oldTable;
41
if (oldSchema == null) {
44
oldTable = oldSchema.getTable(newTableName);
48
45
if (oldSchema == null) {
49
46
for (PgIndex index : newTable.getIndexes()) {
47
searchPathHelper.outputSearchPath(writer);
52
index.getCreationSQL(arguments.isQuoteNames()));
49
writer.println(index.getCreationSQL());
55
52
for (PgIndex index : getNewIndexes(
56
53
oldSchema.getTable(newTableName), newTable)) {
54
searchPathHelper.outputSearchPath(writer);
59
index.getCreationSQL(arguments.isQuoteNames()));
56
writer.println(index.getCreationSQL());
66
* Outputs commands for dropping indexes that exist no more.
63
* Outputs statements for dropping indexes that exist no more.
68
65
* @param writer writer the output should be written to
69
* @param arguments object containing arguments settings
70
66
* @param oldSchema original schema
71
67
* @param newSchema new schema
68
* @param searchPathHelper search path helper
73
70
public static void dropIndexes(final PrintWriter writer,
74
final PgDiffArguments arguments, final PgSchema oldSchema,
75
final PgSchema newSchema) {
71
final PgSchema oldSchema, final PgSchema newSchema,
72
final SearchPathHelper searchPathHelper) {
76
73
for (final PgTable newTable : newSchema.getTables()) {
77
74
final String newTableName = newTable.getName();
78
75
final PgTable oldTable;
105
103
private static List<PgIndex> getDropIndexes(final PgTable oldTable,
106
104
final PgTable newTable) {
105
@SuppressWarnings("CollectionWithoutInitialCapacity")
107
106
final List<PgIndex> list = new ArrayList<PgIndex>();
109
if ((newTable != null) && (oldTable != null)) {
108
if (newTable != null && oldTable != null) {
110
109
for (final PgIndex index : oldTable.getIndexes()) {
111
110
if (!newTable.containsIndex(index.getName())
112
111
|| !newTable.getIndex(index.getName()).equals(index)) {