|
37 | 37 | import java.util.Collection;
|
38 | 38 | import java.util.LinkedHashSet;
|
39 | 39 | import java.util.List;
|
| 40 | +import lombok.AllArgsConstructor; |
| 41 | +import lombok.Builder; |
| 42 | +import lombok.NoArgsConstructor; |
40 | 43 | import org.bson.BsonDocument;
|
41 | 44 | import org.bson.types.ObjectId;
|
42 | 45 | import org.hibernate.MappingException;
|
@@ -76,35 +79,37 @@ public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
|
76 | 79 |
|
77 | 80 | @Test
|
78 | 81 | void testArrayAndCollectionValues() {
|
79 |
| - var item = new ItemWithArrayAndCollectionValues( |
80 |
| - 1, |
| 82 | + var item = ItemWithArrayAndCollectionValues.builder() |
| 83 | + .id(1) |
81 | 84 | // TODO-HIBERNATE-48 sprinkle on `null` array/collection elements
|
82 |
| - new byte[] {2, 3}, |
83 |
| - new char[] {'s', 't', 'r'}, |
84 |
| - new int[] {5}, |
85 |
| - new long[] {Long.MAX_VALUE, 6}, |
86 |
| - new double[] {Double.MAX_VALUE}, |
87 |
| - new boolean[] {true}, |
88 |
| - new Character[] {'s', 't', 'r'}, |
89 |
| - new Integer[] {7}, |
90 |
| - new Long[] {8L}, |
91 |
| - new Double[] {9.1d}, |
92 |
| - new Boolean[] {true}, |
93 |
| - new String[] {"str"}, |
94 |
| - new BigDecimal[] {BigDecimal.valueOf(10.1)}, |
95 |
| - new ObjectId[] {new ObjectId("000000000000000000000001")}, |
96 |
| - new StructAggregateEmbeddableIntegrationTests.Single[] { |
| 85 | + .bytes(new byte[] {2, 3}) |
| 86 | + .chars(new char[] {'s', 't', 'r'}) |
| 87 | + .ints(new int[] {5}) |
| 88 | + .longs(new long[] {Long.MAX_VALUE, 6}) |
| 89 | + .doubles(new double[] {Double.MAX_VALUE}) |
| 90 | + .booleans(new boolean[] {true}) |
| 91 | + .boxedChars(new Character[] {'s', 't', 'r'}) |
| 92 | + .boxedInts(new Integer[] {7}) |
| 93 | + .boxedLongs(new Long[] {8L}) |
| 94 | + .boxedDoubles(new Double[] {9.1d}) |
| 95 | + .boxedBooleans(new Boolean[] {true}) |
| 96 | + .strings(new String[] {"str"}) |
| 97 | + .bigDecimals(new BigDecimal[] {BigDecimal.valueOf(10.1)}) |
| 98 | + .objectIds(new ObjectId[] {new ObjectId("000000000000000000000001")}) |
| 99 | + .structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[] { |
97 | 100 | new StructAggregateEmbeddableIntegrationTests.Single(1)
|
98 |
| - }, |
99 |
| - List.of('s', 't', 'r'), |
100 |
| - List.of(5), |
101 |
| - List.of(Long.MAX_VALUE, 6L), |
102 |
| - List.of(Double.MAX_VALUE), |
103 |
| - List.of(true), |
104 |
| - List.of("str"), |
105 |
| - List.of(BigDecimal.valueOf(10.1)), |
106 |
| - List.of(new ObjectId("000000000000000000000001")), |
107 |
| - List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))); |
| 101 | + }) |
| 102 | + .charsCollection(List.of('s', 't', 'r')) |
| 103 | + .intsCollection(List.of(5)) |
| 104 | + .longsCollection(List.of(Long.MAX_VALUE, 6L)) |
| 105 | + .doublesCollection(List.of(Double.MAX_VALUE)) |
| 106 | + .booleansCollection(List.of(true)) |
| 107 | + .stringsCollection(List.of("str")) |
| 108 | + .bigDecimalsCollection(List.of(BigDecimal.valueOf(10.1))) |
| 109 | + .objectIdsCollection(List.of(new ObjectId("000000000000000000000001"))) |
| 110 | + .structAggregateEmbeddablesCollection(List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))) |
| 111 | + .build(); |
| 112 | + |
108 | 113 | sessionFactoryScope.inTransaction(session -> session.persist(item));
|
109 | 114 | assertCollectionContainsExactly(
|
110 | 115 | """
|
@@ -185,32 +190,34 @@ void testArrayAndCollectionValues() {
|
185 | 190 |
|
186 | 191 | @Test
|
187 | 192 | void testArrayAndCollectionEmptyValues() {
|
188 |
| - var item = new ItemWithArrayAndCollectionValues( |
189 |
| - 1, |
190 |
| - new byte[0], |
191 |
| - new char[0], |
192 |
| - new int[0], |
193 |
| - new long[0], |
194 |
| - new double[0], |
195 |
| - new boolean[0], |
196 |
| - new Character[0], |
197 |
| - new Integer[0], |
198 |
| - new Long[0], |
199 |
| - new Double[0], |
200 |
| - new Boolean[0], |
201 |
| - new String[0], |
202 |
| - new BigDecimal[0], |
203 |
| - new ObjectId[0], |
204 |
| - new StructAggregateEmbeddableIntegrationTests.Single[0], |
205 |
| - List.of(), |
206 |
| - List.of(), |
207 |
| - List.of(), |
208 |
| - List.of(), |
209 |
| - List.of(), |
210 |
| - List.of(), |
211 |
| - List.of(), |
212 |
| - List.of(), |
213 |
| - List.of()); |
| 193 | + var item = ItemWithArrayAndCollectionValues.builder() |
| 194 | + .id(1) |
| 195 | + .bytes(new byte[0]) |
| 196 | + .chars(new char[0]) |
| 197 | + .ints(new int[0]) |
| 198 | + .longs(new long[0]) |
| 199 | + .doubles(new double[0]) |
| 200 | + .booleans(new boolean[0]) |
| 201 | + .boxedChars(new Character[0]) |
| 202 | + .boxedInts(new Integer[0]) |
| 203 | + .boxedLongs(new Long[0]) |
| 204 | + .boxedDoubles(new Double[0]) |
| 205 | + .boxedBooleans(new Boolean[0]) |
| 206 | + .strings(new String[0]) |
| 207 | + .bigDecimals(new BigDecimal[0]) |
| 208 | + .objectIds(new ObjectId[0]) |
| 209 | + .structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[0]) |
| 210 | + .charsCollection(List.of()) |
| 211 | + .intsCollection(List.of()) |
| 212 | + .longsCollection(List.of()) |
| 213 | + .doublesCollection(List.of()) |
| 214 | + .booleansCollection(List.of()) |
| 215 | + .stringsCollection(List.of()) |
| 216 | + .bigDecimalsCollection(List.of()) |
| 217 | + .objectIdsCollection(List.of()) |
| 218 | + .structAggregateEmbeddablesCollection(List.of()) |
| 219 | + .build(); |
| 220 | + |
214 | 221 | sessionFactoryScope.inTransaction(session -> session.persist(item));
|
215 | 222 | assertCollectionContainsExactly(
|
216 | 223 | """
|
@@ -291,34 +298,36 @@ void testArrayAndCollectionNullValues() {
|
291 | 298 |
|
292 | 299 | @Test
|
293 | 300 | void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections() {
|
294 |
| - var arraysAndCollections = new ArraysAndCollections( |
295 |
| - new byte[] {2, 3}, |
296 |
| - new char[] {'s', 't', 'r'}, |
297 |
| - new int[] {5}, |
298 |
| - new long[] {Long.MAX_VALUE, 6}, |
299 |
| - new double[] {Double.MAX_VALUE}, |
300 |
| - new boolean[] {true}, |
301 |
| - new Character[] {'s', 't', 'r'}, |
302 |
| - new Integer[] {7}, |
303 |
| - new Long[] {8L}, |
304 |
| - new Double[] {9.1d}, |
305 |
| - new Boolean[] {true}, |
306 |
| - new String[] {"str"}, |
307 |
| - new BigDecimal[] {BigDecimal.valueOf(10.1)}, |
308 |
| - new ObjectId[] {new ObjectId("000000000000000000000001")}, |
309 |
| - new StructAggregateEmbeddableIntegrationTests.Single[] { |
| 301 | + var arraysAndCollections = ArraysAndCollections.builder() |
| 302 | + .bytes(new byte[] {2, 3}) |
| 303 | + .chars(new char[] {'s', 't', 'r'}) |
| 304 | + .ints(new int[] {5}) |
| 305 | + .longs(new long[] {Long.MAX_VALUE, 6}) |
| 306 | + .doubles(new double[] {Double.MAX_VALUE}) |
| 307 | + .booleans(new boolean[] {true}) |
| 308 | + .boxedChars(new Character[] {'s', 't', 'r'}) |
| 309 | + .boxedInts(new Integer[] {7}) |
| 310 | + .boxedLongs(new Long[] {8L}) |
| 311 | + .boxedDoubles(new Double[] {9.1d}) |
| 312 | + .boxedBooleans(new Boolean[] {true}) |
| 313 | + .strings(new String[] {"str"}) |
| 314 | + .bigDecimals(new BigDecimal[] {BigDecimal.valueOf(10.1)}) |
| 315 | + .objectIds(new ObjectId[] {new ObjectId("000000000000000000000001")}) |
| 316 | + .structAggregateEmbeddables(new StructAggregateEmbeddableIntegrationTests.Single[] { |
310 | 317 | new StructAggregateEmbeddableIntegrationTests.Single(1)
|
311 |
| - }, |
312 |
| - List.of('s', 't', 'r'), |
| 318 | + }) |
| 319 | + .charsCollection(List.of('s', 't', 'r')) |
313 | 320 | // Hibernate ORM uses `LinkedHashSet`, forcing us to also use it, but messing up the order anyway
|
314 |
| - new LinkedHashSet<>(List.of(5)), |
315 |
| - List.of(Long.MAX_VALUE, 6L), |
316 |
| - List.of(Double.MAX_VALUE), |
317 |
| - List.of(true), |
318 |
| - List.of("str"), |
319 |
| - List.of(BigDecimal.valueOf(10.1)), |
320 |
| - List.of(new ObjectId("000000000000000000000001")), |
321 |
| - List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))); |
| 321 | + .intsCollection(new LinkedHashSet<>(List.of(5))) |
| 322 | + .longsCollection(List.of(Long.MAX_VALUE, 6L)) |
| 323 | + .doublesCollection(List.of(Double.MAX_VALUE)) |
| 324 | + .booleansCollection(List.of(true)) |
| 325 | + .stringsCollection(List.of("str")) |
| 326 | + .bigDecimalsCollection(List.of(BigDecimal.valueOf(10.1))) |
| 327 | + .objectIdsCollection(List.of(new ObjectId("000000000000000000000001"))) |
| 328 | + .structAggregateEmbeddablesCollection(List.of(new StructAggregateEmbeddableIntegrationTests.Single(1))) |
| 329 | + .build(); |
| 330 | + |
322 | 331 | var item = new ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections(
|
323 | 332 | 1, new ArraysAndCollections[] {arraysAndCollections}, List.of());
|
324 | 333 | sessionFactoryScope.inTransaction(session -> session.persist(item));
|
@@ -489,6 +498,9 @@ private static void assertCollectionContainsExactly(String documentAsJsonObject)
|
489 | 498 |
|
490 | 499 | @Entity
|
491 | 500 | @Table(name = "items")
|
| 501 | + @NoArgsConstructor |
| 502 | + @AllArgsConstructor |
| 503 | + @Builder |
492 | 504 | static class ItemWithArrayAndCollectionValues {
|
493 | 505 | @Id
|
494 | 506 | int id;
|
@@ -517,82 +529,18 @@ static class ItemWithArrayAndCollectionValues {
|
517 | 529 | Collection<BigDecimal> bigDecimalsCollection;
|
518 | 530 | Collection<ObjectId> objectIdsCollection;
|
519 | 531 | Collection<StructAggregateEmbeddableIntegrationTests.Single> structAggregateEmbeddablesCollection;
|
520 |
| - |
521 |
| - ItemWithArrayAndCollectionValues() {} |
522 |
| - |
523 |
| - ItemWithArrayAndCollectionValues( |
524 |
| - int id, |
525 |
| - byte[] bytes, |
526 |
| - char[] chars, |
527 |
| - int[] ints, |
528 |
| - long[] longs, |
529 |
| - double[] doubles, |
530 |
| - boolean[] booleans, |
531 |
| - Character[] boxedChars, |
532 |
| - Integer[] boxedInts, |
533 |
| - Long[] boxedLongs, |
534 |
| - Double[] boxedDoubles, |
535 |
| - Boolean[] boxedBooleans, |
536 |
| - String[] strings, |
537 |
| - BigDecimal[] bigDecimals, |
538 |
| - ObjectId[] objectIds, |
539 |
| - StructAggregateEmbeddableIntegrationTests.Single[] structAggregateEmbeddables, |
540 |
| - Collection<Character> charsCollection, |
541 |
| - Collection<Integer> intsCollection, |
542 |
| - Collection<Long> longsCollection, |
543 |
| - Collection<Double> doublesCollection, |
544 |
| - Collection<Boolean> booleansCollection, |
545 |
| - Collection<String> stringsCollection, |
546 |
| - Collection<BigDecimal> bigDecimalsCollection, |
547 |
| - Collection<ObjectId> objectIdsCollection, |
548 |
| - Collection<StructAggregateEmbeddableIntegrationTests.Single> structAggregateEmbeddablesCollection) { |
549 |
| - this.id = id; |
550 |
| - this.bytes = bytes; |
551 |
| - this.chars = chars; |
552 |
| - this.ints = ints; |
553 |
| - this.longs = longs; |
554 |
| - this.doubles = doubles; |
555 |
| - this.booleans = booleans; |
556 |
| - this.boxedChars = boxedChars; |
557 |
| - this.boxedInts = boxedInts; |
558 |
| - this.boxedLongs = boxedLongs; |
559 |
| - this.boxedDoubles = boxedDoubles; |
560 |
| - this.boxedBooleans = boxedBooleans; |
561 |
| - this.strings = strings; |
562 |
| - this.bigDecimals = bigDecimals; |
563 |
| - this.objectIds = objectIds; |
564 |
| - this.structAggregateEmbeddables = structAggregateEmbeddables; |
565 |
| - this.charsCollection = charsCollection; |
566 |
| - this.intsCollection = intsCollection; |
567 |
| - this.longsCollection = longsCollection; |
568 |
| - this.doublesCollection = doublesCollection; |
569 |
| - this.booleansCollection = booleansCollection; |
570 |
| - this.stringsCollection = stringsCollection; |
571 |
| - this.bigDecimalsCollection = bigDecimalsCollection; |
572 |
| - this.objectIdsCollection = objectIdsCollection; |
573 |
| - this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection; |
574 |
| - } |
575 | 532 | }
|
576 | 533 |
|
577 | 534 | @Entity
|
578 | 535 | @Table(name = "items")
|
| 536 | + @NoArgsConstructor |
| 537 | + @AllArgsConstructor |
579 | 538 | static class ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections {
|
580 | 539 | @Id
|
581 | 540 | int id;
|
582 | 541 |
|
583 | 542 | ArraysAndCollections[] structAggregateEmbeddables;
|
584 | 543 | Collection<ArraysAndCollections> structAggregateEmbeddablesCollection;
|
585 |
| - |
586 |
| - ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections() {} |
587 |
| - |
588 |
| - ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections( |
589 |
| - int id, |
590 |
| - ArraysAndCollections[] structAggregateEmbeddables, |
591 |
| - Collection<ArraysAndCollections> structAggregateEmbeddablesCollection) { |
592 |
| - this.id = id; |
593 |
| - this.structAggregateEmbeddables = structAggregateEmbeddables; |
594 |
| - this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection; |
595 |
| - } |
596 | 544 | }
|
597 | 545 |
|
598 | 546 | @Nested
|
@@ -670,36 +618,25 @@ void testCollectionOfEmbeddablesElementCollectionValue() {
|
670 | 618 |
|
671 | 619 | @Entity
|
672 | 620 | @Table(name = "items")
|
| 621 | + @NoArgsConstructor |
| 622 | + @AllArgsConstructor |
673 | 623 | static class ItemWithBoxedBytesArrayValue {
|
674 | 624 | @Id
|
675 | 625 | int id;
|
676 | 626 |
|
677 | 627 | byte[] bytes;
|
678 | 628 | Byte[] boxedBytes;
|
679 |
| - |
680 |
| - ItemWithBoxedBytesArrayValue() {} |
681 |
| - |
682 |
| - ItemWithBoxedBytesArrayValue(int id, byte[] bytes, Byte[] boxedBytes) { |
683 |
| - this.id = id; |
684 |
| - this.bytes = bytes; |
685 |
| - this.boxedBytes = boxedBytes; |
686 |
| - } |
687 | 629 | }
|
688 | 630 |
|
689 | 631 | @Entity
|
690 | 632 | @Table(name = "items")
|
| 633 | + @NoArgsConstructor |
| 634 | + @AllArgsConstructor |
691 | 635 | static class ItemWithBytesCollectionValue {
|
692 | 636 | @Id
|
693 | 637 | int id;
|
694 | 638 |
|
695 | 639 | Collection<Byte> bytes;
|
696 |
| - |
697 |
| - ItemWithBytesCollectionValue() {} |
698 |
| - |
699 |
| - ItemWithBytesCollectionValue(int id, Collection<Byte> bytes) { |
700 |
| - this.id = id; |
701 |
| - this.bytes = bytes; |
702 |
| - } |
703 | 640 | }
|
704 | 641 |
|
705 | 642 | /**
|
|
0 commit comments