KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > jdbc > ResultSetMetaData


1 package com.quadcap.jdbc;
2
3 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
4  *
5  * This software is distributed under the Quadcap Free Software License.
6  * This software may be used or modified for any purpose, personal or
7  * commercial. Open Source redistributions are permitted. Commercial
8  * redistribution of larger works derived from, or works which bundle
9  * this software requires a "Commercial Redistribution License"; see
10  * http://www.quadcap.com/purchase.
11  *
12  * Redistributions qualify as "Open Source" under one of the following terms:
13  *
14  * Redistributions are made at no charge beyond the reasonable cost of
15  * materials and delivery.
16  *
17  * Redistributions are accompanied by a copy of the Source Code or by an
18  * irrevocable offer to provide a copy of the Source Code for up to three
19  * years at the cost of materials and delivery. Such redistributions
20  * must allow further use, modification, and redistribution of the Source
21  * Code under substantially the same terms as this license.
22  *
23  * Redistributions of source code must retain the copyright notices as they
24  * appear in each source code file, these license terms, and the
25  * disclaimer/limitation of liability set forth as paragraph 6 below.
26  *
27  * Redistributions in binary form must reproduce this Copyright Notice,
28  * these license terms, and the disclaimer/limitation of liability set
29  * forth as paragraph 6 below, in the documentation and/or other materials
30  * provided with the distribution.
31  *
32  * The Software is provided on an "AS IS" basis. No warranty is
33  * provided that the Software is free of defects, or fit for a
34  * particular purpose.
35  *
36  * Limitation of Liability. Quadcap Software shall not be liable
37  * for any damages suffered by the Licensee or any third party resulting
38  * from use of the Software.
39  */

40
41 import java.sql.SQLException JavaDoc;
42
43 import com.quadcap.sql.Column;
44 import com.quadcap.sql.Cursor;
45 import com.quadcap.sql.Tuple;
46
47 import com.quadcap.sql.types.Type;
48
49 import com.quadcap.util.Debug;
50
51 /**
52  * This class implements the <code>java.sql.ResultSetMetaData</code>
53  * interface, which provides a mechanism to obtain information about
54  * the columns in a <code>ResultSet</code> object.
55  *
56  * @author Stan Bailes
57  */

