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
129 @Results({
130 @Result(id = true, property = "id", column = "id")
131 })
132 @TypeDiscriminator(
133 column = "draft",
134 javaType = int.class,
135 cases = {@Case(value = "1", type = DraftPost.class,
136 results = {@Result(id = true, property = "id", column = "id")})}
137 )
138
139 List<Post> selectPostsWithResultMap();
140
141
142
143
144 @Select("SELECT * FROM "
145 + "blog WHERE id = #{id}")
146
147 Blog selectBlog(int id);
148
149
150
151
152 @Select("SELECT * FROM "
153 + "blog WHERE id = #{id}")
154 @ConstructorArgs({
155 @Arg(column = "id", javaType = int.class, id = true),
156 @Arg(column = "title", javaType = String.class),
157 @Arg(column = "author_id", javaType = Author.class, select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor"),
158 @Arg(column = "id", javaType = List.class, select = "selectPostsForBlog")
159 })
160
161 Blog selectBlogUsingConstructor(int id);
162
163 Blog selectBlogUsingConstructorWithResultMap(int i);
164
165 Blog selectBlogUsingConstructorWithResultMapAndProperties(int i);
166
167 Blog selectBlogUsingConstructorWithResultMapCollection(int i);
168
169 Blog selectBlogByIdUsingConstructor(int id);
170
171
172
173
174 @Select("SELECT * FROM "
175 + "blog WHERE id = #{id}")
176
177 Map<String, Object> selectBlogAsMap(Map<String, Object> params);
178
179
180
181
182 @Select("SELECT * FROM "
183 + "post WHERE subject like #{query}")
184
185 List<Post> selectPostsLike(RowBounds bounds, String query);
186
187
188
189
190 @Select("SELECT * FROM "
191 + "post WHERE subject like #{subjectQuery} and body like #{bodyQuery}")
192
193 List<Post> selectPostsLikeSubjectAndBody(RowBounds bounds, @Param("subjectQuery") String subjectQuery,
194 @Param("bodyQuery") String bodyQuery);
195
196
197
198
199 @Select("SELECT * FROM "
200 + "post WHERE id = #{id}")
201
202 List<Post> selectPostsById(int id);
203
204
205
206
207 @Select("SELECT * FROM blog "
208 + "WHERE id = #{id} AND title = #{nonExistentParam,jdbcType=VARCHAR}")
209
210 Blog selectBlogByNonExistentParam(@Param("id") int id);
211
212
213 @Select("SELECT * FROM blog "
214 + "WHERE id = #{id} AND title = #{params.nonExistentParam,jdbcType=VARCHAR}")
215
216 Blog selectBlogByNonExistentNestedParam(@Param("id") int id, @Param("params") Map<String, Object> params);
217
218 @Select("SELECT * FROM blog WHERE id = #{id}")
219 Blog selectBlogByNullParam(Integer id);
220
221
222
223
224 @Select("SELECT * FROM blog "
225 + "WHERE id = #{0} AND title = #{1}")
226
227 Blog selectBlogByDefault30ParamNames(int id, String title);
228
229
230 @Select("SELECT * FROM blog "
231 + "WHERE id = #{param1} AND title = #{param2}")
232
233 Blog selectBlogByDefault31ParamNames(int id, String title);
234
235
236
237
238 @Select("SELECT * FROM blog "
239 + "WHERE ${column} = #{id} AND title = #{value}")
240
241 Blog selectBlogWithAParamNamedValue(@Param("column") String column, @Param("id") int id,
242 @Param("value") String title);
243
244
245
246
247 @Select({
248 "SELECT *",
249 "FROM blog"
250 })
251 @Results({
252 @Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor")),
253 @Result(property = "posts", column = "id", many = @Many(select = "selectPostsById"))
254 })
255
256 List<Blog> selectBlogsWithAutorAndPosts();
257
258
259 @Select({
260 "SELECT *",
261 "FROM blog"
262 })
263 @Results({
264 @Result(property = "author", column = "author_id", one = @One(select = "org.apache.ibatis.binding.BoundAuthorMapper.selectAuthor", fetchType = FetchType.EAGER)),
265 @Result(property = "posts", column = "id", many = @Many(select = "selectPostsById", fetchType = FetchType.EAGER))
266 })
267
268 List<Blog> selectBlogsWithAutorAndPostsEagerly();
269
270 }