1515 */
1616package examples .simple ;
1717
18- import static examples .simple .SimpleTableDynamicSqlSupport .*;
18+ import static examples .simple .PersonDynamicSqlSupport .*;
1919import static org .mybatis .dynamic .sql .SqlBuilder .*;
2020
2121import java .util .List ;
5555 *
5656 */
5757@ Mapper
58- public interface SimpleTableMapperNewStyle {
58+ public interface PersonMapper {
5959
6060 @ InsertProvider (type =SqlProviderAdapter .class , method ="insert" )
61- int insert (InsertStatementProvider <SimpleTableRecord > insertStatement );
61+ int insert (InsertStatementProvider <PersonRecord > insertStatement );
6262
6363 @ InsertProvider (type =SqlProviderAdapter .class , method ="insertMultiple" )
64- int insertMultiple (MultiRowInsertStatementProvider <SimpleTableRecord > insertStatement );
64+ int insertMultiple (MultiRowInsertStatementProvider <PersonRecord > insertStatement );
6565
6666 @ UpdateProvider (type =SqlProviderAdapter .class , method ="update" )
6767 int update (UpdateStatementProvider updateStatement );
@@ -73,13 +73,14 @@ public interface SimpleTableMapperNewStyle {
7373 @ Result (column ="last_name" , property ="lastName" , jdbcType =JdbcType .VARCHAR , typeHandler =LastNameTypeHandler .class ),
7474 @ Result (column ="birth_date" , property ="birthDate" , jdbcType =JdbcType .DATE ),
7575 @ Result (column ="employed" , property ="employed" , jdbcType =JdbcType .VARCHAR , typeHandler =YesNoTypeHandler .class ),
76- @ Result (column ="occupation" , property ="occupation" , jdbcType =JdbcType .VARCHAR )
76+ @ Result (column ="occupation" , property ="occupation" , jdbcType =JdbcType .VARCHAR ),
77+ @ Result (column ="address_id" , property ="addressId" , jdbcType =JdbcType .INTEGER )
7778 })
78- List <SimpleTableRecord > selectMany (SelectStatementProvider selectStatement );
79+ List <PersonRecord > selectMany (SelectStatementProvider selectStatement );
7980
8081 @ SelectProvider (type =SqlProviderAdapter .class , method ="select" )
8182 @ ResultMap ("SimpleTableResult" )
82- Optional <SimpleTableRecord > selectOne (SelectStatementProvider selectStatement );
83+ Optional <PersonRecord > selectOne (SelectStatementProvider selectStatement );
8384
8485 @ DeleteProvider (type =SqlProviderAdapter .class , method ="delete" )
8586 int delete (DeleteStatementProvider deleteStatement );
@@ -89,13 +90,13 @@ public interface SimpleTableMapperNewStyle {
8990
9091 default long count (MyBatis3CountHelper helper ) {
9192 return helper .apply (SelectDSL .selectWithMapper (this ::count , SqlBuilder .count ())
92- .from (simpleTable ))
93+ .from (person ))
9394 .build ()
9495 .execute ();
9596 }
9697
9798 default int delete (MyBatis3DeleteHelper helper ) {
98- return helper .apply (MyBatis3Utils .deleteFrom (this ::delete , simpleTable ))
99+ return helper .apply (MyBatis3Utils .deleteFrom (this ::delete , person ))
99100 .build ()
100101 .execute ();
101102 }
@@ -106,116 +107,123 @@ default int deleteByPrimaryKey(Integer id_) {
106107 );
107108 }
108109
109- default int insert (SimpleTableRecord record ) {
110+ default int insert (PersonRecord record ) {
110111 return insert (SqlBuilder .insert (record )
111- .into (simpleTable )
112+ .into (person )
112113 .map (id ).toProperty ("id" )
113114 .map (firstName ).toProperty ("firstName" )
114115 .map (lastName ).toProperty ("lastName" )
115116 .map (birthDate ).toProperty ("birthDate" )
116117 .map (employed ).toProperty ("employed" )
117118 .map (occupation ).toProperty ("occupation" )
119+ .map (addressId ).toProperty ("addressId" )
118120 .build ()
119121 .render (RenderingStrategy .MYBATIS3 ));
120122 }
121123
122- default int insertMultiple (List <SimpleTableRecord > records ) {
124+ default int insertMultiple (List <PersonRecord > records ) {
123125 return insertMultiple (SqlBuilder .insertMultiple (records )
124- .into (simpleTable )
126+ .into (person )
125127 .map (id ).toProperty ("id" )
126128 .map (firstName ).toProperty ("firstName" )
127129 .map (lastName ).toProperty ("lastName" )
128130 .map (birthDate ).toProperty ("birthDate" )
129131 .map (employed ).toProperty ("employed" )
130132 .map (occupation ).toProperty ("occupation" )
133+ .map (addressId ).toProperty ("addressId" )
131134 .build ()
132135 .render (RenderingStrategy .MYBATIS3 ));
133136 }
134137
135- default int insertSelective (SimpleTableRecord record ) {
138+ default int insertSelective (PersonRecord record ) {
136139 return insert (SqlBuilder .insert (record )
137- .into (simpleTable )
140+ .into (person )
138141 .map (id ).toPropertyWhenPresent ("id" , record ::getId )
139142 .map (firstName ).toPropertyWhenPresent ("firstName" , record ::getFirstName )
140143 .map (lastName ).toPropertyWhenPresent ("lastName" , record ::getLastName )
141144 .map (birthDate ).toPropertyWhenPresent ("birthDate" , record ::getBirthDate )
142145 .map (employed ).toPropertyWhenPresent ("employed" , record ::getEmployed )
143146 .map (occupation ).toPropertyWhenPresent ("occupation" , record ::getOccupation )
147+ .map (addressId ).toPropertyWhenPresent ("addressId" , record ::getAddressId )
144148 .build ()
145149 .render (RenderingStrategy .MYBATIS3 ));
146150 }
147151
148- default Optional <SimpleTableRecord > selectOne (MyBatis3SelectOneHelper <SimpleTableRecord > helper ) {
149- return helper .apply (SelectDSL .selectWithMapper (this ::selectOne , id .as ("A_ID" ), firstName , lastName , birthDate , employed , occupation )
150- .from (simpleTable ))
152+ default Optional <PersonRecord > selectOne (MyBatis3SelectOneHelper <PersonRecord > helper ) {
153+ return helper .apply (SelectDSL .selectWithMapper (this ::selectOne , id .as ("A_ID" ), firstName , lastName , birthDate , employed , occupation , addressId )
154+ .from (person ))
151155 .build ()
152156 .execute ();
153157 }
154158
155- default List <SimpleTableRecord > select (MyBatis3SelectListHelper <SimpleTableRecord > helper ) {
156- return helper .apply (SelectDSL .selectWithMapper (this ::selectMany , id .as ("A_ID" ), firstName , lastName , birthDate , employed , occupation )
157- .from (simpleTable ))
159+ default List <PersonRecord > select (MyBatis3SelectListHelper <PersonRecord > helper ) {
160+ return helper .apply (SelectDSL .selectWithMapper (this ::selectMany , id .as ("A_ID" ), firstName , lastName , birthDate , employed , occupation , addressId )
161+ .from (person ))
158162 .build ()
159163 .execute ();
160164 }
161165
162- default List <SimpleTableRecord > selectDistinct (MyBatis3SelectListHelper <SimpleTableRecord > helper ) {
163- return helper .apply (SelectDSL .selectDistinctWithMapper (this ::selectMany , id .as ("A_ID" ), firstName , lastName , birthDate , employed , occupation )
164- .from (simpleTable ))
166+ default List <PersonRecord > selectDistinct (MyBatis3SelectListHelper <PersonRecord > helper ) {
167+ return helper .apply (SelectDSL .selectDistinctWithMapper (this ::selectMany , id .as ("A_ID" ), firstName , lastName , birthDate , employed , occupation , addressId )
168+ .from (person ))
165169 .build ()
166170 .execute ();
167171 }
168172
169- default Optional <SimpleTableRecord > selectByPrimaryKey (Integer id_ ) {
173+ default Optional <PersonRecord > selectByPrimaryKey (Integer id_ ) {
170174 return selectOne (h ->
171175 h .where (id , isEqualTo (id_ ))
172176 );
173177 }
174178
175179 default int update (MyBatis3UpdateHelper helper ) {
176- return helper .apply (MyBatis3Utils .update (this ::update , simpleTable ))
180+ return helper .apply (MyBatis3Utils .update (this ::update , person ))
177181 .build ()
178182 .execute ();
179183 }
180184
181- static UpdateDSL <MyBatis3UpdateModelToIntAdapter > setAll (SimpleTableRecord record ,
185+ static UpdateDSL <MyBatis3UpdateModelToIntAdapter > setAll (PersonRecord record ,
182186 UpdateDSL <MyBatis3UpdateModelToIntAdapter > dsl ) {
183187 return dsl .set (id ).equalTo (record ::getId )
184188 .set (firstName ).equalTo (record ::getFirstName )
185189 .set (lastName ).equalTo (record ::getLastName )
186190 .set (birthDate ).equalTo (record ::getBirthDate )
187191 .set (employed ).equalTo (record ::getEmployed )
188- .set (occupation ).equalTo (record ::getOccupation );
192+ .set (occupation ).equalTo (record ::getOccupation )
193+ .set (addressId ).equalTo (record ::getAddressId );
189194 }
190195
191- static UpdateDSL <MyBatis3UpdateModelToIntAdapter > setSelective (SimpleTableRecord record ,
196+ static UpdateDSL <MyBatis3UpdateModelToIntAdapter > setSelective (PersonRecord record ,
192197 UpdateDSL <MyBatis3UpdateModelToIntAdapter > dsl ) {
193198 return dsl .set (id ).equalToWhenPresent (record ::getId )
194199 .set (firstName ).equalToWhenPresent (record ::getFirstName )
195200 .set (lastName ).equalToWhenPresent (record ::getLastName )
196201 .set (birthDate ).equalToWhenPresent (record ::getBirthDate )
197202 .set (employed ).equalToWhenPresent (record ::getEmployed )
198- .set (occupation ).equalToWhenPresent (record ::getOccupation );
203+ .set (occupation ).equalToWhenPresent (record ::getOccupation )
204+ .set (addressId ).equalToWhenPresent (record ::getAddressId );
199205 }
200206
201- default int updateByPrimaryKey (SimpleTableRecord record ) {
207+ default int updateByPrimaryKey (PersonRecord record ) {
202208 return update (h ->
203209 h .set (firstName ).equalTo (record ::getFirstName )
204210 .set (lastName ).equalTo (record ::getLastName )
205211 .set (birthDate ).equalTo (record ::getBirthDate )
206212 .set (employed ).equalTo (record ::getEmployed )
207213 .set (occupation ).equalTo (record ::getOccupation )
214+ .set (addressId ).equalTo (record ::getAddressId )
208215 .where (id , isEqualTo (record ::getId ))
209216 );
210217 }
211218
212- default int updateByPrimaryKeySelective (SimpleTableRecord record ) {
219+ default int updateByPrimaryKeySelective (PersonRecord record ) {
213220 return update (h ->
214221 h .set (firstName ).equalToWhenPresent (record ::getFirstName )
215222 .set (lastName ).equalToWhenPresent (record ::getLastName )
216223 .set (birthDate ).equalToWhenPresent (record ::getBirthDate )
217224 .set (employed ).equalToWhenPresent (record ::getEmployed )
218225 .set (occupation ).equalToWhenPresent (record ::getOccupation )
226+ .set (addressId ).equalToWhenPresent (record ::getAddressId )
219227 .where (id , isEqualTo (record ::getId ))
220228 );
221229 }
0 commit comments