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  /**
25   * The annotation that specify a method that provide an SQL for updating record(s).
26   *
27   * <p><br>
28   * <b>How to use:</b>
29   * <pre>
30   * public interface UserMapper {
31   *
32   *   &#064;UpdateProvider(type = SqlProvider.class, method = "update")
33   *   boolean update(User user);
34   *
35   *   public static class SqlProvider {
36   *     public static String update() {
37   *       return "UPDATE users SET name = #{name} WHERE id = #{id}";
38   *     }
39   *   }
40   *
41   * }
42   * </pre>
43   * @author Clinton Begin
44   */
45  @Documented
46  @Retention(RetentionPolicy.RUNTIME)
47  @Target(ElementType.METHOD)
48  public @interface UpdateProvider {
49  
50    /**
51     * Specify a type that implements an SQL provider method.
52     *
53     * @return a type that implements an SQL provider method
54     * @since 3.5.2
55     * @see #type()
56     */
57    Class<?> value() default void.class;
58  
59    /**
60     * Specify a type that implements an SQL provider method.
61     * <p>
62     * This attribute is alias of {@link #value()}.
63     * </p>
64     *
65     * @return a type that implements an SQL provider method
66     * @see #value()
67     */
68    Class<?> type() default void.class;
69  
70    /**
71     * Specify a method for providing an SQL.
72     *
73     * <p>
74     * Since 3.5.1, this attribute can omit.
75     * If this attribute omit, the MyBatis will call a method that decide by following rules.
76     * <ul>
77     *   <li>
78     *     If class that specified the {@link #type()} attribute implements the {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver},
79     *     the MyBatis use a method that returned by it
80     *   </li>
81     *   <li>
82     *     If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}(= not implement it or it was returned {@code null}),
83     *     the MyBatis will search and use a fallback method that named {@code provideSql} from specified type
84     *   </li>
85     * </ul>
86     *
87     * @return a method name of method for providing an SQL
88     */
89    String method() default "";
90  
91  }