Skip to content

Commit 910513c

Browse files
committed
Undo "Hack-in null support to how the tests behave"
HIBERNATE-58
1 parent c4986fa commit 910513c

File tree

7 files changed

+37
-21
lines changed

7 files changed

+37
-21
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.hibernate.testing.orm.junit.SessionFactoryScope;
4848
import org.hibernate.testing.orm.junit.SessionFactoryScopeAware;
4949
import org.hibernate.testing.orm.junit.Setting;
50+
import org.junit.jupiter.api.Disabled;
5051
import org.junit.jupiter.api.Nested;
5152
import org.junit.jupiter.api.Test;
5253
import org.junit.jupiter.api.extension.ExtendWith;
@@ -242,7 +243,7 @@ void testArrayAndCollectionEmptyValues() {
242243
}
243244

244245
@Test
245-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
246+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
246247
void testArrayAndCollectionNullValues() {
247248
var item = new ItemWithArrayAndCollectionValues(
248249
1, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
@@ -406,7 +407,7 @@ void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndColl
406407
* @see StructAggregateEmbeddableIntegrationTests#testNestedValueHavingNullArraysAndCollections()
407408
*/
408409
@Test
409-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
410+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
410411
public void testArrayAndCollectionValuesOfEmptyStructAggregateEmbeddables() {
411412
var emptyStructAggregateEmbeddable = new ArraysAndCollections(
412413
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.hibernate.testing.orm.junit.SessionFactory;
3333
import org.hibernate.testing.orm.junit.SessionFactoryScope;
3434
import org.hibernate.testing.orm.junit.SessionFactoryScopeAware;
35+
import org.junit.jupiter.api.Disabled;
3536
import org.junit.jupiter.api.Nested;
3637
import org.junit.jupiter.api.Test;
3738
import org.junit.jupiter.api.extension.ExtendWith;
@@ -96,7 +97,7 @@ void testSimpleEntityInsertion() {
9697
}
9798

9899
@Test
99-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
100+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
100101
void testEntityWithNullFieldValuesInsertion() {
101102
sessionFactoryScope.inTransaction(session -> session.persist(new Item(
102103
1,
@@ -217,7 +218,7 @@ void testSimpleUpdate() {
217218
}
218219

219220
@Test
220-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
221+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
221222
void testSimpleUpdateWithNullFieldValues() {
222223
sessionFactoryScope.inTransaction(session -> {
223224
var item = new Item(
@@ -289,7 +290,7 @@ void testDynamicUpdate() {
289290
}
290291

291292
@Test
292-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
293+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
293294
void testDynamicUpdateWithNullFieldValues() {
294295
sessionFactoryScope.inTransaction(session -> {
295296
var item = new ItemDynamicallyUpdated(1, false, true);
@@ -336,7 +337,7 @@ void testFindByPrimaryKey() {
336337
}
337338

338339
@Test
339-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
340+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
340341
void testFindByPrimaryKeyWithNullFieldValues() {
341342
var item = new Item(
342343
1, 'c', 1, Long.MAX_VALUE, Double.MAX_VALUE, true, null, null, null, null, null, null, null, null);

src/integrationTest/java/com/mongodb/hibernate/embeddable/EmbeddableIntegrationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.hibernate.testing.orm.junit.SessionFactory;
4949
import org.hibernate.testing.orm.junit.SessionFactoryScope;
5050
import org.hibernate.testing.orm.junit.SessionFactoryScopeAware;
51+
import org.junit.jupiter.api.Disabled;
5152
import org.junit.jupiter.api.Nested;
5253
import org.junit.jupiter.api.Test;
5354
import org.junit.jupiter.api.extension.ExtendWith;
@@ -145,7 +146,7 @@ void testFlattenedValues() {
145146
}
146147

147148
@Test
148-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
149+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
149150
void testFlattenedNullValueOrHavingNulls() {
150151
var item = new ItemWithFlattenedValues(
151152
new Single(1),
@@ -406,7 +407,7 @@ void testFlattenedValueHavingEmptyArraysAndCollections() {
406407
* @see ArrayAndCollectionIntegrationTests#testArrayAndCollectionValuesOfEmptyStructAggregateEmbeddables()
407408
*/
408409
@Test
409-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
410+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
410411
public void testFlattenedValueHavingNullArraysAndCollections() {
411412
var emptyEmbeddable = new ArraysAndCollections(
412413
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,

src/integrationTest/java/com/mongodb/hibernate/embeddable/StructAggregateEmbeddableIntegrationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.hibernate.testing.orm.junit.SessionFactory;
4848
import org.hibernate.testing.orm.junit.SessionFactoryScope;
4949
import org.hibernate.testing.orm.junit.SessionFactoryScopeAware;
50+
import org.junit.jupiter.api.Disabled;
5051
import org.junit.jupiter.api.Nested;
5152
import org.junit.jupiter.api.Test;
5253
import org.junit.jupiter.api.extension.ExtendWith;
@@ -159,7 +160,7 @@ void testNestedValues() {
159160
}
160161

161162
@Test
162-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
163+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
163164
void testNestedNullValueOrHavingNulls() {
164165
var item = new ItemWithNestedValues(
165166
new EmbeddableIntegrationTests.Single(1),
@@ -418,7 +419,7 @@ void testNestedValueHavingEmptyArraysAndCollections() {
418419
* @see ArrayAndCollectionIntegrationTests#testArrayAndCollectionValuesOfEmptyStructAggregateEmbeddables()
419420
*/
420421
@Test
421-
// @Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
422+
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
422423
public void testNestedValueHavingNullArraysAndCollections() {
423424
var emptyStructAggregateEmbeddable = new ArraysAndCollections(
424425
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,

src/main/java/com/mongodb/hibernate/internal/type/MongoStructJdbcType.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static com.mongodb.hibernate.internal.type.ValueConversions.isNull;
2424
import static com.mongodb.hibernate.internal.type.ValueConversions.toBsonValue;
2525
import static com.mongodb.hibernate.internal.type.ValueConversions.toDomainValue;
26-
import static com.mongodb.hibernate.internal.type.ValueConversions.toNullDomainValue;
2726

2827
import com.mongodb.hibernate.internal.FeatureNotSupportedException;
2928
import com.mongodb.hibernate.jdbc.MongoArray;
@@ -105,13 +104,14 @@ public EmbeddableMappingType getEmbeddableMappingType() {
105104
* {@link #createJdbcValue(Object, WrapperOptions)} is not called by Hibernate ORM.
106105
*/
107106
@Override
108-
public @Nullable BsonValue createJdbcValue(@Nullable Object domainValue, WrapperOptions options) {
107+
public BsonValue createJdbcValue(@Nullable Object domainValue, WrapperOptions options) {
109108
throw fail();
110109
}
111110

112111
private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions options) throws SQLException {
113112
if (domainValue == null) {
114-
return toBsonValue(domainValue);
113+
throw new FeatureNotSupportedException(
114+
"TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 return toBsonValue(domainValue)");
115115
}
116116
var embeddableMappingType = getEmbeddableMappingType();
117117
var result = new BsonDocument();
@@ -129,6 +129,10 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
129129
}
130130
var fieldName = jdbcValueSelectable.getSelectableName();
131131
var value = embeddableMappingType.getValue(domainValue, columnIndex);
132+
if (value == null) {
133+
throw new FeatureNotSupportedException(
134+
"TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48");
135+
}
132136
BsonValue bsonValue;
133137
var jdbcMapping = jdbcValueSelectable.getJdbcMapping();
134138
var jdbcTypeCode = jdbcMapping.getJdbcType().getJdbcTypeCode();
@@ -140,7 +144,7 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
140144
} else if (jdbcTypeCode == MongoArrayJdbcType.JDBC_TYPE.getVendorTypeNumber()) {
141145
@SuppressWarnings("unchecked")
142146
ValueBinder<Object> valueBinder = jdbcMapping.getJdbcValueBinder();
143-
bsonValue = toBsonValue(value == null ? null : valueBinder.getBindValue(value, options));
147+
bsonValue = toBsonValue(valueBinder.getBindValue(value, options));
144148
} else {
145149
bsonValue = toBsonValue(value);
146150
}
@@ -159,7 +163,8 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
159163
public Object @Nullable [] extractJdbcValues(@Nullable Object rawJdbcValue, WrapperOptions options)
160164
throws SQLException {
161165
if (isNull(rawJdbcValue)) {
162-
return null;
166+
throw new FeatureNotSupportedException(
167+
"TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 return null");
163168
}
164169
if (!(rawJdbcValue instanceof BsonDocument bsonDocument)) {
165170
throw fail();
@@ -171,10 +176,10 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
171176
var jdbcMapping =
172177
embeddableMappingType.getJdbcValueSelectable(elementIdx).getJdbcMapping();
173178
var jdbcTypeCode = jdbcMapping.getJdbcType().getJdbcTypeCode();
174-
var javaTypeClass = jdbcMapping.getMappedJavaType().getJavaTypeClass();
175179
Object domainValue;
176180
if (isNull(value)) {
177-
domainValue = toNullDomainValue();
181+
throw new FeatureNotSupportedException("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48"
182+
+ " domainValue = ValueConversions.toNullDomainValue, where toNullDomainValue returns null");
178183
} else if (jdbcTypeCode == getJdbcTypeCode()) {
179184
if (!(jdbcMapping.getJdbcValueExtractor() instanceof Extractor<?> structValueExtractor)) {
180185
throw fail();
@@ -194,7 +199,8 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
194199
new MongoArray(value.asArray().toArray()),
195200
options);
196201
} else {
197-
domainValue = toDomainValue(value, javaTypeClass);
202+
domainValue =
203+
toDomainValue(value, jdbcMapping.getMappedJavaType().getJavaTypeClass());
198204
}
199205
result[elementIdx++] = domainValue;
200206
}

src/main/java/com/mongodb/hibernate/internal/type/ValueConversions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ private ValueConversions() {}
5656

5757
public static BsonValue toBsonValue(@Nullable Object value) throws SQLFeatureNotSupportedException {
5858
if (value == null) {
59-
return BsonNull.VALUE;
59+
throw new SQLFeatureNotSupportedException(
60+
"TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 return BsonNull.VALUE");
6061
} else if (value instanceof BsonDocument v) {
6162
return v;
6263
} else if (value instanceof Boolean v) {
@@ -177,7 +178,8 @@ static boolean isNull(@Nullable Object value) {
177178
static @Nullable Object toDomainValue(@Nullable BsonValue value, Class<?> domainType)
178179
throws SQLFeatureNotSupportedException {
179180
if (isNull(value)) {
180-
return toNullDomainValue();
181+
throw new SQLFeatureNotSupportedException("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48"
182+
+ " return toNullDomainValue(), where toNullDomainValue returns null");
181183
} else if (value instanceof BsonDocument v) {
182184
return v;
183185
} else if (value instanceof BsonBoolean v) {

src/main/java/com/mongodb/hibernate/jdbc/MongoPreparedStatement.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException {
9090
checkClosed();
9191
checkParameterIndex(parameterIndex);
9292
switch (sqlType) {
93+
case Types.ARRAY:
9394
case Types.BLOB:
9495
case Types.CLOB:
9596
case Types.DATALINK:
@@ -101,10 +102,13 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException {
101102
case Types.REF:
102103
case Types.ROWID:
103104
case Types.SQLXML:
105+
case Types.STRUCT:
104106
throw new SQLFeatureNotSupportedException(
105107
"Unsupported SQL type: " + JDBCType.valueOf(sqlType).getName());
106108
}
107-
setParameter(parameterIndex, toBsonValue((Object) null));
109+
throw new SQLFeatureNotSupportedException(
110+
"TODO-HIBERNATE-74 https://jira.mongodb.org/browse/HIBERNATE-74, TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48"
111+
+ " setParameter(parameterIndex, ValueConversions.toBsonValue((Object) null))");
108112
}
109113

110114
@Override

0 commit comments

Comments
 (0)