Source code: org/hsqldb/util/JDBCTypes.java
1 /* Copyrights and Licenses
2 *
3 * This product includes Hypersonic SQL.
4 * Originally developed by Thomas Mueller and the Hypersonic SQL Group.
5 *
6 * Copyright (c) 1995-2000 by the Hypersonic SQL Group. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice, this list of conditions
10 * and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice, this list of
12 * conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * - All advertising materials mentioning features or use of this software must display the
15 * following acknowledgment: "This product includes Hypersonic SQL."
16 * - Products derived from this software may not be called "Hypersonic SQL" nor may
17 * "Hypersonic SQL" appear in their names without prior written permission of the
18 * Hypersonic SQL Group.
19 * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
20 * product includes Hypersonic SQL."
21 * This software is provided "as is" and any expressed or implied warranties, including, but
22 * not limited to, the implied warranties of merchantability and fitness for a particular purpose are
23 * disclaimed. In no event shall the Hypersonic SQL Group or its contributors be liable for any
24 * direct, indirect, incidental, special, exemplary, or consequential damages (including, but
25 * not limited to, procurement of substitute goods or services; loss of use, data, or profits;
26 * or business interruption). However caused any on any theory of liability, whether in contract,
27 * strict liability, or tort (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 * This software consists of voluntary contributions made by many individuals on behalf of the
30 * Hypersonic SQL Group.
31 *
32 *
33 * For work added by the HSQL Development Group:
34 *
35 * Copyright (c) 2001-2002, The HSQL Development Group
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions are met:
40 *
41 * Redistributions of source code must retain the above copyright notice, this
42 * list of conditions and the following disclaimer, including earlier
43 * license statements (above) and comply with all above license conditions.
44 *
45 * Redistributions in binary form must reproduce the above copyright notice,
46 * this list of conditions and the following disclaimer in the documentation
47 * and/or other materials provided with the distribution, including earlier
48 * license statements (above) and comply with all above license conditions.
49 *
50 * Neither the name of the HSQL Development Group nor the names of its
51 * contributors may be used to endorse or promote products derived from this
52 * software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
58 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
59 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
60 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
61 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
62 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 */
66
67
68 package org.hsqldb.util;
69
70 import java.sql.*;
71 import java.util.*;
72
73 /**
74 * Base class for conversion from a different databases
75 *
76 * @author Nicolas BAZIN
77 * @version 1.7.0
78 */
79 class JDBCTypes {
80
81 private Hashtable hStringJDBCtypes;
82 private Hashtable hIntJDBCtypes;
83
84 JDBCTypes() {
85
86 hStringJDBCtypes = new Hashtable();
87 hIntJDBCtypes = new Hashtable();
88
89 //#ifdef JAVA2
90 hStringJDBCtypes.put(new Integer(java.sql.Types.ARRAY), "ARRAY");
91 hStringJDBCtypes.put(new Integer(java.sql.Types.BLOB), "BLOB");
92 hStringJDBCtypes.put(new Integer(java.sql.Types.CLOB), "CLOB");
93 hStringJDBCtypes.put(new Integer(java.sql.Types.DISTINCT),
94 "DISTINCT");
95 hStringJDBCtypes.put(new Integer(java.sql.Types.JAVA_OBJECT),
96 "JAVA_OBJECT");
97 hStringJDBCtypes.put(new Integer(java.sql.Types.REF), "REF");
98 hStringJDBCtypes.put(new Integer(java.sql.Types.STRUCT), "STRUCT");
99
100 //#endif JAVA2
101 hStringJDBCtypes.put(new Integer(java.sql.Types.BIGINT), "BIGINT");
102 hStringJDBCtypes.put(new Integer(java.sql.Types.BINARY), "BINARY");
103 hStringJDBCtypes.put(new Integer(java.sql.Types.BIT), "BIT");
104 hStringJDBCtypes.put(new Integer(java.sql.Types.CHAR), "CHAR");
105 hStringJDBCtypes.put(new Integer(java.sql.Types.DATE), "DATE");
106 hStringJDBCtypes.put(new Integer(java.sql.Types.DECIMAL), "DECIMAL");
107 hStringJDBCtypes.put(new Integer(java.sql.Types.DOUBLE), "DOUBLE");
108 hStringJDBCtypes.put(new Integer(java.sql.Types.FLOAT), "FLOAT");
109 hStringJDBCtypes.put(new Integer(java.sql.Types.INTEGER), "INTEGER");
110 hStringJDBCtypes.put(new Integer(java.sql.Types.LONGVARBINARY),
111 "LONGVARBINARY");
112 hStringJDBCtypes.put(new Integer(java.sql.Types.LONGVARCHAR),
113 "LONGVARCHAR");
114 hStringJDBCtypes.put(new Integer(java.sql.Types.NULL), "NULL");
115 hStringJDBCtypes.put(new Integer(java.sql.Types.NUMERIC), "NUMERIC");
116 hStringJDBCtypes.put(new Integer(java.sql.Types.OTHER), "OTHER");
117 hStringJDBCtypes.put(new Integer(java.sql.Types.REAL), "REAL");
118 hStringJDBCtypes.put(new Integer(java.sql.Types.SMALLINT),
119 "SMALLINT");
120 hStringJDBCtypes.put(new Integer(java.sql.Types.TIME), "TIME");
121 hStringJDBCtypes.put(new Integer(java.sql.Types.TIMESTAMP),
122 "TIMESTAMP");
123 hStringJDBCtypes.put(new Integer(java.sql.Types.TINYINT), "TINYINT");
124 hStringJDBCtypes.put(new Integer(java.sql.Types.VARBINARY),
125 "VARBINARY");
126 hStringJDBCtypes.put(new Integer(java.sql.Types.VARCHAR), "VARCHAR");
127
128 //#ifdef JAVA2
129 hIntJDBCtypes.put("ARRAY", new Integer(java.sql.Types.ARRAY));
130 hIntJDBCtypes.put("BLOB", new Integer(java.sql.Types.BLOB));
131 hIntJDBCtypes.put("CLOB", new Integer(java.sql.Types.CLOB));
132 hIntJDBCtypes.put("DISTINCT", new Integer(java.sql.Types.DISTINCT));
133 hIntJDBCtypes.put("JAVA_OBJECT",
134 new Integer(java.sql.Types.JAVA_OBJECT));
135 hIntJDBCtypes.put("REF", new Integer(java.sql.Types.REF));
136 hIntJDBCtypes.put("STRUCT", new Integer(java.sql.Types.STRUCT));
137
138 //#endif JAVA2
139 hIntJDBCtypes.put("BIGINT", new Integer(java.sql.Types.BIGINT));
140 hIntJDBCtypes.put("BINARY", new Integer(java.sql.Types.BINARY));
141 hIntJDBCtypes.put("BIT", new Integer(java.sql.Types.BIT));
142 hIntJDBCtypes.put("CHAR", new Integer(java.sql.Types.CHAR));
143 hIntJDBCtypes.put("DATE", new Integer(java.sql.Types.DATE));
144 hIntJDBCtypes.put("DECIMAL", new Integer(java.sql.Types.DECIMAL));
145 hIntJDBCtypes.put("DOUBLE", new Integer(java.sql.Types.DOUBLE));
146 hIntJDBCtypes.put("FLOAT", new Integer(java.sql.Types.FLOAT));
147 hIntJDBCtypes.put("INTEGER", new Integer(java.sql.Types.INTEGER));
148 hIntJDBCtypes.put("LONGVARBINARY",
149 new Integer(java.sql.Types.LONGVARBINARY));
150 hIntJDBCtypes.put("LONGVARCHAR",
151 new Integer(java.sql.Types.LONGVARCHAR));
152 hIntJDBCtypes.put("NULL", new Integer(java.sql.Types.NULL));
153 hIntJDBCtypes.put("NUMERIC", new Integer(java.sql.Types.NUMERIC));
154 hIntJDBCtypes.put("OTHER", new Integer(java.sql.Types.OTHER));
155 hIntJDBCtypes.put("REAL", new Integer(java.sql.Types.REAL));
156 hIntJDBCtypes.put("SMALLINT", new Integer(java.sql.Types.SMALLINT));
157 hIntJDBCtypes.put("TIME", new Integer(java.sql.Types.TIME));
158 hIntJDBCtypes.put("TIMESTAMP", new Integer(java.sql.Types.TIMESTAMP));
159 hIntJDBCtypes.put("TINYINT", new Integer(java.sql.Types.TINYINT));
160 hIntJDBCtypes.put("VARBINARY", new Integer(java.sql.Types.VARBINARY));
161 hIntJDBCtypes.put("VARCHAR", new Integer(java.sql.Types.VARCHAR));
162 }
163
164 public Hashtable getHashtable() {
165 return hStringJDBCtypes;
166 }
167
168 public String toString(int type) {
169 return (String) hStringJDBCtypes.get(new Integer(type));
170 }
171
172 public int toInt(String type) throws Exception {
173
174 Integer tempInteger = (Integer) hIntJDBCtypes.get(type);
175
176 return tempInteger.intValue();
177 }
178 }