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