%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
com.workingdogs.village.Column |
|
|
1 | package com.workingdogs.village; |
|
2 | ||
3 | /* |
|
4 | * Licensed to the Apache Software Foundation (ASF) under one |
|
5 | * or more contributor license agreements. See the NOTICE file |
|
6 | * distributed with this work for additional information |
|
7 | * regarding copyright ownership. The ASF licenses this file |
|
8 | * to you under the Apache License, Version 2.0 (the |
|
9 | * "License"); you may not use this file except in compliance |
|
10 | * with the License. You may obtain a copy of the License at |
|
11 | * |
|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
13 | * |
|
14 | * Unless required by applicable law or agreed to in writing, |
|
15 | * software distributed under the License is distributed on an |
|
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
17 | * KIND, either express or implied. See the License for the |
|
18 | * specific language governing permissions and limitations |
|
19 | * under the License. |
|
20 | */ |
|
21 | ||
22 | import java.sql.ResultSetMetaData; |
|
23 | import java.sql.SQLException; |
|
24 | import java.sql.Types; |
|
25 | ||
26 | /** |
|
27 | * This class represents a Column in the database and its associated meta information. A <a href="Record.html">Record</A> is a |
|
28 | * collection of columns. |
|
29 | * |
|
30 | * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> |
|
31 | * @version $Revision: 568 $ |
|
32 | */ |
|
33 | public class Column |
|
34 | { |
|
35 | /** column number in a schema object */ |
|
36 | 0 | private int columnNumber = -1; |
37 | ||
38 | /** name of the column */ |
|
39 | 0 | private String name = ""; |
40 | ||
41 | /** example: this column is of type "String" */ |
|
42 | 0 | private String columnTypeName = ""; |
43 | ||
44 | /** what java.sql.Type is this column? */ |
|
45 | 0 | private int columnType = Types.LONGVARCHAR; |
46 | ||
47 | /** name of table that this column belongs to */ |
|
48 | 0 | private String tableName = ""; |
49 | ||
50 | /** is null allowed for this column? */ |
|
51 | 0 | private boolean nullAllowed = false; |
52 | ||
53 | /** is this an auto increment column? */ |
|
54 | 0 | private boolean autoIncrement = false; |
55 | ||
56 | /** is this a read only column? */ |
|
57 | 0 | private boolean readOnly = false; |
58 | ||
59 | /** is this a searchable column? */ |
|
60 | 0 | private boolean searchable = false; |
61 | ||
62 | /** what is the scale of this column? */ |
|
63 | 0 | private int scale = -1; |
64 | ||
65 | /** what is the precision of this column? */ |
|
66 | 0 | private int precision = -1; |
67 | ||
68 | /** what is the length of this column? */ |
|
69 | 0 | private int length = -1; |
70 | ||
71 | /** |
|
72 | * constructor |
|
73 | */ |
|
74 | public Column() |
|
75 | 0 | { |
76 | 0 | this.columnNumber = -1; |
77 | 0 | this.name = ""; |
78 | 0 | this.columnTypeName = ""; |
79 | 0 | this.tableName = ""; |
80 | 0 | this.columnType = Types.LONGVARCHAR; |
81 | 0 | this.nullAllowed = false; |
82 | 0 | this.autoIncrement = false; |
83 | 0 | this.readOnly = false; |
84 | 0 | this.searchable = false; |
85 | 0 | this.scale = -1; |
86 | 0 | this.precision = -1; |
87 | 0 | this.length = -1; |
88 | 0 | } |
89 | ||
90 | /** |
|
91 | * internal package method for populating a Column instance |
|
92 | * |
|
93 | * @param rsmd TODO: DOCUMENT ME! |
|
94 | * @param colNum TODO: DOCUMENT ME! |
|
95 | * @param tableName TODO: DOCUMENT ME! |
|
96 | * |
|
97 | * @throws SQLException TODO: DOCUMENT ME! |
|
98 | */ |
|
99 | void populate(ResultSetMetaData rsmd, int colNum, String tableName) |
|
100 | throws SQLException |
|
101 | { |
|
102 | 0 | this.columnNumber = colNum; |
103 | 0 | this.name = rsmd.getColumnName(columnNumber); |
104 | ||
105 | // Workaround for Sybase jConnect 5.2 and older. |
|
106 | try |
|
107 | { |
|
108 | 0 | this.tableName = rsmd.getTableName(columnNumber); |
109 | ||
110 | // ResultSetMetaData may report table name as the empty |
|
111 | // string when a database-specific function has been |
|
112 | // called to generate a Column. |
|
113 | 0 | if ((this.tableName == null) || class="keyword">this.tableName.equals("")) |
114 | { |
|
115 | 0 | if (tableName != null) |
116 | { |
|
117 | 0 | this.tableName = tableName; |
118 | } |
|
119 | else |
|
120 | { |
|
121 | 0 | this.tableName = ""; |
122 | } |
|
123 | } |
|
124 | } |
|
125 | 0 | catch (RuntimeException e) |
126 | { |
|
127 | 0 | if (tableName != null) |
128 | { |
|
129 | 0 | this.tableName = tableName; |
130 | } |
|
131 | else |
|
132 | { |
|
133 | 0 | this.tableName = ""; |
134 | } |
|
135 | 0 | } |
136 | ||
137 | 0 | this.columnTypeName = rsmd.getColumnTypeName(columnNumber); |
138 | 0 | this.columnType = rsmd.getColumnType(columnNumber); |
139 | 0 | this.nullAllowed = rsmd.isNullable(columnNumber) == 1; |
140 | 0 | this.autoIncrement = rsmd.isAutoIncrement(columnNumber); |
141 | ||
142 | // The JDBC spec is VERY unclear about what this means and as |
|
143 | // such, it should be ignored. Derby returns true all the time. |
|
144 | // Sybase and Informix say it's unsupported (and false). |
|
145 | 0 | this.readOnly = false; // rsmd.isReadOnly (columnNumber); |
146 | ||
147 | 0 | this.searchable = rsmd.isSearchable(columnNumber); |
148 | 0 | this.scale = rsmd.getScale(columnNumber); |
149 | ||
150 | try |
|
151 | { |
|
152 | 0 | this.precision = rsmd.getPrecision(columnNumber); |
153 | } |
|
154 | 0 | catch (NumberFormatException assumedTooLarge) |
155 | { |
|
156 | // This may happen if the precision is too large for an |
|
157 | // int, with column types such as MySQL BIGINT, Oracle |
|
158 | // BLOB, etc.. See bug #4625851 at the JDC for details. |
|
159 | 0 | this.precision = Integer.MAX_VALUE; |
160 | 0 | } |
161 | ||
162 | 0 | this.length = rsmd.getColumnDisplaySize(columnNumber); |
163 | 0 | } |
164 | ||
165 | /** |
|
166 | * the name of the column |
|
167 | * |
|
168 | * @return the name of the column |
|
169 | */ |
|
170 | public String name() |
|
171 | { |
|
172 | 0 | return this.name; |
173 | } |
|
174 | ||
175 | /** |
|
176 | * the data type of a column |
|
177 | * |
|
178 | * @return the java.sql.Types String |
|
179 | */ |
|
180 | public String dbType() |
|
181 | { |
|
182 | 0 | return this.columnTypeName; |
183 | } |
|
184 | ||
185 | /** |
|
186 | * the data type of a column |
|
187 | * |
|
188 | * @return the java.sql.Types enum |
|
189 | */ |
|
190 | public int typeEnum() |
|
191 | { |
|
192 | 0 | return this.columnType; |
193 | } |
|
194 | ||
195 | /** |
|
196 | * does this column allow null? |
|
197 | * |
|
198 | * @return whether or not the column has null Allowed |
|
199 | */ |
|
200 | public boolean nullAllowed() |
|
201 | { |
|
202 | 0 | return this.nullAllowed; |
203 | } |
|
204 | ||
205 | /** |
|
206 | * does this column auto increment? |
|
207 | * |
|
208 | * @return whether or not this column auto increments |
|
209 | */ |
|
210 | public boolean autoIncrement() |
|
211 | { |
|
212 | 0 | return this.autoIncrement; |
213 | } |
|
214 | ||
215 | /** |
|
216 | * is this column read only? |
|
217 | * |
|
218 | * @return whether or not this column is read only |
|
219 | */ |
|
220 | public boolean readOnly() |
|
221 | { |
|
222 | 0 | return this.readOnly; |
223 | } |
|
224 | ||
225 | /** |
|
226 | * is this column searchable? |
|
227 | * |
|
228 | * @return true if this column is searchable |
|
229 | */ |
|
230 | public boolean searchable() |
|
231 | { |
|
232 | 0 | return this.searchable; |
233 | } |
|
234 | ||
235 | /** |
|
236 | * the scale of the column |
|
237 | * |
|
238 | * @return the scale of the column |
|
239 | */ |
|
240 | public int scale() |
|
241 | { |
|
242 | 0 | return this.scale; |
243 | } |
|
244 | ||
245 | /** |
|
246 | * the precision of the column |
|
247 | * |
|
248 | * @return the precision of the column |
|
249 | */ |
|
250 | public int precision() |
|
251 | { |
|
252 | 0 | return this.precision; |
253 | } |
|
254 | ||
255 | /** |
|
256 | * the storage length of a column |
|
257 | * |
|
258 | * @return the storage length of a column |
|
259 | */ |
|
260 | public int length() |
|
261 | { |
|
262 | 0 | return this.length; |
263 | } |
|
264 | ||
265 | /** |
|
266 | * the type of the column as a string |
|
267 | * |
|
268 | * @return the type of the column as a string |
|
269 | */ |
|
270 | public String type() |
|
271 | { |
|
272 | 0 | if (isBoolean()) |
273 | { |
|
274 | 0 | return "BOOLEAN"; |
275 | } |
|
276 | 0 | else if (isByte()) |
277 | { |
|
278 | 0 | return "BYTE"; |
279 | } |
|
280 | 0 | else if (isShort()) |
281 | { |
|
282 | 0 | return "SHORT"; |
283 | } |
|
284 | 0 | else if (isInt()) |
285 | { |
|
286 | 0 | return "INTEGER"; |
287 | } |
|
288 | 0 | else if (isLong()) |
289 | { |
|
290 | 0 | return "LONG"; |
291 | } |
|
292 | 0 | else if (isFloat()) |
293 | { |
|
294 | 0 | return "FLOAT"; |
295 | } |
|
296 | 0 | else if (isDouble()) |
297 | { |
|
298 | 0 | return "DOUBLE"; |
299 | } |
|
300 | 0 | else if (isBigDecimal()) |
301 | { |
|
302 | 0 | return "BIGDECIMAL"; |
303 | } |
|
304 | 0 | else if (isDate()) |
305 | { |
|
306 | 0 | return "DATE"; |
307 | } |
|
308 | 0 | else if (isTime()) |
309 | { |
|
310 | 0 | return "TIME"; |
311 | } |
|
312 | 0 | else if (isTimestamp()) |
313 | { |
|
314 | 0 | return "TIMESTAMP"; |
315 | } |
|
316 | 0 | else if (isString()) |
317 | { |
|
318 | 0 | return "STRING"; |
319 | } |
|
320 | 0 | else if (isBinary()) |
321 | { |
|
322 | 0 | return "BINARY"; |
323 | } |
|
324 | 0 | else if (isVarBinary()) |
325 | { |
|
326 | 0 | return "VARBINARY"; |
327 | } |
|
328 | 0 | else if (isLongVarBinary()) |
329 | { |
|
330 | 0 | return "LONGVARBINARY"; |
331 | } |
|
332 | ||
333 | 0 | return "UNKNOWN TYPE: " + typeEnum(); |
334 | } |
|
335 | ||
336 | /** |
|
337 | * column isBoolean: -7 |
|
338 | * |
|
339 | * @return TODO: DOCUMENT ME! |
|
340 | */ |
|
341 | public boolean isBoolean() |
|
342 | { |
|
343 | 0 | return this.typeEnum() == Types.BIT; |
344 | } |
|
345 | ||
346 | /** |
|
347 | * column isBigDecimal: 2 || 3 |
|
348 | * |
|
349 | * @return TODO: DOCUMENT ME! |
|
350 | */ |
|
351 | public boolean isBigDecimal() |
|
352 | { |
|
353 | 0 | return (this.typeEnum() == Types.NUMERIC) || (class="keyword">this.typeEnum() == Types.DECIMAL); |
354 | } |
|
355 | ||
356 | /** |
|
357 | * column isBinary: -2 |
|
358 | * |
|
359 | * @return TODO: DOCUMENT ME! |
|
360 | */ |
|
361 | public boolean isBinary() |
|
362 | { |
|
363 | 0 | return this.typeEnum() == Types.BINARY; |
364 | } |
|
365 | ||
366 | /** |
|
367 | * column isByte: -6 |
|
368 | * |
|
369 | * @return TODO: DOCUMENT ME! |
|
370 | */ |
|
371 | public boolean isByte() |
|
372 | { |
|
373 | 0 | return this.typeEnum() == Types.TINYINT; |
374 | } |
|
375 | ||
376 | /** |
|
377 | * column isBytes: -4 || -3 || -2 |
|
378 | * |
|
379 | * @return TODO: DOCUMENT ME! |
|
380 | */ |
|
381 | public boolean isBytes() |
|
382 | { |
|
383 | 0 | return (this.typeEnum() == Types.LONGVARBINARY) |
384 | || (this.typeEnum() == Types.VARBINARY) |
|
385 | || (this.columnType == Types.BINARY); |
|
386 | } |
|
387 | ||
388 | /** |
|
389 | * column isBytes: 91 |
|
390 | * |
|
391 | * @return TODO: DOCUMENT ME! |
|
392 | */ |
|
393 | public boolean isDate() |
|
394 | { |
|
395 | 0 | return this.typeEnum() == Types.DATE; |
396 | } |
|
397 | ||
398 | /** |
|
399 | * column isDouble: 6 || 8 |
|
400 | * |
|
401 | * @return TODO: DOCUMENT ME! |
|
402 | */ |
|
403 | public boolean isDouble() |
|
404 | { |
|
405 | 0 | return (this.typeEnum() == Types.FLOAT) || (class="keyword">this.typeEnum() == Types.DOUBLE); |
406 | } |
|
407 | ||
408 | /** |
|
409 | * column isFloat: 7 |
|
410 | * |
|
411 | * @return TODO: DOCUMENT ME! |
|
412 | */ |
|
413 | public boolean isFloat() |
|
414 | { |
|
415 | 0 | return this.typeEnum() == Types.REAL; |
416 | } |
|
417 | ||
418 | /** |
|
419 | * column isInt: 4 |
|
420 | * |
|
421 | * @return TODO: DOCUMENT ME! |
|
422 | */ |
|
423 | public boolean isInt() |
|
424 | { |
|
425 | 0 | return this.typeEnum() == Types.INTEGER; |
426 | } |
|
427 | ||
428 | /** |
|
429 | * column isLong: -5 |
|
430 | * |
|
431 | * @return TODO: DOCUMENT ME! |
|
432 | */ |
|
433 | public boolean isLong() |
|
434 | { |
|
435 | 0 | return this.typeEnum() == Types.BIGINT; |
436 | } |
|
437 | ||
438 | /** |
|
439 | * column isShort: 5 |
|
440 | * |
|
441 | * @return TODO: DOCUMENT ME! |
|
442 | */ |
|
443 | public boolean isShort() |
|
444 | { |
|
445 | 0 | return this.typeEnum() == Types.SMALLINT; |
446 | } |
|
447 | ||
448 | /** |
|
449 | * column isString: -1 || -11 || 12 |
|
450 | * |
|
451 | * @return TODO: DOCUMENT ME! |
|
452 | */ |
|
453 | public boolean isString() |
|
454 | { |
|
455 | 0 | return (this.typeEnum() == Types.LONGVARCHAR) |
456 | || (this.typeEnum() == Types.VARCHAR) |
|
457 | || (this.typeEnum() == 11); |
|
458 | } |
|
459 | ||
460 | /** |
|
461 | * column isTime: 92 |
|
462 | * |
|
463 | * @return TODO: DOCUMENT ME! |
|
464 | */ |
|
465 | public boolean isTime() |
|
466 | { |
|
467 | 0 | return this.typeEnum() == Types.TIME; |
468 | } |
|
469 | ||
470 | /** |
|
471 | * column isTimestamp: 93 |
|
472 | * |
|
473 | * @return TODO: DOCUMENT ME! |
|
474 | */ |
|
475 | public boolean isTimestamp() |
|
476 | { |
|
477 | 0 | return this.typeEnum() == Types.TIMESTAMP; |
478 | } |
|
479 | ||
480 | /** |
|
481 | * column isVarBinary: -3 |
|
482 | * |
|
483 | * @return TODO: DOCUMENT ME! |
|
484 | */ |
|
485 | public boolean isVarBinary() |
|
486 | { |
|
487 | 0 | return this.typeEnum() == Types.VARBINARY; |
488 | } |
|
489 | ||
490 | /** |
|
491 | * column isLongVarBinary: -4 |
|
492 | * |
|
493 | * @return TODO: DOCUMENT ME! |
|
494 | */ |
|
495 | public boolean isLongVarBinary() |
|
496 | { |
|
497 | 0 | return this.typeEnum() == Types.LONGVARBINARY; |
498 | } |
|
499 | ||
500 | /** |
|
501 | * unknown use |
|
502 | * |
|
503 | * @return TODO: DOCUMENT ME! |
|
504 | * |
|
505 | * @throws DataSetException TODO: DOCUMENT ME! |
|
506 | */ |
|
507 | public String dbKonaMethod() |
|
508 | throws DataSetException |
|
509 | { |
|
510 | 0 | throw new DataSetException("Method not implemented: Unknown use!"); |
511 | } |
|
512 | ||
513 | /** |
|
514 | * unknown use |
|
515 | * |
|
516 | * @return TODO: DOCUMENT ME! |
|
517 | * |
|
518 | * @throws DataSetException TODO: DOCUMENT ME! |
|
519 | */ |
|
520 | public String javaType() |
|
521 | throws DataSetException |
|
522 | { |
|
523 | 0 | throw new DataSetException("Method not implemented: Unknown use!"); |
524 | } |
|
525 | ||
526 | /** |
|
527 | * unknown use |
|
528 | * |
|
529 | * @return TODO: DOCUMENT ME! |
|
530 | * |
|
531 | * @throws DataSetException TODO: DOCUMENT ME! |
|
532 | */ |
|
533 | public final String preparedStatemntBindMethod() |
|
534 | throws DataSetException |
|
535 | { |
|
536 | 0 | throw new DataSetException("Method not implemented: Unknown use!"); |
537 | } |
|
538 | ||
539 | /** |
|
540 | * unknown use |
|
541 | * |
|
542 | * @return TODO: DOCUMENT ME! |
|
543 | * |
|
544 | * @throws DataSetException TODO: DOCUMENT ME! |
|
545 | */ |
|
546 | public final String resultSetMethod() |
|
547 | throws DataSetException |
|
548 | { |
|
549 | 0 | throw new DataSetException("Method not implemented: Unknown use!"); |
550 | } |
|
551 | ||
552 | /** |
|
553 | * TODO: DOCUMENT ME! |
|
554 | * |
|
555 | * @return TODO: DOCUMENT ME! |
|
556 | */ |
|
557 | public String getTableName() |
|
558 | { |
|
559 | 0 | return tableName; |
560 | } |
|
561 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |