View Javadoc
1   /**
2    *    Copyright 2009-2019 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.mapping.StatementType;
25  
26  /**
27   * The annotation that specify an SQL for retrieving a key value.
28   *
29   * <p><br>
30   * <b>How to use:</b>
31   * <pre>
32   * public interface UserMapper {
33   *   &#064;SelectKey(statement = "SELECT identity('users')", keyProperty = "id", before = true, resultType = int.class)
34   *   &#064;Insert("INSERT INTO users (id, name) VALUES(#{id}, #{name})")
35   *   boolean insert(User user);
36   * }
37   * </pre>
38   * @author Clinton Begin
39   */
40  @Documented
41  @Retention(RetentionPolicy.RUNTIME)
42  @Target(ElementType.METHOD)
43  public @interface SelectKey {
44    /**
45     * Returns an SQL for retrieving a key value.
46     *
47     * @return an SQL for retrieving a key value
48     */
49    String[] statement();
50  
51    /**
52     * Returns property names that holds a key value.
53     * <p>
54     * If you specify multiple property, please separate using comma(',').
55     * </p>
56     *
57     * @return property names that separate with comma(',')
58     */
59    String keyProperty();
60  
61    /**
62     * Returns column names that retrieves a key value.
63     * <p>
64     * If you specify multiple column, please separate using comma(',').
65     * </p>
66     *
67     * @return column names that separate with comma(',')
68     */
69    String keyColumn() default "";
70  
71    /**
72     * Returns whether retrieves a key value before executing insert/update statement.
73     *
74     * @return {@code true} if execute before; {@code false} if otherwise
75     */
76    boolean before();
77  
78    /**
79     * Returns the key value type.
80     *
81     * @return the key value type
82     */
83    Class<?> resultType();
84  
85    /**
86     * Returns the statement type to use.
87     *
88     * @return the statement type
89     */
90    StatementType statementType() default StatementType.PREPARED;
91  }