|
41 | 41 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.PREVIOUS_STATUS; |
42 | 42 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.STATUS; |
43 | 43 | import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity; |
44 | | -import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; |
| 44 | +import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptableOrNull; |
45 | 45 | import static org.hibernate.engine.internal.ManagedTypeHelper.asSelfDirtinessTracker; |
46 | | -import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy; |
47 | | -import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; |
48 | 46 | import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker; |
49 | 47 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfManagedEntity; |
50 | 48 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker; |
|
56 | 54 | import static org.hibernate.engine.spi.Status.SAVING; |
57 | 55 | import static org.hibernate.internal.util.StringHelper.nullIfEmpty; |
58 | 56 | import static org.hibernate.pretty.MessageHelper.infoString; |
59 | | -import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; |
60 | 57 |
|
61 | 58 | /** |
62 | 59 | * A base implementation of {@link EntityEntry}. |
@@ -390,46 +387,31 @@ private boolean isUnequivocallyNonDirty(Object entity) { |
390 | 387 | } |
391 | 388 |
|
392 | 389 | private boolean isNonDirtyViaCustomStrategy(Object entity) { |
393 | | - if ( isPersistentAttributeInterceptable( entity ) ) { |
394 | | - final PersistentAttributeInterceptor interceptor = |
395 | | - asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor(); |
396 | | - if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) { |
| 390 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 391 | + if ( interceptable != null ) { |
| 392 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor |
| 393 | + && !interceptor.isInitialized() ) { |
397 | 394 | // we never have to check an uninitialized proxy |
398 | 395 | return true; |
399 | 396 | } |
400 | 397 | } |
401 | | - |
402 | | - final SessionImplementor session = (SessionImplementor) getPersistenceContext().getSession(); |
403 | | - final CustomEntityDirtinessStrategy customEntityDirtinessStrategy = |
404 | | - session.getFactory().getCustomEntityDirtinessStrategy(); |
| 398 | + final var session = (SessionImplementor) getPersistenceContext().getSession(); |
| 399 | + final var customEntityDirtinessStrategy = session.getFactory().getCustomEntityDirtinessStrategy(); |
405 | 400 | return customEntityDirtinessStrategy.canDirtyCheck( entity, persister, session ) |
406 | 401 | && !customEntityDirtinessStrategy.isDirty( entity, persister, session ); |
407 | 402 | } |
408 | 403 |
|
409 | 404 | private boolean isNonDirtyViaTracker(Object entity) { |
410 | | - final boolean uninitializedProxy; |
411 | | - if ( isPersistentAttributeInterceptable( entity ) ) { |
412 | | - final PersistentAttributeInterceptor interceptor = |
413 | | - asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor(); |
414 | | - if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) { |
415 | | - return !lazinessInterceptor.hasWrittenFieldNames(); |
416 | | - } |
417 | | - else { |
418 | | - uninitializedProxy = false; |
| 405 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 406 | + if ( interceptable != null ) { |
| 407 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor ) { |
| 408 | + return !interceptor.hasWrittenFieldNames(); |
419 | 409 | } |
420 | 410 | } |
421 | | - else if ( isHibernateProxy( entity ) ) { |
422 | | - uninitializedProxy = extractLazyInitializer( entity ).isUninitialized(); |
423 | | - } |
424 | | - else { |
425 | | - uninitializedProxy = false; |
426 | | - } |
427 | | - // we never have to check an uninitialized proxy |
428 | | - return uninitializedProxy |
429 | | - || !persister.hasCollections() |
430 | | - && !persister.hasMutableProperties() |
431 | | - && !asSelfDirtinessTracker( entity ).$$_hibernate_hasDirtyAttributes() |
432 | | - && asManagedEntity( entity ).$$_hibernate_useTracker(); |
| 411 | + return !persister.hasCollections() |
| 412 | + && !persister.hasMutableProperties() |
| 413 | + && asManagedEntity( entity ).$$_hibernate_useTracker() |
| 414 | + && !asSelfDirtinessTracker( entity ).$$_hibernate_hasDirtyAttributes(); |
433 | 415 | } |
434 | 416 |
|
435 | 417 | @Override |
|
0 commit comments