|
10 | 10 | import java.io.Serializable; |
11 | 11 |
|
12 | 12 | import org.hibernate.AssertionFailure; |
13 | | -import org.hibernate.CustomEntityDirtinessStrategy; |
14 | 13 | import org.hibernate.HibernateException; |
15 | 14 | import org.hibernate.LockMode; |
16 | 15 | import org.hibernate.UnsupportedLockAttemptException; |
|
21 | 20 | import org.hibernate.engine.spi.EntityKey; |
22 | 21 | import org.hibernate.engine.spi.ManagedEntity; |
23 | 22 | import org.hibernate.engine.spi.PersistenceContext; |
24 | | -import org.hibernate.engine.spi.PersistentAttributeInterceptor; |
25 | 23 | import org.hibernate.engine.spi.SelfDirtinessTracker; |
26 | 24 | import org.hibernate.engine.spi.SessionFactoryImplementor; |
27 | 25 | import org.hibernate.engine.spi.SessionImplementor; |
|
41 | 39 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.PREVIOUS_STATUS; |
42 | 40 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.STATUS; |
43 | 41 | import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity; |
44 | | -import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; |
| 42 | +import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptableOrNull; |
45 | 43 | 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 | 44 | import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker; |
49 | 45 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfManagedEntity; |
50 | 46 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker; |
|
56 | 52 | import static org.hibernate.engine.spi.Status.SAVING; |
57 | 53 | import static org.hibernate.internal.util.StringHelper.nullIfEmpty; |
58 | 54 | import static org.hibernate.pretty.MessageHelper.infoString; |
59 | | -import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; |
60 | 55 |
|
61 | 56 | /** |
62 | 57 | * A base implementation of {@link EntityEntry}. |
@@ -390,46 +385,31 @@ private boolean isUnequivocallyNonDirty(Object entity) { |
390 | 385 | } |
391 | 386 |
|
392 | 387 | private boolean isNonDirtyViaCustomStrategy(Object entity) { |
393 | | - if ( isPersistentAttributeInterceptable( entity ) ) { |
394 | | - final PersistentAttributeInterceptor interceptor = |
395 | | - asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor(); |
396 | | - if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) { |
| 388 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 389 | + if ( interceptable != null ) { |
| 390 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor |
| 391 | + && !interceptor.isInitialized() ) { |
397 | 392 | // we never have to check an uninitialized proxy |
398 | 393 | return true; |
399 | 394 | } |
400 | 395 | } |
401 | | - |
402 | | - final SessionImplementor session = (SessionImplementor) getPersistenceContext().getSession(); |
403 | | - final CustomEntityDirtinessStrategy customEntityDirtinessStrategy = |
404 | | - session.getFactory().getCustomEntityDirtinessStrategy(); |
| 396 | + final var session = (SessionImplementor) getPersistenceContext().getSession(); |
| 397 | + final var customEntityDirtinessStrategy = session.getFactory().getCustomEntityDirtinessStrategy(); |
405 | 398 | return customEntityDirtinessStrategy.canDirtyCheck( entity, persister, session ) |
406 | 399 | && !customEntityDirtinessStrategy.isDirty( entity, persister, session ); |
407 | 400 | } |
408 | 401 |
|
409 | 402 | 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; |
| 403 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 404 | + if ( interceptable != null ) { |
| 405 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor ) { |
| 406 | + return !interceptor.hasWrittenFieldNames(); |
419 | 407 | } |
420 | 408 | } |
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(); |
| 409 | + return !persister.hasCollections() |
| 410 | + && !persister.hasMutableProperties() |
| 411 | + && asManagedEntity( entity ).$$_hibernate_useTracker() |
| 412 | + && !asSelfDirtinessTracker( entity ).$$_hibernate_hasDirtyAttributes(); |
433 | 413 | } |
434 | 414 |
|
435 | 415 | @Override |
|
0 commit comments