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 deleting record(s).
26   *
27   * <p><br>
28   * <b>How to use:</b>
29   * <pre>
30   * public interface UserMapper {
31   *
32   *   &#064;DeleteProvider(type = SqlProvider.class, method = "deleteById")
33   *   boolean deleteById(int id);
34   *
35   *   public static class SqlProvider {
36   *     public static String deleteById() {
37   *       return "DELETE FROM users 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 DeleteProvider {
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     * @return a type that implements an SQL provider method
65     * @see #value()
66     */
67    Class<?> type() default void.class;
68  
69    /**
70     * Specify a method for providing an SQL.
71     *
72     * <p>
73     * Since 3.5.1, this attribute can omit.
74     * If this attribute omit, the MyBatis will call a method that decide by following rules.
75     * <ul>
76     *   <li>
77     *     If class that specified the {@link #type()} attribute implements the {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver},
78     *     the MyBatis use a method that returned by it
79     *   </li>
80     *   <li>
81     *     If cannot resolve a method by {@link org.apache.ibatis.builder.annotation.ProviderMethodResolver}(= not implement it or it was returned {@code null}),
82     *     the MyBatis will search and use a fallback method that named {@code provideSql} from specified type
83     *   </li>
84     * </ul>
85     *
86     * @return a method name of method for providing an SQL
87     */
88    String method() default "";
89  
90  }