~ubuntu-branches/ubuntu/karmic/apgdiff/karmic

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2008-09-09 15:42:54 UTC
  • Revision ID: james.westby@ubuntu.com-20080909154254-458sv7ew1rczdal1
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: PgDiffFunctions.java 90 2008-08-01 17:06:19Z fordfrog $
 
3
 */
 
4
package cz.startnet.utils.pgdiff;
 
5
 
 
6
import cz.startnet.utils.pgdiff.schema.PgFunction;
 
7
import cz.startnet.utils.pgdiff.schema.PgSchema;
 
8
 
 
9
import java.io.PrintWriter;
 
10
 
 
11
/**
 
12
 * Diffs functions.
 
13
 *
 
14
 * @author fordfrog
 
15
 * @version $Id: PgDiffFunctions.java 90 2008-08-01 17:06:19Z fordfrog $
 
16
 */
 
17
public class PgDiffFunctions {
 
18
 
 
19
    /**
 
20
     * Creates a new instance of PgDiffFunctions.
 
21
     */
 
22
    private PgDiffFunctions() {
 
23
        super();
 
24
    }
 
25
 
 
26
    /**
 
27
     * Outputs commands for differences in functions.
 
28
     *
 
29
     * @param writer writer the output should be written to
 
30
     * @param arguments object containing arguments settings
 
31
     * @param oldSchema original schema
 
32
     * @param newSchema new schema
 
33
     */
 
34
    public static void diffFunctions(
 
35
        final PrintWriter writer,
 
36
        final PgDiffArguments arguments,
 
37
        final PgSchema oldSchema,
 
38
        final PgSchema newSchema) {
 
39
        // Drop functions that exist no more
 
40
        if (oldSchema != null) {
 
41
            for (PgFunction oldFunction : oldSchema.getFunctions()) {
 
42
                if (!newSchema.containsFunction(oldFunction.getDeclaration())) {
 
43
                    writer.println();
 
44
                    writer.println(oldFunction.getDropSQL());
 
45
                }
 
46
            }
 
47
        }
 
48
 
 
49
        // Add new functions and replace modified functions
 
50
        for (PgFunction newFunction : newSchema.getFunctions()) {
 
51
            final PgFunction oldFunction;
 
52
 
 
53
            if (oldSchema == null) {
 
54
                oldFunction = null;
 
55
            } else {
 
56
                oldFunction = oldSchema.getFunction(
 
57
                    newFunction.getDeclaration());
 
58
            }
 
59
 
 
60
            if ((oldFunction == null) || !newFunction.equals(oldFunction,
 
61
                arguments.isIgnoreFunctionWhitespace())) {
 
62
                writer.println();
 
63
                writer.println(newFunction.getCreationSQL());
 
64
            }
 
65
        }
 
66
    }
 
67
}