KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > type > JdbcTypeRegistry


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

16 package com.ibatis.sqlmap.engine.type;
17
18 import java.sql.Types JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 /**
23  * Singleton
24  */

25 public class JdbcTypeRegistry {
26
27   /**
28    * Value for the unknown type
29    */

30   public static final int UNKNOWN_TYPE = -99999999;
31   
32   private static final Map JavaDoc TYPE_MAP = new HashMap JavaDoc();
33
34   /**
35    * Value for a JDBC 3.o datalink type
36    */

37   public final static int JDBC_30_DATALINK = 70;
38
39   /**
40    * Value for a JDBC 3.o boolean type
41    */

42   public final static int JDBC_30_BOOLEAN = 16;
43
44   static {
45     initializeTypes();
46   }
47
48   private JdbcTypeRegistry() {
49   }
50
51   private static void setType(String JavaDoc name, int value) {
52     TYPE_MAP.put(name, new Integer JavaDoc(value));
53   }
54
55   /**
56    * Looks up a type by name, and returns it's int value (from java.sql.Types)
57    *
58    * @param name - the type name
59    *
60    * @return - the int value (from java.sql.Types)
61    */

62   public static int getType(String JavaDoc name) {
63     if (name == null)
64       return UNKNOWN_TYPE;
65     Integer JavaDoc i = (Integer JavaDoc) TYPE_MAP.get(name);
66     if (i != null) {
67       return i.intValue();
68     } else {
69       return UNKNOWN_TYPE;
70     }
71   }
72
73   private static void initializeTypes() {
74     setType("ARRAY", Types.ARRAY);
75     setType("BIGINT", Types.BIGINT);
76     setType("BINARY", Types.BINARY);
77     setType("BIT", Types.BIT);
78     setType("BLOB", Types.BLOB);
79     setType("BOOLEAN", JDBC_30_BOOLEAN);
80     setType("CHAR", Types.CHAR);
81     setType("CLOB", Types.CLOB);
82     setType("DATALINK", JDBC_30_DATALINK);
83     setType("DATE", Types.DATE);
84     setType("DECIMAL", Types.DECIMAL);
85     setType("DISTINCT", Types.DISTINCT);
86     setType("DOUBLE", Types.DOUBLE);
87     setType("FLOAT", Types.FLOAT);
88     setType("INTEGER", Types.INTEGER);
89     setType("JAVA_OBJECT", Types.JAVA_OBJECT);
90     setType("LONGVARBINARY", Types.LONGVARBINARY);
91     setType("LONGVARCHAR", Types.LONGVARCHAR);
92     setType("NULL", Types.NULL);
93     setType("NUMERIC", Types.NUMERIC);
94     setType("OTHER", Types.OTHER);
95     setType("REAL", Types.REAL);
96     setType("REF", Types.REF);
97     setType("SMALLINT", Types.SMALLINT);
98     setType("STRUCT", Types.STRUCT);
99     setType("TIME", Types.TIME);
100     setType("TIMESTAMP", Types.TIMESTAMP);
101     setType("TINYINT", Types.TINYINT);
102     setType("VARBINARY", Types.VARBINARY);
103     setType("VARCHAR", Types.VARCHAR);
104
105     setType("CH", Types.CHAR);
106     setType("VC", Types.VARCHAR);
107
108     setType("DT", Types.DATE);
109     setType("TM", Types.TIME);
110     setType("TS", Types.TIMESTAMP);
111
112     setType("NM", Types.NUMERIC);
113     setType("II", Types.INTEGER);
114     setType("BI", Types.BIGINT);
115     setType("SI", Types.SMALLINT);
116     setType("TI", Types.TINYINT);
117
118     setType("DC", Types.DECIMAL);
119     setType("DB", Types.DOUBLE);
120     setType("FL", Types.FLOAT);
121
122     setType("ORACLECURSOR", -10);
123
124   }
125
126 }
127
Popular Tags