JdbcType.java

  1. /*
  2.  *    Copyright 2009-2024 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.  *       https://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 ARRAY data type - but a custom type handler is still required
  26.    */
  27.   ARRAY(Types.ARRAY),

  28.   BIT(Types.BIT),

  29.   TINYINT(Types.TINYINT),

  30.   SMALLINT(Types.SMALLINT),

  31.   INTEGER(Types.INTEGER),

  32.   BIGINT(Types.BIGINT),

  33.   FLOAT(Types.FLOAT),

  34.   REAL(Types.REAL),

  35.   DOUBLE(Types.DOUBLE),

  36.   NUMERIC(Types.NUMERIC),

  37.   DECIMAL(Types.DECIMAL),

  38.   CHAR(Types.CHAR),

  39.   VARCHAR(Types.VARCHAR),

  40.   LONGVARCHAR(Types.LONGVARCHAR),

  41.   DATE(Types.DATE),

  42.   TIME(Types.TIME),

  43.   TIMESTAMP(Types.TIMESTAMP),

  44.   BINARY(Types.BINARY),

  45.   VARBINARY(Types.VARBINARY),

  46.   LONGVARBINARY(Types.LONGVARBINARY),

  47.   NULL(Types.NULL),

  48.   OTHER(Types.OTHER),

  49.   BLOB(Types.BLOB),

  50.   CLOB(Types.CLOB),

  51.   BOOLEAN(Types.BOOLEAN),

  52.   CURSOR(-10), // Oracle

  53.   UNDEFINED(Integer.MIN_VALUE + 1000),

  54.   NVARCHAR(Types.NVARCHAR), // JDK6

  55.   NCHAR(Types.NCHAR), // JDK6

  56.   NCLOB(Types.NCLOB), // JDK6

  57.   STRUCT(Types.STRUCT),

  58.   JAVA_OBJECT(Types.JAVA_OBJECT),

  59.   DISTINCT(Types.DISTINCT),

  60.   REF(Types.REF),

  61.   DATALINK(Types.DATALINK),

  62.   ROWID(Types.ROWID), // JDK6

  63.   LONGNVARCHAR(Types.LONGNVARCHAR), // JDK6

  64.   SQLXML(Types.SQLXML), // JDK6

  65.   DATETIMEOFFSET(-155), // SQL Server 2008

  66.   TIME_WITH_TIMEZONE(Types.TIME_WITH_TIMEZONE), // JDBC 4.2 JDK8

  67.   TIMESTAMP_WITH_TIMEZONE(Types.TIMESTAMP_WITH_TIMEZONE); // JDBC 4.2 JDK8

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

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

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

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

  81. }