1 /* 2 * Copyright 2009-2023 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 * @Options(useGeneratedKeys = true, keyProperty = "id") 36 * @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 * </p> 114 * 115 * @return property names that separate with comma(',') 116 */ 117 String keyProperty() default ""; 118 119 /** 120 * Returns column names that retrieves a key value. 121 * <p> 122 * If you specify multiple column, please separate using comma(','). 123 * </p> 124 * 125 * @return column names that separate with comma(',') 126 */ 127 String keyColumn() default ""; 128 129 /** 130 * Returns result set names. 131 * <p> 132 * If you specify multiple result set, please separate using comma(','). 133 * </p> 134 * 135 * @return result set names that separate with comma(',') 136 */ 137 String resultSets() default ""; 138 139 /** 140 * @return A database id that correspond this options 141 * 142 * @since 3.5.5 143 */ 144 String databaseId() default ""; 145 146 /** 147 * The container annotation for {@link Options}. 148 * 149 * @author Kazuki Shimizu 150 * 151 * @since 3.5.5 152 */ 153 @Documented 154 @Retention(RetentionPolicy.RUNTIME) 155 @Target(ElementType.METHOD) 156 @interface List { 157 Options[] value(); 158 } 159 160 }