KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sql > rowset > RowSetMetaDataImpl


1 /*
2  * @(#)RowSetMetaDataImpl.java 1.7 04/05/29
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sql.rowset;
9
10 import java.sql.*;
11 import javax.sql.*;
12 import java.io.*;
13
14 import java.lang.reflect.*;
15
16 /**
17  * Provides implementations for the methods that set and get
18  * metadata information about a <code>RowSet</code> object's columns.
19  * A <code>RowSetMetaDataImpl</code> object keeps track of the
20  * number of columns in the rowset and maintains an internal array
21  * of column attributes for each column.
22  * <P>
23  * A <code>RowSet</code> object creates a <code>RowSetMetaDataImpl</code>
24  * object internally in order to set and retrieve information about
25  * its columns.
26  * <P>
27  * NOTE: All metadata in a <code>RowSetMetaDataImpl</code> object
28  * should be considered as unavailable until the <code>RowSet</code> object
29  * that it describes is populated.
30  * Therefore, any <code>RowSetMetaDataImpl</code> method that retrieves information
31  * is defined as having unspecified behavior when it is called
32  * before the <code>RowSet</code> object contains data.
33  */

34 public class RowSetMetaDataImpl implements RowSetMetaData, Serializable {
35
36     /**
37      * The number of columns in the <code>RowSet</code> object that created
38      * this <code>RowSetMetaDataImpl</code> object.
39      * @serial
40      */

41     private int colCount;
42
43     /**
44      * An array of <code>ColInfo</code> objects used to store information
45      * about each column in the <code>RowSet</code> object for which
46      * this <code>RowSetMetaDataImpl</code> object was created. The first
47      * <code>ColInfo</code> object in this array contains information about
48      * the first column in the <code>RowSet</code> object, the second element
49      * contains information about the second column, and so on.
50      * @serial
51      */

52     private ColInfo[] colInfo;
53
54     /**
55      * Checks to see that the designated column is a valid column number for
56      * the <code>RowSet</code> object for which this <code>RowSetMetaDataImpl</code>
57      * was created. To be valid, a column number must be greater than
58      * <code>0</code> and less than or equal to the number of columns in a row.
59      * @throws <code>SQLException</code> with the message "Invalid column index"
60      * if the given column number is out of the range of valid column
61      * numbers for the <code>RowSet</code> object
62      */

63     private void checkColRange(int col) throws SQLException {
64         if (col <= 0 || col > colCount) {
65             throw new SQLException("Invalid column index :"+col);
66         }
67     }
68     
69     /**
70      * Checks to see that the given SQL type is a valid column type and throws an
71      * <code>SQLException</code> object if it is not.
72      * To be valid, a SQL type must be one of the constant values
73      * in the <code><a HREF="../../sql/Types.html">java.sql.Types</a></code>
74      * class.
75      *
76      * @param SQLType an <code>int</code> defined in the class <code>java.sql.Types</code>
77      * @throws SQLException if the given <code>int</code> is not a constant defined in the
78      * class <code>java.sql.Types</code>
79      */

80     private void checkColType(int SQLType) throws SQLException {
81         try {
82             Class JavaDoc c = java.sql.Types JavaDoc.class;
83             Field[] publicFields = c.getFields();
84             int fieldValue = 0;
85             for (int i = 0; i < publicFields.length; i++) {
86                 fieldValue = publicFields[i].getInt(c);
87                 if (fieldValue == SQLType) {
88                     return;
89                  }
90             }
91         } catch (Exception JavaDoc e) {
92             throw new SQLException(e.getMessage());
93         }
94         throw new SQLException("Invalid SQL type for column");
95     }
96
97     /**
98      * Sets to the given number the number of columns in the <code>RowSet</code>
99      * object for which this <code>RowSetMetaDataImpl</code> object was created.
100      *
101      * @param columnCount an <code>int</code> giving the number of columns in the
102      * <code>RowSet</code> object
103      * @throws SQLException if the given number is equal to or less than zero
104      */

105     public void setColumnCount(int columnCount) throws SQLException {
106
107         if (columnCount <= 0) {
108             throw new SQLException("Invalid column count. Cannot be less " +
109                 "or equal to zero");
110         }
111         
112        colCount = columnCount;
113        
114        // If the colCount is Integer.MAX_VALUE,
115
// we do not initialize the colInfo object.
116
// even if we try to initialize the colCount with
117
// colCount = Integer.MAx_VALUE-1, the colInfo
118
// initialization fails throwing an ERROR
119
// OutOfMemory Exception. So we do not initialize
120
// colInfo at Integer.MAX_VALUE. This is to pass TCK.
121

122        if(!(colCount == Integer.MAX_VALUE)) {
123         colInfo = new ColInfo[colCount + 1];
124            
125            for (int i=1; i <= colCount; i++) {
126                  colInfo[i] = new ColInfo();
127            }
128        }
129        
130         
131     }
132
133     /**
134      * Sets whether the designated column is automatically
135      * numbered, thus read-only, to the given <code>boolean</code>
136      * value.
137      *
138      * @param columnIndex the first column is 1, the second is 2, and so on;
139      * must be between <code>1</code> and the number of columns
140      * in the rowset, inclusive
141      * @param property <code>true</code> if the given column is
142      * automatically incremented; <code>false</code>
143      * otherwise
144      * @throws <code>SQLException</code> if a database access error occurs or
145      * the given index is out of bounds
146      */

147     public void setAutoIncrement(int columnIndex, boolean property) throws SQLException {
148         checkColRange(columnIndex);
149         colInfo[columnIndex].autoIncrement = property;
150     }
151
152     /**
153      * Sets whether the name of the designated column is case sensitive to
154      * the given <code>boolean</code>.
155      *
156      * @param columnIndex the first column is 1, the second is 2, and so on;
157      * must be between <code>1</code> and the number of columns
158      * in the rowset, inclusive
159      * @param property <code>true</code> to indicate that the column
160      * name is case sensitive; <code>false</code> otherwise
161      * @throws SQLException if a database access error occurs or
162      * the given column number is out of bounds
163      */

164     public void setCaseSensitive(int columnIndex, boolean property) throws SQLException {
165         checkColRange(columnIndex);
166         colInfo[columnIndex].caseSensitive = property;
167     }
168
169     /**
170      * Sets whether a value stored in the designated column can be used
171      * in a <code>WHERE</code> clause to the given <code>boolean</code> value.
172      *
173      * @param columnIndex the first column is 1, the second is 2, and so on;
174      * must be between <code>1</code> and the number
175      * of columns in the rowset, inclusive
176      * @param property <code>true</code> to indicate that a column
177      * value can be used in a <code>WHERE</code> clause;
178      * <code>false</code> otherwise
179      *
180      * @throws <code>SQLException</code> if a database access error occurs or
181      * the given column number is out of bounds
182      */

183     public void setSearchable(int columnIndex, boolean property)
184         throws SQLException {
185         checkColRange(columnIndex);
186         colInfo[columnIndex].searchable = property;
187     }
188   
189     /**
190      * Sets whether a value stored in the designated column is a cash
191      * value to the given <code>boolean</code>.
192      *
193      * @param columnIndex the first column is 1, the second is 2, and so on;
194      * must be between <code>1</code> and the number of columns,
195      * inclusive between <code>1</code> and the number of columns, inclusive
196      * @param property true if the value is a cash value; false otherwise.
197      * @throws <code>SQLException</code> if a database access error occurs
198      * or the given column number is out of bounds
199      */

200     public void setCurrency(int columnIndex, boolean property)
201         throws SQLException {
202         checkColRange(columnIndex);
203         colInfo[columnIndex].currency = property;
204     }
205   
206     /**
207      * Sets whether a value stored in the designated column can be set
208      * to <code>NULL</code> to the given constant from the interface
209      * <code>ResultSetMetaData</code>.
210      *
211      * @param columnIndex the first column is 1, the second is 2, and so on;
212      * must be between <code>1</code> and the number of columns, inclusive
213      * @param property one of the following <code>ResultSetMetaData</code> constants:
214      * <code>columnNoNulls</code>,
215      * <code>columnNullable</code>, or
216      * <code>columnNullableUnknown</code>
217      *
218      * @throws <code>SQLException</code> if a database access error occurs,
219      * the given column number is out of bounds, or the value supplied
220      * for the <i>property</i> parameter is not one of the following
221      * constants:
222      * <code>ResultSetMetaData.columnNoNulls</code>,
223      * <code>ResultSetMetaData.columnNullable</code>, or
224      * <code>ResultSetMetaData.columnNullableUnknown</code>
225      */

226     public void setNullable(int columnIndex, int property) throws SQLException {
227         if ((property < ResultSetMetaData.columnNoNulls) ||
228             property > ResultSetMetaData.columnNullableUnknown) {
229                 throw new SQLException("Invalid nullable constant set. Must be " +
230                     "either columnNoNulls, columnNullable or columnNullableUnknown");
231         }
232         checkColRange(columnIndex);
233         colInfo[columnIndex].nullable = property;
234     }
235
236     /**
237      * Sets whether a value stored in the designated column is a signed
238      * number to the given <code>boolean</code>.
239      *
240      * @param columnIndex the first column is 1, the second is 2, and so on;
241      * must be between <code>1</code> and the number of columns, inclusive
242      * @param property <code>true</code> to indicate that a column
243      * value is a signed number;
244      * <code>false</code> to indicate that it is not
245      * @throws SQLException if a database access error occurs
246      * or the given column number is out of bounds
247      */

248     public void setSigned(int columnIndex, boolean property) throws SQLException {
249         checkColRange(columnIndex);
250         colInfo[columnIndex].signed = property;
251     }
252   
253     /**
254      * Sets the normal maximum number of chars in the designated column
255      * to the given number.
256      *
257      * @param columnIndex the first column is 1, the second is 2, and so on;
258      * must be between <code>1</code> and the number of columns, inclusive
259      * @param size the maximum size of the column in chars; must be
260      * <code>0</code> or more
261      * @throws SQLException if a database access error occurs,
262      * the given column number is out of bounds, or <i>size</i> is
263      * less than <code>0</code>
264      */

265     public void setColumnDisplaySize(int columnIndex, int size) throws SQLException {
266         if (size < 0) {
267             throw new SQLException("Invalid column display size. Cannot be less " +
268                 "than zero");
269     }
270         checkColRange(columnIndex);
271         colInfo[columnIndex].columnDisplaySize = size;
272     }
273   
274     /**
275      * Sets the suggested column label for use in printouts and
276      * displays, if any, to <i>label</i>. If <i>label</i> is
277      * <code>null</code>, the column label is set to an empty string
278      * ("").
279      *
280      * @param columnIndex the first column is 1, the second is 2, and so on;
281      * must be between <code>1</code> and the number of columns, inclusive
282      * @param label the column label to be used in printouts and displays; if the
283      * column label is <code>null</code>, an empty <code>String</code> is
284      * set
285      * @throws SQLException if a database access error occurs
286      * or the given column index is out of bounds
287      */

288     public void setColumnLabel(int columnIndex, String JavaDoc label) throws SQLException {
289         checkColRange(columnIndex);
290     if (label != null) {
291         colInfo[columnIndex].columnLabel = new String JavaDoc(label);
292         } else {
293         colInfo[columnIndex].columnLabel = new String JavaDoc("");
294         }
295     }
296   
297     /**
298      * Sets the column name of the designated column to the given name.
299      *
300      * @param columnIndex the first column is 1, the second is 2, and so on;
301      * must be between <code>1</code> and the number of columns, inclusive
302      * @param columnName a <code>String</code> object indicating the column name;
303      * if the given name is <code>null</code>, an empty <code>String</code>
304      * is set
305      * @throws SQLException if a database access error occurs or the given column
306      * index is out of bounds
307      */

308     public void setColumnName(int columnIndex, String JavaDoc columnName) throws SQLException {
309         checkColRange(columnIndex);
310         if (columnName != null) {
311             colInfo[columnIndex].columnName = new String JavaDoc(columnName);
312         } else {
313             colInfo[columnIndex].columnName = new String JavaDoc("");
314         }
315     }
316   
317     /**
318      * Sets the designated column's table's schema name, if any, to
319      * <i>schemaName</i>. If <i>schemaName</i> is <code>null</code>,
320      * the schema name is set to an empty string ("").
321      *
322      * @param columnIndex the first column is 1, the second is 2, and so on;
323      * must be between <code>1</code> and the number of columns, inclusive
324      * @param schemaName the schema name for the table from which a value in the
325      * designated column was derived; may be an empty <code>String</code>
326      * or <code>null</code>
327      * @throws SQLException if a database access error occurs
328      * or the given column number is out of bounds
329      */

330     public void setSchemaName(int columnIndex, String JavaDoc schemaName) throws SQLException {
331         checkColRange(columnIndex);
332     if (schemaName != null ) {
333         colInfo[columnIndex].schemaName = new String JavaDoc(schemaName);
334     } else {
335         colInfo[columnIndex].schemaName = new String JavaDoc("");
336     }
337     }
338   
339     /**
340      * Sets the total number of decimal digits in a value stored in the
341      * designated column to the given number.
342      *
343      * @param columnIndex the first column is 1, the second is 2, and so on;
344      * must be between <code>1</code> and the number of columns, inclusive
345      * @param precision the total number of decimal digits; must be <code>0</code>
346      * or more
347      * @throws SQLException if a database access error occurs,
348      * <i>columnIndex</i> is out of bounds, or <i>precision</i>
349      * is less than <code>0</code>
350      */

351     public void setPrecision(int columnIndex, int precision) throws SQLException {
352         
353         if (precision < 0) {
354             throw new SQLException("Invalid precision value. Cannot be less " +
355                 "than zero");
356     }
357         checkColRange(columnIndex);
358         colInfo[columnIndex].colPrecision = precision;
359     }
360   
361     /**
362      * Sets the number of digits to the right of the decimal point in a value
363      * stored in the designated column to the given number.
364      *
365      * @param columnIndex the first column is 1, the second is 2, and so on;
366      * must be between <code>1</code> and the number of columns, inclusive
367      * @param scale the number of digits to the right of the decimal point; must be
368      * zero or greater
369      * @throws SQLException if a database access error occurs,
370      * <i>columnIndex</i> is out of bounds, or <i>scale</i>
371      * is less than <code>0</code>
372      */

373     public void setScale(int columnIndex, int scale) throws SQLException {
374         if (scale < 0) {
375             throw new SQLException("Invalid scale size. Cannot be less " +
376                 "than zero");
377     }
378         checkColRange(columnIndex);
379         colInfo[columnIndex].colScale = scale;
380     }
381   
382     /**
383      * Sets the name of the table from which the designated column
384      * was derived to the given table name.
385      *
386      * @param columnIndex the first column is 1, the second is 2, and so on;
387      * must be between <code>1</code> and the number of columns, inclusive
388      * @param tableName the column's table name; may be <code>null</code> or an
389      * empty string
390      * @throws SQLException if a database access error occurs
391      * or the given column number is out of bounds
392      */

393     public void setTableName(int columnIndex, String JavaDoc tableName) throws SQLException {
394         checkColRange(columnIndex);
395         if (tableName != null) {
396             colInfo[columnIndex].tableName = new String JavaDoc(tableName);
397         } else {
398             colInfo[columnIndex].tableName = new String JavaDoc("");
399         }
400     }
401   
402     /**
403      * Sets the catalog name of the table from which the designated
404      * column was derived to <i>catalogName</i>. If <i>catalogName</i>
405      * is <code>null</code>, the catalog name is set to an empty string.
406      *
407      * @param columnIndex the first column is 1, the second is 2, and so on;
408      * must be between <code>1</code> and the number of columns, inclusive
409      * @param catalogName the column's table's catalog name; if the catalogName
410      * is <code>null</code>, an empty <code>String</code> is set
411      * @throws SQLException if a database access error occurs
412      * or the given column number is out of bounds
413      */

414     public void setCatalogName(int columnIndex, String JavaDoc catalogName) throws SQLException {
415         checkColRange(columnIndex);
416     if (catalogName != null)
417         colInfo[columnIndex].catName = new String JavaDoc(catalogName);
418     else
419         colInfo[columnIndex].catName = new String JavaDoc("");
420     }
421   
422     /**
423      * Sets the SQL type code for values stored in the designated column
424      * to the given type code from the class <code>java.sql.Types</code>.
425      *
426      * @param columnIndex the first column is 1, the second is 2, and so on;
427      * must be between <code>1</code> and the number of columns, inclusive
428      * @param SQLType the designated column's SQL type, which must be one of the
429      * constants in the class <code>java.sql.Types</code>
430      * @throws SQLException if a database access error occurs,
431      * the given column number is out of bounds, or the column type
432      * specified is not one of the constants in
433      * <code>java.sql.Types</code>
434      * @see java.sql.Types
435      */

436     public void setColumnType(int columnIndex, int SQLType) throws SQLException {
437         // examine java.sql.Type reflectively, loop on the fields and check
438
// this. Separate out into a private method
439
checkColType(SQLType);
440         checkColRange(columnIndex);
441         colInfo[columnIndex].colType = SQLType;
442     }
443
444     /**
445      * Sets the type name used by the data source for values stored in the
446      * designated column to the given type name.
447      *
448      * @param columnIndex the first column is 1, the second is 2, and so on;
449      * must be between <code>1</code> and the number of columns, inclusive
450      * @param typeName the data source-specific type name; if <i>typeName</i> is
451      * <code>null</code>, an empty <code>String</code> is set
452      * @throws SQLException if a database access error occurs
453      * or the given column number is out of bounds
454      */

455     public void setColumnTypeName(int columnIndex, String JavaDoc typeName)
456         throws SQLException {
457         checkColRange(columnIndex);
458         if (typeName != null) {
459             colInfo[columnIndex].colTypeName = new String JavaDoc(typeName);
460         } else {
461             colInfo[columnIndex].colTypeName = new String JavaDoc("");
462         }
463     }
464
465     /**
466      * Retrieves the number of columns in the <code>RowSet</code> object
467      * for which this <code>RowSetMetaDataImpl</code> object was created.
468      *
469      * @return the number of columns
470      * @throws SQLException if an error occurs determining the column count
471      */

472     public int getColumnCount() throws SQLException {
473         return colCount;
474     }
475
476     /**
477      * Retrieves whether a value stored in the designated column is
478      * automatically numbered, and thus readonly.
479      *
480      * @param columnIndex the first column is 1, the second is 2, and so on;
481      * must be between <code>1</code> and the number of columns, inclusive
482      * @return <code>true</code> if the column is automatically numbered;
483      * <code>false</code> otherwise
484      * @throws SQLException if a database access error occurs
485      * or the given column number is out of bounds
486      */

487     public boolean isAutoIncrement(int columnIndex) throws SQLException {
488         checkColRange(columnIndex);
489         return colInfo[columnIndex].autoIncrement;
490     }
491
492     /**
493      * Indicates whether the case of the designated column's name
494      * matters.
495      *
496      * @param columnIndex the first column is 1, the second is 2, and so on;
497      * must be between <code>1</code> and the number of columns, inclusive
498      * @return <code>true</code> if the column name is case sensitive;
499      * <code>false</code> otherwise
500      * @throws SQLException if a database access error occurs
501      * or the given column number is out of bounds
502      */

503     public boolean isCaseSensitive(int columnIndex) throws SQLException {
504         checkColRange(columnIndex);
505         return colInfo[columnIndex].caseSensitive;
506     }
507
508     /**
509      * Indicates whether a value stored in the designated column
510      * can be used in a <code>WHERE</code> clause.
511      *
512      * @param columnIndex the first column is 1, the second is 2, and so on;
513      * must be between <code>1</code> and the number of columns, inclusive
514      * @return <code>true</code> if a value in the designated column can be used in a
515      * <code>WHERE</code> clause; <code>false</code> otherwise
516      * @throws SQLException if a database access error occurs
517      * or the given column number is out of bounds
518      */

519     public boolean isSearchable(int columnIndex) throws SQLException {
520         checkColRange(columnIndex);
521         return colInfo[columnIndex].searchable;
522     }
523
524     /**
525      * Indicates whether a value stored in the designated column
526      * is a cash value.
527      *
528      * @param columnIndex the first column is 1, the second is 2, and so on;
529      * must be between <code>1</code> and the number of columns, inclusive
530      * @return <code>true</code> if a value in the designated column is a cash value;
531      * <code>false</code> otherwise
532      * @throws SQLException if a database access error occurs
533      * or the given column number is out of bounds
534      */

535     public boolean isCurrency(int columnIndex) throws SQLException {
536         checkColRange(columnIndex);
537         return colInfo[columnIndex].currency;
538     }
539
540     /**
541      * Retrieves a constant indicating whether it is possible
542      * to store a <code>NULL</code> value in the designated column.
543      *
544      * @param columnIndex the first column is 1, the second is 2, and so on;
545      * must be between <code>1</code> and the number of columns, inclusive
546      * @return a constant from the <code>ResultSetMetaData</code> interface;
547      * either <code>columnNoNulls</code>,
548      * <code>columnNullable</code>, or
549      * <code>columnNullableUnknown</code>
550      * @throws SQLException if a database access error occurs
551      * or the given column number is out of bounds
552      */

553     public int isNullable(int columnIndex) throws SQLException {
554         checkColRange(columnIndex);
555         return colInfo[columnIndex].nullable;
556     }
557
558     /**
559      * Indicates whether a value stored in the designated column is
560      * a signed number.
561      *
562      * @param columnIndex the first column is 1, the second is 2, and so on;
563      * must be between <code>1</code> and the number of columns, inclusive
564      * @return <code>true</code> if if a value in the designated column is a signed
565      * number; <code>false</code> otherwise
566      * @throws SQLException if a database access error occurs
567      * or the given column number is out of bounds
568      */

569     public boolean isSigned(int columnIndex) throws SQLException {
570         checkColRange(columnIndex);
571         return colInfo[columnIndex].signed;
572     }
573
574     /**
575      * Retrieves the normal maximum width in chars of the designated column.
576      *
577      * @param columnIndex the first column is 1, the second is 2, and so on;
578      * must be between <code>1</code> and the number of columns, inclusive
579      * @return the maximum number of chars that can be displayed in the designated
580      * column
581      * @throws SQLException if a database access error occurs
582      * or the given column number is out of bounds
583      */

584     public int getColumnDisplaySize(int columnIndex) throws SQLException {
585         checkColRange(columnIndex);
586         return colInfo[columnIndex].columnDisplaySize;
587     }
588
589     /**
590      * Retrieves the the suggested column title for the designated
591      * column for use in printouts and displays.
592      *
593      * @param columnIndex the first column is 1, the second is 2, and so on;
594      * must be between <code>1</code> and the number of columns, inclusive
595      * @return the suggested column name to use in printouts and displays
596      * @throws SQLException if a database access error occurs
597      * or the given column number is out of bounds
598      */

599     public String JavaDoc getColumnLabel(int columnIndex) throws SQLException {
600         checkColRange(columnIndex);
601         return colInfo[columnIndex].columnLabel;
602     }
603
604     /**
605      * Retrieves the name of the designated column.
606      *
607      * @param columnIndex the first column is 1, the second is 2, and so on;
608      * must be between <code>1</code> and the number of columns, inclusive
609      * @return the column name of the designated column
610      * @throws SQLException if a database access error occurs
611      * or the given column number is out of bounds
612      */

613     public String JavaDoc getColumnName(int columnIndex) throws SQLException {
614         checkColRange(columnIndex);
615         return colInfo[columnIndex].columnName;
616     }
617
618     /**
619      * Retrieves the schema name of the table from which the value
620      * in the designated column was derived.
621      *
622      * @param columnIndex the first column is 1, the second is 2, and so on;
623      * must be between <code>1</code> and the number of columns,
624      * inclusive
625      * @return the schema name or an empty <code>String</code> if no schema
626      * name is available
627      * @throws SQLException if a database access error occurs
628      * or the given column number is out of bounds
629      */

630     public String JavaDoc getSchemaName(int columnIndex) throws SQLException {
631         checkColRange(columnIndex);
632         String JavaDoc str ="";
633         if(colInfo[columnIndex].schemaName == null){
634         } else {
635               str = colInfo[columnIndex].schemaName;
636         }
637         return str;
638     }
639
640     /**
641      * Retrieves the total number of digits for values stored in
642      * the designated column.
643      *
644      * @param columnIndex the first column is 1, the second is 2, and so on;
645      * must be between <code>1</code> and the number of columns, inclusive
646      * @return the precision for values stored in the designated column
647      * @throws SQLException if a database access error occurs
648      * or the given column number is out of bounds
649      */

650     public int getPrecision(int columnIndex) throws SQLException {
651         checkColRange(columnIndex);
652         return colInfo[columnIndex].colPrecision;
653     }
654
655     /**
656      * Retrieves the number of digits to the right of the decimal point
657      * for values stored in the designated column.
658      *
659      * @param columnIndex the first column is 1, the second is 2, and so on;
660      * must be between <code>1</code> and the number of columns, inclusive
661      * @return the scale for values stored in the designated column
662      * @throws SQLException if a database access error occurs
663      * or the given column number is out of bounds
664      */

665     public int getScale(int columnIndex) throws SQLException {
666         checkColRange(columnIndex);
667         return colInfo[columnIndex].colScale;
668     }
669
670     /**
671      * Retrieves the name of the table from which the value
672      * in the designated column was derived.
673      *
674      * @param columnIndex the first column is 1, the second is 2, and so on;
675      * must be between <code>1</code> and the number of columns, inclusive
676      * @return the table name or an empty <code>String</code> if no table name
677      * is available
678      * @throws SQLException if a database access error occurs
679      * or the given column number is out of bounds
680      */

681     public String JavaDoc getTableName(int columnIndex) throws SQLException {
682         checkColRange(columnIndex);
683         return colInfo[columnIndex].tableName;
684     }
685
686     /**
687      * Retrieves the catalog name of the table from which the value
688      * in the designated column was derived.
689      *
690      * @param columnIndex the first column is 1, the second is 2, and so on;
691      * must be between <code>1</code> and the number of columns, inclusive
692      * @return the catalog name of the column's table or an empty
693      * <code>String</code> if no catalog name is available
694      * @throws SQLException if a database access error occurs
695      * or the given column number is out of bounds
696      */

697     public String JavaDoc getCatalogName(int columnIndex) throws SQLException {
698         checkColRange(columnIndex);
699         String JavaDoc str ="";
700         if(colInfo[columnIndex].catName == null){
701         } else {
702            str = colInfo[columnIndex].catName;
703         }
704         return str;
705     }
706
707     /**
708      * Retrieves the type code (one of the <code>java.sql.Types</code>
709      * constants) for the SQL type of the value stored in the
710      * designated column.
711      *
712      * @param columnIndex the first column is 1, the second is 2, and so on;
713      * must be between <code>1</code> and the number of columns, inclusive
714      * @return an <code>int</code> representing the SQL type of values
715      * stored in the designated column
716      * @throws SQLException if a database access error occurs
717      * or the given column number is out of bounds
718      * @see java.sql.Types
719      */

720     public int getColumnType(int columnIndex) throws SQLException {
721         checkColRange(columnIndex);
722         return colInfo[columnIndex].colType;
723     }
724
725     /**
726      * Retrieves the DBMS-specific type name for values stored in the
727      * designated column.
728      *
729      * @param columnIndex the first column is 1, the second is 2, and so on;
730      * must be between <code>1</code> and the number of columns, inclusive
731      * @return the type name used by the data source
732      * @throws SQLException if a database access error occurs
733      * or the given column number is out of bounds
734      */

735     public String JavaDoc getColumnTypeName(int columnIndex) throws SQLException {
736         checkColRange(columnIndex);
737         return colInfo[columnIndex].colTypeName;
738     }
739     
740     
741     /**
742      * Indicates whether the designated column is definitely
743      * not writable, thus readonly.
744      *
745      * @param columnIndex the first column is 1, the second is 2, and so on;
746      * must be between <code>1</code> and the number of columns, inclusive
747      * @return <code>true</code> if this <code>RowSet</code> object is read-Only
748      * and thus not updatable; <code>false</code> otherwise
749      * @throws SQLException if a database access error occurs
750      * or the given column number is out of bounds
751      */

752     public boolean isReadOnly(int columnIndex) throws SQLException {
753         checkColRange(columnIndex);
754         return colInfo[columnIndex].readOnly;
755     }
756
757     /**
758      * Indicates whether it is possible for a write operation on
759      * the designated column to succeed. A return value of
760      * <code>true</code> means that a write operation may or may
761      * not succeed.
762      *
763      * @param columnIndex the first column is 1, the second is 2, and so on;
764      * must be between <code>1</code> and the number of columns, inclusive
765      * @return <code>true</code> if a write operation on the designated column may
766      * will succeed; <code>false</code> otherwise
767      * @throws SQLException if a database access error occurs
768      * or the given column number is out of bounds
769      */

770     public boolean isWritable(int columnIndex) throws SQLException {
771         checkColRange(columnIndex);
772         return colInfo[columnIndex].writable;
773     }
774
775     /**
776      * Indicates whether a write operation on the designated column
777      * will definitely succeed.
778      *
779      * @param columnIndex the first column is 1, the second is 2, and so on;
780      * must be between <code>1</code> and the number of columns, inclusive
781      * @return <code>true</code> if a write operation on the designated column will
782      * definitely succeed; <code>false</code> otherwise
783      * @throws SQLException if a database access error occurs
784      * or the given column number is out of bounds
785      */

786     public boolean isDefinitelyWritable(int columnIndex)
787         throws SQLException { return true;}
788
789     /**
790      * Retrieves the fully-qualified name of the class in the Java
791      * programming language to which a value in the designated column
792      * will be mapped. For example, if the value is an <code>int</code>,
793      * the class name returned by this method will be
794      * <code>java.lang.Integer</code>.
795      * <P>
796      * If the value in the designated column has a custom mapping,
797      * this method returns the name of the class that implements
798      * <code>SQLData</code>. When the method <code>ResultSet.getObject</code>
799      * is called to retrieve a value from the designated column, it will
800      * create an instance of this class or one of its subclasses.
801      *
802      * @param columnIndex the first column is 1, the second is 2, and so on;
803      * must be between <code>1</code> and the number of columns, inclusive
804      * @return the fully-qualified name of the class in the Java programming
805      * language that would be used by the method <code>RowSet.getObject</code> to
806      * retrieve the value in the specified column. This is the class
807      * name used for custom mapping when there is a custom mapping.
808      * @throws SQLException if a database access error occurs
809      * or the given column number is out of bounds
810      */

811     public String JavaDoc getColumnClassName(int columnIndex) throws SQLException {
812         String JavaDoc className = (new String JavaDoc()).getClass().getName();
813         
814         int sqlType = getColumnType(columnIndex);
815
816         switch (sqlType) {
817
818         case Types.NUMERIC:
819         case Types.DECIMAL:
820             className = (new java.math.BigDecimal JavaDoc(0)).getClass().getName ();
821             break;
822
823         case Types.BIT:
824             className = (new Boolean JavaDoc(false)).getClass().getName ();
825             break;
826
827         case Types.TINYINT:
828             className = (new Byte JavaDoc("0")).getClass().getName ();
829             break;
830
831         case Types.SMALLINT:
832             className = (new Short JavaDoc("0")).getClass().getName ();
833             break;
834
835         case Types.INTEGER:
836             className = (new Integer JavaDoc(0)).getClass().getName ();
837             break;
838
839         case Types.BIGINT:
840             className = (new Long JavaDoc(0)).getClass().getName ();
841             break;
842
843         case Types.REAL:
844             className = (new Float JavaDoc(0)).getClass().getName ();
845             break;
846
847         case Types.FLOAT:
848         case Types.DOUBLE:
849             className = (new Double JavaDoc(0)).getClass().getName();
850             break;
851             
852         case Types.BINARY:
853         case Types.VARBINARY:
854         case Types.LONGVARBINARY:
855             byte[] b = {};
856             className = (b.getClass()).getName();
857             break;
858
859         case Types.DATE:
860             className = (new java.sql.Date JavaDoc(123456)).getClass().getName ();
861             break;
862
863         case Types.TIME:
864             className = (new java.sql.Time JavaDoc(123456)).getClass().getName ();
865             break;
866             
867         case Types.TIMESTAMP:
868             className = (new java.sql.Timestamp JavaDoc(123456)).getClass().getName ();
869             break;
870             
871         case Types.BLOB:
872             byte[] blob = {};
873             className = (blob.getClass()).getName();
874             break;
875
876         case Types.CLOB:
877             char[] c = {};
878             className = (c.getClass()).getName();
879             break;
880         }
881         
882         return className;
883     }
884     
885     static final long serialVersionUID = 6893806403181801867L;
886     
887     private class ColInfo implements Serializable {
888         /**
889          * The field that indicates whether the value in this column is a number
890          * that is incremented automatically, which makes the value read-only.
891          * <code>true</code> means that the value in this column
892          * is automatically numbered; <code>false</code> means that it is not.
893          *
894          * @serial
895          */

896         public boolean autoIncrement;
897
898         /**
899          * The field that indicates whether the value in this column is case sensitive.
900          * <code>true</code> means that it is; <code>false</code> that it is not.
901          *
902          * @serial
903          */

904         public boolean caseSensitive;
905         
906         /**
907          * The field that indicates whether the value in this column is a cash value
908          * <code>true</code> means that it is; <code>false</code> that it is not.
909          *
910          * @serial
911          */

912         public boolean currency;
913
914         /**
915          * The field that indicates whether the value in this column is nullable.
916          * The possible values are the <code>ResultSet</code> constants
917          * <code>columnNoNulls</code>, <code>columnNullable</code>, and
918          * <code>columnNullableUnknown</code>.
919          *
920          * @serial
921          */

922         public int nullable;
923         
924         /**
925          * The field that indicates whether the value in this column is a signed number.
926          * <code>true</code> means that it is; <code>false</code> that it is not.
927          *
928          * @serial
929          */

930         public boolean signed;
931         
932         /**
933          * The field that indicates whether the value in this column can be used in
934          * a <code>WHERE</code> clause.
935          * <code>true</code> means that it can; <code>false</code> that it cannot.
936          *
937          * @serial
938          */

939         public boolean searchable;
940         
941         /**
942          * The field that indicates the normal maximum width in characters for
943          * this column.
944          *
945          * @serial
946          */

947         public int columnDisplaySize;
948         
949         /**
950          * The field that holds the suggested column title for this column, to be
951          * used in printing and displays.
952          *
953          * @serial
954          */

955         public String JavaDoc columnLabel;
956         
957         /**
958          * The field that holds the name of this column.
959          *
960          * @serial
961          */

962         public String JavaDoc columnName;
963         
964         /**
965          * The field that holds the schema name for the table from which this column
966          * was derived.
967          *
968          * @serial
969          */

970         public String JavaDoc schemaName;
971         
972         /**
973          * The field that holds the precision of the value in this column. For number
974          * types, the precision is the total number of decimal digits; for character types,
975          * it is the maximum number of characters; for binary types, it is the maximum
976          * length in bytes.
977          *
978          * @serial
979          */

980         public int colPrecision;
981         
982         /**
983          * The field that holds the scale (number of digits to the right of the decimal
984          * point) of the value in this column.
985          *
986          * @serial
987          */

988         public int colScale;
989         
990         /**
991          * The field that holds the name of the table from which this column
992          * was derived. This value may be the empty string if there is no
993          * table name, such as when this column is produced by a join.
994          *
995          * @serial
996          */

997         public String JavaDoc tableName ="";
998         
999         /**
1000         * The field that holds the catalog name for the table from which this column
1001         * was derived. If the DBMS does not support catalogs, the value may be the
1002         * empty string.
1003         *
1004         * @serial
1005         */

1006        public String JavaDoc catName;
1007        
1008        /**
1009         * The field that holds the type code from the class <code>java.sql.Types</code>
1010         * indicating the type of the value in this column.
1011         *
1012         * @serial
1013         */

1014        public int colType;
1015        
1016        /**
1017         * The field that holds the the type name used by this particular data source
1018         * for the value stored in this column.
1019         *
1020         * @serial
1021         */

1022        public String JavaDoc colTypeName;
1023        
1024        /**
1025         * The field that holds the updatablity boolean per column of a RowSet
1026         *
1027         * @serial
1028         */

1029        public boolean readOnly = false;
1030        
1031        /**
1032         * The field that hold the writable boolean per column of a RowSet
1033         *
1034         *@serial
1035         */

1036        public boolean writable = true;
1037    }
1038}
1039
1040
1041
1042
Popular Tags