KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > in > co > daffodil > db > jdbc > TempResultSetMetaData


1 package in.co.daffodil.db.jdbc;
2
3 import java.sql.*;
4 import com.daffodilwoods.database.resource.*;
5 import in.co.daffodil.db.general.*;
6 /**
7  * Title:
8  * Description:
9  * Copyright: Copyright (c) 2002
10  * Company:
11  * @author
12  * @version 1.0
13  */

14 /**
15  * 1. CatalogName
16  * 2. SchemaName
17  * 3. TableName
18  * 4. ColumnName
19  * 5. ColumnType
20  * 6. ColumnLabel
21  * 7. Precision
22  * 8. Scale
23  * 9. DisplaySize
24  * 10. ColumnTypeName
25  * 11. ColumnClassName
26  * 12. isAutoIncrement
27  * 13. isCaseSensitive
28  * 14. isCurrency
29  * 15. isSigned
30  * 16. isReadOnly
31  * 17. isWritable
32  * 18. isDefinitelyWritable
33  * 19. isSearchable
34  * 20. isNullable
35  */

36 public class TempResultSetMetaData implements ResultSetMetaData{
37
38     Object JavaDoc[][] characteristics;
39     DaffodilDBConnection connection;
40
41     public TempResultSetMetaData(Object JavaDoc[][] characteristics) {
42         try{
43             this.characteristics=characteristics;
44             if(characteristics==null) {
45                 DException dex = new DException("DSE232", null);
46                 throw dex.getSqlException(connection.getLocale());
47                 }
48         }catch(Exception JavaDoc E){
49         }
50     }
51     /**
52      * Returns the number of columns in this <code>ResultSet</code> object.
53      *
54      * @return the number of columns
55      * @exception SQLException if a database access error occurs
56      */

57     public int getColumnCount() throws SQLException{
58         return characteristics.length;
59     }
60
61     /**
62      * Indicates whether the designated column is automatically numbered, thus read-only.
63      *
64      * @param column the first column is 1, the second is 2, ...
65      * @return <code>true</code> if so; <code>false</code> otherwise
66      * @exception SQLException if a database access error occurs
67      */

68     public boolean isAutoIncrement(int column) throws SQLException{
69         try {
70         column=getValidColumn(column);
71         Boolean JavaDoc auto=(Boolean JavaDoc)characteristics[column][11];
72         return auto==null?false:auto.booleanValue();
73         }catch(Exception JavaDoc e) {
74             DaffodilDBExceptionHandler.handle("Error Found In isAutoIncrement" , "" , e,connection.getLocale());
75         }
76         return false;
77     }
78
79     /**
80      * Indicates whether a column's case matters.
81      *
82      * @param column the first column is 1, the second is 2, ...
83      * @return <code>true</code> if so; <code>false</code> otherwise
84      * @exception SQLException if a database access error occurs
85      */

86     public boolean isCaseSensitive(int column) throws SQLException{
87         try {
88         column=getValidColumn(column);
89         Boolean JavaDoc caseSensitive=(Boolean JavaDoc)characteristics[column][12];
90         return caseSensitive==null?false:caseSensitive.booleanValue();
91         }catch(Exception JavaDoc e) {
92             DaffodilDBExceptionHandler.handle("Error Found In isCaseSensitive " , "" , e,connection.getLocale());
93             return false;
94         }
95     }
96
97
98     /**
99      * Indicates whether the designated column can be used in a where clause.
100      *
101      * @param column the first column is 1, the second is 2, ...
102      * @return <code>true</code> if so; <code>false</code> otherwise
103      * @exception SQLException if a database access error occurs
104      */

105     public boolean isSearchable(int column) throws SQLException{
106         try {
107         column=getValidColumn(column);
108         Boolean JavaDoc isSearchable=(Boolean JavaDoc)characteristics[column][18];
109         return isSearchable==null?false:isSearchable.booleanValue();
110         }catch(Exception JavaDoc e) {
111             DaffodilDBExceptionHandler.handle("Error Found In isSearchable " , "" , e,connection.getLocale());
112             return false;
113         }
114     }
115
116
117     /**
118      * Indicates whether the designated column is a cash value.
119      *
120      * @param column the first column is 1, the second is 2, ...
121      * @return <code>true</code> if so; <code>false</code> otherwise
122      * @exception SQLException if a database access error occurs
123      */

124     public boolean isCurrency(int column) throws SQLException{
125         try {
126         column=getValidColumn(column);
127         Boolean JavaDoc isCurrency=(Boolean JavaDoc)characteristics[column][13];
128         return isCurrency==null?false:isCurrency.booleanValue();
129         }catch(Exception JavaDoc e) {
130             DaffodilDBExceptionHandler.handle("Error Found In isCurrency " , "" , e,connection.getLocale());
131             return false;
132         }
133     }
134
135
136     /**
137      * Indicates the nullability of values in the designated column.
138      *
139      * @param column the first column is 1, the second is 2, ...
140      * @return the nullability status of the given column; one of <code>columnNoNulls</code>,
141      * <code>columnNullable</code> or <code>columnNullableUnknown</code>
142      * @exception SQLException if a database access error occurs
143      */

144     public int isNullable(int column) throws SQLException{
145         try {
146         column=getValidColumn(column);
147         Integer JavaDoc isNullable=(Integer JavaDoc)characteristics[column][19];
148         return isNullable==null?columnNullableUnknown:isNullable.intValue();
149         }catch(Exception JavaDoc e) {
150             DaffodilDBExceptionHandler.handle("Error Found In is isNullable" , "" , e,connection.getLocale());
151             return Integer.MIN_VALUE;
152         }
153     }
154
155
156     /**
157      * Indicates whether values in the designated column are signed numbers.
158      *
159      * @param column the first column is 1, the second is 2, ...
160      * @return <code>true</code> if so; <code>false</code> otherwise
161      * @exception SQLException if a database access error occurs
162      */

163     public boolean isSigned(int column) throws SQLException{
164         try{
165         column=getValidColumn(column);
166         Boolean JavaDoc isSigned=(Boolean JavaDoc)characteristics[column][14];
167         return isSigned==null?false:isSigned.booleanValue();
168         }catch(Exception JavaDoc e) {
169             DaffodilDBExceptionHandler.handle("Error Found In is isSigned" , "" , e,connection.getLocale());
170             return false;
171         }
172
173
174     }
175
176
177     /**
178      * Indicates the designated column's normal maximum width in characters.
179      *
180      * @param column the first column is 1, the second is 2, ...
181      * @return the normal maximum number of characters allowed as the width
182      * of the designated column
183      * @exception SQLException if a database access error occurs
184      */

185     public int getColumnDisplaySize(int column) throws SQLException{
186         try{
187         column=getValidColumn(column);
188         Integer JavaDoc dispSize=(Integer JavaDoc)characteristics[column][8];
189         return dispSize==null?0:dispSize.intValue();
190         }catch(Exception JavaDoc e) {
191             DaffodilDBExceptionHandler.handle("Error Found In is getColumnDisplaySize" , "" , e,connection.getLocale());
192             return Integer.MIN_VALUE;
193         }
194     }
195
196
197     /**
198      * Gets the designated column's suggested title for use in printouts and
199      * displays.
200      *
201      * @param column the first column is 1, the second is 2, ...
202      * @return the suggested column title
203      * @exception SQLException if a database access error occurs
204      */

205     public String JavaDoc getColumnLabel(int column) throws SQLException{
206         try {
207         column=getValidColumn(column);
208         return characteristics[column][5]==null?null:(String JavaDoc)characteristics[column][5];
209         }catch(Exception JavaDoc e) {
210             DaffodilDBExceptionHandler.handle("Error Found In is getColumnLabel" , "" , e,connection.getLocale());
211             return null;
212         }
213
214     }
215
216
217     /**
218      * Get the designated column's name.
219      *
220      * @param column the first column is 1, the second is 2, ...
221      * @return column name
222      * @exception SQLException if a database access error occurs
223      */

224     public String JavaDoc getColumnName(int column) throws SQLException{
225         try {
226         column=getValidColumn(column);
227         return characteristics[column][3]==null?null:(String JavaDoc)characteristics[column][3];
228         }catch(Exception JavaDoc e) {
229             DaffodilDBExceptionHandler.handle("Error Found In is getColumnName" , "" , e,connection.getLocale());
230             return null;
231         }
232     }
233
234
235     /**
236      * Get the designated column's table's schema.
237      *
238      * @param column the first column is 1, the second is 2, ...
239      * @return schema name or "" if not applicable
240      * @exception SQLException if a database access error occurs
241      */

242     public String JavaDoc getSchemaName(int column) throws SQLException {
243         try {
244         column=getValidColumn(column);
245         return characteristics[column][1]==null?"":(String JavaDoc)characteristics[column][1];
246         }catch(Exception JavaDoc e) {
247             DaffodilDBExceptionHandler.handle("Error Found In is getSchemaName" , "" , e,connection.getLocale());
248             return null;
249         }
250
251
252
253     }
254
255
256     /**
257      * Get the designated column's number of decimal digits.
258      *
259      * @param column the first column is 1, the second is 2, ...
260      * @return precision
261      * @exception SQLException if a database access error occurs
262      */

263     public int getPrecision(int column) throws SQLException{
264         try {
265         column=getValidColumn(column);
266         Integer JavaDoc precision=(Integer JavaDoc)characteristics[column][6];
267         return precision==null?0:precision.intValue();
268         }catch(Exception JavaDoc e) {
269             DaffodilDBExceptionHandler.handle("Error Found In is getPrecision" , "" , e,connection.getLocale());
270             return Integer.MIN_VALUE;
271         }
272
273
274     }
275
276
277     /**
278      * Gets the designated column's number of digits to right of the decimal point.
279      *
280      * @param column the first column is 1, the second is 2, ...
281      * @return scale
282      * @exception SQLException if a database access error occurs
283      */

284     public int getScale(int column) throws SQLException{
285         try {
286         column=getValidColumn(column);
287         Integer JavaDoc scale=(Integer JavaDoc)characteristics[column][7];
288         return scale==null?0:scale.intValue();
289         }catch(Exception JavaDoc e) {
290             DaffodilDBExceptionHandler.handle("Error Found In is getScale" , "" , e,connection.getLocale());
291             return Integer.MIN_VALUE;
292         }
293
294
295     }
296
297
298     /**
299      * Gets the designated column's table name.
300      *
301      * @param column the first column is 1, the second is 2, ...
302      * @return table name or "" if not applicable
303      * @exception SQLException if a database access error occurs
304      */

305     public String JavaDoc getTableName(int column) throws SQLException{
306         try {
307         column=getValidColumn(column);
308         return characteristics[column][2]==null?"":(String JavaDoc)characteristics[column][2];
309         }catch(Exception JavaDoc e) {
310             DaffodilDBExceptionHandler.handle("Error Found In is getTableName" , "" , e,connection.getLocale());
311             return null;
312         }
313
314     }
315
316     /**
317      * Gets the designated column's table's catalog name.
318      *
319      * @param column the first column is 1, the second is 2, ...
320      * @return the name of the catalog for the table in which the given column
321      * appears or "" if not applicable
322      * @exception SQLException if a database access error occurs
323      */

324     public String JavaDoc getCatalogName(int column) throws SQLException{
325         try {
326         column=getValidColumn(column);
327         return characteristics[column][0]==null?"":(String JavaDoc)characteristics[column][0];
328         }catch(Exception JavaDoc e) {
329             DaffodilDBExceptionHandler.handle("Error Found In is getCatalgName" , "" , e,connection.getLocale());
330             return null;
331         }
332
333
334     }
335
336     /**
337      * Retrieves the designated column's SQL type.
338      *
339      * @param column the first column is 1, the second is 2, ...
340      * @return SQL type from java.sql.Types
341      * @exception SQLException if a database access error occurs
342      * @see Types
343      */

344     public int getColumnType(int column) throws SQLException{
345         try {
346         column=getValidColumn(column);
347         Integer JavaDoc value=(Integer JavaDoc)characteristics[column][4];
348         return value==null?0:value.intValue();
349         }catch(Exception JavaDoc e) {
350             DaffodilDBExceptionHandler.handle("Error Found In is getColumnType" , "" , e,connection.getLocale());
351             return Integer.MIN_VALUE;
352         }
353
354     }
355
356
357     /**
358      * Retrieves the designated column's database-specific type name.
359      *
360      * @param column the first column is 1, the second is 2, ...
361      * @return type name used by the database. If the column type is
362      * a user-defined type, then a fully-qualified type name is returned.
363      * @exception SQLException if a database access error occurs
364      */

365     public String JavaDoc getColumnTypeName(int column) throws SQLException{
366         try {
367         column=getValidColumn(column);
368         return characteristics[column][9]==null?null:(String JavaDoc)characteristics[column][9];
369         }catch(Exception JavaDoc e) {
370             DaffodilDBExceptionHandler.handle("Error Found In is getColumnTypeName" , "" , e,connection.getLocale());
371             return null;
372         }
373
374     }
375
376
377     /**
378      * Indicates whether the designated column is definitely not writable.
379      *
380      * @param column the first column is 1, the second is 2, ...
381      * @return <code>true</code> if so; <code>false</code> otherwise
382      * @exception SQLException if a database access error occurs
383      */

384     public boolean isReadOnly(int column) throws SQLException{
385         try {
386         column=getValidColumn(column);
387         Boolean JavaDoc isReadOnly=(Boolean JavaDoc)characteristics[column][15];
388         return isReadOnly==null?false:isReadOnly.booleanValue();
389         }catch(Exception JavaDoc e) {
390             DaffodilDBExceptionHandler.handle("Error Found In is isReadOnly" , "" , e,connection.getLocale());
391             return false;
392         }
393
394     }
395
396
397     /**
398      * Indicates whether it is possible for a write on the designated column to succeed.
399      *
400      * @param column the first column is 1, the second is 2, ...
401      * @return <code>true</code> if so; <code>false</code> otherwise
402      * @exception SQLException if a database access error occurs
403      */

404     public boolean isWritable(int column) throws SQLException{
405         try {
406         column=getValidColumn(column);
407         Boolean JavaDoc isWritable=(Boolean JavaDoc)characteristics[column][16];
408         return isWritable==null?false:isWritable.booleanValue();
409         }catch(Exception JavaDoc e) {
410             DaffodilDBExceptionHandler.handle("Error Found In is isWritable" , "" , e,connection.getLocale());
411             return false;
412         }
413
414     }
415
416
417     /**
418      * Indicates whether a write on the designated column will definitely succeed.
419      *
420      * @param column the first column is 1, the second is 2, ...
421      * @return <code>true</code> if so; <code>false</code> otherwise
422      * @exception SQLException if a database access error occurs
423      */

424     public boolean isDefinitelyWritable(int column) throws SQLException{
425         try {
426         column=getValidColumn(column);
427         Boolean JavaDoc isDefinitelyWritable=(Boolean JavaDoc)characteristics[column][17];
428         return isDefinitelyWritable==null?false:isDefinitelyWritable.booleanValue();
429         }catch(Exception JavaDoc e) {
430             DaffodilDBExceptionHandler.handle("Error Found In is isDefinitelyWritable" , "" , e,connection.getLocale());
431             return false;
432         }
433
434     }
435
436
437
438     /**
439      * <p>Returns the fully-qualified name of the Java class whose instances
440      * are manufactured if the method <code>ResultSet.getObject</code>
441      * is called to retrieve a value
442      * from the column. <code>ResultSet.getObject</code> may return a subclass of the
443      * class returned by this method.
444      *
445      * @param column the first column is 1, the second is 2, ...
446      * @return the fully-qualified name of the class in the Java programming
447      * language that would be used by the method
448      * <code>ResultSet.getObject</code> to retrieve the value in the specified
449      * column. This is the class name used for custom mapping.
450      * @exception SQLException if a database access error occurs
451      * @since 1.2
452      */

453     public String JavaDoc getColumnClassName(int column) throws SQLException{
454         try {
455         column=getValidColumn(column);
456         return characteristics[column][10]==null?null:(String JavaDoc)characteristics[column][10];
457         }catch(Exception JavaDoc e) {
458             DaffodilDBExceptionHandler.handle("Error Found In is getColumnClassName" , "" , e,connection.getLocale());
459             return null;
460         }
461
462     }
463     private int getValidColumn(int column)throws SQLException{
464         try {
465         if(characteristics==null || column < 1 || column>characteristics.length) {
466                 DException dex = new DException("DSE737", null);
467                 throw dex.getSqlException(connection.getLocale());
468             }
469         return column-1;
470         }catch(Exception JavaDoc e) {
471             DaffodilDBExceptionHandler.handle("Error Found In is getValidColumn" , "" , e,connection.getLocale());
472             return Integer.MIN_VALUE;
473         }
474
475
476     }
477
478         public void setConnection(DaffodilDBConnection connection) {
479           this.connection = connection;
480         }
481
482         public DaffodilDBConnection getConnection() {
483           return connection;
484         }
485 }
486
Popular Tags