@@ -55,18 +55,18 @@ public abstract class AbstractStandardBasicType<T>
5555
5656 public AbstractStandardBasicType (JdbcType jdbcType , JavaType <T > javaType ) {
5757 this .jdbcType = jdbcType ;
58- this .sqlTypes = new int [] { jdbcType .getDdlTypeCode () };
5958 this .javaType = javaType ;
59+ sqlTypes = new int [] { jdbcType .getDdlTypeCode () };
6060
61- this . jdbcValueBinder = jdbcType .getBinder ( javaType );
62- this . jdbcValueExtractor = jdbcType .getExtractor ( javaType );
63- this . jdbcLiteralFormatter = jdbcType .getJdbcLiteralFormatter ( javaType );
61+ jdbcValueBinder = jdbcType .getBinder ( javaType );
62+ jdbcValueExtractor = jdbcType .getExtractor ( javaType );
63+ jdbcLiteralFormatter = jdbcType .getJdbcLiteralFormatter ( javaType );
6464
6565 //A very simple dispatch optimisation, make these a constant:
66- this . javaTypeClass = javaType .getJavaTypeClass ();
67- this . mutabilityPlan = javaType .getMutabilityPlan ();
68- this . javatypeComparator = javaType .getComparator ();
69- this . typeForEqualsHashCode = javaType .useObjectEqualsHashCode () ? null : this ;
66+ javaTypeClass = javaType .getJavaTypeClass ();
67+ mutabilityPlan = javaType .getMutabilityPlan ();
68+ javatypeComparator = javaType .getComparator ();
69+ typeForEqualsHashCode = javaType .useObjectEqualsHashCode () ? null : this ;
7070 }
7171
7272 @ Override
@@ -174,7 +174,6 @@ public final boolean isEqual(Object x, Object y, SessionFactoryImplementor facto
174174 }
175175
176176 @ Override
177- @ SuppressWarnings ("unchecked" )
178177 public boolean isEqual (Object one , Object another ) {
179178 if ( one == another ) {
180179 return true ;
@@ -186,19 +185,15 @@ else if ( typeForEqualsHashCode == null ) {
186185 return one .equals ( another );
187186 }
188187 else {
189- return javaType .areEqual ( ( T ) one , ( T ) another );
188+ return javaType .areEqual ( javaType . cast ( one ), javaType . cast ( another ) );
190189 }
191190 }
192191
193192 @ Override
194- @ SuppressWarnings ("unchecked" )
195- public int getHashCode (Object x ) {
196- if ( typeForEqualsHashCode == null ) {
197- return x .hashCode ();
198- }
199- else {
200- return javaType .extractHashCode ( (T ) x );
201- }
193+ public int getHashCode (Object object ) {
194+ return typeForEqualsHashCode == null
195+ ? object .hashCode ()
196+ : javaType .extractHashCode ( javaType .cast ( object ) );
202197 }
203198
204199 @ Override
@@ -212,9 +207,8 @@ public final int getHashCode(Object x, SessionFactoryImplementor factory) {
212207 }
213208
214209 @ Override
215- @ SuppressWarnings ("unchecked" )
216210 public final int compare (Object x , Object y ) {
217- return this .javatypeComparator .compare ( ( T ) x , ( T ) y );
211+ return this .javatypeComparator .compare ( javaType . cast ( x ) , javaType . cast ( y ) );
218212 }
219213
220214 @ Override
@@ -228,9 +222,11 @@ public final boolean isDirty(Object old, Object current, boolean[] checkable, Sh
228222 }
229223
230224 protected final boolean isDirty (Object old , Object current ) {
231- // MutableMutabilityPlan.INSTANCE is a special plan for which we always have to assume the value is dirty,
232- // because we can't actually copy a value, but have no knowledge about the mutability of the java type
233- return getMutabilityPlan () == MutableMutabilityPlan .INSTANCE || !isSame ( old , current );
225+ // MutableMutabilityPlan.INSTANCE is a special plan for which we always
226+ // have to assume the value is dirty, because we can't actually copy a
227+ // value, but have no knowledge about the mutability of the java type
228+ return getMutabilityPlan () == MutableMutabilityPlan .INSTANCE
229+ || !isSame ( old , current );
234230 }
235231
236232 @ Override
@@ -247,22 +243,23 @@ public final void nullSafeSet(
247243 PreparedStatement st ,
248244 Object value ,
249245 int index ,
250- final SharedSessionContractImplementor session ) throws SQLException {
251- //noinspection unchecked
252- nullSafeSet ( st , ( T ) value , index , (WrapperOptions ) session );
246+ final SharedSessionContractImplementor session )
247+ throws SQLException {
248+ nullSafeSet ( st , javaType . cast ( value ) , index , (WrapperOptions ) session );
253249 }
254250
255- protected void nullSafeSet (PreparedStatement st , T value , int index , WrapperOptions options ) throws SQLException {
251+ protected void nullSafeSet (PreparedStatement st , T value , int index , WrapperOptions options )
252+ throws SQLException {
256253 getJdbcValueBinder ().bind ( st , value , index , options );
257254 }
258255
259256 @ Override
260- @ SuppressWarnings ("unchecked" )
261257 public final String toLoggableString (Object value , SessionFactoryImplementor factory ) {
262- if ( value == LazyPropertyInitializer .UNFETCHED_PROPERTY || !Hibernate .isInitialized ( value ) ) {
263- return "<uninitialized>" ;
264- }
265- return javaType .extractLoggableRepresentation ( (T ) value );
258+ return value == LazyPropertyInitializer .UNFETCHED_PROPERTY
259+ || !Hibernate .isInitialized ( value )
260+ ? "<uninitialized>"
261+ : javaType .extractLoggableRepresentation (
262+ javaType .coerce ( value , factory ::getTypeConfiguration ) );
266263 }
267264
268265 @ Override
@@ -271,19 +268,17 @@ public final boolean isMutable() {
271268 }
272269
273270 @ Override
274- @ SuppressWarnings ("unchecked" )
275271 public final Object deepCopy (Object value , SessionFactoryImplementor factory ) {
276- return deepCopy ( ( T ) value );
272+ return deepCopy ( javaType . cast ( value ) );
277273 }
278274
279275 protected final T deepCopy (T value ) {
280276 return getMutabilityPlan ().deepCopy ( value );
281277 }
282278
283279 @ Override
284- @ SuppressWarnings ("unchecked" )
285280 public final Serializable disassemble (Object value , SharedSessionContractImplementor session , Object owner ) throws HibernateException {
286- return getMutabilityPlan ().disassemble ( ( T ) value , session );
281+ return getMutabilityPlan ().disassemble ( javaType . cast ( value ) , session );
287282 }
288283
289284 @ Override
@@ -296,16 +291,14 @@ public final void beforeAssemble(Serializable cached, SharedSessionContractImple
296291 }
297292
298293 @ Override
299- @ SuppressWarnings ("unchecked" )
300294 public final Object replace (Object original , Object target , SharedSessionContractImplementor session , Object owner , Map <Object , Object > copyCache ) {
301295 return original == null && target == null
302296 ? null
303- : javaType .getReplacement ( ( T ) original , ( T ) target , session );
297+ : javaType .getReplacement ( javaType . cast ( original ) , javaType . cast ( target ) , session );
304298
305299 }
306300
307301 @ Override
308- @ SuppressWarnings ("unchecked" )
309302 public Object replace (
310303 Object original ,
311304 Object target ,
@@ -314,6 +307,9 @@ public Object replace(
314307 Map <Object , Object > copyCache ,
315308 ForeignKeyDirection foreignKeyDirection ) {
316309 return ForeignKeyDirection .FROM_PARENT == foreignKeyDirection
310+ // TODO: use cast() .. currently failing on embeddable discriminators where
311+ // the concrete class is passed in instead of its disciminator value
312+ // ? javaType.getReplacement( javaType.cast( original ) , javaType.cast( target ) , session )
317313 ? javaType .getReplacement ( (T ) original , (T ) target , session )
318314 : target ;
319315 }
@@ -325,20 +321,12 @@ public boolean canDoExtraction() {
325321
326322 @ Override
327323 public T extract (CallableStatement statement , int startIndex , final SharedSessionContractImplementor session ) throws SQLException {
328- return getJdbcValueExtractor ().extract (
329- statement ,
330- startIndex ,
331- session
332- );
324+ return getJdbcValueExtractor ().extract ( statement , startIndex , session );
333325 }
334326
335327 @ Override
336328 public T extract (CallableStatement statement , String paramName , final SharedSessionContractImplementor session ) throws SQLException {
337- return getJdbcValueExtractor ().extract (
338- statement ,
339- paramName ,
340- session
341- );
329+ return getJdbcValueExtractor ().extract ( statement , paramName , session );
342330 }
343331
344332 @ Override
@@ -347,7 +335,8 @@ public void nullSafeSet(
347335 Object value ,
348336 int index ,
349337 boolean [] settable ,
350- SharedSessionContractImplementor session ) throws SQLException {
338+ SharedSessionContractImplementor session )
339+ throws SQLException {
351340
352341 }
353342
@@ -356,9 +345,8 @@ public void nullSafeSet(CallableStatement st, T value, String name, SharedSessio
356345 nullSafeSet ( st , value , name , (WrapperOptions ) session );
357346 }
358347
359- @ SuppressWarnings ("unchecked" )
360348 protected final void nullSafeSet (CallableStatement st , Object value , String name , WrapperOptions options ) throws SQLException {
361- getJdbcValueBinder ().bind ( st , ( T ) value , name , options );
349+ getJdbcValueBinder ().bind ( st , javaType . cast ( value ) , name , options );
362350 }
363351
364352 @ Override
@@ -379,7 +367,7 @@ public CastType getCastType() {
379367 // Due to that, we have to handle some conversions in wrap/unwrap of BooleanJavaType
380368 // and the cast type determination here. Note that we interpret the converter in ConvertedBasicTypeImpl
381369 // to properly determine the correct cast type
382- final JdbcType jdbcType = getJdbcType ();
370+ final var jdbcType = getJdbcType ();
383371 final int jdbcTypeCode = jdbcType .getDdlTypeCode ();
384372 switch ( jdbcTypeCode ) {
385373 case Types .BIT :
0 commit comments