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.annotations;
17  
18  import java.lang.annotation.Documented;
19  import java.lang.annotation.ElementType;
20  import java.lang.annotation.Retention;
21  import java.lang.annotation.RetentionPolicy;
22  import java.lang.annotation.Target;
23  
24  import org.apache.ibatis.type.JdbcType;
25  import org.apache.ibatis.type.TypeHandler;
26  import org.apache.ibatis.type.UnknownTypeHandler;
27  
28  /**
29   * The annotation that be grouping conditional mapping definitions.
30   *
31   * <p>
32   * <b>How to use:</b>
33   *
34   * <pre>
35   * public interface UserMapper {
36   *   &#064;Select("SELECT id, name, type FROM users ORDER BY id")
37   *   &#064;TypeDiscriminator(
38   *     column = "type",
39   *     javaType = String.class,
40   *     cases = {
41   *       &#064;Case(value = "1", type = PremiumUser.class),
42   *       &#064;Case(value = "2", type = GeneralUser.class),
43   *       &#064;Case(value = "3", type = TemporaryUser.class)
44   *     }
45   *   )
46   *   List&lt;User&gt; selectAll();
47   * }
48   * </pre>
49   *
50   * @author Clinton Begin
51   */
52  @Documented
53  @Retention(RetentionPolicy.RUNTIME)
54  @Target(ElementType.METHOD)
55  public @interface TypeDiscriminator {
56  
57    /**
58     * Returns the column name(column label) that hold conditional value.
59     *
60     * @return the column name(column label)
61     */
62    String column();
63  
64    /**
65     * Return the java type for conditional value.
66     *
67     * @return the java type
68     */
69    Class<?> javaType() default void.class;
70  
71    /**
72     * Return the jdbc type for column that hold conditional value.
73     *
74     * @return the jdbc type
75     */
76    JdbcType jdbcType() default JdbcType.UNDEFINED;
77  
78    /**
79     * Returns the {@link TypeHandler} type for retrieving a column value from result set.
80     *
81     * @return the {@link TypeHandler} type
82     */
83    Class<? extends TypeHandler> typeHandler() default UnknownTypeHandler.class;
84  
85    /**
86     * Returns conditional mapping definitions.
87     *
88     * @return conditional mapping definitions
89     */
90    Case[] cases();
91  }