17
17
package com .mongodb .hibernate .internal .type ;
18
18
19
19
import static com .mongodb .hibernate .internal .MongoAssertions .assertFalse ;
20
+ import static com .mongodb .hibernate .internal .MongoAssertions .assertInstanceOf ;
20
21
import static com .mongodb .hibernate .internal .MongoAssertions .assertNotNull ;
21
22
import static com .mongodb .hibernate .internal .MongoAssertions .assertTrue ;
22
23
import static com .mongodb .hibernate .internal .MongoAssertions .fail ;
@@ -137,9 +138,7 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
137
138
var jdbcMapping = jdbcValueSelectable .getJdbcMapping ();
138
139
var jdbcTypeCode = jdbcMapping .getJdbcType ().getJdbcTypeCode ();
139
140
if (jdbcTypeCode == getJdbcTypeCode ()) {
140
- if (!(jdbcMapping .getJdbcValueBinder () instanceof Binder <?> structValueBinder )) {
141
- throw fail ();
142
- }
141
+ var structValueBinder = assertInstanceOf (jdbcMapping .getJdbcValueBinder (), Binder .class );
143
142
bsonValue = structValueBinder .getJdbcType ().createBsonValue (value , options );
144
143
} else if (jdbcTypeCode == MongoArrayJdbcType .JDBC_TYPE .getVendorTypeNumber ()) {
145
144
@ SuppressWarnings ("unchecked" )
@@ -166,9 +165,7 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
166
165
throw new FeatureNotSupportedException (
167
166
"TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 return null" );
168
167
}
169
- if (!(rawJdbcValue instanceof BsonDocument bsonDocument )) {
170
- throw fail ();
171
- }
168
+ var bsonDocument = assertInstanceOf (rawJdbcValue , BsonDocument .class );
172
169
var embeddableMappingType = getEmbeddableMappingType ();
173
170
var result = new Object [bsonDocument .size ()];
174
171
var elementIdx = 0 ;
@@ -181,17 +178,12 @@ private BsonValue createBsonValue(@Nullable Object domainValue, WrapperOptions o
181
178
throw new FeatureNotSupportedException (
182
179
"TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 domainValue = null" );
183
180
} else if (jdbcTypeCode == getJdbcTypeCode ()) {
184
- if (!(jdbcMapping .getJdbcValueExtractor () instanceof Extractor <?> structValueExtractor )) {
185
- throw fail ();
186
- }
181
+ var structValueExtractor = assertInstanceOf (jdbcMapping .getJdbcValueExtractor (), Extractor .class );
187
182
domainValue = structValueExtractor .getJdbcType ().extractJdbcValues (value , options );
188
183
} else if (jdbcTypeCode == MongoArrayJdbcType .JDBC_TYPE .getVendorTypeNumber ()) {
189
- if (!(jdbcMapping .getJdbcType () instanceof MongoArrayJdbcType arrayJdbcType )) {
190
- throw fail ();
191
- }
192
- if (!(jdbcMapping .getJdbcValueExtractor () instanceof BasicExtractor <?> jdbcValueExtractor )) {
193
- throw fail ();
194
- }
184
+ var arrayJdbcType = assertInstanceOf (jdbcMapping .getJdbcType (), MongoArrayJdbcType .class );
185
+ BasicExtractor <?> jdbcValueExtractor =
186
+ assertInstanceOf (jdbcMapping .getJdbcValueExtractor (), BasicExtractor .class );
195
187
domainValue = arrayJdbcType .getArray (jdbcValueExtractor , toArrayDomainValue (value ), options );
196
188
} else {
197
189
domainValue =
@@ -223,10 +215,7 @@ private final class Binder<X> extends BasicBinder<X> {
223
215
224
216
@ Override
225
217
public MongoStructJdbcType getJdbcType () {
226
- if (!(super .getJdbcType () instanceof MongoStructJdbcType structJdbcType )) {
227
- throw fail ();
228
- }
229
- return structJdbcType ;
218
+ return assertInstanceOf (super .getJdbcType (), MongoStructJdbcType .class );
230
219
}
231
220
232
221
@ Override
@@ -256,10 +245,7 @@ private final class Extractor<X> extends BasicExtractor<X> {
256
245
257
246
@ Override
258
247
public MongoStructJdbcType getJdbcType () {
259
- if (!(super .getJdbcType () instanceof MongoStructJdbcType structJdbcType )) {
260
- throw fail ();
261
- }
262
- return structJdbcType ;
248
+ return assertInstanceOf (super .getJdbcType (), MongoStructJdbcType .class );
263
249
}
264
250
265
251
@ Override
0 commit comments