Skip to content

Commit d5f2407

Browse files
DavideDdreab8
authored andcommitted
CacheLoaderHelper refactoring
1 parent 4476925 commit d5f2407

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

hibernate-core/src/main/java/org/hibernate/loader/internal/CacheLoadHelper.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,32 @@ private CacheLoadHelper() {
7777
*
7878
* @throws HibernateException Generally indicates problems applying a lock mode.
7979
*/
80-
public static PersistenceContextEntry loadFromSessionCache(
81-
EntityKey keyToLoad, LockOptions lockOptions,
82-
LoadEventListener.LoadType options,
83-
SharedSessionContractImplementor session) {
80+
public static PersistenceContextEntry loadFromSessionCache(EntityKey keyToLoad, LockOptions lockOptions, LoadEventListener.LoadType options, SharedSessionContractImplementor session) {
8481
final Object old = session.getEntityUsingInterceptor( keyToLoad );
82+
PersistenceContextEntry.EntityStatus entityStatus = MANAGED;
8583
if ( old != null ) {
8684
// this object was already loaded
8785
final EntityEntry oldEntry = session.getPersistenceContext().getEntry( old );
88-
if ( options.isCheckDeleted() ) {
89-
if ( oldEntry.getStatus().isDeletedOrGone() ) {
90-
LOADING_LOGGER.foundEntityScheduledForRemoval();
91-
return new PersistenceContextEntry( old, REMOVED_ENTITY_MARKER );
92-
}
93-
}
94-
if ( options.isAllowNulls() ) {
95-
final EntityPersister persister =
96-
session.getFactory().getMappingMetamodel()
97-
.getEntityDescriptor( keyToLoad.getEntityName() );
98-
if ( !persister.isInstance( old ) ) {
99-
LOADING_LOGGER.foundEntityWrongType();
100-
return new PersistenceContextEntry( old, INCONSISTENT_RTN_CLASS_MARKER );
101-
}
86+
entityStatus = entityStatus( keyToLoad, options, session, oldEntry, old );
87+
if ( entityStatus == MANAGED ) {
88+
upgradeLock( old, oldEntry, lockOptions, session );
10289
}
103-
upgradeLock( old, oldEntry, lockOptions, session );
10490
}
105-
return new PersistenceContextEntry( old, MANAGED );
91+
return new PersistenceContextEntry( old, entityStatus );
92+
}
93+
94+
// Used by Hibernate Reactive
95+
public static PersistenceContextEntry.EntityStatus entityStatus(EntityKey keyToLoad, LoadEventListener.LoadType options, SharedSessionContractImplementor session, EntityEntry oldEntry, Object old) {
96+
if ( options.isCheckDeleted() && oldEntry.getStatus().isDeletedOrGone() ) {
97+
LOADING_LOGGER.foundEntityScheduledForRemoval();
98+
return REMOVED_ENTITY_MARKER;
99+
}
100+
if ( options.isAllowNulls() && !session.getFactory().getMappingMetamodel()
101+
.getEntityDescriptor( keyToLoad.getEntityName() ).isInstance( old ) ) {
102+
LOADING_LOGGER.foundEntityWrongType();
103+
return INCONSISTENT_RTN_CLASS_MARKER;
104+
}
105+
return MANAGED;
106106
}
107107

108108
/**

0 commit comments

Comments
 (0)