1 |
|
package org.apache.torque.engine.database.model; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.Hashtable; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.apache.commons.collections.map.ListOrderedMap; |
29 |
|
import org.xml.sax.Attributes; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@author |
35 |
|
@author |
36 |
|
@author |
37 |
|
@version |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 86 (86) |
Complexity: 32 |
Complexity Density: 0.65 |
|
39 |
|
public class ForeignKey |
40 |
|
{ |
41 |
|
private String foreignTableName; |
42 |
|
private String name; |
43 |
|
private String onUpdate; |
44 |
|
private String onDelete; |
45 |
|
private Table parentTable; |
46 |
|
private List localColumns = new ArrayList(3); |
47 |
|
private List foreignColumns = new ArrayList(3); |
48 |
|
private Map options = Collections.synchronizedMap(new ListOrderedMap()); |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private static final String NONE = "NONE"; |
53 |
|
private static final String SETNULL = "SETNULL"; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
60 |
0
|
public void loadFromXML(Attributes attrib)... |
61 |
|
{ |
62 |
0
|
foreignTableName = attrib.getValue("foreignTable"); |
63 |
0
|
name = attrib.getValue("name"); |
64 |
0
|
onUpdate = attrib.getValue("onUpdate"); |
65 |
0
|
onDelete = attrib.getValue("onDelete"); |
66 |
0
|
onUpdate = normalizeFKey(onUpdate); |
67 |
0
|
onDelete = normalizeFKey(onDelete); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
@return |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
76 |
0
|
private String normalizeFKey(String attrib)... |
77 |
|
{ |
78 |
0
|
if (attrib == null) |
79 |
|
{ |
80 |
0
|
attrib = NONE; |
81 |
|
} |
82 |
|
|
83 |
0
|
attrib = attrib.toUpperCase(); |
84 |
0
|
if (attrib.equals(SETNULL)) |
85 |
|
{ |
86 |
0
|
attrib = "SET NULL"; |
87 |
|
} |
88 |
0
|
return attrib; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@return |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0
|
public boolean hasOnUpdate()... |
97 |
|
{ |
98 |
0
|
return !onUpdate.equals(NONE); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
@return |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
0
|
public boolean hasOnDelete()... |
107 |
|
{ |
108 |
0
|
return !onDelete.equals(NONE); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@return |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0
|
public String getOnUpdate()... |
117 |
|
{ |
118 |
0
|
return onUpdate; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@return |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0
|
public String getOnDelete()... |
127 |
|
{ |
128 |
0
|
return onDelete; |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0
|
public void setOnDelete(String value)... |
137 |
|
{ |
138 |
0
|
onDelete = normalizeFKey(value); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@param |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
0
|
public void setOnUpdate(String value)... |
147 |
|
{ |
148 |
0
|
onUpdate = normalizeFKey(value); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
@return |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0
|
public String getName()... |
157 |
|
{ |
158 |
0
|
return name; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@param |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0
|
public void setName(String name)... |
167 |
|
{ |
168 |
0
|
this.name = name; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@return |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
0
|
public String getForeignTableName()... |
177 |
|
{ |
178 |
0
|
return foreignTableName; |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@param |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
186 |
0
|
public void setForeignTableName(String tableName)... |
187 |
|
{ |
188 |
0
|
foreignTableName = tableName; |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
@param |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0
|
public void setTable(Table parent)... |
197 |
|
{ |
198 |
0
|
parentTable = parent; |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@return |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0
|
public Table getTable()... |
207 |
|
{ |
208 |
0
|
return parentTable; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
@return |
215 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
0
|
public String getTableName()... |
217 |
|
{ |
218 |
0
|
return parentTable.getName(); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
@param |
225 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
0
|
public void addReference(Attributes attrib)... |
227 |
|
{ |
228 |
0
|
addReference(attrib.getValue("local"), attrib.getValue("foreign")); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
@param |
235 |
|
@param |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
237 |
0
|
public void addReference(String local, String foreign)... |
238 |
|
{ |
239 |
0
|
localColumns.add(local); |
240 |
0
|
foreignColumns.add(foreign); |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
@return |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
248 |
0
|
public String getLocalColumnNames()... |
249 |
|
{ |
250 |
0
|
return Column.makeList(getLocalColumns()); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
@return |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
258 |
0
|
public String getForeignColumnNames()... |
259 |
|
{ |
260 |
0
|
return Column.makeList(getForeignColumns()); |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
@return |
267 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
268 |
0
|
public List getLocalColumns()... |
269 |
|
{ |
270 |
0
|
return localColumns; |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
@return |
278 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
279 |
0
|
public Hashtable getLocalForeignMapping()... |
280 |
|
{ |
281 |
0
|
Hashtable h = new Hashtable(); |
282 |
|
|
283 |
0
|
for (int i = 0; i < localColumns.size(); i++) |
284 |
|
{ |
285 |
0
|
h.put(localColumns.get(i), foreignColumns.get(i)); |
286 |
|
} |
287 |
|
|
288 |
0
|
return h; |
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
@return |
295 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
296 |
0
|
public List getForeignColumns()... |
297 |
|
{ |
298 |
0
|
return foreignColumns; |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
@return |
306 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
307 |
0
|
public Hashtable getForeignLocalMapping()... |
308 |
|
{ |
309 |
0
|
Hashtable h = new Hashtable(); |
310 |
|
|
311 |
0
|
for (int i = 0; i < localColumns.size(); i++) |
312 |
|
{ |
313 |
0
|
h.put(foreignColumns.get(i), localColumns.get(i)); |
314 |
|
} |
315 |
|
|
316 |
0
|
return h; |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
@return |
323 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
324 |
0
|
public String toString()... |
325 |
|
{ |
326 |
0
|
StringBuffer result = new StringBuffer(); |
327 |
0
|
result.append(" <foreign-key foreignTable=\"") |
328 |
|
.append(getForeignTableName()) |
329 |
|
.append("\" name=\"") |
330 |
|
.append(getName()) |
331 |
|
.append("\">\n"); |
332 |
|
|
333 |
0
|
for (int i = 0; i < localColumns.size(); i++) |
334 |
|
{ |
335 |
0
|
result.append(" <reference local=\"") |
336 |
|
.append(localColumns.get(i)) |
337 |
|
.append("\" foreign=\"") |
338 |
|
.append(foreignColumns.get(i)) |
339 |
|
.append("\"/>\n"); |
340 |
|
} |
341 |
0
|
result.append(" </foreign-key>\n"); |
342 |
0
|
return result.toString(); |
343 |
|
} |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
@param |
349 |
|
@param |
350 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
351 |
0
|
public void addOption(String key, String value)... |
352 |
|
{ |
353 |
0
|
options.put(key, value); |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
@param |
361 |
|
@return |
362 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
363 |
0
|
public String getOption(String key)... |
364 |
|
{ |
365 |
0
|
return (String) options.get(key); |
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@return |
377 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
378 |
0
|
public Map getOptions()... |
379 |
|
{ |
380 |
0
|
return options; |
381 |
|
} |
382 |
|
} |