KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lateralnz > c3d > DCResultSetMetaData


1 /* ====================================================================
2  * The LateralNZ Software License, Version 1.0
3  *
4  * Copyright (c) 2003 LateralNZ. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by
21  * LateralNZ (http://www.lateralnz.org/) and other third parties."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "LateralNZ" must not be used to endorse or promote
26  * products derived from this software without prior written
27  * permission. For written permission, please
28  * contact oss@lateralnz.org.
29  *
30  * 5. Products derived from this software may not be called "Panther",
31  * or "Lateral" or "LateralNZ", nor may "PANTHER" or "LATERAL" or
32  * "LATERALNZ" appear in their name, without prior written
33  * permission of LateralNZ.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of LateralNZ. For more
51  * information on Lateral, please see http://www.lateralnz.com/ or
52  * http://www.lateralnz.org
53  *
54  */

55 package org.lateralnz.c3d;
56
57 import java.io.Serializable JavaDoc;
58 import java.sql.ResultSetMetaData JavaDoc;
59 import java.sql.SQLException JavaDoc;
60 import java.sql.Types JavaDoc;
61
62 public class DCResultSetMetaData implements Serializable JavaDoc, ResultSetMetaData JavaDoc {
63   
64   private static final String JavaDoc INDEX_OUT_OF_RANGE = "index out of range";
65   private static final String JavaDoc STRING_CLASSNAME = java.lang.String JavaDoc.class.getName();
66   
67   private String JavaDoc[] catalogNames;
68   private String JavaDoc[] columnClassNames;
69   private int columnCount;
70   private int[] columnDisplaySizes;
71   private String JavaDoc[] columnLabels;
72   private String JavaDoc[] columnNames;
73   private int[] columnTypes;
74   private String JavaDoc[] columnTypeNames;
75   private int[] precisions;
76   private int[] scales;
77   private String JavaDoc[] schemaNames;
78   private String JavaDoc[] tableNames;
79   private boolean[] autoIncrement;
80   private boolean[] caseSensitive;
81   private boolean[] currency;
82   private int[] nullable;
83   private boolean[] searchable;
84   private boolean[] signed;
85   
86   public DCResultSetMetaData() {
87     columnCount = 0;
88   }
89   
90   public DCResultSetMetaData(String JavaDoc[] colNames) {
91     columnCount = colNames.length;
92     
93     init();
94     
95     for (int i = 0; i < columnCount; i++) {
96       catalogNames[i] = "";
97       columnClassNames[i] = STRING_CLASSNAME;
98       columnDisplaySizes[i] = 1024;
99       columnLabels[i] = colNames[i];
100       columnNames[i] = colNames[i];
101       columnTypes[i] = Types.VARCHAR;
102       columnTypeNames[i] = "varchar";
103       precisions[i] = 0;
104       scales[i] = 0;
105       schemaNames[i] = "";
106       tableNames[i] = "";
107       autoIncrement[i] = false;
108       caseSensitive[i] = true;
109       currency[i] = false;
110       nullable[i] = ResultSetMetaData.columnNoNulls;
111       searchable[i] = false;
112       signed[i] = false;
113     }
114   }
115   
116   public DCResultSetMetaData(ResultSetMetaData JavaDoc md) throws SQLException JavaDoc {
117     columnCount = md.getColumnCount();
118     init();
119     
120     for (int i = 0, j = 1; i < columnCount; i++, j++) {
121       catalogNames[i] = md.getCatalogName(j);
122       columnClassNames[i] = md.getColumnClassName(j);
123       columnDisplaySizes[i] = md.getColumnDisplaySize(j);
124       columnLabels[i] = md.getColumnLabel(j);
125       columnNames[i] = md.getColumnName(j);
126       columnTypes[i] = md.getColumnType(j);
127       columnTypeNames[i] = md.getColumnTypeName(j);
128       precisions[i] = md.getPrecision(j);
129       scales[i] = md.getScale(j);
130       schemaNames[i] = md.getSchemaName(j);
131       tableNames[i] = md.getTableName(j);
132       autoIncrement[i] = md.isAutoIncrement(j);
133       caseSensitive[i] = md.isCaseSensitive(j);
134       currency[i] = md.isCurrency(j);
135       nullable[i] = md.isNullable(j);
136       searchable[i] = md.isSearchable(j);
137       signed[i] = md.isSigned(j);
138     }
139   }
140   
141   private void init() {
142     catalogNames = new String JavaDoc[columnCount];
143     columnClassNames = new String JavaDoc[columnCount];
144     columnDisplaySizes = new int[columnCount];
145     columnLabels = new String JavaDoc[columnCount];
146     columnNames = new String JavaDoc[columnCount];
147     columnTypes = new int[columnCount];
148     columnTypeNames = new String JavaDoc[columnCount];
149     precisions = new int[columnCount];
150     scales = new int[columnCount];
151     schemaNames = new String JavaDoc[columnCount];
152     tableNames = new String JavaDoc[columnCount];
153     autoIncrement = new boolean[columnCount];
154     caseSensitive = new boolean[columnCount];
155     currency = new boolean[columnCount];
156     nullable = new int[columnCount];
157     searchable = new boolean[columnCount];
158     signed = new boolean[columnCount];
159   }
160   
161   public String JavaDoc getCatalogName(int param) throws SQLException JavaDoc {
162     param = param - 1;
163     if (catalogNames == null || param > catalogNames.length) {
164       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
165     }
166     return catalogNames[param];
167   }
168   
169   public String JavaDoc getColumnClassName(int param) throws SQLException JavaDoc {
170     param = param - 1;
171     if (columnClassNames == null || param > columnClassNames.length) {
172       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
173     }
174     return columnClassNames[param];
175   }
176   
177   public int getColumnCount() throws SQLException JavaDoc {
178     return columnCount;
179   }
180   
181   public int getColumnDisplaySize(int param) throws SQLException JavaDoc {
182     param = param - 1;
183     if (columnDisplaySizes == null || param > columnDisplaySizes.length) {
184       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
185     }
186     return columnDisplaySizes[param];
187   }
188   
189   public String JavaDoc getColumnLabel(int param) throws SQLException JavaDoc {
190     param = param - 1;
191     if (columnLabels == null || param > columnLabels.length) {
192       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
193     }
194     return columnLabels[param];
195   }
196   
197   public String JavaDoc getColumnName(int param) throws SQLException JavaDoc {
198     param = param - 1;
199     if (columnNames == null || param > columnNames.length) {
200       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
201     }
202     return columnNames[param];
203   }
204   
205   public int getColumnType(int param) throws SQLException JavaDoc {
206     param = param - 1;
207     if (columnTypes == null || param > columnTypes.length) {
208       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
209     }
210     return columnTypes[param];
211   }
212   
213   public String JavaDoc getColumnTypeName(int param) throws SQLException JavaDoc {
214     param = param - 1;
215     if (columnTypeNames == null || param > columnTypeNames.length) {
216       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
217     }
218     return columnTypeNames[param];
219   }
220   
221   public int getPrecision(int param) throws SQLException JavaDoc {
222     param = param - 1;
223     if (precisions == null || param > precisions.length) {
224       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
225     }
226     return precisions[param];
227   }
228   
229   public int getScale(int param) throws SQLException JavaDoc {
230     param = param - 1;
231     if (scales == null || param > scales.length) {
232       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
233     }
234     return scales[param];
235   }
236   
237   public String JavaDoc getSchemaName(int param) throws SQLException JavaDoc {
238     param = param - 1;
239     if (schemaNames == null || param > schemaNames.length) {
240       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
241     }
242     return schemaNames[param];
243   }
244   
245   public String JavaDoc getTableName(int param) throws SQLException JavaDoc {
246     param = param - 1;
247     if (tableNames == null || param > tableNames.length) {
248       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
249     }
250     return tableNames[param];
251   }
252   
253   public boolean isAutoIncrement(int param) throws SQLException JavaDoc {
254     param = param - 1;
255     if (autoIncrement == null || param > autoIncrement.length) {
256       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
257     }
258     return autoIncrement[param];
259   }
260   
261   public boolean isCaseSensitive(int param) throws SQLException JavaDoc {
262     param = param - 1;
263     if (caseSensitive == null || param > caseSensitive.length) {
264       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
265     }
266     return caseSensitive[param];
267   }
268   
269   public boolean isCurrency(int param) throws SQLException JavaDoc {
270     param = param - 1;
271     if (currency == null || param > currency.length) {
272       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
273     }
274     return currency[param];
275   }
276   
277   public boolean isDefinitelyWritable(int param) throws SQLException JavaDoc {
278     return false;
279   }
280   
281   public int isNullable(int param) throws SQLException JavaDoc {
282     param = param - 1;
283     if (nullable == null || param > nullable.length) {
284       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
285     }
286     return nullable[param];
287   }
288   
289   public boolean isReadOnly(int param) throws SQLException JavaDoc {
290     return true;
291   }
292   
293   public boolean isSearchable(int param) throws SQLException JavaDoc {
294     param = param - 1;
295     if (searchable == null || param > searchable.length) {
296       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
297     }
298     return searchable[param];
299   }
300   
301   public boolean isSigned(int param) throws SQLException JavaDoc {
302     param = param - 1;
303     if (signed == null || param > signed.length) {
304       throw new SQLException JavaDoc(INDEX_OUT_OF_RANGE);
305     }
306     return signed[param];
307   }
308   
309   public boolean isWritable(int param) throws SQLException JavaDoc {
310     return false;
311   }
312   
313 }
314
Popular Tags