~ubuntu-branches/ubuntu/raring/apgdiff/raring

« 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-11 09:08:18 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20101011090818-sdw8yfemrnxo328k
Tags: 2.2.2-1
* New upstream version.
* Using changelog included in zipfile, thanks Miroslav for providing this.
* Update manpage.

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
 
36
     * @param searchPathHelper search path helper
33
37
     */
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;
40
 
 
41
 
            if (oldSchema == null) {
42
 
                oldTable = null;
43
 
            } else {
44
 
                oldTable = oldSchema.getTable(newTableName);
45
 
            }
46
43
 
47
44
            // Add new indexes
48
45
            if (oldSchema == null) {
49
46
                for (PgIndex index : newTable.getIndexes()) {
 
47
                    searchPathHelper.outputSearchPath(writer);
50
48
                    writer.println();
51
 
                    writer.println(
52
 
                            index.getCreationSQL(arguments.isQuoteNames()));
 
49
                    writer.println(index.getCreationSQL());
53
50
                }
54
51
            } else {
55
52
                for (PgIndex index : getNewIndexes(
56
53
                        oldSchema.getTable(newTableName), newTable)) {
 
54
                    searchPathHelper.outputSearchPath(writer);
57
55
                    writer.println();
58
 
                    writer.println(
59
 
                            index.getCreationSQL(arguments.isQuoteNames()));
 
56
                    writer.println(index.getCreationSQL());
60
57
                }
61
58
            }
62
59
        }
63
60
    }
64
61
 
65
62
    /**
66
 
     * Outputs commands for dropping indexes that exist no more.
 
63
     * Outputs statements for dropping indexes that exist no more.
67
64
     *
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
72
69
     */
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;
85
82
 
86
83
            // Drop indexes that do not exist in new schema or are modified
87
84
            for (final PgIndex index : getDropIndexes(oldTable, newTable)) {
 
85
                searchPathHelper.outputSearchPath(writer);
88
86
                writer.println();
89
 
                writer.println(index.getDropSQL(arguments.isQuoteNames()));
 
87
                writer.println(index.getDropSQL());
90
88
            }
91
89
        }
92
90
    }
104
102
     */
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>();
108
107
 
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)) {
128
127
     */
129
128
    private static List<PgIndex> getNewIndexes(final PgTable oldTable,
130
129
            final PgTable newTable) {
 
130
        @SuppressWarnings("CollectionWithoutInitialCapacity")
131
131
        final List<PgIndex> list = new ArrayList<PgIndex>();
132
132
 
133
133
        if (newTable != null) {