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