@@ -287,6 +287,36 @@ public void testUnionSelectWithoutWhere() {
287
287
}
288
288
}
289
289
290
+ @ Test
291
+ public void testUnionAllSelectWithoutWhere () {
292
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
293
+ AnimalDataMapper mapper = sqlSession .getMapper (AnimalDataMapper .class );
294
+
295
+ SelectStatementProvider selectStatement = select (id , animalName , bodyWeight , brainWeight )
296
+ .from (animalData )
297
+ .unionAll ()
298
+ .selectDistinct (id , animalName , bodyWeight , brainWeight )
299
+ .from (animalData )
300
+ .orderBy (id )
301
+ .build ()
302
+ .render (RenderingStrategy .MYBATIS3 );
303
+
304
+ String expected = "select id, animal_name, body_weight, brain_weight "
305
+ + "from AnimalData "
306
+ + "union all "
307
+ + "select distinct id, animal_name, body_weight, brain_weight "
308
+ + "from AnimalData "
309
+ + "order by id" ;
310
+
311
+ List <AnimalData > animals = mapper .selectMany (selectStatement );
312
+ assertAll (
313
+ () -> assertThat (selectStatement .getSelectStatement ()).isEqualTo (expected ),
314
+ () -> assertThat (animals .size ()).isEqualTo (130 ),
315
+ () -> assertThat (selectStatement .getParameters ().size ()).isEqualTo (0 )
316
+ );
317
+ }
318
+ }
319
+
290
320
@ Test
291
321
public void testUnionSelectWithTableAliases () {
292
322
try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
@@ -324,6 +354,43 @@ public void testUnionSelectWithTableAliases() {
324
354
}
325
355
}
326
356
357
+ @ Test
358
+ public void testUnionAllSelectWithTableAliases () {
359
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
360
+ AnimalDataMapper mapper = sqlSession .getMapper (AnimalDataMapper .class );
361
+
362
+ SelectStatementProvider selectStatement = select (id , animalName , bodyWeight , brainWeight )
363
+ .from (animalData , "a" )
364
+ .where (id , isLessThan (20 ))
365
+ .unionAll ()
366
+ .select (id , animalName , bodyWeight , brainWeight )
367
+ .from (animalData , "b" )
368
+ .where (id , isGreaterThan (40 ))
369
+ .orderBy (id )
370
+ .build ()
371
+ .render (RenderingStrategy .MYBATIS3 );
372
+
373
+ String expected = "select a.id, a.animal_name, a.body_weight, a.brain_weight "
374
+ + "from AnimalData a "
375
+ + "where a.id < #{parameters.p1,jdbcType=INTEGER} "
376
+ + "union all "
377
+ + "select b.id, b.animal_name, b.body_weight, b.brain_weight "
378
+ + "from AnimalData b "
379
+ + "where b.id > #{parameters.p2,jdbcType=INTEGER} "
380
+ + "order by id" ;
381
+
382
+ List <AnimalData > animals = mapper .selectMany (selectStatement );
383
+
384
+ assertAll (
385
+ () -> assertThat (selectStatement .getSelectStatement ()).isEqualTo (expected ),
386
+ () -> assertThat (animals .size ()).isEqualTo (44 ),
387
+ () -> assertThat (selectStatement .getParameters ().size ()).isEqualTo (2 ),
388
+ () -> assertThat (selectStatement .getParameters ().get ("p1" )).isEqualTo (20 ),
389
+ () -> assertThat (selectStatement .getParameters ().get ("p2" )).isEqualTo (40 )
390
+ );
391
+ }
392
+ }
393
+
327
394
@ Test
328
395
public void testUnionSelectWithTableAndColumnAliases () {
329
396
try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
0 commit comments