KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > util > JDBCTypes


1 /* Copyright (c) 2001-2005, The HSQL Development Group
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the HSQL Development Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31
32 package org.hsqldb.util;
33
34 import java.util.Hashtable JavaDoc;
35
36 /**
37  * Base class for conversion from a different databases
38  *
39  * @author Nicolas BAZIN
40  * @version 1.7.0
41  */

42 class JDBCTypes {
43
44     public static final int JAVA_OBJECT = 2000;
45     public static final int DISTINCT = 2001;
46     public static final int STRUCT = 2002;
47     public static final int ARRAY = 2003;
48     public static final int BLOB = 2004;
49     public static final int CLOB = 2005;
50     public static final int REF = 2006;
51     private Hashtable JavaDoc hStringJDBCtypes;
52     private Hashtable JavaDoc hIntJDBCtypes;
53
54     JDBCTypes() {
55
56         hStringJDBCtypes = new Hashtable JavaDoc();
57         hIntJDBCtypes = new Hashtable JavaDoc();
58
59         hStringJDBCtypes.put(new Integer JavaDoc(ARRAY), "ARRAY");
60         hStringJDBCtypes.put(new Integer JavaDoc(BLOB), "BLOB");
61         hStringJDBCtypes.put(new Integer JavaDoc(CLOB), "CLOB");
62         hStringJDBCtypes.put(new Integer JavaDoc(DISTINCT), "DISTINCT");
63         hStringJDBCtypes.put(new Integer JavaDoc(JAVA_OBJECT), "JAVA_OBJECT");
64         hStringJDBCtypes.put(new Integer JavaDoc(REF), "REF");
65         hStringJDBCtypes.put(new Integer JavaDoc(STRUCT), "STRUCT");
66
67         //
68
hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.BIGINT), "BIGINT");
69         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.BINARY), "BINARY");
70         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.BIT), "BIT");
71         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.CHAR), "CHAR");
72         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.DATE), "DATE");
73         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.DECIMAL), "DECIMAL");
74         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.DOUBLE), "DOUBLE");
75         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.FLOAT), "FLOAT");
76         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.INTEGER), "INTEGER");
77         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.LONGVARBINARY),
78                              "LONGVARBINARY");
79         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.LONGVARCHAR),
80                              "LONGVARCHAR");
81         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.NULL), "NULL");
82         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.NUMERIC), "NUMERIC");
83         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.OTHER), "OTHER");
84         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.REAL), "REAL");
85         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.SMALLINT),
86                              "SMALLINT");
87         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.TIME), "TIME");
88         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.TIMESTAMP),
89                              "TIMESTAMP");
90         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.TINYINT), "TINYINT");
91         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.VARBINARY),
92                              "VARBINARY");
93         hStringJDBCtypes.put(new Integer JavaDoc(java.sql.Types.VARCHAR), "VARCHAR");
94
95         //
96
hIntJDBCtypes.put("ARRAY", new Integer JavaDoc(ARRAY));
97         hIntJDBCtypes.put("BLOB", new Integer JavaDoc(BLOB));
98         hIntJDBCtypes.put("CLOB", new Integer JavaDoc(CLOB));
99         hIntJDBCtypes.put("DISTINCT", new Integer JavaDoc(DISTINCT));
100         hIntJDBCtypes.put("JAVA_OBJECT", new Integer JavaDoc(JAVA_OBJECT));
101         hIntJDBCtypes.put("REF", new Integer JavaDoc(REF));
102         hIntJDBCtypes.put("STRUCT", new Integer JavaDoc(STRUCT));
103
104         //
105
hIntJDBCtypes.put("BIGINT", new Integer JavaDoc(java.sql.Types.BIGINT));
106         hIntJDBCtypes.put("BINARY", new Integer JavaDoc(java.sql.Types.BINARY));
107         hIntJDBCtypes.put("BIT", new Integer JavaDoc(java.sql.Types.BIT));
108         hIntJDBCtypes.put("CHAR", new Integer JavaDoc(java.sql.Types.CHAR));
109         hIntJDBCtypes.put("DATE", new Integer JavaDoc(java.sql.Types.DATE));
110         hIntJDBCtypes.put("DECIMAL", new Integer JavaDoc(java.sql.Types.DECIMAL));
111         hIntJDBCtypes.put("DOUBLE", new Integer JavaDoc(java.sql.Types.DOUBLE));
112         hIntJDBCtypes.put("FLOAT", new Integer JavaDoc(java.sql.Types.FLOAT));
113         hIntJDBCtypes.put("INTEGER", new Integer JavaDoc(java.sql.Types.INTEGER));
114         hIntJDBCtypes.put("LONGVARBINARY",
115                           new Integer JavaDoc(java.sql.Types.LONGVARBINARY));
116         hIntJDBCtypes.put("LONGVARCHAR",
117                           new Integer JavaDoc(java.sql.Types.LONGVARCHAR));
118         hIntJDBCtypes.put("NULL", new Integer JavaDoc(java.sql.Types.NULL));
119         hIntJDBCtypes.put("NUMERIC", new Integer JavaDoc(java.sql.Types.NUMERIC));
120         hIntJDBCtypes.put("OTHER", new Integer JavaDoc(java.sql.Types.OTHER));
121         hIntJDBCtypes.put("REAL", new Integer JavaDoc(java.sql.Types.REAL));
122         hIntJDBCtypes.put("SMALLINT", new Integer JavaDoc(java.sql.Types.SMALLINT));
123         hIntJDBCtypes.put("TIME", new Integer JavaDoc(java.sql.Types.TIME));
124         hIntJDBCtypes.put("TIMESTAMP", new Integer JavaDoc(java.sql.Types.TIMESTAMP));
125         hIntJDBCtypes.put("TINYINT", new Integer JavaDoc(java.sql.Types.TINYINT));
126         hIntJDBCtypes.put("VARBINARY", new Integer JavaDoc(java.sql.Types.VARBINARY));
127         hIntJDBCtypes.put("VARCHAR", new Integer JavaDoc(java.sql.Types.VARCHAR));
128     }
129
130     public Hashtable JavaDoc getHashtable() {
131         return hStringJDBCtypes;
132     }
133
134     public String JavaDoc toString(int type) {
135         return (String JavaDoc) hStringJDBCtypes.get(new Integer JavaDoc(type));
136     }
137
138     public int toInt(String JavaDoc type) throws Exception JavaDoc {
139
140         Integer JavaDoc tempInteger = (Integer JavaDoc) hIntJDBCtypes.get(type);
141
142         return tempInteger.intValue();
143     }
144 }
145
Popular Tags