KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > jdbc > DjResultSetMetaData


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.genimen.djeneric.jdbc;
32
33 import java.sql.ResultSetMetaData JavaDoc;
34 import java.sql.SQLException JavaDoc;
35
36 import com.genimen.djeneric.repository.DjDomain;
37
38 /**
39  * @author Gert Rijs
40  * @version 1.0
41  */

42
43 public class DjResultSetMetaData implements ResultSetMetaData JavaDoc
44 {
45   DjResultSet _rs = null;
46
47   /* package */
48   DjResultSetMetaData(DjResultSet p_rs) throws SQLException JavaDoc
49   {
50     this._rs = p_rs;
51   }
52
53   protected void finalize()
54   {
55     try
56     {
57       super.finalize();
58       _rs = null;
59     }
60     catch (Throwable JavaDoc e)
61     {
62     }
63   }
64
65   /**
66    * Returns the number of columns in this <code>ResultSet</code> object.
67    *
68    * @return the number of columns
69    * @exception SQLException
70    * if a database access error occurs
71    */

72   public int getColumnCount() throws SQLException JavaDoc
73   {
74     return _rs._columns.size();
75   }
76
77   /**
78    * Indicates whether the designated column is automatically numbered, thus
79    * read-only.
80    *
81    * @param column
82    * the first column is 1, the second is 2, ...
83    * @return <code>true</code> if so; <code>false</code> otherwise
84    * @exception SQLException
85    * if a database access error occurs
86    */

87   public boolean isAutoIncrement(int column) throws SQLException JavaDoc
88   {
89     return false;
90   }
91
92   /**
93    * Indicates whether a column's case matters.
94    *
95    * @param column
96    * the first column is 1, the second is 2, ...
97    * @return <code>true</code> if so; <code>false</code> otherwise
98    * @exception SQLException
99    * if a database access error occurs
100    */

101   public boolean isCaseSensitive(int column) throws SQLException JavaDoc
102   {
103     return true;
104   }
105
106   /**
107    * Indicates whether the designated column can be used in a where clause.
108    *
109    * @param column
110    * the first column is 1, the second is 2, ...
111    * @return <code>true</code> if so; <code>false</code> otherwise
112    * @exception SQLException
113    * if a database access error occurs
114    */

115   public boolean isSearchable(int column) throws SQLException JavaDoc
116   {
117     return true;
118   }
119
120   /**
121    * Indicates whether the designated column is a cash value.
122    *
123    * @param column
124    * the first column is 1, the second is 2, ...
125    * @return <code>true</code> if so; <code>false</code> otherwise
126    * @exception SQLException
127    * if a database access error occurs
128    */

129   public boolean isCurrency(int column) throws SQLException JavaDoc
130   {
131     return false;
132   }
133
134   /**
135    * Indicates the nullability of values in the designated column.
136    *
137    * @param column
138    * the first column is 1, the second is 2, ...
139    * @return the nullability status of the given column; one of <code>columnNoNulls</code>,
140    * <code>columnNullable</code> or <code>columnNullableUnknown</code>
141    * @exception SQLException
142    * if a database access error occurs
143    */

144   public int isNullable(int column) throws SQLException JavaDoc
145   {
146     return _rs.getColumnDefinition(column).isRequired() ? columnNoNulls : columnNullable;
147   }
148
149   /**
150    * Indicates whether values in the designated column are signed numbers.
151    *
152    * @param column
153    * the first column is 1, the second is 2, ...
154    * @return <code>true</code> if so; <code>false</code> otherwise
155    * @exception SQLException
156    * if a database access error occurs
157    */

158   public boolean isSigned(int column) throws SQLException JavaDoc
159   {
160     int tc = _rs.getColumnDefinition(column).getType().getTypeCode();
161     switch (tc)
162     {
163       case DjDomain.BIGDECIMAL_TYPE :
164       case DjDomain.INT_TYPE :
165       case DjDomain.LONG_TYPE :
166         return true;
167     }
168     return false;
169   }
170
171   /**
172    * Indicates the designated column's normal maximum width in characters.
173    *
174    * @param column
175    * the first column is 1, the second is 2, ...
176    * @return the normal maximum number of characters allowed as the width of
177    * the designated column
178    * @exception SQLException
179    * if a database access error occurs
180    */

181   public int getColumnDisplaySize(int column) throws SQLException JavaDoc
182   {
183     return _rs.getColumnDefinition(column).getLength();
184   }
185
186   /**
187    * Gets the designated column's suggested title for use in printouts and
188    * displays.
189    *
190    * @param column
191    * the first column is 1, the second is 2, ...
192    * @return the suggested column title
193    * @exception SQLException
194    * if a database access error occurs
195    */

196   public String JavaDoc getColumnLabel(int column) throws SQLException JavaDoc
197   {
198     return _rs.getColumnDefinition(column).getPrompt();
199   }
200
201   /**
202    * Get the designated column's name.
203    *
204    * @param column
205    * the first column is 1, the second is 2, ...
206    * @return column name
207    * @exception SQLException
208    * if a database access error occurs
209    */

210   public String JavaDoc getColumnName(int column) throws SQLException JavaDoc
211   {
212     return _rs.getColumnDefinition(column).getName();
213   }
214
215   /**
216    * Get the designated column's table's schema.
217    *
218    * @param column
219    * the first column is 1, the second is 2, ...
220    * @return schema name or "" if not applicable
221    * @exception SQLException
222    * if a database access error occurs
223    */

224   public String JavaDoc getSchemaName(int column) throws SQLException JavaDoc
225   {
226     return "";
227   }
228
229   /**
230    * Get the designated column's number of decimal digits.
231    *
232    * @param column
233    * the first column is 1, the second is 2, ...
234    * @return precision
235    * @exception SQLException
236    * if a database access error occurs
237    */

238   public int getPrecision(int column) throws SQLException JavaDoc
239   {
240     return _rs.getColumnDefinition(column).getLength();
241   }
242
243   /**
244    * Gets the designated column's number of digits to right of the decimal
245    * point.
246    *
247    * @param column
248    * the first column is 1, the second is 2, ...
249    * @return scale
250    * @exception SQLException
251    * if a database access error occurs
252    */

253   public int getScale(int column) throws SQLException JavaDoc
254   {
255     return _rs.getColumnDefinition(column).getDecimals();
256   }
257
258   /**
259    * Gets the designated column's table name.
260    *
261    * @param column
262    * the first column is 1, the second is 2, ...
263    * @return table name or "" if not applicable
264    * @exception SQLException
265    * if a database access error occurs
266    */

267   public String JavaDoc getTableName(int column) throws SQLException JavaDoc
268   {
269     return _rs.getColumnDefinition(column).getExtent().getName();
270   }
271
272   /**
273    * Gets the designated column's table's catalog name.
274    *
275    * @param column
276    * the first column is 1, the second is 2, ...
277    * @return column name or "" if not applicable
278    * @exception SQLException
279    * if a database access error occurs
280    */

281   public String JavaDoc getCatalogName(int column) throws SQLException JavaDoc
282   {
283     return "";
284   }
285
286   /**
287    * Retrieves the designated column's SQL type.
288    *
289    * @param column
290    * the first column is 1, the second is 2, ...
291    * @return SQL type from java.sql.Types
292    * @exception SQLException
293    * if a database access error occurs
294    * @see Types
295    */

296   public int getColumnType(int column) throws SQLException JavaDoc
297   {
298     switch (_rs.getColumnDefinition(column).getTypeCode())
299     {
300       case DjDomain.BIGDECIMAL_TYPE :
301         return java.sql.Types.DECIMAL;
302       case DjDomain.INT_TYPE :
303         return java.sql.Types.INTEGER;
304       case DjDomain.LONG_TYPE :
305         return java.sql.Types.INTEGER;
306       case DjDomain.STRING_TYPE :
307         return java.sql.Types.VARCHAR;
308       case DjDomain.DATE_TYPE :
309         return java.sql.Types.DATE;
310     }
311
312     return java.sql.Types.VARCHAR;
313   }
314
315   /**
316    * Retrieves the designated column's database-specific type name.
317    *
318    * @param column
319    * the first column is 1, the second is 2, ...
320    * @return type name used by the database. If the column type is a
321    * user-defined type, then a fully-qualified type name is returned.
322    * @exception SQLException
323    * if a database access error occurs
324    */

325   public String JavaDoc getColumnTypeName(int column) throws SQLException JavaDoc
326   {
327     switch (getColumnType(column))
328     {
329       case java.sql.Types.DECIMAL :
330         return "DECIMAL";
331       case java.sql.Types.TIMESTAMP :
332         return "TIMESTAMP";
333       case java.sql.Types.VARCHAR :
334         return "STRING";
335     }
336     DjAssert.check(false);
337     return null;
338   }
339
340   /**
341    * Indicates whether the designated column is definitely not writable.
342    *
343    * @param column
344    * the first column is 1, the second is 2, ...
345    * @return <code>true</code> if so; <code>false</code> otherwise
346    * @exception SQLException
347    * if a database access error occurs
348    */

349   public boolean isReadOnly(int column) throws SQLException JavaDoc
350   {
351     return true;
352   }
353
354   /**
355    * Indicates whether it is possible for a write on the designated column to
356    * succeed.
357    *
358    * @param column
359    * the first column is 1, the second is 2, ...
360    * @return <code>true</code> if so; <code>false</code> otherwise
361    * @exception SQLException
362    * if a database access error occurs
363    */

364   public boolean isWritable(int column) throws SQLException JavaDoc
365   {
366     return false;
367   }
368
369   /**
370    * Indicates whether a write on the designated column will definitely
371    * succeed.
372    *
373    * @param column
374    * the first column is 1, the second is 2, ...
375    * @return <code>true</code> if so; <code>false</code> otherwise
376    * @exception SQLException
377    * if a database access error occurs
378    */

379   public boolean isDefinitelyWritable(int column) throws SQLException JavaDoc
380   {
381     return false;
382   }
383
384   //--------------------------JDBC 2.0-----------------------------------
385

386   /**
387    * <p>
388    * Returns the fully-qualified name of the Java class whose instances are
389    * manufactured if the method <code>ResultSet.getObject</code> is called to
390    * retrieve a value from the column. <code>ResultSet.getObject</code> may
391    * return a subclass of the class returned by this method.
392    *
393    * @return the fully-qualified name of the class in the Java programming
394    * language that would be used by the method <code>ResultSet.getObject</code>
395    * to retrieve the value in the specified column. This is the class
396    * name used for custom mapping.
397    * @exception SQLException
398    * if a database access error occurs
399    * @since 1.2
400    * @see <a HREF="package-summary.html#2.0 API">What Is in the JDBC 2.0 API
401    * </a>
402    */

403   public String JavaDoc getColumnClassName(int column) throws SQLException JavaDoc
404   {
405     switch (getColumnType(column))
406     {
407       case java.sql.Types.DECIMAL :
408         return "java.math.BigDecimal";
409       case java.sql.Types.TIMESTAMP :
410         return "java.util.Calendar";
411       case java.sql.Types.VARCHAR :
412         return "java.lang.String";
413     }
414     DjAssert.check(false);
415     return null;
416   }
417 }
Popular Tags