<<Back to http://devdoc.net
Mine with nofee-ng to get DevFee back!
View Javadoc
1   /**
2    *    Copyright 2009-2015 the original author or authors.
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 org.apache.ibatis.type;
17  
18  import java.sql.Types;
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  /**
23   * @author Clinton Begin
24   */
25  public enum JdbcType {
26    /*
27     * This is added to enable basic support for the
28     * ARRAY data type - but a custom type handler is still required
29     */
30    ARRAY(Types.ARRAY),
31    BIT(Types.BIT),
32    TINYINT(Types.TINYINT),
33    SMALLINT(Types.SMALLINT),
34    INTEGER(Types.INTEGER),
35    BIGINT(Types.BIGINT),
36    FLOAT(Types.FLOAT),
37    REAL(Types.REAL),
38    DOUBLE(Types.DOUBLE),
39    NUMERIC(Types.NUMERIC),
40    DECIMAL(Types.DECIMAL),
41    CHAR(Types.CHAR),
42    VARCHAR(Types.VARCHAR),
43    LONGVARCHAR(Types.LONGVARCHAR),
44    DATE(Types.DATE),
45    TIME(Types.TIME),
46    TIMESTAMP(Types.TIMESTAMP),
47    BINARY(Types.BINARY),
48    VARBINARY(Types.VARBINARY),
49    LONGVARBINARY(Types.LONGVARBINARY),
50    NULL(Types.NULL),
51    OTHER(Types.OTHER),
52    BLOB(Types.BLOB),
53    CLOB(Types.CLOB),
54    BOOLEAN(Types.BOOLEAN),
55    CURSOR(-10), // Oracle
56    UNDEFINED(Integer.MIN_VALUE + 1000),
57    NVARCHAR(Types.NVARCHAR), // JDK6
58    NCHAR(Types.NCHAR), // JDK6
59    NCLOB(Types.NCLOB), // JDK6
60    STRUCT(Types.STRUCT);
61  
62    public final int TYPE_CODE;
63    private static Map<Integer,JdbcType> codeLookup = new HashMap<Integer,JdbcType>();
64  
65    static {
66      for (JdbcType type : JdbcType.values()) {
67        codeLookup.put(type.TYPE_CODE, type);
68      }
69    }
70  
71    JdbcType(int code) {
72      this.TYPE_CODE = code;
73    }
74  
75    public static JdbcType forCode(int code)  {
76      return codeLookup.get(code);
77    }
78  
79  }