@@ -412,7 +412,7 @@ class CanonicalSpringKotlinTest {
412
412
}
413
413
414
414
assertThat(records).hasSize(3 )
415
- with (records[0 ]!! ) {
415
+ with (records[0 ]) {
416
416
assertThat(id).isEqualTo(1 )
417
417
assertThat(firstName).isEqualTo(" Fred" )
418
418
assertThat(lastName).isEqualTo(" Flintstone" )
@@ -422,7 +422,7 @@ class CanonicalSpringKotlinTest {
422
422
assertThat(addressId).isEqualTo(1 )
423
423
}
424
424
425
- with (records[2 ]!! ) {
425
+ with (records[2 ]) {
426
426
assertThat(id).isEqualTo(3 )
427
427
assertThat(firstName).isEqualTo(" Pebbles" )
428
428
assertThat(lastName).isEqualTo(" Flintstone" )
@@ -485,7 +485,7 @@ class CanonicalSpringKotlinTest {
485
485
}
486
486
487
487
assertThat(records).hasSize(3 )
488
- with (records[0 ]!! ) {
488
+ with (records[0 ]) {
489
489
assertThat(id).isEqualTo(1 )
490
490
assertThat(firstName).isEqualTo(" Fred" )
491
491
assertThat(lastName).isEqualTo(" Flintstone" )
@@ -495,7 +495,7 @@ class CanonicalSpringKotlinTest {
495
495
assertThat(addressId).isEqualTo(1 )
496
496
}
497
497
498
- with (records[2 ]!! ) {
498
+ with (records[2 ]) {
499
499
assertThat(id).isEqualTo(3 )
500
500
assertThat(firstName).isEqualTo(" Pebbles" )
501
501
assertThat(lastName).isEqualTo(" Flintstone" )
@@ -558,7 +558,7 @@ class CanonicalSpringKotlinTest {
558
558
}
559
559
560
560
assertThat(records).hasSize(3 )
561
- with (records[0 ]!! ) {
561
+ with (records[0 ]) {
562
562
assertThat(id).isEqualTo(1 )
563
563
assertThat(firstName).isEqualTo(" Fred" )
564
564
assertThat(lastName).isEqualTo(" Flintstone" )
@@ -568,7 +568,80 @@ class CanonicalSpringKotlinTest {
568
568
assertThat(addressId).isEqualTo(1 )
569
569
}
570
570
571
- with (records[2 ]!! ) {
571
+ with (records[2 ]) {
572
+ assertThat(id).isEqualTo(3 )
573
+ assertThat(firstName).isEqualTo(" Pebbles" )
574
+ assertThat(lastName).isEqualTo(" Flintstone" )
575
+ assertThat(birthDate).isNotNull()
576
+ assertThat(employed).isEqualTo(" No" )
577
+ assertThat(occupation).isNull()
578
+ assertThat(addressId).isEqualTo(1 )
579
+ }
580
+ }
581
+
582
+ @Test
583
+ fun testRawSelectWithUnionAllAndDistinct () {
584
+ val selectStatement = select(
585
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
586
+ addressId
587
+ ).from(Person ) {
588
+ where(id, isEqualTo(1 ))
589
+ union {
590
+ select(
591
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
592
+ addressId
593
+ ).from(Person ) {
594
+ where(id, isEqualTo(2 ))
595
+ }
596
+ }
597
+ unionAll {
598
+ selectDistinct(
599
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
600
+ addressId
601
+ ).from(Person , " p" ) {
602
+ where(id, isEqualTo(3 ))
603
+ }
604
+ }
605
+ }
606
+
607
+ val expected = " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
608
+ " from Person " +
609
+ " where id = :p1 " +
610
+ " union " +
611
+ " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
612
+ " from Person " +
613
+ " where id = :p2 " +
614
+ " union all " +
615
+ " select distinct p.id as A_ID, p.first_name, p.last_name, p.birth_date, p.employed, p.occupation, p.address_id " +
616
+ " from Person p " +
617
+ " where p.id = :p3"
618
+
619
+ assertThat(selectStatement.selectStatement).isEqualTo(expected)
620
+
621
+ val records = template.selectList(selectStatement) { rs, _ ->
622
+ val record = PersonRecord ()
623
+ record.id = rs.getInt(1 )
624
+ record.firstName = rs.getString(2 )
625
+ record.lastName = rs.getString(3 )
626
+ record.birthDate = rs.getTimestamp(4 )
627
+ record.employed = rs.getString(5 )
628
+ record.occupation = rs.getString(6 )
629
+ record.addressId = rs.getInt(7 )
630
+ record
631
+ }
632
+
633
+ assertThat(records).hasSize(3 )
634
+ with (records[0 ]) {
635
+ assertThat(id).isEqualTo(1 )
636
+ assertThat(firstName).isEqualTo(" Fred" )
637
+ assertThat(lastName).isEqualTo(" Flintstone" )
638
+ assertThat(birthDate).isNotNull()
639
+ assertThat(employed).isEqualTo(" Yes" )
640
+ assertThat(occupation).isEqualTo(" Brontosaurus Operator" )
641
+ assertThat(addressId).isEqualTo(1 )
642
+ }
643
+
644
+ with (records[2 ]) {
572
645
assertThat(id).isEqualTo(3 )
573
646
assertThat(firstName).isEqualTo(" Pebbles" )
574
647
assertThat(lastName).isEqualTo(" Flintstone" )
0 commit comments