KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb > Utilities


1 package org.apache.ojb.tools.mapping.reversedb;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 import java.sql.Types JavaDoc;
20
21 /**
22  *
23  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
24  * @version $Id: Utilities.java,v 1.1.2.1 2005/12/21 22:32:04 tomdz Exp $
25  */

26
27 public class Utilities
28 {
29   public static final java.util.Map JavaDoc hmJDBCTypeToName
30       = new java.util.HashMap JavaDoc();
31   public static final java.util.Map JavaDoc mJDBCNameToType
32       = new java.util.TreeMap JavaDoc();
33
34   public static final java.util.Vector JavaDoc vJDBCTypeNames = new java.util.Vector JavaDoc();
35
36   public static final java.util.HashMap JavaDoc hmJDBCTypeToJavaType
37       = new java.util.HashMap JavaDoc();
38   
39   public static final java.util.Vector JavaDoc vJavaTypes = new java.util.Vector JavaDoc();
40   
41   static
42   {
43       hmJDBCTypeToName.put(new Integer JavaDoc(Types.ARRAY), "ARRAY");
44       hmJDBCTypeToName.put(new Integer JavaDoc(Types.BIGINT), "BIGINT");
45       hmJDBCTypeToName.put(new Integer JavaDoc(Types.BINARY), "BINARY");
46       hmJDBCTypeToName.put(new Integer JavaDoc(Types.BIT), "BIT");
47       hmJDBCTypeToName.put(new Integer JavaDoc(Types.BLOB), "BLOB");
48       hmJDBCTypeToName.put(new Integer JavaDoc(Types.CHAR), "CHAR");
49       hmJDBCTypeToName.put(new Integer JavaDoc(Types.CLOB), "CLOB");
50       hmJDBCTypeToName.put(new Integer JavaDoc(Types.DATE), "DATE");
51       hmJDBCTypeToName.put(new Integer JavaDoc(Types.DECIMAL), "DECIMAL");
52       hmJDBCTypeToName.put(new Integer JavaDoc(Types.DISTINCT), "DISTINCT");
53       hmJDBCTypeToName.put(new Integer JavaDoc(Types.DOUBLE), "DOUBLE");
54       hmJDBCTypeToName.put(new Integer JavaDoc(Types.FLOAT), "FLOAT");
55       hmJDBCTypeToName.put(new Integer JavaDoc(Types.INTEGER), "INTEGER");
56       hmJDBCTypeToName.put(new Integer JavaDoc(Types.JAVA_OBJECT), "OBJECT");
57       hmJDBCTypeToName.put(new Integer JavaDoc(Types.LONGVARBINARY), "LONGVARBINARY");
58       hmJDBCTypeToName.put(new Integer JavaDoc(Types.LONGVARCHAR), "LONGVARCHAR");
59       hmJDBCTypeToName.put(new Integer JavaDoc(Types.NULL), "NULL");
60       hmJDBCTypeToName.put(new Integer JavaDoc(Types.NUMERIC), "NUMERIC");
61       hmJDBCTypeToName.put(new Integer JavaDoc(Types.OTHER), "OTHER");
62       hmJDBCTypeToName.put(new Integer JavaDoc(Types.REAL), "REAL");
63       hmJDBCTypeToName.put(new Integer JavaDoc(Types.REF), "REF");
64       hmJDBCTypeToName.put(new Integer JavaDoc(Types.SMALLINT), "SMALLINT");
65       hmJDBCTypeToName.put(new Integer JavaDoc(Types.STRUCT), "STRUCT");
66       hmJDBCTypeToName.put(new Integer JavaDoc(Types.TIME), "TIME");
67       hmJDBCTypeToName.put(new Integer JavaDoc(Types.TIMESTAMP), "TIMESTAMP");
68       hmJDBCTypeToName.put(new Integer JavaDoc(Types.TINYINT), "TINYINT");
69       hmJDBCTypeToName.put(new Integer JavaDoc(Types.VARBINARY), "VARBINARY");
70       hmJDBCTypeToName.put(new Integer JavaDoc(Types.VARCHAR), "VARCHAR");
71
72       // Build a map containing the name to typecode mapping
73
java.util.Iterator JavaDoc it = hmJDBCTypeToName.entrySet().iterator();
74       while (it.hasNext())
75       {
76         java.util.Map.Entry aEntry = (java.util.Map.Entry)it.next();
77         mJDBCNameToType.put (aEntry.getValue(), aEntry.getKey());
78       }
79       
80       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.ARRAY), "Object[]");
81       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.BIGINT), "Long");
82       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.BINARY), "byte[]");
83       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.BIT), "Byte");
84       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.BLOB), "byte[]");
85       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.CHAR), "String");
86       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.CLOB), "String");
87       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.DATE), "java.sql.Date");
88       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.DECIMAL), "Long");
89       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.DISTINCT), "????");
90       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.DOUBLE), "Double");
91       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.FLOAT), "Double");
92       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.INTEGER), "Long");
93       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.JAVA_OBJECT), "Object");
94       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.LONGVARBINARY), "byte[]");
95       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.LONGVARCHAR), "byte[]");
96       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.NULL), "Object");
97       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.NUMERIC), "Long");
98       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.OTHER), "Object");
99       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.REAL), "Long");
100       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.REF), "Object");
101       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.SMALLINT), "Long");
102       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.STRUCT), "Object");
103       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.TIME), "java.sql.Time");
104       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.TIMESTAMP), "java.sql.Timestamp");
105       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.TINYINT), "Long");
106       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.VARBINARY), "byte[]");
107       hmJDBCTypeToJavaType.put(new Integer JavaDoc(Types.VARCHAR), "String");
108       
109       vJavaTypes.addAll(new java.util.TreeSet JavaDoc(hmJDBCTypeToJavaType.values()));
110       java.util.Collections.sort(vJavaTypes);
111       
112       vJDBCTypeNames.addAll(new java.util.TreeSet JavaDoc(hmJDBCTypeToName.values()));
113       java.util.Collections.sort(vJDBCTypeNames);
114   }
115   
116   /** Creates a new instance of Utilities */
117   private Utilities ()
118   {
119   }
120   
121   public static String JavaDoc getTypeNameFromJDBCType(int jdbcType)
122   {
123     return (String JavaDoc)Utilities.hmJDBCTypeToName.get(new Integer JavaDoc(jdbcType));
124   }
125 }
126
127 /***************************** Changelog *****************************
128 // $Log: Utilities.java,v $
129 // Revision 1.1.2.1 2005/12/21 22:32:04 tomdz
130 // Updated license
131 //
132 // Revision 1.1 2004/05/05 16:39:05 arminw
133 // fix fault
134 // wrong package structure used:
135 // org.apache.ojb.tools.reversdb
136 // org.apache.ojb.tools.reversdb2
137 //
138 // instead of
139 // org.apache.ojb.tools.mapping.reversdb
140 // org.apache.ojb.tools.mapping.reversdb2
141 //
142 // Revision 1.1 2004/05/04 13:45:01 arminw
143 // move reverseDB stuff
144 //
145 // Revision 1.6 2004/04/04 23:53:42 brianm
146 // Fixed initial copyright dates to match cvs repository
147 //
148 // Revision 1.5 2004/03/11 18:16:22 brianm
149 // ASL 2.0
150 //
151 // Revision 1.4 2003/12/12 16:37:16 brj
152 // removed unnecessary casts, semicolons etc.
153 //
154 // Revision 1.3 2003/09/10 06:45:00 mpoeschl
155 // remove duplicated license
156 //
157 // Revision 1.2 2002/06/17 19:34:33 jvanzyl
158 // Correcting all the package references.
159 // PR:
160 // Obtained from:
161 // Submitted by:
162 // Reviewed by:
163 //
164 // Revision 1.1.1.1 2002/06/17 18:16:52 jvanzyl
165 // Initial OJB import
166 //
167 // Revision 1.2 2002/05/16 11:47:09 florianbruckner
168 // fix CR/LF issue, change license to ASL
169 //
170 // Revision 1.1 2002/04/18 11:44:16 mpoeschl
171 //
172 // move files to new location
173 //
174 // Revision 1.3 2002/04/07 09:05:16 thma
175 // *** empty log message ***
176 //
177 // Revision 1.2 2002/03/11 17:36:05 florianbruckner
178 // fix line break issue for these files that were previously checked in with -kb
179 //
180 // Revision 1.1 2002/03/04 17:19:32 thma
181 // initial checking for Florians Reverse engineering tool
182 //
183 // Revision 1.1.1.1 2002/02/20 13:35:25 Administrator
184 // initial import
185 //
186 /***************************** Changelog *****************************/

187
Popular Tags