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