Skip to content

Commit d7b51e5

Browse files
committed
Add Instant support.
HIBERNATE-42
1 parent 2411aa6 commit d7b51e5

14 files changed

+1174
-68
lines changed

src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import jakarta.persistence.Table;
3636
import java.math.BigDecimal;
3737
import java.sql.SQLFeatureNotSupportedException;
38+
import java.time.Instant;
3839
import java.util.Collection;
3940
import java.util.LinkedHashSet;
4041
import java.util.List;
@@ -94,6 +95,7 @@ void testArrayAndCollectionValues() {
9495
new String[] {null, "str"},
9596
new BigDecimal[] {null, BigDecimal.valueOf(10.1)},
9697
new ObjectId[] {new ObjectId("000000000000000000000001"), null},
98+
new Instant[] {Instant.parse("2007-12-03T10:15:30Z")},
9799
new StructAggregateEmbeddableIntegrationTests.Single[] {
98100
new StructAggregateEmbeddableIntegrationTests.Single(1), null
99101
},
@@ -105,7 +107,8 @@ void testArrayAndCollectionValues() {
105107
asList("str", null),
106108
asList(BigDecimal.valueOf(10.1), null),
107109
asList(null, new ObjectId("000000000000000000000001")),
108-
asList(new StructAggregateEmbeddableIntegrationTests.Single(1), null));
110+
asList(new StructAggregateEmbeddableIntegrationTests.Single(1), null),
111+
List.of(Instant.parse("2007-12-03T10:15:30Z")));
109112
sessionFactoryScope.inTransaction(session -> session.persist(item));
110113
assertCollectionContainsExactly(
111114
"""
@@ -134,7 +137,9 @@ void testArrayAndCollectionValues() {
134137
stringsCollection: ["str", null],
135138
bigDecimalsCollection: [{$numberDecimal: "10.1"}, null],
136139
objectIdsCollection: [null, {$oid: "000000000000000000000001"}],
137-
structAggregateEmbeddablesCollection: [{a: 1}, null]
140+
structAggregateEmbeddablesCollection: [{a: 1}, null],
141+
instants: [{"$date": "2007-12-03T10:15:30Z"}],
142+
instantsCollection: [{"$date": "2007-12-03T10:15:30Z"}]
138143
}
139144
""");
140145
var loadedItem = sessionFactoryScope.fromTransaction(
@@ -176,7 +181,9 @@ void testArrayAndCollectionValues() {
176181
stringsCollection: ["str", null],
177182
bigDecimalsCollection: [{$numberDecimal: "10.1"}, null],
178183
objectIdsCollection: [null, {$oid: "000000000000000000000001"}],
179-
structAggregateEmbeddablesCollection: [{a: 1}, null]
184+
structAggregateEmbeddablesCollection: [{a: 1}, null],
185+
instants: [{"$date": "2007-12-03T10:15:30Z"}],
186+
instantsCollection: [{"$date": "2007-12-03T10:15:30Z"}]
180187
}
181188
""");
182189
loadedItem = sessionFactoryScope.fromTransaction(
@@ -202,6 +209,7 @@ void testArrayAndCollectionEmptyValues() {
202209
new String[0],
203210
new BigDecimal[0],
204211
new ObjectId[0],
212+
new Instant[0],
205213
new StructAggregateEmbeddableIntegrationTests.Single[0],
206214
List.of(),
207215
List.of(),
@@ -211,6 +219,7 @@ void testArrayAndCollectionEmptyValues() {
211219
List.of(),
212220
List.of(),
213221
List.of(),
222+
List.of(),
214223
List.of());
215224
sessionFactoryScope.inTransaction(session -> session.persist(item));
216225
assertCollectionContainsExactly(
@@ -240,7 +249,9 @@ void testArrayAndCollectionEmptyValues() {
240249
stringsCollection: [],
241250
bigDecimalsCollection: [],
242251
objectIdsCollection: [],
243-
structAggregateEmbeddablesCollection: []
252+
structAggregateEmbeddablesCollection: [],
253+
instants: [],
254+
instantsCollection: []
244255
}
245256
""");
246257
var loadedItem = sessionFactoryScope.fromTransaction(
@@ -252,7 +263,7 @@ void testArrayAndCollectionEmptyValues() {
252263
void testArrayAndCollectionNullValues() {
253264
var item = new ItemWithArrayAndCollectionValues(
254265
1, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
255-
null, null, null, null, null, null, null);
266+
null, null, null, null, null, null, null, null, null);
256267
sessionFactoryScope.inTransaction(session -> session.persist(item));
257268
assertCollectionContainsExactly(
258269
"""
@@ -281,7 +292,9 @@ void testArrayAndCollectionNullValues() {
281292
stringsCollection: null,
282293
bigDecimalsCollection: null,
283294
objectIdsCollection: null,
284-
structAggregateEmbeddablesCollection: null
295+
structAggregateEmbeddablesCollection: null,
296+
instants: null,
297+
instantsCollection: null
285298
}
286299
""");
287300
var loadedItem = sessionFactoryScope.fromTransaction(
@@ -306,6 +319,7 @@ void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndColl
306319
new String[] {"str"},
307320
new BigDecimal[] {BigDecimal.valueOf(10.1)},
308321
new ObjectId[] {new ObjectId("000000000000000000000001")},
322+
new Instant[] {Instant.parse("2007-12-03T10:15:30Z")},
309323
new StructAggregateEmbeddableIntegrationTests.Single[] {
310324
new StructAggregateEmbeddableIntegrationTests.Single(1)
311325
},
@@ -318,7 +332,8 @@ void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndColl
318332
List.of("str"),
319333
List.of(BigDecimal.valueOf(10.1)),
320334
List.of(new ObjectId("000000000000000000000001")),
321-
List.of(new StructAggregateEmbeddableIntegrationTests.Single(1)));
335+
List.of(new StructAggregateEmbeddableIntegrationTests.Single(1)),
336+
List.of(Instant.parse("2007-12-03T10:15:30Z")));
322337
var item = new ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections(
323338
1, new ArraysAndCollections[] {arraysAndCollections}, List.of());
324339
sessionFactoryScope.inTransaction(session -> session.persist(item));
@@ -350,7 +365,9 @@ void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndColl
350365
stringsCollection: ["str"],
351366
bigDecimalsCollection: [{$numberDecimal: "10.1"}],
352367
objectIdsCollection: [{$oid: "000000000000000000000001"}],
353-
structAggregateEmbeddablesCollection: [{a: 1}]
368+
structAggregateEmbeddablesCollection: [{a: 1}],
369+
instants: [{"$date": "2007-12-03T10:15:30Z"}],
370+
instantsCollection: [{"$date": "2007-12-03T10:15:30Z"}]
354371
}],
355372
structAggregateEmbeddablesCollection: []
356373
}
@@ -395,7 +412,9 @@ void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndColl
395412
stringsCollection: ["str"],
396413
bigDecimalsCollection: [{$numberDecimal: "10.1"}],
397414
objectIdsCollection: [{$oid: "000000000000000000000001"}],
398-
structAggregateEmbeddablesCollection: [{a: 1}]
415+
structAggregateEmbeddablesCollection: [{a: 1}],
416+
instants: [{"$date": "2007-12-03T10:15:30Z"}],
417+
instantsCollection: [{"$date": "2007-12-03T10:15:30Z"}]
399418
}]
400419
}
401420
""");
@@ -413,7 +432,7 @@ void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndColl
413432
public void testArrayAndCollectionValuesOfEmptyStructAggregateEmbeddables() {
414433
var emptyStructAggregateEmbeddable = new ArraysAndCollections(
415434
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
416-
null, null, null, null, null, null, null);
435+
null, null, null, null, null, null, null, null, null);
417436
var item = new ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndCollections(
418437
1,
419438
new ArraysAndCollections[] {emptyStructAggregateEmbeddable},
@@ -447,7 +466,9 @@ public void testArrayAndCollectionValuesOfEmptyStructAggregateEmbeddables() {
447466
stringsCollection: null,
448467
bigDecimalsCollection: null,
449468
objectIdsCollection: null,
450-
structAggregateEmbeddablesCollection: null
469+
structAggregateEmbeddablesCollection: null,
470+
instants: null,
471+
instantsCollection: null,
451472
}],
452473
structAggregateEmbeddablesCollection: [{
453474
bytes: null,
@@ -473,7 +494,9 @@ public void testArrayAndCollectionValuesOfEmptyStructAggregateEmbeddables() {
473494
stringsCollection: null,
474495
bigDecimalsCollection: null,
475496
objectIdsCollection: null,
476-
structAggregateEmbeddablesCollection: null
497+
structAggregateEmbeddablesCollection: null,
498+
instants: null,
499+
instantsCollection: null,
477500
}]
478501
}
479502
""");
@@ -506,6 +529,7 @@ static class ItemWithArrayAndCollectionValues {
506529
String[] strings;
507530
BigDecimal[] bigDecimals;
508531
ObjectId[] objectIds;
532+
Instant[] instants;
509533
StructAggregateEmbeddableIntegrationTests.Single[] structAggregateEmbeddables;
510534
Collection<Character> charsCollection;
511535
Collection<Integer> intsCollection;
@@ -516,6 +540,7 @@ static class ItemWithArrayAndCollectionValues {
516540
Collection<BigDecimal> bigDecimalsCollection;
517541
Collection<ObjectId> objectIdsCollection;
518542
Collection<StructAggregateEmbeddableIntegrationTests.Single> structAggregateEmbeddablesCollection;
543+
Collection<Instant> instantsCollection;
519544

520545
ItemWithArrayAndCollectionValues() {}
521546

@@ -535,6 +560,7 @@ static class ItemWithArrayAndCollectionValues {
535560
String[] strings,
536561
BigDecimal[] bigDecimals,
537562
ObjectId[] objectIds,
563+
Instant[] instants,
538564
StructAggregateEmbeddableIntegrationTests.Single[] structAggregateEmbeddables,
539565
Collection<Character> charsCollection,
540566
Collection<Integer> intsCollection,
@@ -544,7 +570,8 @@ static class ItemWithArrayAndCollectionValues {
544570
Collection<String> stringsCollection,
545571
Collection<BigDecimal> bigDecimalsCollection,
546572
Collection<ObjectId> objectIdsCollection,
547-
Collection<StructAggregateEmbeddableIntegrationTests.Single> structAggregateEmbeddablesCollection) {
573+
Collection<StructAggregateEmbeddableIntegrationTests.Single> structAggregateEmbeddablesCollection,
574+
List<Instant> instantsCollection) {
548575
this.id = id;
549576
this.bytes = bytes;
550577
this.chars = chars;
@@ -570,6 +597,8 @@ static class ItemWithArrayAndCollectionValues {
570597
this.bigDecimalsCollection = bigDecimalsCollection;
571598
this.objectIdsCollection = objectIdsCollection;
572599
this.structAggregateEmbeddablesCollection = structAggregateEmbeddablesCollection;
600+
this.instants = instants;
601+
this.instantsCollection = instantsCollection;
573602
}
574603
}
575604

0 commit comments

Comments
 (0)