1 package com.explosion.expfmodules.rdbmsconn.dbom;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5
6 import org.apache.log4j.LogManager;
7 import org.apache.log4j.Logger;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 /***
30 * A java object which represents a column as it is described by the database
31 * MetaData object. It also supports the metadata supplied from the ResultSet
32 * object.
33 *
34 * You need to be aware that these two sets of data may be populated at
35 * different times and so certain methods of this class may work dependant on
36 * context.
37 *
38 * The context dependant values are
39 *
40 * boolean autoIncrement; boolean writable; boolean signed; boolean searchable;
41 * boolean readOnly; boolean definitelyWritable; boolean currency; boolean
42 * caseSensitive;
43 *
44 * @author Stephen Cowx Description:
45 *
46 */
47
48 public class DBEntityColumn implements Serializable
49 {
50 private static Logger log = LogManager.getLogger(DBEntityColumn.class);
51 private String columnName = null;
52 private boolean isSorted = true;
53 private int index = -1;
54 private int size = 0;
55 private String typeName = null;
56 private int type;
57 private Object defaultValue = null;
58 private String remarks = null;
59 private boolean primaryKey = false;
60 private boolean foreignKey = false;
61 private boolean nullable = false;
62 private int bufferLength;
63 private short decimalDigits;
64 private boolean pseudoColumn = false;
65 private boolean bestRowIdentifier = false;
66
67
68 private boolean autoIncrement = false;
69 private boolean writable = true;
70 private boolean signed = true;
71 private boolean searchable = true;
72 private boolean readOnly = false;
73 private boolean definitelyWritable = true;
74 private boolean currency = false;
75 private boolean caseSensitive = false;
76
77 /***
78 * Returns the columns name
79 *
80 * @return
81 */
82 public String getColumnName()
83 {
84 return columnName;
85 }
86
87 /***
88 * Sets the columns Name
89 *
90 * @param columnName
91 */
92 public void setColumnName(String columnName)
93 {
94 this.columnName = columnName;
95 }
96
97 /***
98 * Returns the columns name as a string
99 *
100 * @return
101 */
102 public String toString()
103 {
104 return this.getColumnName();
105 }
106
107 /***
108 * @return Returns the defaultValue.
109 */
110 public Object getDefaultValue()
111 {
112 return defaultValue;
113 }
114
115 /***
116 * @param defaultValue The defaultValue to set.
117 */
118 public void setDefaultValue(Object defaultValue)
119 {
120 this.defaultValue = defaultValue;
121 }
122
123 /***
124 * @return Returns the foreignKey.
125 */
126 public boolean isForeignKey()
127 {
128 return foreignKey;
129 }
130
131 /***
132 * @param foreignKey The foreignKey to set.
133 */
134 public void setForeignKey(boolean foreignKey)
135 {
136 this.foreignKey = foreignKey;
137 }
138
139 /***
140 * @return Returns the columnIndex.
141 */
142 public int getIndex()
143 {
144 return index;
145 }
146
147 /***
148 * @param index The index to set.
149 */
150 public void setIndex(int index)
151 {
152 this.index = index;
153 }
154
155 /***
156 * @return Returns the isSorted.
157 */
158 public boolean isSorted()
159 {
160 return isSorted;
161 }
162
163 /***
164 * @param isSorted The isSorted to set.
165 */
166 public void setSorted(boolean isSorted)
167 {
168 this.isSorted = isSorted;
169 }
170
171 /***
172 * @return Returns the primaryKey.
173 */
174 public boolean isPrimaryKey()
175 {
176 return primaryKey;
177 }
178
179 /***
180 * @param primaryKey The primaryKey to set.
181 */
182 public void setPrimaryKey(boolean primaryKey)
183 {
184 this.primaryKey = primaryKey;
185 }
186
187 /***
188 * @return Returns the remarks.
189 */
190 public String getRemarks()
191 {
192 return remarks;
193 }
194
195 /***
196 * @param remarks The remarks to set.
197 */
198 public void setRemarks(String remarks)
199 {
200 this.remarks = remarks;
201 }
202
203 /***
204 * @return Returns the size.
205 */
206 public int getSize()
207 {
208 return size;
209 }
210
211 /***
212 * @param size The size to set.
213 */
214 public void setSize(int size)
215 {
216 this.size = size;
217 }
218
219 /***
220 * @return Returns the typeName.
221 */
222 public String getTypeName()
223 {
224 return typeName;
225 }
226
227 /***
228 * @param typeName The typeName to set.
229 */
230 public void setTypeName(String typeName)
231 {
232 this.typeName = typeName;
233 }
234
235 /***
236 * @return Returns the type.
237 */
238 public int getType()
239 {
240 return type;
241 }
242
243 /***
244 * @param type The type to set.
245 */
246 public void setType(int type)
247 {
248 this.type = type;
249 }
250
251 /***
252 * @return Returns the nullable.
253 */
254 public boolean isNullable()
255 {
256 return nullable;
257 }
258
259 /***
260 * @param nullable The nullable to set.
261 */
262 public void setNullable(boolean nullable)
263 {
264 this.nullable = nullable;
265 }
266
267 /***
268 * Indicates whether the designated column is automatically numbered, thus
269 * read-only.
270 */
271 public boolean isAutoIncrement()
272 {
273 return autoIncrement;
274 }
275
276 /*** Indicates whether a column's case matters. */
277 public boolean isCaseSensitive()
278 {
279 return caseSensitive;
280 }
281
282 /*** Indicates whether the designated column is a cash value. */
283 public boolean isCurrency()
284 {
285 return currency;
286 }
287
288 /***
289 * Indicates whether a write on the designated column will definitely
290 * succeed.
291 */
292 public boolean isDefinitelyWritable()
293 {
294 return definitelyWritable;
295 }
296
297 /*** /** Indicates whether the designated column is definitely not writable. */
298 public boolean isReadOnly()
299 {
300 return readOnly;
301 }
302
303 /*** Indicates whether the designated column can be used in a where clause. */
304 public boolean isSearchable()
305 {
306 return searchable;
307 }
308
309 /*** Indicates whether values in the designated column are signed numbers. */
310 public boolean isSigned()
311 {
312 return signed;
313 }
314
315 /***
316 * Indicates whether it is possible for a write on the designated column to
317 * succeed.
318 */
319 public boolean isWritable()
320 {
321 return writable;
322 }
323
324 /***
325 * @param autoIncrement The autoIncrement to set.
326 */
327 public void setAutoIncrement(boolean autoIncrement)
328 {
329 this.autoIncrement = autoIncrement;
330 }
331
332 /***
333 * @param caseSensitive The caseSensitive to set.
334 */
335 public void setCaseSensitive(boolean caseSensitive)
336 {
337 this.caseSensitive = caseSensitive;
338 }
339
340 /***
341 * @param currency The currency to set.
342 */
343 public void setCurrency(boolean currency)
344 {
345 this.currency = currency;
346 }
347
348 /***
349 * @param definitelyWritable The definitelyWritable to set.
350 */
351 public void setDefinitelyWritable(boolean definitelyWritable)
352 {
353 this.definitelyWritable = definitelyWritable;
354 }
355
356 /***
357 * @param readOnly The readOnly to set.
358 */
359 public void setReadOnly(boolean readOnly)
360 {
361 this.readOnly = readOnly;
362 }
363
364 /***
365 * @param searchable The searchable to set.
366 */
367 public void setSearchable(boolean searchable)
368 {
369 this.searchable = searchable;
370 }
371
372 /***
373 * @param signed The signed to set.
374 */
375 public void setSigned(boolean signed)
376 {
377 this.signed = signed;
378 }
379
380 /***
381 * @param writable The writable to set.
382 */
383 public void setWritable(boolean writable)
384 {
385 this.writable = writable;
386 }
387
388
389
390
391
392 private static HashMap nonSortableTypes;
393
394 public boolean isSortable()
395 {
396 if (nonSortableTypes == null)
397 {
398 nonSortableTypes = new HashMap();
399 nonSortableTypes.put("java.sql.Types.STRUCT","");
400 nonSortableTypes.put("java.sql.Types.ARRAY","");
401 }
402
403 log.debug(this.getTypeName() + "," + this.getType());
404
405 if (nonSortableTypes.get(this.getTypeName()) != null)
406 return false;
407 else
408 return true;
409 }
410
411 /***
412 * @param bufferLength
413 */
414 public void setBufferLength(int bufferLength)
415 {
416 this.bufferLength = bufferLength;
417 }
418
419 /***
420 *
421 * @return
422 */
423 public int getBufferLength()
424 {
425 return bufferLength;
426 }
427
428 /***
429 * @param decimalDigits
430 */
431 public void setDecimalDigits(short decimalDigits)
432 {
433 this.decimalDigits = decimalDigits;
434 }
435
436 /***
437 *
438 * @return
439 */
440 public short getDecimalDigits()
441 {
442 return decimalDigits;
443 }
444
445 /***
446 * @param pseudoColumn
447 */
448 public void setPseudoColumn(boolean pseudoColumn)
449 {
450 this.pseudoColumn = pseudoColumn;
451 }
452
453 /***
454 *
455 * @return
456 */
457 public boolean isPseudoColumn()
458 {
459 return pseudoColumn;
460 }
461
462 /***
463 * Returns true if the database metadata indicates that this is a best row identifier
464 * @return
465 */
466 public boolean isBestRowIdentifier()
467 {
468 return bestRowIdentifier;
469 }
470
471 /***
472 * Set to true to indicate that this column is a bestRowIdentifier column
473 * @return
474 */
475 public void setBestRowIdentifier(boolean bestRowIdentifier)
476 {
477 this.bestRowIdentifier = bestRowIdentifier;
478 }
479 }