View Javadoc
1   /*
2    *    Copyright 2009-2023 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.jdbc;
17  
18  import org.apache.ibatis.type.BigDecimalTypeHandler;
19  import org.apache.ibatis.type.BlobTypeHandler;
20  import org.apache.ibatis.type.BooleanTypeHandler;
21  import org.apache.ibatis.type.ByteArrayTypeHandler;
22  import org.apache.ibatis.type.ByteTypeHandler;
23  import org.apache.ibatis.type.ClobTypeHandler;
24  import org.apache.ibatis.type.DateOnlyTypeHandler;
25  import org.apache.ibatis.type.DateTypeHandler;
26  import org.apache.ibatis.type.DoubleTypeHandler;
27  import org.apache.ibatis.type.FloatTypeHandler;
28  import org.apache.ibatis.type.IntegerTypeHandler;
29  import org.apache.ibatis.type.JdbcType;
30  import org.apache.ibatis.type.LongTypeHandler;
31  import org.apache.ibatis.type.ObjectTypeHandler;
32  import org.apache.ibatis.type.ShortTypeHandler;
33  import org.apache.ibatis.type.SqlDateTypeHandler;
34  import org.apache.ibatis.type.SqlTimeTypeHandler;
35  import org.apache.ibatis.type.SqlTimestampTypeHandler;
36  import org.apache.ibatis.type.StringTypeHandler;
37  import org.apache.ibatis.type.TimeOnlyTypeHandler;
38  import org.apache.ibatis.type.TypeHandler;
39  
40  /**
41   * @author Clinton Begin
42   * @author Adam Gent
43   */
44  public enum Null {
45    BOOLEAN(new BooleanTypeHandler(), JdbcType.BOOLEAN),
46  
47    BYTE(new ByteTypeHandler(), JdbcType.TINYINT),
48  
49    SHORT(new ShortTypeHandler(), JdbcType.SMALLINT),
50  
51    INTEGER(new IntegerTypeHandler(), JdbcType.INTEGER),
52  
53    LONG(new LongTypeHandler(), JdbcType.BIGINT),
54  
55    FLOAT(new FloatTypeHandler(), JdbcType.FLOAT),
56  
57    DOUBLE(new DoubleTypeHandler(), JdbcType.DOUBLE),
58  
59    BIGDECIMAL(new BigDecimalTypeHandler(), JdbcType.DECIMAL),
60  
61    STRING(new StringTypeHandler(), JdbcType.VARCHAR),
62  
63    CLOB(new ClobTypeHandler(), JdbcType.CLOB),
64  
65    LONGVARCHAR(new ClobTypeHandler(), JdbcType.LONGVARCHAR),
66  
67    BYTEARRAY(new ByteArrayTypeHandler(), JdbcType.LONGVARBINARY),
68  
69    BLOB(new BlobTypeHandler(), JdbcType.BLOB),
70  
71    LONGVARBINARY(new BlobTypeHandler(), JdbcType.LONGVARBINARY),
72  
73    OBJECT(new ObjectTypeHandler(), JdbcType.OTHER),
74  
75    OTHER(new ObjectTypeHandler(), JdbcType.OTHER),
76  
77    TIMESTAMP(new DateTypeHandler(), JdbcType.TIMESTAMP),
78  
79    DATE(new DateOnlyTypeHandler(), JdbcType.DATE),
80  
81    TIME(new TimeOnlyTypeHandler(), JdbcType.TIME),
82  
83    SQLTIMESTAMP(new SqlTimestampTypeHandler(), JdbcType.TIMESTAMP),
84  
85    SQLDATE(new SqlDateTypeHandler(), JdbcType.DATE),
86  
87    SQLTIME(new SqlTimeTypeHandler(), JdbcType.TIME);
88  
89    private final TypeHandler<?> typeHandler;
90    private final JdbcType jdbcType;
91  
92    Null(TypeHandler<?> typeHandler, JdbcType jdbcType) {
93      this.typeHandler = typeHandler;
94      this.jdbcType = jdbcType;
95    }
96  
97    public TypeHandler<?> getTypeHandler() {
98      return typeHandler;
99    }
100 
101   public JdbcType getJdbcType() {
102     return jdbcType;
103   }
104 }