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.keygen;
17  
18  import java.util.List;
19  import java.util.Map;
20  import java.util.Set;
21  
22  import org.apache.ibatis.annotations.Insert;
23  import org.apache.ibatis.annotations.Options;
24  import org.apache.ibatis.annotations.Param;
25  import org.apache.ibatis.reflection.ParamNameResolver;
26  
27  public interface CountryMapper {
28  
29    @Options(useGeneratedKeys = true, keyProperty = "id")
30    @Insert({ "insert into country (countryname,countrycode) values (#{countryname},#{countrycode})" })
31    int insertBean(Country country);
32  
33    @Options(useGeneratedKeys = true, keyProperty = "id")
34    @Insert({ "insert into country (countryname,countrycode) values (#{country.countryname},#{country.countrycode})" })
35    int insertNamedBean(@Param("country") Country country);
36  
37    @Options(useGeneratedKeys = true, keyProperty = "country.id")
38    @Insert({ "insert into country (countryname,countrycode) values (#{country.countryname},#{country.countrycode})" })
39    int insertNamedBean_keyPropertyWithParamName(@Param("country") Country country);
40  
41    int insertList(List<Country> countries);
42  
43    int insertNamedList(@Param("countries") List<Country> countries);
44  
45    int insertSet(Set<Country> countries);
46  
47    int insertNamedSet(@Param("countries") Set<Country> countries);
48  
49    int insertArray(Country[] countries);
50  
51    int insertNamedArray(@Param("countries") Country[] countries);
52  
53    @Options(useGeneratedKeys = true, keyProperty = "country.id")
54    @Insert({ "insert into country (countryname,countrycode) values (#{country.countryname},#{country.countrycode})" })
55    int insertMultiParams(@Param("country") Country country, @Param("someId") Integer someId);
56  
57    @Options(useGeneratedKeys = true, keyProperty = "id")
58    @Insert({ "insert into country (countryname,countrycode) values (#{country.countryname},#{country.countrycode})" })
59    int insertMultiParams_keyPropertyWithoutParamName(@Param("country") Country country, @Param("someId") Integer someId);
60  
61    @Options(useGeneratedKeys = true, keyProperty = "bogus.id")
62    @Insert({ "insert into country (countryname,countrycode) values (#{country.countryname},#{country.countrycode})" })
63    int insertMultiParams_keyPropertyWithWrongParamName(@Param("country") Country country,
64        @Param("someId") Integer someId);
65  
66    int insertListAndSomeId(@Param("list") List<Country> countries, @Param("someId") Integer someId);
67  
68    int insertSetAndSomeId(@Param("collection") Set<Country> countries, @Param("someId") Integer someId);
69  
70    int insertArrayAndSomeId(@Param("array") Country[] countries, @Param("someId") Integer someId);
71  
72    int insertList_MultiParams(@Param("countries") List<Country> countries, @Param("someId") Integer someId);
73  
74    int insertSet_MultiParams(@Param("countries") Set<Country> countries, @Param("someId") Integer someId);
75  
76    int insertArray_MultiParams(@Param("countries") Country[] countries, @Param("someId") Integer someId);
77  
78    int insertUndefineKeyProperty(Country country);
79  
80    @Options(useGeneratedKeys = true, keyProperty = "id,code")
81    @Insert({ "insert into planet (name) values (#{name})" })
82    int insertPlanet(Planet planet);
83  
84    int insertPlanets(List<Planet> planets);
85  
86    @Options(useGeneratedKeys = true, keyProperty = "planet.id,planet.code")
87    @Insert({ "insert into planet (name) values (#{planet.name})" })
88    int insertPlanet_MultiParams(@Param("planet") Planet planet, @Param("someId") Integer someId);
89  
90    int insertPlanets_MultiParams(@Param("planets") List<Planet> planets, @Param("someId") Integer someId);
91  
92    @Options(useGeneratedKeys = true, keyProperty = "planet.id,map.code")
93    @Insert({ "insert into planet (name) values (#{planet.name})" })
94    int insertAssignKeysToTwoParams(@Param("planet") Planet planet, @Param("map") Map<String, Object> map);
95  
96    @Options(useGeneratedKeys = true, keyProperty = "id")
97    @Insert({ "insert into country (countryname,countrycode) values ('a','A'), ('b', 'B')" })
98    int tooManyGeneratedKeys(Country country);
99  
100   @Options(useGeneratedKeys = true, keyProperty = "country.id")
101   @Insert({ "insert into country (countryname,countrycode) values ('a','A'), ('b', 'B')" })
102   int tooManyGeneratedKeysParamMap(@Param("country") Country country, @Param("someId") Integer someId);
103 
104   int insertWeirdCountries(List<NpeCountry> list);
105 
106   // If the only parameter has a name 'param2', keyProperty must include the prefix 'param2.'.
107   @Options(useGeneratedKeys = true, keyProperty = ParamNameResolver.GENERIC_NAME_PREFIX + "2.id")
108   @Insert({ "insert into country (countryname,countrycode) values (#{param2.countryname},#{param2.countrycode})" })
109   int singleParamWithATrickyName(@Param(ParamNameResolver.GENERIC_NAME_PREFIX + "2") Country country);
110 
111   @Options(useGeneratedKeys = true, keyProperty = "id")
112   @Insert({ "insert into country (countryname,countrycode) values (#{countryname},#{countrycode})" })
113   int insertMap(Map<String, Object> map);
114 }