1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.binding;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import org.apache.ibatis.annotations.Arg;
22 import org.apache.ibatis.annotations.CacheNamespace;
23 import org.apache.ibatis.annotations.Case;
24 import org.apache.ibatis.annotations.ConstructorArgs;
25 import org.apache.ibatis.annotations.Many;
26 import org.apache.ibatis.annotations.MapKey;
27 import org.apache.ibatis.annotations.One;
28 import org.apache.ibatis.annotations.Param;
29 import org.apache.ibatis.annotations.Result;
30 import org.apache.ibatis.annotations.ResultType;
31 import org.apache.ibatis.annotations.Results;
32 import org.apache.ibatis.annotations.Select;
33 import org.apache.ibatis.annotations.SelectProvider;
34 import org.apache.ibatis.annotations.TypeDiscriminator;
35 import org.apache.ibatis.cursor.Cursor;
36 import org.apache.ibatis.domain.blog.Author;
37 import org.apache.ibatis.domain.blog.Blog;
38 import org.apache.ibatis.domain.blog.DraftPost;
39 import org.apache.ibatis.domain.blog.Post;
40 import org.apache.ibatis.mapping.FetchType;
41 import org.apache.ibatis.session.ResultHandler;
42 import org.apache.ibatis.session.RowBounds;
43
44 @CacheNamespace(readWrite = false)
45 public interface BoundBlogMapper {
46
47
48
49 Blog selectBlogWithPostsUsingSubSelect(int id);
50
51
52
53 int selectRandom();
54
55
56
57 @Select({ "SELECT * FROM blog" })
58 @MapKey("id")
59 Map<Integer, Blog> selectBlogsAsMapById();
60
61 @Select({ "SELECT * FROM blog ORDER BY id" })
62 @MapKey("id")
63 Map<Integer, Blog> selectRangeBlogsAsMapById(RowBounds rowBounds);
64
65
66
67
68 @Select({
69 "SELECT *",
70 "FROM blog"
71 })
72
73 List<Blog> selectBlogs();
74
75
76 @Select({
77 "SELECT *",
78 "FROM blog",
79 "ORDER BY id"
80 })
81
82 @ResultType(Blog.class)
83 void collectRangeBlogs(ResultHandler<Object> blog, RowBounds rowBounds);
84
85
86 @Select({
87 "SELECT *",
88 "FROM blog",
89 "ORDER BY id"
90 })
91
92 Cursor<Blog> openRangeBlogs(RowBounds rowBounds);
93
94
95
96 List<Blog> selectBlogsFromXML();
97
98
99
100
101 @Select({
102 "SELECT *",
103 "FROM blog"
104 })
105
106 List<Map<String, Object>> selectBlogsAsMaps();
107
108
109
110 @SelectProvider(type = BoundBlogSql.class, method = "selectBlogsSql")
111 List<Blog> selectBlogsUsingProvider();
112
113
114
115 @Select("SELECT * FROM post ORDER BY id")
116
117 @TypeDiscriminator(
118 column = "draft",
119 javaType = String.class,
120 cases = {@Case(value = "1", type = DraftPost.class)}
121 )
122
123 List<Post> selectPosts();
124
125
126
127 @Select("SELECT * FROM post ORDER BY id")
128 @Results({ @Result(id = true, property = "id", column = "id") })
129
130 @TypeDiscriminator(
131 column = "draft",
132 javaType = int.class,
133 cases = {@Case(value = "1", type = DraftPost.class,
134 results = {@Result(id = true, property = "id", column = "id")})}
135 )
136
137 List<Post> selectPostsWithResultMap();
138
139
140
141
142 @Select("SELECT * FROM "
143 + "blog WHERE id = #{id}")
144
145 Blog selectBlog(int id);
146
147
148
149
150 @Select("SELECT * FROM blog "
151 + "WHERE id = #{id}")
152 @ConstructorArgs({
153 @Arg(column = "id", javaType = int.class, id = true),
154 @Arg(column = "title", javaType = String.class),
155 @Arg(column = "author_id", javaType = Author.class, select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor"),
156 @Arg(column = "id", javaType = List.class, select = "selectPostsForBlog")
157 })
158
159 Blog selectBlogUsingConstructor(int id);
160
161 Blog selectBlogUsingConstructorWithResultMap(int i);
162
163 Blog selectBlogUsingConstructorWithResultMapAndProperties(int i);
164
165 Blog selectBlogUsingConstructorWithResultMapCollection(int i);
166
167 Blog selectBlogByIdUsingConstructor(int id);
168
169
170
171
172 @Select("SELECT * FROM blog "
173 + "WHERE id = #{id}")
174
175 Map<String, Object> selectBlogAsMap(Map<String, Object> params);
176
177
178
179
180 @Select("SELECT * FROM post "
181 + "WHERE subject like #{query}")
182
183 List<Post> selectPostsLike(RowBounds bounds, String query);
184
185
186
187
188 @Select("SELECT * FROM post "
189 + "WHERE subject like #{subjectQuery} and body like #{bodyQuery}")
190
191 List<Post> selectPostsLikeSubjectAndBody(RowBounds bounds, @Param("subjectQuery") String subjectQuery,
192 @Param("bodyQuery") String bodyQuery);
193
194
195
196
197 @Select("SELECT * FROM post "
198 + "WHERE id = #{id}")
199
200 List<Post> selectPostsById(int id);
201
202
203
204
205 @Select("SELECT * FROM blog "
206 + "WHERE id = #{id} AND title = #{nonExistentParam,jdbcType=VARCHAR}")
207
208 Blog selectBlogByNonExistentParam(@Param("id") int id);
209
210
211 @Select("SELECT * FROM blog "
212 + "WHERE id = #{id} AND title = #{params.nonExistentParam,jdbcType=VARCHAR}")
213
214 Blog selectBlogByNonExistentNestedParam(@Param("id") int id, @Param("params") Map<String, Object> params);
215
216 @Select("SELECT * FROM blog WHERE id = #{id}")
217 Blog selectBlogByNullParam(Integer id);
218
219
220
221
222 @Select("SELECT * FROM blog "
223 + "WHERE id = #{0} AND title = #{1}")
224
225 Blog selectBlogByDefault30ParamNames(int id, String title);
226
227
228 @Select("SELECT * FROM blog "
229 + "WHERE id = #{param1} AND title = #{param2}")
230
231 Blog selectBlogByDefault31ParamNames(int id, String title);
232
233
234
235
236 @Select("SELECT * FROM blog "
237 + "WHERE ${column} = #{id} AND title = #{value}")
238
239 Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id") int id,
240 @Param("value") String title);
241
242
243
244
245 @Select({
246 "SELECT *",
247 "FROM blog"
248 })
249 @Results({
250 @Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor")),
251 @Result(property = "posts", column = "id", many = @Many(select = "selectPostsById"))
252 })
253
254 List<Blog> selectBlogsWithAutorAndPosts();
255
256
257 @Select({
258 "SELECT *",
259 "FROM blog"
260 })
261 @Results({
262 @Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor", fetchType = FetchType.EAGER)),
263 @Result(property = "posts", column = "id", many = @Many(select = "selectPostsById", fetchType = FetchType.EAGER))
264 })
265
266 List<Blog> selectBlogsWithAutorAndPostsEagerly();
267
268 }