View Javadoc
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.binding;
17  
18  import java.util.List;
19  
20  import org.apache.ibatis.annotations.*;
21  import org.apache.ibatis.domain.blog.Author;
22  import org.apache.ibatis.domain.blog.Post;
23  import org.apache.ibatis.domain.blog.Section;
24  import org.apache.ibatis.executor.BatchResult;
25  import org.apache.ibatis.session.RowBounds;
26  
27  @CacheNamespace(readWrite = false)
28  public interface BoundAuthorMapper {
29  
30    //======================================================
31  
32    List<Post> findPostsInArray(Integer[] ids);
33  
34    //======================================================
35  
36    List<Post> findPostsInList(List<Integer> ids);
37  
38    //======================================================
39  
40    int insertAuthor(Author author);
41  
42    int insertAuthorInvalidSelectKey(Author author);
43  
44    int insertAuthorInvalidInsert(Author author);
45  
46    int insertAuthorDynamic(Author author);
47  
48    //======================================================
49  
50    @ConstructorArgs({
51        @Arg(column = "AUTHOR_ID", javaType = int.class)
52    })
53    @Results({
54        @Result(property = "username", column = "AUTHOR_USERNAME"),
55        @Result(property = "password", column = "AUTHOR_PASSWORD"),
56        @Result(property = "email", column = "AUTHOR_EMAIL"),
57        @Result(property = "bio", column = "AUTHOR_BIO")
58    })
59    @Select({
60        "SELECT ",
61        "  ID as AUTHOR_ID,",
62        "  USERNAME as AUTHOR_USERNAME,",
63        "  PASSWORD as AUTHOR_PASSWORD,",
64        "  EMAIL as AUTHOR_EMAIL,",
65        "  BIO as AUTHOR_BIO",
66        "FROM AUTHOR WHERE ID = #{id}"})
67    Author selectAuthor(int id);
68  
69    //======================================================
70  
71    @Result(property = "id", column = "AUTHOR_ID", id = true)
72    @Result(property = "username", column = "AUTHOR_USERNAME")
73    @Result(property = "password", column = "AUTHOR_PASSWORD")
74    @Result(property = "email", column = "AUTHOR_EMAIL")
75    @Result(property = "bio", column = "AUTHOR_BIO")
76    @Select({
77      "SELECT ",
78      "  ID as AUTHOR_ID,",
79      "  USERNAME as AUTHOR_USERNAME,",
80      "  PASSWORD as AUTHOR_PASSWORD,",
81      "  EMAIL as AUTHOR_EMAIL,",
82      "  BIO as AUTHOR_BIO",
83      "FROM AUTHOR WHERE ID = #{id}"})
84    Author selectAuthorMapToPropertiesUsingRepeatable(int id);
85  
86    //======================================================
87  
88    @ConstructorArgs({
89        @Arg(column = "AUTHOR_ID", javaType = Integer.class),
90        @Arg(column = "AUTHOR_USERNAME", javaType = String.class),
91        @Arg(column = "AUTHOR_PASSWORD", javaType = String.class),
92        @Arg(column = "AUTHOR_EMAIL", javaType = String.class),
93        @Arg(column = "AUTHOR_BIO", javaType = String.class),
94        @Arg(column = "AUTHOR_SECTION", javaType = Section.class)
95    })
96    @Select({
97        "SELECT ",
98        "  ID as AUTHOR_ID,",
99        "  USERNAME as AUTHOR_USERNAME,",
100       "  PASSWORD as AUTHOR_PASSWORD,",
101       "  EMAIL as AUTHOR_EMAIL,",
102       "  BIO as AUTHOR_BIO," +
103           "  FAVOURITE_SECTION as AUTHOR_SECTION",
104       "FROM AUTHOR WHERE ID = #{id}"})
105   Author selectAuthorConstructor(int id);
106 
107   //======================================================
108 
109   @Arg(column = "AUTHOR_ID", javaType = Integer.class, id = true)
110   @Arg(column = "AUTHOR_USERNAME", javaType = String.class)
111   @Arg(column = "AUTHOR_PASSWORD", javaType = String.class)
112   @Arg(column = "AUTHOR_EMAIL", javaType = String.class)
113   @Arg(column = "AUTHOR_BIO", javaType = String.class)
114   @Arg(column = "AUTHOR_SECTION", javaType = Section.class)
115   @Select({
116     "SELECT ",
117     "  ID as AUTHOR_ID,",
118     "  USERNAME as AUTHOR_USERNAME,",
119     "  PASSWORD as AUTHOR_PASSWORD,",
120     "  EMAIL as AUTHOR_EMAIL,",
121     "  BIO as AUTHOR_BIO," +
122       "  FAVOURITE_SECTION as AUTHOR_SECTION",
123     "FROM AUTHOR WHERE ID = #{id}"})
124   Author selectAuthorMapToConstructorUsingRepeatable(int id);
125 
126   //======================================================
127 
128   @Arg(column = "AUTHOR_ID", javaType = int.class)
129   @Result(property = "username", column = "AUTHOR_USERNAME")
130   @Select({
131     "SELECT ",
132     "  ID as AUTHOR_ID,",
133     "  USERNAME as AUTHOR_USERNAME,",
134     "  PASSWORD as AUTHOR_PASSWORD,",
135     "  EMAIL as AUTHOR_EMAIL,",
136     "  BIO as AUTHOR_BIO",
137     "FROM AUTHOR WHERE ID = #{id}"})
138   Author selectAuthorUsingSingleRepeatable(int id);
139 
140   //======================================================
141 
142   @ConstructorArgs({
143     @Arg(column = "AUTHOR_ID", javaType = Integer.class),
144     @Arg(column = "AUTHOR_USERNAME", javaType = String.class),
145     @Arg(column = "AUTHOR_PASSWORD", javaType = String.class),
146     @Arg(column = "AUTHOR_EMAIL", javaType = String.class),
147     @Arg(column = "AUTHOR_BIO", javaType = String.class)
148   })
149   @Arg(column = "AUTHOR_SECTION", javaType = Section.class)
150   @Select({
151     "SELECT ",
152     "  ID as AUTHOR_ID,",
153     "  USERNAME as AUTHOR_USERNAME,",
154     "  PASSWORD as AUTHOR_PASSWORD,",
155     "  EMAIL as AUTHOR_EMAIL,",
156     "  BIO as AUTHOR_BIO," +
157       "  FAVOURITE_SECTION as AUTHOR_SECTION",
158     "FROM AUTHOR WHERE ID = #{id}"})
159   Author selectAuthorUsingBothArgAndConstructorArgs(int id);
160 
161   //======================================================
162 
163   @Results(
164     @Result(property = "id", column = "AUTHOR_ID")
165   )
166   @Result(property = "username", column = "AUTHOR_USERNAME")
167   @Select({
168     "SELECT ",
169     "  ID as AUTHOR_ID,",
170     "  USERNAME as AUTHOR_USERNAME",
171     "FROM AUTHOR WHERE ID = #{id}"})
172   Author selectAuthorUsingBothResultAndResults(int id);
173 
174   //======================================================
175 
176   List<Post> findThreeSpecificPosts(@Param("one") int one,
177                                     RowBounds rowBounds,
178                                     @Param("two") int two,
179                                     int three);
180 
181   @Flush
182   List<BatchResult> flush();
183 
184 }