KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > dba > TypesMapping


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

56 package org.objectstyle.cayenne.dba;
57
58 import java.sql.DatabaseMetaData JavaDoc;
59 import java.sql.ResultSet JavaDoc;
60 import java.sql.SQLException JavaDoc;
61 import java.sql.Types JavaDoc;
62 import java.util.ArrayList JavaDoc;
63 import java.util.HashMap JavaDoc;
64 import java.util.Iterator JavaDoc;
65 import java.util.List JavaDoc;
66 import java.util.Map JavaDoc;
67 import java.util.Set JavaDoc;
68
69 /**
70  * A utility class that handles mappings of JDBC data types to
71  * the database types and Java types. Also contains methods that
72  * provide information about JDBC types.
73  *
74  *
75  * @author Michael Shengaout
76  * @author Andrei Adamchik
77  */

78 public class TypesMapping {
79     // Never use "-1" or any other normal integer, since there
80
// is a big chance it is being reserved in java.sql.Types
81
public static final int NOT_DEFINED = Integer.MAX_VALUE;
82
83     // char constants for the sql data types
84
public static final String JavaDoc SQL_ARRAY = "ARRAY";
85     public static final String JavaDoc SQL_BIGINT = "BIGINT";
86     public static final String JavaDoc SQL_BINARY = "BINARY";
87     public static final String JavaDoc SQL_BIT = "BIT";
88     public static final String JavaDoc SQL_BLOB = "BLOB";
89     public static final String JavaDoc SQL_CLOB = "CLOB";
90     public static final String JavaDoc SQL_CHAR = "CHAR";
91     public static final String JavaDoc SQL_DATE = "DATE";
92     public static final String JavaDoc SQL_DECIMAL = "DECIMAL";
93     public static final String JavaDoc SQL_DOUBLE = "DOUBLE";
94     public static final String JavaDoc SQL_FLOAT = "FLOAT";
95     public static final String JavaDoc SQL_INTEGER = "INTEGER";
96     public static final String JavaDoc SQL_LONGVARCHAR = "LONGVARCHAR";
97     public static final String JavaDoc SQL_LONGVARBINARY = "LONGVARBINARY";
98     public static final String JavaDoc SQL_NUMERIC = "NUMERIC";
99     public static final String JavaDoc SQL_REAL = "REAL";
100     public static final String JavaDoc SQL_SMALLINT = "SMALLINT";
101     public static final String JavaDoc SQL_TINYINT = "TINYINT";
102     public static final String JavaDoc SQL_TIME = "TIME";
103     public static final String JavaDoc SQL_TIMESTAMP = "TIMESTAMP";
104     public static final String JavaDoc SQL_VARBINARY = "VARBINARY";
105     public static final String JavaDoc SQL_VARCHAR = "VARCHAR";
106     public static final String JavaDoc SQL_OTHER = "OTHER";
107
108     // char constants for Java data types
109
public static final String JavaDoc JAVA_LONG = "java.lang.Long";
110     public static final String JavaDoc JAVA_BYTES = "byte[]";
111     public static final String JavaDoc JAVA_BOOLEAN = "java.lang.Boolean";
112     public static final String JavaDoc JAVA_STRING = "java.lang.String";
113     public static final String JavaDoc JAVA_SQLDATE = "java.sql.Date";
114     public static final String JavaDoc JAVA_UTILDATE = "java.util.Date";
115     public static final String JavaDoc JAVA_BIGDECIMAL = "java.math.BigDecimal";
116     public static final String JavaDoc JAVA_DOUBLE = "java.lang.Double";
117     public static final String JavaDoc JAVA_FLOAT = "java.lang.Float";
118     public static final String JavaDoc JAVA_INTEGER = "java.lang.Integer";
119     public static final String JavaDoc JAVA_SHORT = "java.lang.Short";
120     public static final String JavaDoc JAVA_BYTE = "java.lang.Byte";
121     public static final String JavaDoc JAVA_TIME = "java.sql.Time";
122     public static final String JavaDoc JAVA_TIMESTAMP = "java.sql.Timestamp";
123
124     /** Keys: SQL string type names,
125      * Values: SQL int type definitions from java.sql.Types */

126     private static final Map JavaDoc sqlStringType = new HashMap JavaDoc();
127
128     /** Keys: SQL int type definitions from java.sql.Types,
129      * Values: SQL string type names */

130     private static final Map JavaDoc sqlEnumType = new HashMap JavaDoc();
131
132     /** Keys: SQL int type definitions from java.sql.Types,
133      * Values: java class names */

134     private static final Map JavaDoc sqlEnumJava = new HashMap JavaDoc();
135
136     /** Keys: java class names,
137      * Values: SQL int type definitions from java.sql.Types */

138     private static final Map JavaDoc javaSqlEnum = new HashMap JavaDoc();
139
140     static {
141         sqlStringType.put(SQL_ARRAY, new Integer JavaDoc(Types.ARRAY));
142         sqlStringType.put(SQL_BIGINT, new Integer JavaDoc(Types.BIGINT));
143         sqlStringType.put(SQL_BINARY, new Integer JavaDoc(Types.BINARY));
144         sqlStringType.put(SQL_BIT, new Integer JavaDoc(Types.BIT));
145         sqlStringType.put(SQL_BLOB, new Integer JavaDoc(Types.BLOB));
146         sqlStringType.put(SQL_CLOB, new Integer JavaDoc(Types.CLOB));
147         sqlStringType.put(SQL_CHAR, new Integer JavaDoc(Types.CHAR));
148         sqlStringType.put(SQL_DATE, new Integer JavaDoc(Types.DATE));
149         sqlStringType.put(SQL_DECIMAL, new Integer JavaDoc(Types.DECIMAL));
150         sqlStringType.put(SQL_DOUBLE, new Integer JavaDoc(Types.DOUBLE));
151         sqlStringType.put(SQL_FLOAT, new Integer JavaDoc(Types.FLOAT));
152         sqlStringType.put(SQL_INTEGER, new Integer JavaDoc(Types.INTEGER));
153         sqlStringType.put(SQL_LONGVARCHAR, new Integer JavaDoc(Types.LONGVARCHAR));
154         sqlStringType.put(SQL_LONGVARBINARY, new Integer JavaDoc(Types.LONGVARBINARY));
155         sqlStringType.put(SQL_NUMERIC, new Integer JavaDoc(Types.NUMERIC));
156         sqlStringType.put(SQL_REAL, new Integer JavaDoc(Types.REAL));
157         sqlStringType.put(SQL_SMALLINT, new Integer JavaDoc(Types.SMALLINT));
158         sqlStringType.put(SQL_TINYINT, new Integer JavaDoc(Types.TINYINT));
159         sqlStringType.put(SQL_TIME, new Integer JavaDoc(Types.TIME));
160         sqlStringType.put(SQL_TIMESTAMP, new Integer JavaDoc(Types.TIMESTAMP));
161         sqlStringType.put(SQL_VARBINARY, new Integer JavaDoc(Types.VARBINARY));
162         sqlStringType.put(SQL_VARCHAR, new Integer JavaDoc(Types.VARCHAR));
163         sqlStringType.put(SQL_OTHER, new Integer JavaDoc(Types.OTHER));
164
165         sqlEnumType.put(new Integer JavaDoc(Types.ARRAY), SQL_ARRAY);
166         sqlEnumType.put(new Integer JavaDoc(Types.BIGINT), SQL_BIGINT);
167         sqlEnumType.put(new Integer JavaDoc(Types.BINARY), SQL_BINARY);
168         sqlEnumType.put(new Integer JavaDoc(Types.BIT), SQL_BIT);
169         sqlEnumType.put(new Integer JavaDoc(Types.BLOB), SQL_BLOB);
170         sqlEnumType.put(new Integer JavaDoc(Types.CLOB), SQL_CLOB);
171         sqlEnumType.put(new Integer JavaDoc(Types.CHAR), SQL_CHAR);
172         sqlEnumType.put(new Integer JavaDoc(Types.DATE), SQL_DATE);
173         sqlEnumType.put(new Integer JavaDoc(Types.DECIMAL), SQL_DECIMAL);
174         sqlEnumType.put(new Integer JavaDoc(Types.DOUBLE), SQL_DOUBLE);
175         sqlEnumType.put(new Integer JavaDoc(Types.FLOAT), SQL_FLOAT);
176         sqlEnumType.put(new Integer JavaDoc(Types.INTEGER), SQL_INTEGER);
177         sqlEnumType.put(new Integer JavaDoc(Types.LONGVARCHAR), SQL_LONGVARCHAR);
178         sqlEnumType.put(new Integer JavaDoc(Types.LONGVARBINARY), SQL_LONGVARBINARY);
179         sqlEnumType.put(new Integer JavaDoc(Types.NUMERIC), SQL_NUMERIC);
180         sqlEnumType.put(new Integer JavaDoc(Types.REAL), SQL_REAL);
181         sqlEnumType.put(new Integer JavaDoc(Types.SMALLINT), SQL_SMALLINT);
182         sqlEnumType.put(new Integer JavaDoc(Types.TINYINT), SQL_TINYINT);
183         sqlEnumType.put(new Integer JavaDoc(Types.TIME), SQL_TIME);
184         sqlEnumType.put(new Integer JavaDoc(Types.TIMESTAMP), SQL_TIMESTAMP);
185         sqlEnumType.put(new Integer JavaDoc(Types.VARBINARY), SQL_VARBINARY);
186         sqlEnumType.put(new Integer JavaDoc(Types.VARCHAR), SQL_VARCHAR);
187         sqlEnumType.put(new Integer JavaDoc(Types.OTHER), SQL_OTHER);
188
189         sqlEnumJava.put(new Integer JavaDoc(Types.BIGINT), JAVA_LONG);
190         sqlEnumJava.put(new Integer JavaDoc(Types.BINARY), JAVA_BYTES);
191         sqlEnumJava.put(new Integer JavaDoc(Types.BIT), JAVA_BOOLEAN);
192         sqlEnumJava.put(new Integer JavaDoc(Types.BLOB), JAVA_BYTES);
193         sqlEnumJava.put(new Integer JavaDoc(Types.CLOB), JAVA_STRING);
194         sqlEnumJava.put(new Integer JavaDoc(Types.CHAR), JAVA_STRING);
195         sqlEnumJava.put(new Integer JavaDoc(Types.DATE), JAVA_UTILDATE);
196         sqlEnumJava.put(new Integer JavaDoc(Types.DECIMAL), JAVA_BIGDECIMAL);
197         sqlEnumJava.put(new Integer JavaDoc(Types.DOUBLE), JAVA_DOUBLE);
198         sqlEnumJava.put(new Integer JavaDoc(Types.FLOAT), JAVA_FLOAT);
199         sqlEnumJava.put(new Integer JavaDoc(Types.INTEGER), JAVA_INTEGER);
200         sqlEnumJava.put(new Integer JavaDoc(Types.LONGVARCHAR), JAVA_STRING);
201         sqlEnumJava.put(new Integer JavaDoc(Types.LONGVARBINARY), JAVA_BYTES);
202         sqlEnumJava.put(new Integer JavaDoc(Types.NUMERIC), JAVA_BIGDECIMAL);
203         sqlEnumJava.put(new Integer JavaDoc(Types.REAL), JAVA_FLOAT);
204         sqlEnumJava.put(new Integer JavaDoc(Types.SMALLINT), JAVA_SHORT);
205         sqlEnumJava.put(new Integer JavaDoc(Types.TINYINT), JAVA_BYTE);
206         sqlEnumJava.put(new Integer JavaDoc(Types.TIME), JAVA_UTILDATE);
207         sqlEnumJava.put(new Integer JavaDoc(Types.TIMESTAMP), JAVA_UTILDATE);
208         sqlEnumJava.put(new Integer JavaDoc(Types.VARBINARY), JAVA_BYTES);
209         sqlEnumJava.put(new Integer JavaDoc(Types.VARCHAR), JAVA_STRING);
210
211         javaSqlEnum.put(JAVA_LONG, new Integer JavaDoc(Types.BIGINT));
212         javaSqlEnum.put(JAVA_BYTES, new Integer JavaDoc(Types.BINARY));
213         javaSqlEnum.put(JAVA_BOOLEAN, new Integer JavaDoc(Types.BIT));
214         javaSqlEnum.put(JAVA_STRING, new Integer JavaDoc(Types.VARCHAR));
215         javaSqlEnum.put(JAVA_SQLDATE, new Integer JavaDoc(Types.DATE));
216         javaSqlEnum.put(JAVA_TIMESTAMP, new Integer JavaDoc(Types.TIMESTAMP));
217         javaSqlEnum.put(JAVA_BIGDECIMAL, new Integer JavaDoc(Types.DECIMAL));
218         javaSqlEnum.put(JAVA_DOUBLE, new Integer JavaDoc(Types.DOUBLE));
219         javaSqlEnum.put(JAVA_FLOAT, new Integer JavaDoc(Types.FLOAT));
220         javaSqlEnum.put(JAVA_INTEGER, new Integer JavaDoc(Types.INTEGER));
221         javaSqlEnum.put(JAVA_SHORT, new Integer JavaDoc(Types.SMALLINT));
222         javaSqlEnum.put(JAVA_BYTE, new Integer JavaDoc(Types.TINYINT));
223         javaSqlEnum.put(JAVA_TIME, new Integer JavaDoc(Types.TIME));
224         javaSqlEnum.put(JAVA_TIMESTAMP, new Integer JavaDoc(Types.TIMESTAMP));
225     }
226
227     /**
228      * Returns true if supplied type can have a length attribute
229      * as a part of column definition.
230      */

231     public static boolean supportsLength(int type) {
232         return type == Types.BINARY
233             || type == Types.CHAR
234             || type == Types.DECIMAL
235             || type == Types.DOUBLE
236             || type == Types.FLOAT
237             || type == Types.NUMERIC
238             || type == Types.REAL
239             || type == Types.VARBINARY
240             || type == Types.VARCHAR;
241     }
242
243     /**
244      * Returns true if supplied type is a numeric type.
245      */

246     public static boolean isNumeric(int type) {
247         return type == Types.BIGINT
248             || type == Types.BIT
249             || type == Types.DECIMAL
250             || type == Types.DOUBLE
251             || type == Types.FLOAT
252             || type == Types.INTEGER
253             || type == Types.NUMERIC
254             || type == Types.REAL
255             || type == Types.SMALLINT
256             || type == Types.TINYINT;
257     }
258
259     /**
260      * Returns true if supplied type is a decimal type.
261      */

262     public static boolean isDecimal(int type) {
263         return type == Types.DECIMAL
264             || type == Types.DOUBLE
265             || type == Types.FLOAT
266             || type == Types.REAL
267             || type == Types.NUMERIC;
268     }
269
270     /** Returns an array of string names of the default JDBC data types.*/
271     public static String JavaDoc[] getDatabaseTypes() {
272         Set JavaDoc keys = sqlStringType.keySet();
273         int len = keys.size();
274         String JavaDoc[] types = new String JavaDoc[len];
275
276         Iterator JavaDoc it = keys.iterator();
277         for (int i = 0; i < len; i++) {
278             types[i] = (String JavaDoc) it.next();
279         }
280
281         return types;
282     }
283
284     /** Method implements an algorithm to pick a data type from a list of alternatives
285     * that most closely matches JDBC data type. */

286     protected static String JavaDoc pickDataType(int jdbcType, TypeInfo[] alts) {
287         int len = alts.length;
288
289         if (len == 0)
290             return null;
291
292         if (len == 1)
293             return alts[0].name;
294
295         // now the fun starts.. try to guess the right type
296

297         String JavaDoc jdbcName = getSqlNameByType(jdbcType).toUpperCase();
298
299         // 1. exact match
300
for (int i = 0; i < len; i++) {
301             if (jdbcName.equalsIgnoreCase(alts[i].name))
302                 return alts[i].name;
303         }
304
305         // 2. filter those with biggest precision
306
long maxPrec = 0;
307         for (int i = 0; i < len; i++) {
308             if (maxPrec < alts[i].precision) {
309                 maxPrec = alts[i].precision;
310             }
311         }
312
313         List JavaDoc list = new ArrayList JavaDoc();
314         for (int i = 0; i < len; i++) {
315             if (maxPrec == alts[i].precision) {
316                 list.add(alts[i]);
317             }
318         }
319
320         // work with smaller list now.....
321
int slen = list.size();
322         if (slen == 1)
323             return ((TypeInfo) list.get(0)).name;
324
325         // start/end match
326
for (int i = 0; i < slen; i++) {
327             String JavaDoc uppercase = ((TypeInfo) list.get(i)).name.toUpperCase();
328             if (uppercase.startsWith(jdbcName) || uppercase.endsWith(jdbcName))
329                 return ((TypeInfo) list.get(i)).name;
330         }
331
332         // in the middle match
333
for (int i = 0; i < slen; i++) {
334             String JavaDoc uppercase = ((TypeInfo) list.get(i)).name.toUpperCase();
335
336             if (uppercase.indexOf(jdbcName) >= 0)
337                 return ((TypeInfo) list.get(i)).name;
338         }
339
340         // out of ideas... return the first one
341
return ((TypeInfo) list.get(0)).name;
342     }
343
344     /**
345      * Returns a JDBC int type for SQL typem name.
346      */

347     public static int getSqlTypeByName(String JavaDoc typeName) {
348         Integer JavaDoc tmp = (Integer JavaDoc) sqlStringType.get(typeName);
349         return (null == tmp) ? NOT_DEFINED : tmp.intValue();
350     }
351
352     /**
353      * Returns a String representation of the SQL type from its JDBC code.
354      */

355     public static String JavaDoc getSqlNameByType(int type) {
356         return (String JavaDoc) sqlEnumType.get(new Integer JavaDoc(type));
357     }
358
359     /**
360      * Returns default java.sql.Types type by the Java type name.
361      *
362      * @param javaTypeName Fully qualified Java Class name.
363      * @return The SQL type or NOT_DEFINED if no type found.
364      */

365     public static int getSqlTypeByJava(String JavaDoc javaTypeName) {
366         Integer JavaDoc temp = (Integer JavaDoc) javaSqlEnum.get(javaTypeName);
367         return (null == temp) ? NOT_DEFINED : temp.intValue();
368     }
369
370     /**
371      * Guesses a default JDBC type for the Java class.
372      *
373      * @since 1.1
374      */

375     public static int getSqlTypeByJava(Class JavaDoc javaClass) {
376         while (javaClass != null) {
377             Object JavaDoc type = javaSqlEnum.get(javaClass.getName());
378             if (type != null) {
379                 return ((Number JavaDoc) type).intValue();
380             }
381
382             javaClass = javaClass.getSuperclass();
383         }
384
385         return NOT_DEFINED;
386     }
387
388     /**
389      * Get the corresponding Java type by its java.sql.Types counterpart.
390      *
391      * @return Fully qualified Java type name or null if not found.
392      */

393     public static String JavaDoc getJavaBySqlType(int type) {
394         return (String JavaDoc) sqlEnumJava.get(new Integer JavaDoc(type));
395     }
396
397     /**
398       * Get the corresponding Java type by its java.sql.Types counterpart.
399       *
400       * @return Fully qualified Java type name or null if not found.
401       */

402     public static String JavaDoc getJavaBySqlType(int type, int length, int precision) {
403
404         if (type == Types.NUMERIC && precision == 0) {
405             type = Types.INTEGER;
406         }
407         return (String JavaDoc) sqlEnumJava.get(new Integer JavaDoc(type));
408     }
409
410     // *************************************************************
411
// non-static code
412
// *************************************************************
413

414     protected Map JavaDoc databaseTypes = new HashMap JavaDoc();
415
416     public TypesMapping(DatabaseMetaData JavaDoc metaData) throws SQLException JavaDoc {
417         // map database types to standard JDBC types
418
ResultSet JavaDoc rs = metaData.getTypeInfo();
419
420         try {
421             while (rs.next()) {
422                 TypeInfo info = new TypeInfo();
423                 info.name = rs.getString("TYPE_NAME");
424                 info.jdbcType = rs.getInt("DATA_TYPE");
425                 info.precision = rs.getLong("PRECISION");
426
427                 Integer JavaDoc key = new Integer JavaDoc(info.jdbcType);
428                 List JavaDoc infos = (List JavaDoc) databaseTypes.get(key);
429
430                 if (infos == null) {
431                     infos = new ArrayList JavaDoc();
432                     databaseTypes.put(key, infos);
433                 }
434
435                 infos.add(info);
436             }
437         }
438         finally {
439             rs.close();
440         }
441
442         // do some tricks to substitute for missing datatypes
443

444         // 1. swap TIMESTAMP - DATE
445
Integer JavaDoc ts = new Integer JavaDoc(Types.TIMESTAMP);
446         Integer JavaDoc dt = new Integer JavaDoc(Types.DATE);
447         List JavaDoc tsInfo = (List JavaDoc) databaseTypes.get(ts);
448         List JavaDoc dtInfo = (List JavaDoc) databaseTypes.get(dt);
449
450         if (tsInfo != null && dtInfo == null)
451             databaseTypes.put(dt, tsInfo);
452
453         if (dtInfo != null && tsInfo == null)
454             databaseTypes.put(ts, dtInfo);
455
456         // 2. Swap CLOB - LONGVARCHAR
457
Integer JavaDoc clob = new Integer JavaDoc(Types.CLOB);
458         Integer JavaDoc lvc = new Integer JavaDoc(Types.LONGVARCHAR);
459         List JavaDoc clobInfo = (List JavaDoc) databaseTypes.get(clob);
460         List JavaDoc lvcInfo = (List JavaDoc) databaseTypes.get(lvc);
461
462         if (clobInfo != null && lvcInfo == null)
463             databaseTypes.put(lvc, clobInfo);
464
465         if (lvcInfo != null && clobInfo == null)
466             databaseTypes.put(clob, lvcInfo);
467
468         // 2. Swap BLOB - LONGVARBINARY
469
Integer JavaDoc blob = new Integer JavaDoc(Types.BLOB);
470         Integer JavaDoc lvb = new Integer JavaDoc(Types.LONGVARBINARY);
471         List JavaDoc blobInfo = (List JavaDoc) databaseTypes.get(blob);
472         List JavaDoc lvbInfo = (List JavaDoc) databaseTypes.get(lvb);
473
474         if (blobInfo != null && lvbInfo == null)
475             databaseTypes.put(lvb, blobInfo);
476
477         if (lvbInfo != null && blobInfo == null)
478             databaseTypes.put(blob, lvbInfo);
479     }
480
481     /** Stores (incomplete) information about database data type */
482     static class TypeInfo {
483         String JavaDoc name;
484         int jdbcType;
485         long precision;
486
487         public String JavaDoc toString() {
488             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
489             buf.append("[ TypeInfo: ").append(name);
490             buf.append("\n JDBC Type: ").append(
491                 TypesMapping.getSqlNameByType(jdbcType));
492             buf.append("\n Precision: ").append(precision);
493             buf.append("\n]");
494             return buf.toString();
495         }
496     }
497
498 }
Popular Tags