001: /*
002: * ColumnReference.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.db.report;
013:
014: import workbench.util.StrBuffer;
015: import workbench.util.NumberStringCache;
016:
017: /**
018: *
019: * @author support@sql-workbench.net
020: */
021: public class ColumnReference {
022: public static final String TAG_REFERENCE = "references";
023: public static final String TAG_CONSTRAINT_NAME = "constraint-name";
024: public static final String TAG_UPDATE_RULE = "update-rule";
025: public static final String TAG_DELETE_RULE = "delete-rule";
026: public static final String TAG_DEFER_RULE = "deferrable";
027:
028: private String fkName;
029: private String foreignColumn;
030: private ReportTable foreignTable;
031: private String updateRule;
032: private String deleteRule;
033: private String deferRule;
034: private TagWriter tagWriter = new TagWriter();
035: private int updateRuleValue;
036: private int deleteRuleValue;
037: private int deferrableRuleValue;
038:
039: public ColumnReference() {
040: }
041:
042: public void setNamespace(String namespace) {
043: this .tagWriter.setNamespace(namespace);
044: }
045:
046: public void setUpdateRuleValue(int value) {
047: this .updateRuleValue = value;
048: }
049:
050: public void setDeleteRuleValue(int value) {
051: this .deleteRuleValue = value;
052: }
053:
054: public void setDeferrableRuleValue(int value) {
055: this .deferrableRuleValue = value;
056: }
057:
058: public void setConstraintName(String name) {
059: this .fkName = name;
060: }
061:
062: public void setForeignColumn(String col) {
063: this .foreignColumn = col;
064: }
065:
066: public void setForeignTable(ReportTable tbl) {
067: this .foreignTable = tbl;
068: }
069:
070: public void setUpdateRule(String rule) {
071: this .updateRule = rule;
072: }
073:
074: public String getUpdateRule() {
075: return this .updateRule;
076: }
077:
078: public void setDeleteRule(String rule) {
079: this .deleteRule = rule;
080: }
081:
082: public String getDeleteRule() {
083: return deleteRule;
084: }
085:
086: public void setDeferRule(String rule) {
087: this .deferRule = rule;
088: }
089:
090: public ReportTable getForeignTable() {
091: return this .foreignTable;
092: }
093:
094: public String getFkName() {
095: return fkName;
096: }
097:
098: public String getForeignColumn() {
099: return foreignColumn;
100: }
101:
102: public String toString() {
103: return this .getFkName();
104: }
105:
106: public StrBuffer getXml(StrBuffer indent) {
107: StrBuffer result = new StrBuffer(250);
108: StrBuffer myindent = new StrBuffer(indent);
109: myindent.append(" ");
110: tagWriter.appendOpenTag(result, indent, TAG_REFERENCE);
111: result.append('\n');
112:
113: result.append(getInnerXml(myindent));
114:
115: tagWriter.appendCloseTag(result, indent, TAG_REFERENCE);
116:
117: return result;
118: }
119:
120: public StrBuffer getInnerXml(StrBuffer indent) {
121: StrBuffer result = new StrBuffer(250);
122: this .foreignTable.appendTableNameXml(result, indent);
123: //tagWriter.appendTag(result, indent, ReportTable.TAG_TABLE_NAME, this.foreignTable);
124: tagWriter.appendTag(result, indent,
125: ReportColumn.TAG_COLUMN_NAME, this .foreignColumn);
126: tagWriter.appendTag(result, indent, TAG_CONSTRAINT_NAME,
127: this .fkName);
128:
129: tagWriter.appendTag(result, indent, TAG_DELETE_RULE,
130: this .deleteRule, "jdbcValue", NumberStringCache
131: .getNumberString(this .deleteRuleValue));
132: tagWriter.appendTag(result, indent, TAG_UPDATE_RULE,
133: this .updateRule, "jdbcValue", NumberStringCache
134: .getNumberString(this .updateRuleValue));
135: tagWriter.appendTag(result, indent, TAG_DEFER_RULE,
136: this .deferRule, "jdbcValue", NumberStringCache
137: .getNumberString(this .deferrableRuleValue));
138: return result;
139: }
140:
141: public boolean equals(Object o) {
142: if (o == null)
143: return false;
144: if (o instanceof ColumnReference)
145: return equals((ColumnReference) o);
146: return false;
147: }
148:
149: public boolean equals(ColumnReference ref) {
150: try {
151: return (this .foreignColumn.equals(ref.foreignColumn)
152: && this .foreignTable.equals(ref.foreignTable)
153: && (this .updateRuleValue == ref.updateRuleValue)
154: && (this .deleteRuleValue == ref.deleteRuleValue) && (this .deferrableRuleValue == ref.deferrableRuleValue));
155: } catch (Exception e) {
156: return false;
157: }
158: }
159: }
|