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

« back to all changes in this revision

Viewing changes to src/main/java/cz/startnet/utils/pgdiff/schema/PgSchema.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.schema;
2
7
 
3
8
import cz.startnet.utils.pgdiff.PgDiffUtils;
4
9
 
5
10
import java.util.ArrayList;
 
11
import java.util.Collections;
6
12
import java.util.List;
7
13
 
8
14
/**
15
21
    /**
16
22
     * List of functions defined in the schema.
17
23
     */
 
24
    @SuppressWarnings("CollectionWithoutInitialCapacity")
18
25
    private final List<PgFunction> functions = new ArrayList<PgFunction>();
19
26
    /**
20
27
     * List of sequences defined in the schema.
21
28
     */
 
29
    @SuppressWarnings("CollectionWithoutInitialCapacity")
22
30
    private final List<PgSequence> sequences = new ArrayList<PgSequence>();
23
31
    /**
24
32
     * List of tables defined in the schema.
25
33
     */
 
34
    @SuppressWarnings("CollectionWithoutInitialCapacity")
26
35
    private final List<PgTable> tables = new ArrayList<PgTable>();
27
36
    /**
28
37
     * List of views defined in the schema.
29
38
     */
 
39
    @SuppressWarnings("CollectionWithoutInitialCapacity")
30
40
    private final List<PgView> views = new ArrayList<PgView>();
31
41
    /**
32
42
     * Name of the schema.
36
46
     * Schema authorization.
37
47
     */
38
48
    private String authorization;
 
49
    /**
 
50
     * Optional definition of schema elements.
 
51
     */
 
52
    private String definition;
39
53
 
40
54
    /**
41
55
     * Creates a new PgSchema object.
43
57
     * @param name {@link #name}
44
58
     */
45
59
    public PgSchema(final String name) {
46
 
        super();
47
60
        this.name = name;
48
61
    }
49
62
 
66
79
    }
67
80
 
68
81
    /**
 
82
     * Getter for {@link #definition}.
 
83
     *
 
84
     * @return {@link #definition}
 
85
     */
 
86
    public String getDefinition() {
 
87
        return definition;
 
88
    }
 
89
 
 
90
    /**
 
91
     * Setter for {@link #definition}.
 
92
     *
 
93
     * @param definition {@link #definition}
 
94
     */
 
95
    public void setDefinition(final String definition) {
 
96
        this.definition = definition;
 
97
    }
 
98
 
 
99
    /**
69
100
     * Creates and returns SQL for creation of the schema.
70
101
     *
71
 
     * @param quoteNames whether names should be quoted
72
 
     *
73
102
     * @return created SQL
74
103
     */
75
 
    public String getCreationSQL(final boolean quoteNames) {
76
 
        final StringBuilder sbSQL = new StringBuilder();
 
104
    public String getCreationSQL() {
 
105
        final StringBuilder sbSQL = new StringBuilder(50);
77
106
        sbSQL.append("CREATE SCHEMA ");
78
 
        sbSQL.append(PgDiffUtils.getQuotedName(getName(), quoteNames));
 
107
        sbSQL.append(PgDiffUtils.getQuotedName(getName()));
79
108
 
80
109
        if (getAuthorization() != null) {
81
110
            sbSQL.append(" AUTHORIZATION ");
82
 
            sbSQL.append(
83
 
                    PgDiffUtils.getQuotedName(getAuthorization(), quoteNames));
 
111
            sbSQL.append(PgDiffUtils.getQuotedName(getAuthorization()));
84
112
        }
85
113
 
86
114
        sbSQL.append(';');
89
117
    }
90
118
 
91
119
    /**
92
 
     * Finds function according to specified function
93
 
     * <code>declaration</code>.
 
120
     * Finds function according to specified function <code>signature</code>.
94
121
     *
95
 
     * @param declaration declaration of the function to be searched
 
122
     * @param signature signature of the function to be searched
96
123
     *
97
124
     * @return found function or null if no such function has been found
98
125
     */
99
 
    public PgFunction getFunction(final String declaration) {
100
 
        PgFunction function = null;
101
 
 
102
 
        for (PgFunction curFunction : functions) {
103
 
            if (curFunction.getDeclaration().equals(declaration)) {
104
 
                function = curFunction;
105
 
 
106
 
                break;
 
126
    public PgFunction getFunction(final String signature) {
 
127
        for (PgFunction function : functions) {
 
128
            if (function.getSignature().equals(signature)) {
 
129
                return function;
107
130
            }
108
131
        }
109
132
 
110
 
        return function;
 
133
        return null;
111
134
    }
112
135
 
113
136
    /**
114
 
     * Getter for {@link #functions}.
 
137
     * Getter for {@link #functions}. The list cannot be modified.
115
138
     *
116
139
     * @return {@link #functions}
117
140
     */
118
141
    public List<PgFunction> getFunctions() {
119
 
        return functions;
 
142
        return Collections.unmodifiableList(functions);
120
143
    }
121
144
 
122
145
    /**
151
174
    }
152
175
 
153
176
    /**
154
 
     * Getter for {@link #sequences}.
 
177
     * Getter for {@link #sequences}. The list cannot be modified.
155
178
     *
156
179
     * @return {@link #sequences}
157
180
     */
158
181
    public List<PgSequence> getSequences() {
159
 
        return sequences;
 
182
        return Collections.unmodifiableList(sequences);
160
183
    }
161
184
 
162
185
    /**
181
204
    }
182
205
 
183
206
    /**
184
 
     * Getter for {@link #tables}.
 
207
     * Getter for {@link #tables}. The list cannot be modified.
185
208
     *
186
209
     * @return {@link #tables}
187
210
     */
188
211
    public List<PgTable> getTables() {
189
 
        return tables;
 
212
        return Collections.unmodifiableList(tables);
190
213
    }
191
214
 
192
215
    /**
211
234
    }
212
235
 
213
236
    /**
214
 
     * Getter for {@link #views}.
 
237
     * Getter for {@link #views}. The list cannot be modified.
215
238
     *
216
239
     * @return {@link #views}
217
240
     */
218
241
    public List<PgView> getViews() {
219
 
        return views;
 
242
        return Collections.unmodifiableList(views);
220
243
    }
221
244
 
222
245
    /**
257
280
 
258
281
    /**
259
282
     * Returns true if schema contains function with given
260
 
     * <code>declaration</code>, otherwise false.
 
283
     * <code>signature</code>, otherwise false.
261
284
     *
262
 
     * @param declaration declaration of the function
 
285
     * @param signature signature of the function
263
286
     *
264
287
     * @return true if schema contains function with given
265
 
     *         <code>declaration</code>, otherwise false
 
288
     *         <code>signature</code>, otherwise false
266
289
     */
267
 
    public boolean containsFunction(final String declaration) {
268
 
        boolean found = false;
269
 
 
 
290
    public boolean containsFunction(final String signature) {
270
291
        for (PgFunction function : functions) {
271
 
            if (function.getDeclaration().equals(declaration)) {
272
 
                found = true;
273
 
 
274
 
                break;
 
292
            if (function.getSignature().equals(signature)) {
 
293
                return true;
275
294
            }
276
295
        }
277
296
 
278
 
        return found;
 
297
        return false;
279
298
    }
280
299
 
281
300
    /**