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.Repeatable;
21  import java.lang.annotation.Retention;
22  import java.lang.annotation.RetentionPolicy;
23  import java.lang.annotation.Target;
24  
25  import org.apache.ibatis.mapping.ResultSetType;
26  import org.apache.ibatis.mapping.StatementType;
27  
28  /**
29   * The annotation that specify options for customizing default behaviors.
30   * <p>
31   * <b>How to use:</b>
32   *
33   * <pre>
34   * public interface UserMapper {
35   *   &#064;Options(useGeneratedKeys = true, keyProperty = "id")
36   *   &#064;Insert("INSERT INTO users (name) VALUES(#{name})")
37   *   boolean insert(User user);
38   * }
39   * </pre>
40   *
41   * @author Clinton Begin
42   */
43  @Documented
44  @Retention(RetentionPolicy.RUNTIME)
45  @Target(ElementType.METHOD)
46  @Repeatable(Options.List.class)
47  public @interface Options {
48    /**
49     * The options for the {@link Options#flushCache()}. The default is {@link FlushCachePolicy#DEFAULT}
50     */
51    enum FlushCachePolicy {
52      /** <code>false</code> for select statement; <code>true</code> for insert/update/delete statement. */
53      DEFAULT,
54      /** Flushes cache regardless of the statement type. */
55      TRUE,
56      /** Does not flush cache regardless of the statement type. */
57      FALSE
58    }
59  
60    /**
61     * Returns whether use the 2nd cache feature if assigned the cache.
62     *
63     * @return {@code true} if use; {@code false} if otherwise
64     */
65    boolean useCache() default true;
66  
67    /**
68     * Returns the 2nd cache flush strategy.
69     *
70     * @return the 2nd cache flush strategy
71     */
72    FlushCachePolicy flushCache() default FlushCachePolicy.DEFAULT;
73  
74    /**
75     * Returns the result set type.
76     *
77     * @return the result set type
78     */
79    ResultSetType resultSetType() default ResultSetType.DEFAULT;
80  
81    /**
82     * Return the statement type.
83     *
84     * @return the statement type
85     */
86    StatementType statementType() default StatementType.PREPARED;
87  
88    /**
89     * Returns the fetch size.
90     *
91     * @return the fetch size
92     */
93    int fetchSize() default -1;
94  
95    /**
96     * Returns the statement timeout.
97     *
98     * @return the statement timeout
99     */
100   int timeout() default -1;
101 
102   /**
103    * Returns whether use the generated keys feature supported by JDBC 3.0
104    *
105    * @return {@code true} if use; {@code false} if otherwise
106    */
107   boolean useGeneratedKeys() default false;
108 
109   /**
110    * Returns property names that holds a key value.
111    * <p>
112    * If you specify multiple property, please separate using comma(',').
113    *
114    * @return property names that separate with comma(',')
115    */
116   String keyProperty() default "";
117 
118   /**
119    * Returns column names that retrieves a key value.
120    * <p>
121    * If you specify multiple column, please separate using comma(',').
122    *
123    * @return column names that separate with comma(',')
124    */
125   String keyColumn() default "";
126 
127   /**
128    * Returns result set names.
129    * <p>
130    * If you specify multiple result set, please separate using comma(',').
131    *
132    * @return result set names that separate with comma(',')
133    */
134   String resultSets() default "";
135 
136   /**
137    * @return A database id that correspond this options
138    *
139    * @since 3.5.5
140    */
141   String databaseId() default "";
142 
143   /**
144    * The container annotation for {@link Options}.
145    *
146    * @author Kazuki Shimizu
147    *
148    * @since 3.5.5
149    */
150   @Documented
151   @Retention(RetentionPolicy.RUNTIME)
152   @Target(ElementType.METHOD)
153   @interface List {
154     Options[] value();
155   }
156 
157 }