HHH-9269 Store persister to ReferenceCacheEntryImpl to avoid costly lookup at read time
This commit is contained in:
parent
92bd9e6310
commit
728592007d
|
@ -25,8 +25,6 @@ package org.hibernate.cache.spi.entry;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
/**
|
||||
|
@ -34,11 +32,18 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
*/
|
||||
public class ReferenceCacheEntryImpl implements CacheEntry {
|
||||
private final Object reference;
|
||||
private final String subclass;
|
||||
// passing the persister avoids a costly persister lookup by class name at cache retrieval time
|
||||
private final EntityPersister subclassPersister;
|
||||
|
||||
public ReferenceCacheEntryImpl(Object reference, String subclass) {
|
||||
/**
|
||||
* Constructs a ReferenceCacheEntryImpl
|
||||
*
|
||||
* @param reference The reference entity instance
|
||||
* @param subclassPersister The specific subclass persister
|
||||
*/
|
||||
public ReferenceCacheEntryImpl(Object reference, EntityPersister subclassPersister) {
|
||||
this.reference = reference;
|
||||
this.subclass = subclass;
|
||||
this.subclassPersister = subclassPersister;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,7 +53,11 @@ public class ReferenceCacheEntryImpl implements CacheEntry {
|
|||
|
||||
@Override
|
||||
public String getSubclass() {
|
||||
return subclass;
|
||||
return subclassPersister.getEntityName();
|
||||
}
|
||||
|
||||
public EntityPersister getSubclassPersister() {
|
||||
return subclassPersister;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -590,7 +590,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
|
||||
final EventSource session = event.getSession();
|
||||
final SessionFactoryImplementor factory = session.getFactory();
|
||||
final EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
|
||||
final EntityPersister subclassPersister;
|
||||
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracef(
|
||||
|
@ -613,14 +613,17 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
);
|
||||
}
|
||||
|
||||
entity = ( (ReferenceCacheEntryImpl) entry ).getReference();
|
||||
ReferenceCacheEntryImpl referenceCacheEntry = (ReferenceCacheEntryImpl) entry;
|
||||
entity = referenceCacheEntry.getReference();
|
||||
if ( entity == null ) {
|
||||
throw new IllegalStateException(
|
||||
"Reference cache entry contained null : " + MessageHelper.infoString( persister, entityId, factory )
|
||||
);
|
||||
}
|
||||
subclassPersister = referenceCacheEntry.getSubclassPersister();
|
||||
}
|
||||
else {
|
||||
subclassPersister = factory.getEntityPersister( entry.getSubclass() );
|
||||
final Object optionalObject = event.getInstanceToLoad();
|
||||
entity = optionalObject == null
|
||||
? session.instantiate( subclassPersister, entityId )
|
||||
|
|
|
@ -5042,7 +5042,7 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
@Override
|
||||
public CacheEntry buildCacheEntry(Object entity, Object[] state, Object version, SessionImplementor session) {
|
||||
return new ReferenceCacheEntryImpl( entity, persister.getEntityName() );
|
||||
return new ReferenceCacheEntryImpl( entity, persister );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue