View Javadoc
1   /*
2    *    Copyright 2009-2022 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.submitted.selectkey;
17  
18  import java.util.Map;
19  
20  import org.apache.ibatis.annotations.Insert;
21  import org.apache.ibatis.annotations.InsertProvider;
22  import org.apache.ibatis.annotations.Options;
23  import org.apache.ibatis.annotations.SelectKey;
24  import org.apache.ibatis.annotations.Update;
25  
26  public interface AnnotatedMapper {
27  
28    @Insert("insert into table2 (name) values(#{name})")
29    @SelectKey(statement = "call identity()", keyProperty = "nameId", before = false, resultType = int.class)
30    int insertTable2(Name name);
31  
32    @Insert("insert into table2 (name) values(#{name})")
33    @Options(useGeneratedKeys = true, keyProperty = "nameId,generatedName", keyColumn = "ID,NAME_FRED")
34    int insertTable2WithGeneratedKey(Name name);
35  
36    int insertTable2WithGeneratedKeyXml(Name name);
37  
38    @Insert("insert into table2 (name) values(#{name})")
39    @SelectKey(statement = "select id, name_fred from table2 where id = identity()", keyProperty = "nameId,generatedName", keyColumn = "ID,NAME_FRED", before = false, resultType = Map.class)
40    int insertTable2WithSelectKeyWithKeyMap(Name name);
41  
42    int insertTable2WithSelectKeyWithKeyMapXml(Name name);
43  
44    @Insert("insert into table2 (name) values(#{name})")
45    @SelectKey(statement = "select id as nameId, name_fred as generatedName from table2 where id = identity()", keyProperty = "nameId,generatedName", before = false, resultType = Name.class)
46    int insertTable2WithSelectKeyWithKeyObject(Name name);
47  
48    int insertTable2WithSelectKeyWithKeyObjectXml(Name name);
49  
50    @Insert("insert into table3 (id, name) values(#{nameId}, #{name})")
51    @SelectKey(statement = "call next value for TestSequence", keyProperty = "nameId", before = true, resultType = int.class)
52    int insertTable3(Name name);
53  
54    @InsertProvider(type = SqlProvider.class, method = "insertTable3_2")
55    @SelectKey(statement = "call next value for TestSequence", keyProperty = "nameId", before = true, resultType = int.class)
56    int insertTable3_2(Name name);
57  
58    @Update("update table2 set name = #{name} where id = #{nameId}")
59    @Options(useGeneratedKeys = true, keyProperty = "generatedName")
60    int updateTable2WithGeneratedKey(Name name);
61  
62    int updateTable2WithGeneratedKeyXml(Name name);
63  
64    @Update("update table2 set name = #{name} where id = #{nameId}")
65    @SelectKey(statement = "select name_fred from table2 where id = #{nameId}", keyProperty = "generatedName", keyColumn = "NAME_FRED", before = false, resultType = String.class)
66    int updateTable2WithSelectKeyWithKeyMap(Name name);
67  
68    int updateTable2WithSelectKeyWithKeyMapXml(Name name);
69  
70    @Update("update table2 set name = #{name} where id = #{nameId}")
71    @SelectKey(statement = "select name_fred as generatedName from table2 where id = #{nameId}", keyProperty = "generatedName", before = false, resultType = Name.class)
72    int updateTable2WithSelectKeyWithKeyObject(Name name);
73  
74    int updateTable2WithSelectKeyWithKeyObjectXml(Name name);
75  }