JdbcType.java

  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. import java.sql.Types;
  18. import java.util.HashMap;
  19. import java.util.Map;

  20. /**
  21.  * @author Clinton Begin
  22.  */
  23. public enum JdbcType {
  24.   /*
  25.    * This is added to enable basic support for the
  26.    * ARRAY data type - but a custom type handler is still required
  27.    */
  28.   ARRAY(Types.ARRAY),
  29.   BIT(Types.BIT),
  30.   TINYINT(Types.TINYINT),
  31.   SMALLINT(Types.SMALLINT),
  32.   INTEGER(Types.INTEGER),
  33.   BIGINT(Types.BIGINT),
  34.   FLOAT(Types.FLOAT),
  35.   REAL(Types.REAL),
  36.   DOUBLE(Types.DOUBLE),
  37.   NUMERIC(Types.NUMERIC),
  38.   DECIMAL(Types.DECIMAL),
  39.   CHAR(Types.CHAR),
  40.   VARCHAR(Types.VARCHAR),
  41.   LONGVARCHAR(Types.LONGVARCHAR),
  42.   DATE(Types.DATE),
  43.   TIME(Types.TIME),
  44.   TIMESTAMP(Types.TIMESTAMP),
  45.   BINARY(Types.BINARY),
  46.   VARBINARY(Types.VARBINARY),
  47.   LONGVARBINARY(Types.LONGVARBINARY),
  48.   NULL(Types.NULL),
  49.   OTHER(Types.OTHER),
  50.   BLOB(Types.BLOB),
  51.   CLOB(Types.CLOB),
  52.   BOOLEAN(Types.BOOLEAN),
  53.   CURSOR(-10), // Oracle
  54.   UNDEFINED(Integer.MIN_VALUE + 1000),
  55.   NVARCHAR(Types.NVARCHAR), // JDK6
  56.   NCHAR(Types.NCHAR), // JDK6
  57.   NCLOB(Types.NCLOB), // JDK6
  58.   STRUCT(Types.STRUCT),
  59.   JAVA_OBJECT(Types.JAVA_OBJECT),
  60.   DISTINCT(Types.DISTINCT),
  61.   REF(Types.REF),
  62.   DATALINK(Types.DATALINK),
  63.   ROWID(Types.ROWID), // JDK6
  64.   LONGNVARCHAR(Types.LONGNVARCHAR), // JDK6
  65.   SQLXML(Types.SQLXML), // JDK6
  66.   DATETIMEOFFSET(-155), // SQL Server 2008
  67.   TIME_WITH_TIMEZONE(Types.TIME_WITH_TIMEZONE), // JDBC 4.2 JDK8
  68.   TIMESTAMP_WITH_TIMEZONE(Types.TIMESTAMP_WITH_TIMEZONE); // JDBC 4.2 JDK8

  69.   public final int TYPE_CODE;
  70.   private static Map<Integer,JdbcType> codeLookup = new HashMap<>();

  71.   static {
  72.     for (JdbcType type : JdbcType.values()) {
  73.       codeLookup.put(type.TYPE_CODE, type);
  74.     }
  75.   }

  76.   JdbcType(int code) {
  77.     this.TYPE_CODE = code;
  78.   }

  79.   public static JdbcType forCode(int code)  {
  80.     return codeLookup.get(code);
  81.   }

  82. }