01: /*
02: * SequenceDiff.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.diff;
13:
14: import workbench.db.report.ReportSequence;
15: import workbench.db.report.TagWriter;
16: import workbench.util.StrBuffer;
17:
18: /**
19: * Compares two database sequences for differences in their definition.
20: *
21: * @author support@sql-workbench.net
22: */
23: public class SequenceDiff {
24: public static final String TAG_CREATE_SEQUENCE = "create-sequence";
25: public static final String TAG_UPDATE_SEQUENCE = "update-sequence";
26:
27: private ReportSequence reference;
28: private ReportSequence target;
29: private TagWriter writer;
30: private StrBuffer indent;
31:
32: public SequenceDiff(ReportSequence ref, ReportSequence tar) {
33: reference = ref;
34: target = tar;
35: }
36:
37: public StrBuffer getMigrateTargetXml() {
38: StrBuffer result = new StrBuffer(500);
39: if (this .writer == null)
40: this .writer = new TagWriter();
41:
42: StrBuffer myindent = new StrBuffer(indent);
43: myindent.append(" ");
44: boolean createView = (target == null);
45: boolean different = (target == null || !reference.getSequence()
46: .equals(target.getSequence()));
47: if (!different)
48: return result;
49:
50: writer
51: .appendOpenTag(result, this .indent,
52: (createView ? TAG_CREATE_SEQUENCE
53: : TAG_UPDATE_SEQUENCE));
54: result.append('\n');
55: if (different) {
56: result.append(reference.getXml(myindent));
57: }
58: writer
59: .appendCloseTag(result, this .indent,
60: (createView ? TAG_CREATE_SEQUENCE
61: : TAG_UPDATE_SEQUENCE));
62:
63: return result;
64: }
65:
66: /**
67: * Set the {@link workbench.db.report.TagWriter} to
68: * be used for writing the XML tags
69: */
70: public void setTagWriter(TagWriter tagWriter) {
71: this .writer = tagWriter;
72: }
73:
74: /**
75: * Set an indent for generating the XML
76: */
77: public void setIndent(String ind) {
78: if (ind == null)
79: this .indent = null;
80: this .indent = new StrBuffer(ind);
81: }
82:
83: /**
84: * Set an indent for generating the XML
85: */
86: public void setIndent(StrBuffer ind) {
87: this.indent = ind;
88: }
89:
90: }
|