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.Iterator; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.apache.commons.collections.map.ListOrderedMap; |
29 |
|
import org.apache.commons.lang.StringUtils; |
30 |
|
import org.apache.commons.logging.Log; |
31 |
|
import org.apache.commons.logging.LogFactory; |
32 |
|
import org.apache.torque.engine.EngineException; |
33 |
|
import org.apache.torque.engine.platform.Platform; |
34 |
|
import org.apache.torque.engine.platform.PlatformDefaultImpl; |
35 |
|
import org.xml.sax.Attributes; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@author |
41 |
|
@author |
42 |
|
@author |
43 |
|
@author |
44 |
|
@author |
45 |
|
@author |
46 |
|
@author |
47 |
|
@version |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 443 (443) |
Complexity: 147 |
Complexity Density: 0.57 |
|
49 |
|
public class Column { |
50 |
|
private static final SchemaType DEFAULT_TYPE = SchemaType.VARCHAR; |
51 |
|
|
52 |
|
private static Log log = LogFactory.getLog(Column.class); |
53 |
|
private String name; |
54 |
|
private String description; |
55 |
|
private Domain domain = new Domain(); |
56 |
|
private String javaName = null; |
57 |
|
private String javaNamingMethod; |
58 |
|
private boolean isNotNull = false; |
59 |
|
private boolean isProtected = false; |
60 |
|
private String javaType; |
61 |
|
private Table parentTable; |
62 |
|
private int position; |
63 |
|
private boolean isPrimaryKey = false; |
64 |
|
private boolean isUnique = false; |
65 |
|
private boolean isAutoIncrement = false; |
66 |
|
private List referrers; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private String inheritanceType; |
72 |
|
private boolean isInheritance; |
73 |
|
private boolean isEnumeratedClasses; |
74 |
|
private List inheritanceList; |
75 |
|
private boolean needsTransactionInPostgres; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
private int jdbcType; |
80 |
|
|
81 |
|
|
82 |
|
private boolean correctGetters = false; |
83 |
|
|
84 |
|
|
85 |
|
private String inputValidator = null; |
86 |
|
private Map options; |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0
|
public Column() {... |
92 |
0
|
this(null); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@param |
99 |
|
|
100 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
101 |
0
|
public Column(String name) {... |
102 |
0
|
this.name = name; |
103 |
0
|
options = Collections.synchronizedMap(new ListOrderedMap()); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
@param |
110 |
|
|
111 |
|
|
112 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
113 |
0
|
public static String makeList(List columns) {... |
114 |
0
|
Object obj = columns.get(0); |
115 |
0
|
boolean isColumnList = (obj instanceof Column); |
116 |
0
|
if (isColumnList) { |
117 |
0
|
obj = ((Column) obj).getName(); |
118 |
|
} |
119 |
0
|
StringBuffer buf = new StringBuffer((String) obj); |
120 |
0
|
for (int i = 1; i < columns.size(); i++) { |
121 |
0
|
obj = columns.get(i); |
122 |
0
|
if (isColumnList) { |
123 |
0
|
obj = ((Column) obj).getName(); |
124 |
|
} |
125 |
0
|
buf.append(", ").append(obj); |
126 |
|
} |
127 |
0
|
return buf.toString(); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 6 |
Complexity Density: 0.21 |
|
133 |
0
|
public void loadFromXML(Attributes attrib) {... |
134 |
0
|
String dom = attrib.getValue("domain"); |
135 |
0
|
if (StringUtils.isNotEmpty(dom)) { |
136 |
0
|
domain = new Domain(getTable().getDatabase().getDomain(dom)); |
137 |
|
} else { |
138 |
0
|
domain = new Domain(getPlatform().getDomainForSchemaType(DEFAULT_TYPE)); |
139 |
0
|
setType(attrib.getValue("type")); |
140 |
|
} |
141 |
|
|
142 |
0
|
name = attrib.getValue("name"); |
143 |
|
|
144 |
0
|
javaName = attrib.getValue("javaName"); |
145 |
0
|
javaType = attrib.getValue("javaType"); |
146 |
0
|
if (javaType != null && javaType.length() == 0) { |
147 |
0
|
javaType = null; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
0
|
javaNamingMethod = attrib.getValue("javaNamingMethod"); |
153 |
0
|
if (javaNamingMethod == null) { |
154 |
0
|
javaNamingMethod = parentTable.getDatabase().getDefaultJavaNamingMethod(); |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
0
|
String primaryKey = attrib.getValue("primaryKey"); |
159 |
|
|
160 |
0
|
isPrimaryKey = ("true".equals(primaryKey)); |
161 |
|
|
162 |
|
|
163 |
0
|
if ("true".equals(primaryKey)) { |
164 |
0
|
isNotNull = true; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
0
|
String notNull = attrib.getValue("required"); |
170 |
0
|
isNotNull = (notNull != null && "true".equals(notNull)); |
171 |
|
|
172 |
|
|
173 |
0
|
String autoIncrement = attrib.getValue("autoIncrement"); |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
0
|
isAutoIncrement = ("true".equals(autoIncrement) || (isPrimaryKey() && IDMethod.NATIVE.equals(getTable().getIdMethod()) && Platform.IDENTITY.equals(getPlatform().getNativeIdMethod()) && (!"false".equals(autoIncrement)))); |
180 |
|
|
181 |
0
|
domain.replaceDefaultValue(attrib.getValue("default")); |
182 |
|
|
183 |
0
|
domain.replaceSize(attrib.getValue("size")); |
184 |
0
|
domain.replaceScale(attrib.getValue("scale")); |
185 |
|
|
186 |
0
|
inheritanceType = attrib.getValue("inheritance"); |
187 |
0
|
isInheritance = (inheritanceType != null && !inheritanceType.equals("false")); |
188 |
|
|
189 |
0
|
this.inputValidator = attrib.getValue("inputValidator"); |
190 |
0
|
description = attrib.getValue("description"); |
191 |
|
|
192 |
0
|
isProtected = ("true".equals(attrib.getValue("protected"))); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
0
|
public String getFullyQualifiedName() {... |
199 |
0
|
return (parentTable.getName() + '.' + name); |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
0
|
public String getName() {... |
206 |
0
|
return name; |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
0
|
public void setName(String newName) {... |
213 |
0
|
name = newName; |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
0
|
public String getDescription() {... |
220 |
0
|
return description; |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
@param |
227 |
|
|
228 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
229 |
0
|
public void setDescription(String newDescription) {... |
230 |
0
|
description = newDescription; |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
@return |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
238 |
0
|
public String getJavaName() {... |
239 |
0
|
if (javaName == null) { |
240 |
0
|
List inputs = new ArrayList(2); |
241 |
0
|
inputs.add(name); |
242 |
0
|
inputs.add(javaNamingMethod); |
243 |
0
|
try { |
244 |
0
|
javaName = NameFactory.generateName(NameFactory.JAVA_GENERATOR, inputs); |
245 |
|
} catch (EngineException e) { |
246 |
0
|
log.error(e, e); |
247 |
|
} |
248 |
|
} |
249 |
0
|
return StringUtils.capitalize(javaName); |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
@return |
256 |
|
@since |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
258 |
0
|
public String getGetterName() {... |
259 |
0
|
if (("boolean".equalsIgnoreCase(getJavaNative()) && isCorrectGetters())) { |
260 |
0
|
return "is" + StringUtils.capitalize(getJavaName()); |
261 |
|
} else { |
262 |
0
|
return "get" + StringUtils.capitalize(getJavaName()); |
263 |
|
} |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
@return |
270 |
|
@since |
271 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
272 |
0
|
public String getSetterName() {... |
273 |
0
|
return "set" + StringUtils.capitalize(getJavaName()); |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
279 |
0
|
public String getUncapitalisedJavaName() {... |
280 |
0
|
return StringUtils.uncapitalize(getJavaName()); |
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
@return |
291 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
292 |
0
|
public String getPeerJavaName() {... |
293 |
0
|
String peerName = name.toUpperCase(); |
294 |
0
|
if (peerName.equals("TABLE_NAME") || peerName.equals("DATABASE_NAME")) { |
295 |
0
|
peerName = "_" + peerName; |
296 |
|
} |
297 |
0
|
return peerName; |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
303 |
0
|
public void setJavaName(String javaName) {... |
304 |
0
|
this.javaName = javaName; |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
310 |
0
|
public String getJavaType() {... |
311 |
0
|
return javaType; |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
@return |
318 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
319 |
0
|
public int getPosition() {... |
320 |
0
|
return position; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
@param |
327 |
|
|
328 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
329 |
0
|
public void setPosition(int v) {... |
330 |
0
|
this.position = v; |
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
336 |
0
|
public void setTable(Table parent) {... |
337 |
0
|
parentTable = parent; |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
343 |
0
|
public Table getTable() {... |
344 |
0
|
return parentTable; |
345 |
|
} |
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
350 |
0
|
public String getTableName() {... |
351 |
0
|
return parentTable.getName(); |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
357 |
0
|
public Inheritance addInheritance(Attributes attrib) {... |
358 |
0
|
Inheritance inh = new Inheritance(); |
359 |
0
|
inh.loadFromXML(attrib); |
360 |
0
|
addInheritance(inh); |
361 |
|
|
362 |
0
|
return inh; |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
369 |
0
|
public void addInheritance(Inheritance inh) {... |
370 |
0
|
inh.setColumn(this); |
371 |
0
|
if (inheritanceList == null) { |
372 |
0
|
inheritanceList = new ArrayList(); |
373 |
0
|
isEnumeratedClasses = true; |
374 |
|
} |
375 |
0
|
inheritanceList.add(inh); |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
381 |
0
|
public List getChildren() {... |
382 |
0
|
return inheritanceList; |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
389 |
0
|
public boolean isInheritance() {... |
390 |
0
|
return isInheritance; |
391 |
|
} |
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
396 |
0
|
public boolean isEnumeratedClasses() {... |
397 |
0
|
return isEnumeratedClasses; |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
403 |
0
|
public boolean isNotNull() {... |
404 |
0
|
return isNotNull; |
405 |
|
} |
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
410 |
0
|
public void setNotNull(boolean status) {... |
411 |
0
|
isNotNull = status; |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
@return |
418 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
419 |
0
|
public String getNotNullString() {... |
420 |
0
|
return getTable().getDatabase().getPlatform().getNullString(this.isNotNull()); |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
426 |
0
|
public boolean isProtected() {... |
427 |
0
|
return isProtected; |
428 |
|
} |
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
433 |
0
|
public void setProtected(boolean prot) {... |
434 |
0
|
isProtected = prot; |
435 |
|
} |
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
440 |
0
|
public void setPrimaryKey(boolean pk) {... |
441 |
0
|
isPrimaryKey = pk; |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
447 |
0
|
public boolean isPrimaryKey() {... |
448 |
0
|
return isPrimaryKey; |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
454 |
0
|
public void setUnique(boolean u) {... |
455 |
0
|
isUnique = u; |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
461 |
0
|
public boolean isUnique() {... |
462 |
0
|
return isUnique; |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
468 |
0
|
public boolean requiresTransactionInPostgres() {... |
469 |
0
|
return needsTransactionInPostgres; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
475 |
0
|
public boolean isForeignKey() {... |
476 |
0
|
return (getForeignKey() != null); |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
483 |
0
|
public boolean isMultipleFK() {... |
484 |
0
|
ForeignKey fk = getForeignKey(); |
485 |
0
|
if (fk != null) { |
486 |
0
|
Iterator fks = parentTable.getForeignKeys().iterator(); |
487 |
0
|
while (fks.hasNext()) { |
488 |
0
|
ForeignKey key = (ForeignKey) fks.next(); |
489 |
0
|
if (key.getForeignTableName().equals(fk.getForeignTableName()) && !key.getLocalColumns().contains(this.name)) { |
490 |
0
|
return true; |
491 |
|
} |
492 |
|
} |
493 |
|
} |
494 |
|
|
495 |
|
|
496 |
0
|
return false; |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
502 |
0
|
public ForeignKey getForeignKey() {... |
503 |
0
|
return parentTable.getForeignKey(this.name); |
504 |
|
} |
505 |
|
|
506 |
|
|
507 |
|
|
508 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
509 |
0
|
public String getRelatedTableName() {... |
510 |
0
|
ForeignKey fk = getForeignKey(); |
511 |
0
|
return (fk == null ? null : fk.getForeignTableName()); |
512 |
|
} |
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
518 |
0
|
public String getRelatedColumnName() {... |
519 |
0
|
ForeignKey fk = getForeignKey(); |
520 |
0
|
if (fk == null) { |
521 |
0
|
return null; |
522 |
|
} else { |
523 |
0
|
return fk.getLocalForeignMapping().get(this.name).toString(); |
524 |
|
} |
525 |
|
} |
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
530 |
0
|
public void addReferrer(ForeignKey fk) {... |
531 |
0
|
if (referrers == null) { |
532 |
0
|
referrers = new ArrayList(5); |
533 |
|
} |
534 |
0
|
referrers.add(fk); |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
540 |
0
|
public List getReferrers() {... |
541 |
0
|
if (referrers == null) { |
542 |
0
|
referrers = new ArrayList(5); |
543 |
|
} |
544 |
0
|
return referrers; |
545 |
|
} |
546 |
|
|
547 |
|
|
548 |
|
|
549 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
550 |
0
|
public void setType(String torqueType) {... |
551 |
0
|
SchemaType type = SchemaType.getEnum(torqueType); |
552 |
0
|
if (type == null) { |
553 |
0
|
log.warn("SchemaType " + torqueType + " does not exist"); |
554 |
0
|
type = Column.DEFAULT_TYPE; |
555 |
|
} |
556 |
0
|
setType(type); |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
|
|
561 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
562 |
0
|
public void setType(SchemaType torqueType) {... |
563 |
0
|
domain = new Domain(getPlatform().getDomainForSchemaType(torqueType)); |
564 |
0
|
if (torqueType.equals(SchemaType.VARBINARY) || torqueType.equals(SchemaType.BLOB)) { |
565 |
0
|
needsTransactionInPostgres = true; |
566 |
|
} |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
@deprecated |
573 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
574 |
0
|
public Object getType() {... |
575 |
0
|
return TypeMap.getJdbcType(domain.getType()).getName(); |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
581 |
0
|
public Object getTorqueType() {... |
582 |
0
|
return domain.getType().getName(); |
583 |
|
} |
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
@deprecated |
589 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
590 |
0
|
public boolean isString() {... |
591 |
0
|
return (domain.getType().getName().indexOf("CHAR") != -1); |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
598 |
0
|
public boolean needEscapedValue() {... |
599 |
0
|
String torqueType = domain.getType().getName(); |
600 |
0
|
return (torqueType != null) && (torqueType.equals("VARCHAR") || torqueType.equals("LONGVARCHAR") || torqueType.equals("DATE") || torqueType.equals("DATETIME") || torqueType.equals("TIMESTAMP") || torqueType.equals("TIME") || torqueType.equals("CHAR") || torqueType.equals("CLOB")); |
601 |
|
} |
602 |
|
|
603 |
|
|
604 |
|
|
605 |
|
|
606 |
|
@return |
607 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 8 |
Complexity Density: 0.4 |
|
608 |
0
|
public String toString() {... |
609 |
0
|
StringBuffer result = new StringBuffer(); |
610 |
0
|
result.append(" <column name=\"").append(name).append('"'); |
611 |
|
|
612 |
0
|
if (javaName != null) { |
613 |
0
|
result.append(" javaName=\"").append(javaName).append('"'); |
614 |
|
} |
615 |
|
|
616 |
0
|
if (isPrimaryKey) { |
617 |
0
|
result.append(" primaryKey=\"").append(isPrimaryKey).append('"'); |
618 |
|
} |
619 |
|
|
620 |
0
|
if (isNotNull) { |
621 |
0
|
result.append(" required=\"true\""); |
622 |
|
} else { |
623 |
0
|
result.append(" required=\"false\""); |
624 |
|
} |
625 |
|
|
626 |
0
|
result.append(" type=\"").append(domain.getType().getName()).append('"'); |
627 |
|
|
628 |
0
|
if (domain.getSize() != null) { |
629 |
0
|
result.append(" size=\"").append(domain.getSize()).append('"'); |
630 |
|
} |
631 |
|
|
632 |
0
|
if (domain.getScale() != null) { |
633 |
0
|
result.append(" scale=\"").append(domain.getScale()).append('"'); |
634 |
|
} |
635 |
|
|
636 |
0
|
if (domain.getDefaultValue() != null) { |
637 |
0
|
result.append(" default=\"").append(domain.getDefaultValue()).append('"'); |
638 |
|
} |
639 |
|
|
640 |
0
|
if (isInheritance()) { |
641 |
0
|
result.append(" inheritance=\"").append(inheritanceType).append('"'); |
642 |
|
} |
643 |
|
|
644 |
|
|
645 |
0
|
result.append(" />\n"); |
646 |
|
|
647 |
0
|
return result.toString(); |
648 |
|
} |
649 |
|
|
650 |
|
|
651 |
|
|
652 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
653 |
0
|
public String getSize() {... |
654 |
0
|
return domain.getSize(); |
655 |
|
} |
656 |
|
|
657 |
|
|
658 |
|
|
659 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
660 |
0
|
public void setSize(String newSize) {... |
661 |
0
|
domain.setSize(newSize); |
662 |
|
} |
663 |
|
|
664 |
|
|
665 |
|
|
666 |
|
|
667 |
|
|
668 |
|
|
669 |
|
|
670 |
|
|
671 |
|
@return |
672 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
673 |
0
|
public String getPrecision() {... |
674 |
0
|
String size = getSize(); |
675 |
0
|
if (size == null) { |
676 |
0
|
return size; |
677 |
|
} |
678 |
0
|
int cLoc = size.indexOf(','); |
679 |
0
|
if (cLoc > 0) { |
680 |
0
|
size = size.substring(0, cLoc); |
681 |
|
} |
682 |
0
|
try { |
683 |
0
|
Integer.parseInt(size); |
684 |
|
} catch (NumberFormatException e) { |
685 |
0
|
log.warn("getPrecision(): Size attribute found (" + getSize() + ") was not an integer number, using default of null!"); |
686 |
0
|
size = null; |
687 |
|
} |
688 |
0
|
return size; |
689 |
|
} |
690 |
|
|
691 |
|
|
692 |
|
|
693 |
|
|
694 |
|
|
695 |
|
|
696 |
|
|
697 |
|
|
698 |
|
@return |
699 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
700 |
0
|
public String getScale() {... |
701 |
0
|
String scale = domain.getScale(); |
702 |
|
|
703 |
0
|
if (scale == null) { |
704 |
0
|
scale = getSize(); |
705 |
0
|
if (scale == null) |
706 |
|
{ |
707 |
0
|
return scale; |
708 |
|
} |
709 |
0
|
int cLoc = scale.indexOf(','); |
710 |
0
|
if (cLoc < 0) |
711 |
|
{ |
712 |
0
|
return null; |
713 |
|
} |
714 |
0
|
scale = scale.substring(cLoc + 1); |
715 |
|
} |
716 |
|
|
717 |
|
|
718 |
0
|
try { |
719 |
0
|
Integer.parseInt(scale); |
720 |
|
} catch (NumberFormatException e) { |
721 |
0
|
log.warn("getScale(): Scale (or size=\"p,s\") attribute found (" + scale + ") was not an integer number, using default of null."); |
722 |
0
|
scale = null; |
723 |
|
} |
724 |
0
|
return scale; |
725 |
|
} |
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
730 |
0
|
public void setScale(String newScale) {... |
731 |
0
|
domain.setScale(newScale); |
732 |
|
} |
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
|
737 |
|
@return |
738 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
739 |
0
|
public String printSize() {... |
740 |
0
|
return domain.printSize(); |
741 |
|
} |
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
|
@deprecated |
747 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
748 |
0
|
public String getDefaultSetting() {... |
749 |
0
|
return domain.getDefaultSetting(); |
750 |
|
} |
751 |
|
|
752 |
|
|
753 |
|
|
754 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
755 |
0
|
public void setDefaultValue(String def) {... |
756 |
0
|
domain.setDefaultValue(def); |
757 |
|
} |
758 |
|
|
759 |
|
|
760 |
|
|
761 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
762 |
0
|
public String getDefaultValue() {... |
763 |
0
|
return domain.getDefaultValue(); |
764 |
|
} |
765 |
|
|
766 |
|
|
767 |
|
|
768 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
769 |
0
|
public String getInputValidator() {... |
770 |
0
|
return this.inputValidator; |
771 |
|
} |
772 |
|
|
773 |
|
|
774 |
|
|
775 |
|
|
776 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
777 |
0
|
public boolean isAutoIncrement() {... |
778 |
0
|
return isAutoIncrement; |
779 |
|
} |
780 |
|
|
781 |
|
|
782 |
|
|
783 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
784 |
0
|
public void setAutoIncrement(boolean value) {... |
785 |
0
|
isAutoIncrement = value; |
786 |
|
} |
787 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
788 |
0
|
public String getAutoIncrementString() {... |
789 |
0
|
if (isAutoIncrement() && IDMethod.NATIVE.equals(getTable().getIdMethod())) { |
790 |
0
|
return getPlatform().getAutoIncrement(); |
791 |
|
} |
792 |
0
|
return ""; |
793 |
|
} |
794 |
|
|
795 |
|
|
796 |
|
|
797 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 8 |
Complexity Density: 0.47 |
|
798 |
0
|
public void setTypeFromString(String typeName, String size) {... |
799 |
0
|
String tn = typeName.toUpperCase(); |
800 |
0
|
setType(tn); |
801 |
|
|
802 |
0
|
if (size != null) { |
803 |
0
|
domain.setSize(size); |
804 |
|
} |
805 |
|
|
806 |
0
|
if (tn.indexOf("CHAR") != -1) { |
807 |
0
|
domain.setType(SchemaType.VARCHAR); |
808 |
0
|
} else if (tn.indexOf("INT") != -1) { |
809 |
0
|
domain.setType(SchemaType.INTEGER); |
810 |
0
|
} else if (tn.indexOf("FLOAT") != -1) { |
811 |
0
|
domain.setType(SchemaType.FLOAT); |
812 |
0
|
} else if (tn.indexOf("DATE") != -1) { |
813 |
0
|
domain.setType(SchemaType.DATE); |
814 |
0
|
} else if (tn.indexOf("TIME") != -1) { |
815 |
0
|
domain.setType(SchemaType.TIMESTAMP); |
816 |
0
|
} else if (tn.indexOf("BINARY") != -1) { |
817 |
0
|
domain.setType(SchemaType.LONGVARBINARY); |
818 |
|
} else { |
819 |
0
|
domain.setType(SchemaType.VARCHAR); |
820 |
|
} |
821 |
|
} |
822 |
|
|
823 |
|
|
824 |
|
|
825 |
|
|
826 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
827 |
0
|
public String getJavaObject() {... |
828 |
0
|
return TypeMap.getJavaObject(domain.getType()); |
829 |
|
} |
830 |
|
|
831 |
|
|
832 |
|
|
833 |
|
|
834 |
|
@return |
835 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
836 |
0
|
public String getJavaPrimitive() {... |
837 |
0
|
return TypeMap.getJavaNative(domain.getType()); |
838 |
|
} |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
|
|
844 |
|
|
845 |
|
@return |
846 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
847 |
0
|
public String getJavaNative() {... |
848 |
0
|
String jtype = TypeMap.getJavaNativeObject(domain.getType()); |
849 |
0
|
if (isUsePrimitive()) { |
850 |
0
|
jtype = TypeMap.getJavaNative(domain.getType()); |
851 |
|
} |
852 |
|
|
853 |
0
|
return jtype; |
854 |
|
} |
855 |
|
|
856 |
|
|
857 |
|
|
858 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
859 |
0
|
public String getVillageMethod() {... |
860 |
0
|
String vmethod = TypeMap.getVillageObjectMethod(domain.getType()); |
861 |
0
|
if (isUsePrimitive()) { |
862 |
0
|
vmethod = TypeMap.getVillageMethod(domain.getType()); |
863 |
|
} |
864 |
|
|
865 |
0
|
return vmethod; |
866 |
|
} |
867 |
|
|
868 |
|
|
869 |
|
|
870 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
871 |
0
|
public String getParameterParserMethod() {... |
872 |
0
|
return TypeMap.getPPMethod(domain.getType()); |
873 |
|
} |
874 |
|
|
875 |
|
|
876 |
|
|
877 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
878 |
0
|
public boolean isBooleanInt() {... |
879 |
0
|
return TypeMap.isBooleanInt(domain.getType()); |
880 |
|
} |
881 |
|
|
882 |
|
|
883 |
|
|
884 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
885 |
0
|
public boolean isBooleanChar() {... |
886 |
0
|
return TypeMap.isBooleanChar(domain.getType()); |
887 |
|
} |
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
892 |
0
|
public boolean isBit() {... |
893 |
0
|
return TypeMap.isBit(domain.getType()); |
894 |
|
} |
895 |
|
|
896 |
|
|
897 |
|
|
898 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
899 |
0
|
public boolean isPrimitive() {... |
900 |
0
|
String t = getJavaNative(); |
901 |
0
|
return "boolean".equals(t) || "byte".equals(t) || "short".equals(t) || "int".equals(t) || "long".equals(t) || "float".equals(t) || "double".equals(t) || "char".equals(t); |
902 |
|
} |
903 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
904 |
0
|
public boolean isUsePrimitive() {... |
905 |
0
|
String s = getJavaType(); |
906 |
0
|
return (s != null && s.equals("primitive")) || (s == null && !"object".equals(getTable().getDatabase().getDefaultJavaType())); |
907 |
|
} |
908 |
|
|
909 |
|
|
910 |
|
@return |
911 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
912 |
0
|
public Domain getDomain() {... |
913 |
0
|
return domain; |
914 |
|
} |
915 |
|
|
916 |
|
|
917 |
|
@param |
918 |
|
|
919 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
920 |
0
|
public void setDomain(Domain domain) {... |
921 |
0
|
this.domain = domain; |
922 |
|
} |
923 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
924 |
0
|
private Platform getPlatform() {... |
925 |
0
|
try { |
926 |
0
|
return getTable().getDatabase().getPlatform(); |
927 |
|
} catch (Exception ex) { |
928 |
0
|
log.warn("could not load platform implementation"); |
929 |
|
} |
930 |
0
|
return new PlatformDefaultImpl(); |
931 |
|
} |
932 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 10 |
Complexity Density: 0.48 |
|
933 |
0
|
public String getSqlString() {... |
934 |
0
|
List resultList = new ArrayList(); |
935 |
0
|
resultList.add(getName()); |
936 |
|
|
937 |
0
|
String type = getDomain().getSqlType(); |
938 |
|
|
939 |
0
|
if (getPlatform().hasSize(getDomain().getSqlType())) { |
940 |
0
|
type += getDomain().printSize(); |
941 |
|
} |
942 |
|
|
943 |
0
|
resultList.add(type); |
944 |
|
|
945 |
0
|
String defaultStr = getPlatform().filterInvalidDefaultValues(getDomain().getDefaultValue()); |
946 |
0
|
if (StringUtils.isNotEmpty(defaultStr)) { |
947 |
|
|
948 |
0
|
resultList.add("default"); |
949 |
|
|
950 |
0
|
if (TypeMap.isTextType(getDomain().getType()) && !getPlatform().isSpecialDefault(defaultStr)) { |
951 |
|
|
952 |
0
|
resultList.add(new StringBuffer().append('\'').append(getDefaultValue()).append('\'')); |
953 |
|
} else { |
954 |
0
|
resultList.add(getDefaultValue()); |
955 |
|
} |
956 |
|
} |
957 |
0
|
if (getPlatform().createNotNullBeforeAutoincrement()) { |
958 |
0
|
if (StringUtils.isNotEmpty(getNotNullString())) { |
959 |
0
|
resultList.add(getNotNullString()); |
960 |
|
} |
961 |
|
} |
962 |
0
|
if (StringUtils.isNotEmpty(getAutoIncrementString())) { |
963 |
0
|
resultList.add(getAutoIncrementString()); |
964 |
|
} |
965 |
0
|
if (!getPlatform().createNotNullBeforeAutoincrement()) { |
966 |
0
|
if (StringUtils.isNotEmpty(getNotNullString())) { |
967 |
0
|
resultList.add(getNotNullString()); |
968 |
|
} |
969 |
|
} |
970 |
0
|
return StringUtils.join(resultList.iterator(), ' '); |
971 |
|
} |
972 |
|
|
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
@return |
977 |
|
@since |
978 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
979 |
0
|
public boolean isCorrectGetters() {... |
980 |
0
|
return correctGetters; |
981 |
|
} |
982 |
|
|
983 |
|
|
984 |
|
|
985 |
|
|
986 |
|
|
987 |
|
@param |
988 |
|
|
989 |
|
@since |
990 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
991 |
0
|
public void setCorrectGetters(boolean correctGetters) {... |
992 |
0
|
this.correctGetters = correctGetters; |
993 |
|
} |
994 |
|
|
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
@return |
999 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1000 |
0
|
public String getInheritanceType() {... |
1001 |
0
|
return inheritanceType; |
1002 |
|
} |
1003 |
|
|
1004 |
|
|
1005 |
|
|
1006 |
|
|
1007 |
|
@param |
1008 |
|
|
1009 |
|
@param |
1010 |
|
|
1011 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1012 |
0
|
public void addOption(String key, String value) {... |
1013 |
0
|
options.put(key, value); |
1014 |
|
} |
1015 |
|
|
1016 |
|
|
1017 |
|
|
1018 |
|
|
1019 |
|
@param |
1020 |
|
|
1021 |
|
@return |
1022 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1023 |
0
|
public String getOption(String key) {... |
1024 |
0
|
return (String) options.get(key); |
1025 |
|
} |
1026 |
|
|
1027 |
|
|
1028 |
|
|
1029 |
|
|
1030 |
|
|
1031 |
|
|
1032 |
|
|
1033 |
|
|
1034 |
|
@return |
1035 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1036 |
0
|
public Map getOptions() {... |
1037 |
0
|
return options; |
1038 |
|
} |
1039 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1040 |
0
|
public int getJdbcType() {... |
1041 |
0
|
return jdbcType; |
1042 |
|
} |
1043 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1044 |
0
|
public void setJdbcType(int jdbcType) {... |
1045 |
0
|
this.jdbcType = jdbcType; |
1046 |
|
} |
1047 |
|
} |