View Javadoc
1   /*
2    *    Copyright 2009-2021 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    JAVA_OBJECT(Types.JAVA_OBJECT),
62    DISTINCT(Types.DISTINCT),
63    REF(Types.REF),
64    DATALINK(Types.DATALINK),
65    ROWID(Types.ROWID), // JDK6
66    LONGNVARCHAR(Types.LONGNVARCHAR), // JDK6
67    SQLXML(Types.SQLXML), // JDK6
68    DATETIMEOFFSET(-155), // SQL Server 2008
69    TIME_WITH_TIMEZONE(Types.TIME_WITH_TIMEZONE), // JDBC 4.2 JDK8
70    TIMESTAMP_WITH_TIMEZONE(Types.TIMESTAMP_WITH_TIMEZONE); // JDBC 4.2 JDK8
71  
72    public final int TYPE_CODE;
73    private static Map<Integer,JdbcType> codeLookup = new HashMap<>();
74  
75    static {
76      for (JdbcType type : JdbcType.values()) {
77        codeLookup.put(type.TYPE_CODE, type);
78      }
79    }
80  
81    JdbcType(int code) {
82      this.TYPE_CODE = code;
83    }
84  
85    public static JdbcType forCode(int code)  {
86      return codeLookup.get(code);
87    }
88  
89  }