15
15
*/
16
16
package org .springframework .data .jdbc .core ;
17
17
18
+ import static java .util .Arrays .*;
18
19
import static java .util .Collections .*;
19
20
import static org .assertj .core .api .Assertions .*;
20
21
import static org .assertj .core .api .SoftAssertions .*;
21
22
import static org .springframework .data .jdbc .testing .TestDatabaseFeatures .Feature .*;
22
23
import static org .springframework .test .context .TestExecutionListeners .MergeMode .*;
23
24
25
+ import lombok .Data ;
26
+ import lombok .EqualsAndHashCode ;
27
+ import lombok .Value ;
28
+ import lombok .With ;
29
+
24
30
import java .time .LocalDateTime ;
25
31
import java .util .ArrayList ;
26
- import java .util .Arrays ;
27
32
import java .util .Collections ;
28
33
import java .util .HashMap ;
29
34
import java .util .HashSet ;
44
49
import org .springframework .dao .IncorrectUpdateSemanticsDataAccessException ;
45
50
import org .springframework .dao .OptimisticLockingFailureException ;
46
51
import org .springframework .data .annotation .Id ;
52
+ import org .springframework .data .annotation .PersistenceConstructor ;
47
53
import org .springframework .data .annotation .ReadOnlyProperty ;
48
54
import org .springframework .data .annotation .Version ;
49
55
import org .springframework .data .domain .PageRequest ;
56
62
import org .springframework .data .jdbc .testing .TestDatabaseFeatures ;
57
63
import org .springframework .data .relational .core .conversion .DbActionExecutionException ;
58
64
import org .springframework .data .relational .core .mapping .Column ;
65
+ import org .springframework .data .relational .core .mapping .MappedCollection ;
59
66
import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
60
67
import org .springframework .data .relational .core .mapping .Table ;
61
68
import org .springframework .jdbc .core .namedparam .NamedParameterJdbcOperations ;
64
71
import org .springframework .test .context .junit .jupiter .SpringExtension ;
65
72
import org .springframework .transaction .annotation .Transactional ;
66
73
67
- import lombok .Data ;
68
- import lombok .EqualsAndHashCode ;
69
- import lombok .Value ;
70
- import lombok .With ;
71
-
72
74
/**
73
75
* Integration tests for {@link JdbcAggregateTemplate}.
74
76
*
@@ -502,6 +504,21 @@ public void saveAndLoadAnEntityWithListOfElementsWithoutId() {
502
504
assertThat (reloaded .content ).extracting (e -> e .content ).containsExactly ("content" );
503
505
}
504
506
507
+ @ Test // GH-498 DATAJDBC-273
508
+ @ EnabledOnFeature (SUPPORTS_QUOTED_IDS )
509
+ public void saveAndLoadAnEntityWithListOfElementsInConstructor () {
510
+
511
+ ElementNoId element = new ElementNoId ();
512
+ element .content = "content" ;
513
+ ListParentAllArgs entity = new ListParentAllArgs ("name" , asList (element ));
514
+
515
+ entity = template .save (entity );
516
+
517
+ ListParentAllArgs reloaded = template .findById (entity .id , ListParentAllArgs .class );
518
+
519
+ assertThat (reloaded .content ).extracting (e -> e .content ).containsExactly ("content" );
520
+ }
521
+
505
522
@ Test // DATAJDBC-259
506
523
@ EnabledOnFeature (SUPPORTS_ARRAYS )
507
524
public void saveAndLoadAnEntityWithArray () {
@@ -544,7 +561,7 @@ public void saveAndLoadAnEntityWithMultidimensionalArray() {
544
561
public void saveAndLoadAnEntityWithList () {
545
562
546
563
ListOwner arrayOwner = new ListOwner ();
547
- arrayOwner .digits .addAll (Arrays . asList ("one" , "two" , "three" ));
564
+ arrayOwner .digits .addAll (asList ("one" , "two" , "three" ));
548
565
549
566
ListOwner saved = template .save (arrayOwner );
550
567
@@ -554,15 +571,15 @@ public void saveAndLoadAnEntityWithList() {
554
571
555
572
assertThat (reloaded ).isNotNull ();
556
573
assertThat (reloaded .id ).isEqualTo (saved .id );
557
- assertThat (reloaded .digits ).isEqualTo (Arrays . asList ("one" , "two" , "three" ));
574
+ assertThat (reloaded .digits ).isEqualTo (asList ("one" , "two" , "three" ));
558
575
}
559
576
560
577
@ Test // GH-1033
561
578
@ EnabledOnFeature (SUPPORTS_ARRAYS )
562
579
public void saveAndLoadAnEntityWithListOfDouble () {
563
580
564
581
DoubleListOwner doubleListOwner = new DoubleListOwner ();
565
- doubleListOwner .digits .addAll (Arrays . asList (1.2 , 1.3 , 1.4 ));
582
+ doubleListOwner .digits .addAll (asList (1.2 , 1.3 , 1.4 ));
566
583
567
584
DoubleListOwner saved = template .save (doubleListOwner );
568
585
@@ -572,15 +589,15 @@ public void saveAndLoadAnEntityWithListOfDouble() {
572
589
573
590
assertThat (reloaded ).isNotNull ();
574
591
assertThat (reloaded .id ).isEqualTo (saved .id );
575
- assertThat (reloaded .digits ).isEqualTo (Arrays . asList (1.2 , 1.3 , 1.4 ));
592
+ assertThat (reloaded .digits ).isEqualTo (asList (1.2 , 1.3 , 1.4 ));
576
593
}
577
594
578
595
@ Test // GH-1033, GH-1046
579
596
@ EnabledOnFeature (SUPPORTS_ARRAYS )
580
597
public void saveAndLoadAnEntityWithListOfFloat () {
581
598
582
599
FloatListOwner floatListOwner = new FloatListOwner ();
583
- final List <Float > values = Arrays . asList (1.2f , 1.3f , 1.4f );
600
+ final List <Float > values = asList (1.2f , 1.3f , 1.4f );
584
601
floatListOwner .digits .addAll (values );
585
602
586
603
FloatListOwner saved = template .save (floatListOwner );
@@ -599,7 +616,7 @@ public void saveAndLoadAnEntityWithListOfFloat() {
599
616
public void saveAndLoadAnEntityWithSet () {
600
617
601
618
SetOwner setOwner = new SetOwner ();
602
- setOwner .digits .addAll (Arrays . asList ("one" , "two" , "three" ));
619
+ setOwner .digits .addAll (asList ("one" , "two" , "three" ));
603
620
604
621
SetOwner saved = template .save (setOwner );
605
622
@@ -609,7 +626,7 @@ public void saveAndLoadAnEntityWithSet() {
609
626
610
627
assertThat (reloaded ).isNotNull ();
611
628
assertThat (reloaded .id ).isEqualTo (saved .id );
612
- assertThat (reloaded .digits ).isEqualTo (new HashSet <>(Arrays . asList ("one" , "two" , "three" )));
629
+ assertThat (reloaded .digits ).isEqualTo (new HashSet <>(asList ("one" , "two" , "three" )));
613
630
}
614
631
615
632
@ Test // DATAJDBC-327
@@ -1011,13 +1028,37 @@ static class ChildNoId {
1011
1028
private String content ;
1012
1029
}
1013
1030
1031
+ @ Table ("LIST_PARENT" )
1014
1032
static class ListParent {
1015
1033
1016
1034
@ Column ("id4" ) @ Id private Long id ;
1017
1035
String name ;
1036
+ @ MappedCollection (idColumn = "LIST_PARENT" )
1018
1037
List <ElementNoId > content = new ArrayList <>();
1019
1038
}
1020
1039
1040
+ @ Table ("LIST_PARENT" )
1041
+ static class ListParentAllArgs {
1042
+
1043
+ @ Column ("id4" ) @ Id
1044
+ private final Long id ;
1045
+ private final String name ;
1046
+ @ MappedCollection (idColumn = "LIST_PARENT" )
1047
+ private final List <ElementNoId > content = new ArrayList <>();
1048
+
1049
+ @ PersistenceConstructor
1050
+ ListParentAllArgs (Long id , String name , List <ElementNoId > content ) {
1051
+
1052
+ this .id = id ;
1053
+ this .name = name ;
1054
+ this .content .addAll (content );
1055
+ }
1056
+
1057
+ ListParentAllArgs (String name , List <ElementNoId > content ) {
1058
+ this (null , name , content );
1059
+ }
1060
+ }
1061
+
1021
1062
static class ElementNoId {
1022
1063
private String content ;
1023
1064
}
0 commit comments