21
21
import org .apache .ibatis .session .SqlSession ;
22
22
import org .apache .ibatis .session .SqlSessionFactory ;
23
23
import org .apache .ibatis .session .SqlSessionFactoryBuilder ;
24
- import static org . junit . Assert . assertEquals ;
24
+
25
25
import static org .junit .Assert .*;
26
26
27
27
import org .junit .Before ;
28
+ import org .junit .Ignore ;
28
29
import org .junit .Test ;
29
30
30
31
import java .io .Reader ;
@@ -153,14 +154,79 @@ public void testAnnotatedInsertTable2() {
153
154
}
154
155
155
156
@ Test
156
- public void testAnnotatedInsertTable2WithOptions () {
157
+ public void testAnnotatedInsertTable2WithGeneratedKey () {
158
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
159
+
160
+ try {
161
+ Name name = new Name ();
162
+ name .setName ("barney" );
163
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
164
+ int rows = mapper .insertTable2WithGeneratedKey (name );
165
+ assertEquals (1 , rows );
166
+ assertEquals (22 , name .getNameId ());
167
+ assertEquals ("barney_fred" , name .getGeneratedName ());
168
+ } finally {
169
+ sqlSession .close ();
170
+ }
171
+ }
172
+
173
+ @ Test
174
+ @ Ignore ("HSQLDB is not returning the generated column after the update" )
175
+ public void testAnnotatedUpdateTable2WithGeneratedKey () {
157
176
SqlSession sqlSession = sqlSessionFactory .openSession ();
158
177
159
178
try {
160
179
Name name = new Name ();
161
180
name .setName ("barney" );
162
181
AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
163
- int rows = mapper .insertTable2WithOptions (name );
182
+ int rows = mapper .insertTable2WithGeneratedKey (name );
183
+ assertEquals (1 , rows );
184
+ assertEquals (22 , name .getNameId ());
185
+ assertEquals ("barney_fred" , name .getGeneratedName ());
186
+
187
+ name .setName ("Wilma" );
188
+ rows = mapper .updateTable2WithGeneratedKey (name );
189
+ assertEquals (1 , rows );
190
+ assertEquals (22 , name .getNameId ());
191
+ assertEquals ("Wilma_fred" , name .getGeneratedName ());
192
+ } finally {
193
+ sqlSession .close ();
194
+ }
195
+ }
196
+
197
+ @ Test
198
+ @ Ignore ("HSQLDB is not returning the generated column after the update" )
199
+ public void testAnnotatedUpdateTable2WithGeneratedKeyXml () {
200
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
201
+
202
+ try {
203
+ Name name = new Name ();
204
+ name .setName ("barney" );
205
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
206
+ int rows = mapper .insertTable2WithGeneratedKeyXml (name );
207
+ assertEquals (1 , rows );
208
+ assertEquals (22 , name .getNameId ());
209
+ assertEquals ("barney_fred" , name .getGeneratedName ());
210
+
211
+ name .setName ("Wilma" );
212
+ rows = mapper .updateTable2WithGeneratedKeyXml (name );
213
+ assertEquals (1 , rows );
214
+ assertEquals (22 , name .getNameId ());
215
+ assertEquals ("Wilma_fred" , name .getGeneratedName ());
216
+ } finally {
217
+ sqlSession .close ();
218
+ }
219
+ }
220
+
221
+ @ Test
222
+ public void testAnnotatedInsertTable2WithGeneratedKeyXml () {
223
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
224
+
225
+ try {
226
+ Name name = new Name ();
227
+ name .setName ("barney" );
228
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
229
+ int rows = mapper .insertTable2WithGeneratedKeyXml (name );
164
230
assertEquals (1 , rows );
165
231
assertEquals (22 , name .getNameId ());
166
232
assertEquals ("barney_fred" , name .getGeneratedName ());
@@ -186,6 +252,69 @@ public void testAnnotatedInsertTable2WithSelectKeyWithKeyMap() {
186
252
}
187
253
}
188
254
255
+ @ Test
256
+ public void testAnnotatedUpdateTable2WithSelectKeyWithKeyMap () {
257
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
258
+
259
+ try {
260
+ Name name = new Name ();
261
+ name .setName ("barney" );
262
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
263
+ int rows = mapper .insertTable2WithSelectKeyWithKeyMap (name );
264
+ assertEquals (1 , rows );
265
+ assertEquals (22 , name .getNameId ());
266
+ assertEquals ("barney_fred" , name .getGeneratedName ());
267
+
268
+ name .setName ("Wilma" );
269
+ rows = mapper .updateTable2WithSelectKeyWithKeyMap (name );
270
+ assertEquals (1 , rows );
271
+ assertEquals (22 , name .getNameId ());
272
+ assertEquals ("Wilma_fred" , name .getGeneratedName ());
273
+ } finally {
274
+ sqlSession .close ();
275
+ }
276
+ }
277
+
278
+ @ Test
279
+ public void testAnnotatedInsertTable2WithSelectKeyWithKeyMapXml () {
280
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
281
+
282
+ try {
283
+ Name name = new Name ();
284
+ name .setName ("barney" );
285
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
286
+ int rows = mapper .insertTable2WithSelectKeyWithKeyMapXml (name );
287
+ assertEquals (1 , rows );
288
+ assertEquals (22 , name .getNameId ());
289
+ assertEquals ("barney_fred" , name .getGeneratedName ());
290
+ } finally {
291
+ sqlSession .close ();
292
+ }
293
+ }
294
+
295
+ @ Test
296
+ public void testAnnotatedUpdateTable2WithSelectKeyWithKeyMapXml () {
297
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
298
+
299
+ try {
300
+ Name name = new Name ();
301
+ name .setName ("barney" );
302
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
303
+ int rows = mapper .insertTable2WithSelectKeyWithKeyMapXml (name );
304
+ assertEquals (1 , rows );
305
+ assertEquals (22 , name .getNameId ());
306
+ assertEquals ("barney_fred" , name .getGeneratedName ());
307
+
308
+ name .setName ("Wilma" );
309
+ rows = mapper .updateTable2WithSelectKeyWithKeyMapXml (name );
310
+ assertEquals (1 , rows );
311
+ assertEquals (22 , name .getNameId ());
312
+ assertEquals ("Wilma_fred" , name .getGeneratedName ());
313
+ } finally {
314
+ sqlSession .close ();
315
+ }
316
+ }
317
+
189
318
@ Test
190
319
public void testAnnotatedInsertTable2WithSelectKeyWithKeyObject () {
191
320
SqlSession sqlSession = sqlSessionFactory .openSession ();
@@ -203,6 +332,69 @@ public void testAnnotatedInsertTable2WithSelectKeyWithKeyObject() {
203
332
}
204
333
}
205
334
335
+ @ Test
336
+ public void testAnnotatedUpdateTable2WithSelectKeyWithKeyObject () {
337
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
338
+
339
+ try {
340
+ Name name = new Name ();
341
+ name .setName ("barney" );
342
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
343
+ int rows = mapper .insertTable2WithSelectKeyWithKeyObject (name );
344
+ assertEquals (1 , rows );
345
+ assertEquals (22 , name .getNameId ());
346
+ assertEquals ("barney_fred" , name .getGeneratedName ());
347
+
348
+ name .setName ("Wilma" );
349
+ rows = mapper .updateTable2WithSelectKeyWithKeyObject (name );
350
+ assertEquals (1 , rows );
351
+ assertEquals (22 , name .getNameId ());
352
+ assertEquals ("Wilma_fred" , name .getGeneratedName ());
353
+ } finally {
354
+ sqlSession .close ();
355
+ }
356
+ }
357
+
358
+ @ Test
359
+ public void testAnnotatedUpdateTable2WithSelectKeyWithKeyObjectXml () {
360
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
361
+
362
+ try {
363
+ Name name = new Name ();
364
+ name .setName ("barney" );
365
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
366
+ int rows = mapper .insertTable2WithSelectKeyWithKeyObjectXml (name );
367
+ assertEquals (1 , rows );
368
+ assertEquals (22 , name .getNameId ());
369
+ assertEquals ("barney_fred" , name .getGeneratedName ());
370
+
371
+ name .setName ("Wilma" );
372
+ rows = mapper .updateTable2WithSelectKeyWithKeyObjectXml (name );
373
+ assertEquals (1 , rows );
374
+ assertEquals (22 , name .getNameId ());
375
+ assertEquals ("Wilma_fred" , name .getGeneratedName ());
376
+ } finally {
377
+ sqlSession .close ();
378
+ }
379
+ }
380
+
381
+ @ Test
382
+ public void testAnnotatedInsertTable2WithSelectKeyWithKeyObjectXml () {
383
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
384
+
385
+ try {
386
+ Name name = new Name ();
387
+ name .setName ("barney" );
388
+ AnnotatedMapper mapper = sqlSession .getMapper (AnnotatedMapper .class );
389
+ int rows = mapper .insertTable2WithSelectKeyWithKeyObjectXml (name );
390
+ assertEquals (1 , rows );
391
+ assertEquals (22 , name .getNameId ());
392
+ assertEquals ("barney_fred" , name .getGeneratedName ());
393
+ } finally {
394
+ sqlSession .close ();
395
+ }
396
+ }
397
+
206
398
@ Test
207
399
public void testAnnotatedInsertTable3 () {
208
400
SqlSession sqlSession = sqlSessionFactory .openSession ();
0 commit comments