58 public class ResultSetMetaData implements java.sql.ResultSetMetaData JavaDoc {
59     Cursor cursor;
60
61     /**
62      * @deprecated
63      */

64     public ResultSetMetaData(Cursor cursor) {
65     this.cursor = cursor;
66     }
67     
68     /**
69      * QED doesn't support catalogs.
70      */

71     public String JavaDoc getCatalogName(int column) throws SQLException JavaDoc {
72     return "";
73     }
74
75     /**
76      * Return the fully qualified class name of the Java class to which
77      * the specified column will be mapped
78      *
79      * @param column the column number
80      * @return the column's class name
81      * @exception SQLException may be thrown
82      */

83     public String JavaDoc getColumnClassName(int column) throws SQLException JavaDoc {
84     return getType(column).getJDBCClassName();
85     }
86     
87     /**
88      * Return the number of columns in the <code>ResultSet</code>.
89      *
90      * @return the number of columns in the <code>ResultSet</code>.
91      * @exception SQLException may be thrown
92      */

93     public int getColumnCount() throws SQLException JavaDoc {
94     return cursor.getColumnCount();
95     }
96     
97     /**
98      * Return the normal maximum width in characters of the values in
99      * the specified column
100      *
101      * @param column the column number
102      * @return the maximum display size of a value in this column
103      * @exception SQLException may be thrown
104      */

105     public int getColumnDisplaySize(int column) throws SQLException JavaDoc {
106     Column col = cursor.getColumn(column);
107     int w2;
108     if (col.getType() != null) {
109         w2 = col.getType().getDisplayWidth();
110     } else {
111             w2 = col.getShortName().length();
112         }
113         return w2;
114     }
115     
116     /**
117      * Return the shortest possible name for this column, such that the
118      * name is unique within this <code>ResultSet</code> object.
119      *
120      * @param column the column number
121      * @return the column label
122      * @exception SQLException may be thrown
123      */

124     public String JavaDoc getColumnLabel(int column) throws SQLException JavaDoc {
125     return cursor.getColumn(column).getShortName();
126     }
127     
128     /**
129      * Return the shortest possible name for this column, such that the
130      * name is unique within this <code>ResultSet</code> object.
131      *
132      * @param column the column number
133      * @return the column name
134      * @exception SQLException may be thrown
135      */

136     public String JavaDoc getColumnName(int column) throws SQLException JavaDoc {
137     return cursor.getColumn(column).getShortName();
138     }
139     
140     /**
141      * Return the JDBC type of this column
142      *
143      * @param column the column number
144      * @return the column's JDBC type
145      * @exception SQLException may be thrown
146      */

147     public int getColumnType(int column) throws SQLException JavaDoc {
148     return getType(column).getJDBCType();
149     }
150     
151     /**
152      * Return the SQL type name of this column
153      *
154      * @param column the column number
155      * @return the column's SQL type
156      * @exception SQLException may be thrown
157      */

158     public String JavaDoc getColumnTypeName(int column) throws SQLException JavaDoc {
159     return getType(column).getTypeName();
160     }
161     
162     /**
163      * Return the maximum precision of this column, or -1 if this column
164      * is not a numeric type.
165      *
166      * @param column the column number
167      * @return the column's maximum precision
168      * @exception SQLException may be thrown
169      */

170     public int getPrecision(int column) throws SQLException JavaDoc {
171     return getType(column).getPrecision();
172     }
173     
174     /**
175      * Return the scale of this column, or -1 if this column is not
176      * a numeric type
177      *
178      * @param column the column number
179      * @return the column's scale
180      * @exception SQLException may be thrown
181      */

182     public int getScale(int column) throws SQLException JavaDoc {
183     return getType(column).getScale();
184     }
185     
186     /**
187      * Return the schema name for the table from which this column
188      * is derived. This function works for normal columns, but
189      * returns the empty string for computed columns.
190      *
191      * @param column the column number
192      * @return the column's table's schema's name
193      * @exception SQLException may be thrown
194      */

195     public String JavaDoc getSchemaName(int column) throws SQLException JavaDoc {
196     String JavaDoc s = cursor.getColumn(column).getName();
197     int idx = s.indexOf('.');
198     if (idx >= 0) {
199         return s.substring(0, idx);
200     } else {
201         return "";
202     }
203     }
204     
205     /**
206      * Return name of the table from which this column is derived.
207      *
208      * @param column the column number
209      * @return the column's table's name
210      * @exception SQLException may be thrown
211      */

212     public String JavaDoc getTableName(int column) throws SQLException JavaDoc {
213     String JavaDoc ret = "";
214     Tuple table = cursor.getColumn(column).getRelation();
215     if (table != null) ret = table.getName();
216     return ret;
217     }
218     
219     /**
220      * Return <code>true</code> if this is an auto-increment type.
221      *
222      * @param column the column number
223      * @return false
224      * @exception SQLException may be thrown
225      */

226     public boolean isAutoIncrement(int column) throws SQLException JavaDoc {
227         Column col = cursor.getColumn(column);
228     return cursor.getColumn(column).isAutoIncrement();
229     }
230     
231     /**
232      * Return <code>true</code> if this column is case-sensitive.
233      * QED always returns <code>false</code>.
234      *
235      * @param column the column number
236      * @return false
237      * @exception SQLException may be thrown
238      */

239     public boolean isCaseSensitive(int column) throws SQLException JavaDoc {
240     return getType(column).isCaseSensitive();
241     }
242     
243     /**
244      * Return <code>true</code> if this column is a cash value.
245      * QED always returns <code>false</code>.
246      *
247      * @param column the column number
248      * @return false
249      * @exception SQLException may be thrown
250      */

251     public boolean isCurrency(int column) throws SQLException JavaDoc {
252     return getType(column).isCurrency();
253     }
254     
255     /**
256      * Return <code>true</code> if this column is definitely
257      * writable
258      *
259      * @param column the column number
260      * @return true if this column is writable
261      * @exception SQLException may be thrown
262      */

263     public boolean isDefinitelyWritable(int column) throws SQLException JavaDoc {
264     return cursor.isWritable(column);
265     }
266     
267     /**
268      * Return the JDBC 'nullability' state for this column
269      *
270      * @param column the column number
271      * @return if this column can contain <code>NULL</code>s
272      * @exception SQLException may be thrown
273      */

274     public int isNullable(int column) throws SQLException JavaDoc {
275     return cursor.getColumn(column).getNullable();
276     }
277     
278     /**
279      * Return <code>true</code> if this column is not writable
280      *
281      * @param column the column number
282      * @return true if this column is read-only
283      * @exception SQLException may be thrown
284      */

285     public boolean isReadOnly(int column) throws SQLException JavaDoc {
286     return !cursor.isWritable(column);
287     }
288     
289     /**
290      * Return true if the column can be used in a <code>WHERE</code>
291      * clause. QED always returns <code>true</code>
292      *
293      * @param column the column number
294      * @return true
295      * @exception SQLException may be thrown
296      */

297     public boolean isSearchable(int column) throws SQLException JavaDoc {
298     return true;
299     }
300     
301     /**
302      * Return true if this column contains a signed number. In QED, this
303      * is true for all numeric types and for intervals.
304      *
305      * @param column the column number
306      * @return true if this column contains a signed number
307      * @exception SQLException may be thrown
308      */

309     public boolean isSigned(int column) throws SQLException JavaDoc {
310     return getType(column).isSigned();
311     }
312     
313     /**
314      * Return <code>true</code> if this column is writable.
315      *
316      * @param column the column number
317      * @return true if this column is writable.
318      * @exception SQLException may be thrown
319      */

320     public boolean isWritable(int column) throws SQLException JavaDoc {
321     return cursor.isWritable(column);
322     }
323
324     private Type getType(int column) throws SQLException JavaDoc {
325         Type t = cursor.getColumn(column).getType();
326         return t;
327     }
328     
329 }
330
Popular Tags