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