1 package pl.aislib.tools.mapping.db;
2
3 import java.sql.DatabaseMetaData;
4
5 import org.jdom.CDATA;
6 import org.jdom.Element;
7
8 /***
9 * @author Micha? Ja?tak, AIS.PL
10 */
11 public class ForeignKey {
12
13 private Short fkDeleteRule;
14 private Short fkUpdateRule;
15 private String fkCatalog;
16 private String fkDestinationColumnName;
17 private String fkDestinationTableName;
18 private String fkDestinationName;
19 private String fkSchema;
20 private String fkSourceName;
21 private String fkSourceColumnName;
22 private String fkSourceTableName;
23
24 /***
25 *
26 */
27 protected ForeignKey(String tSourceColumnName) {
28 fkSourceColumnName = tSourceColumnName;
29 }
30
31 /***
32 *
33 */
34 public String getSourceColumnName() {
35 return ((fkSourceColumnName != null) ? new String (fkSourceColumnName) : fkSourceColumnName);
36 }
37
38 /***
39 *
40 */
41 public void setCatalog(String tCatalog) {
42 fkCatalog = tCatalog;
43 }
44
45 /***
46 *
47 */
48 public void setDeleteRule(short tDeleteRule) {
49 fkDeleteRule = new Short(tDeleteRule);
50 }
51
52 /***
53 *
54 */
55 public void setDestinationColumnName(String tDestinationColumnName) {
56 fkDestinationColumnName = tDestinationColumnName;
57 }
58
59 /***
60 *
61 */
62 public void setDestinationName(String tDestinationName) {
63 fkDestinationName = tDestinationName;
64 }
65
66 /***
67 *
68 */
69 public void setDestinationTableName(String tDestinationTableName) {
70 fkDestinationTableName = tDestinationTableName;
71 }
72
73 /***
74 *
75 */
76 public void setSchema(String tSchema) {
77 fkSchema = tSchema;
78 }
79
80 /***
81 *
82 */
83 public void setSourceName(String tSourceName) {
84 fkSourceName = tSourceName;
85 }
86
87 /***
88 *
89 */
90 public void setSourceTableName(String tSourceTableName) {
91 fkSourceTableName = tSourceTableName;
92 }
93
94 /***
95 *
96 */
97 public void setUpdateRule(short tUpdateRule) {
98 fkUpdateRule = new Short(tUpdateRule);
99 }
100
101 /***
102 * FIXME
103 */
104 public String toString() {
105 return new String("");
106 }
107
108 /***
109 * FIXME
110 */
111 private String describeRule(short rule) {
112 String result = null;
113 switch (rule) {
114 case DatabaseMetaData.importedKeyNoAction:
115 result = "No action";
116 break;
117 case DatabaseMetaData.importedKeyCascade:
118 result = "No action";
119 break;
120 }
121 return result;
122 }
123
124 /***
125 * FIXME
126 */
127 public Element toXML() {
128 Element result = new Element ("foreign-key");
129
130 result.setAttribute ("src-column-name", fkSourceColumnName);
131 result.setAttribute ("src-table-name", fkSourceTableName);
132 result.setAttribute ("dest-column-name", fkDestinationColumnName);
133 result.setAttribute ("dest-table-name", fkDestinationTableName);
134
135 if (fkSourceName != null) {
136 result.setAttribute ("src-name", fkSourceName);
137 }
138
139 if (fkDestinationName != null) {
140 result.setAttribute ("dest-name", fkDestinationName);
141 }
142
143 String temp = null;
144 if (fkUpdateRule != null) {
145 temp = describeRule (fkUpdateRule.shortValue());
146 if (temp != null) {
147 result.setAttribute ("update-rule", temp);
148 }
149 }
150
151 if (fkDeleteRule != null) {
152 temp = describeRule (fkDeleteRule.shortValue());
153 if (temp != null) {
154 result.setAttribute ("delete-rule", temp);
155 }
156 }
157
158 return result;
159 }
160
161 }