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