~ubuntu-branches/ubuntu/vivid/apgdiff/vivid

« back to all changes in this revision

Viewing changes to src/main/java/cz/startnet/utils/pgdiff/PgDiffIndexes.java

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2010-10-02 19:35:17 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101002193517-9wesve8sksxcktkc
Tags: 2.2-1
* New upstream version.
* Update homepage location.
* Finally enable test suite, yay!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2006 StartNet s.r.o.
 
3
 *
 
4
 * Distributed under MIT license
 
5
 */
1
6
package cz.startnet.utils.pgdiff;
2
7
 
3
8
import cz.startnet.utils.pgdiff.schema.PgIndex;
20
25
     * Creates a new instance of PgDiffIndexes.
21
26
     */
22
27
    private PgDiffIndexes() {
23
 
        super();
24
28
    }
25
29
 
26
30
    /**
27
 
     * Outputs commands for creation of new indexes.
 
31
     * Outputs statements for creation of new indexes.
28
32
     *
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
33
36
     */
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;
40
 
 
41
 
            if (oldSchema == null) {
42
 
                oldTable = null;
43
 
            } else {
44
 
                oldTable = oldSchema.getTable(newTableName);
45
 
            }
46
41
 
47
42
            // Add new indexes
48
43
            if (oldSchema == null) {
49
44
                for (PgIndex index : newTable.getIndexes()) {
50
45
                    writer.println();
51
 
                    writer.println(
52
 
                            index.getCreationSQL(arguments.isQuoteNames()));
 
46
                    writer.println(index.getCreationSQL());
53
47
                }
54
48
            } else {
55
49
                for (PgIndex index : getNewIndexes(
56
50
                        oldSchema.getTable(newTableName), newTable)) {
57
51
                    writer.println();
58
 
                    writer.println(
59
 
                            index.getCreationSQL(arguments.isQuoteNames()));
 
52
                    writer.println(index.getCreationSQL());
60
53
                }
61
54
            }
62
55
        }
63
56
    }
64
57
 
65
58
    /**
66
 
     * Outputs commands for dropping indexes that exist no more.
 
59
     * Outputs statements for dropping indexes that exist no more.
67
60
     *
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
72
64
     */
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)) {
88
79
                writer.println();
89
 
                writer.println(index.getDropSQL(arguments.isQuoteNames()));
 
80
                writer.println(index.getDropSQL());
90
81
            }
91
82
        }
92
83
    }
104
95
     */
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>();
108
100
 
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)) {
128
120
     */
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>();
132
125
 
133
126
        if (newTable != null) {