HHH-9269 Store persister to ReferenceCacheEntryImpl to avoid costly lookup at read time
This commit is contained in:
parent
3b284d797a
commit
ceaf2e320f
|
@ -25,6 +25,8 @@ package org.hibernate.cache.spi.entry;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialized CacheEntry for storing direct references to entity instances.
|
* Specialized CacheEntry for storing direct references to entity instances.
|
||||||
*
|
*
|
||||||
|
@ -32,17 +34,18 @@ import java.io.Serializable;
|
||||||
*/
|
*/
|
||||||
public class ReferenceCacheEntryImpl implements CacheEntry {
|
public class ReferenceCacheEntryImpl implements CacheEntry {
|
||||||
private final Object reference;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ReferenceCacheEntryImpl
|
* Constructs a ReferenceCacheEntryImpl
|
||||||
*
|
*
|
||||||
* @param reference The reference entity instance
|
* @param reference The reference entity instance
|
||||||
* @param subclass The specific subclass
|
* @param subclassPersister The specific subclass persister
|
||||||
*/
|
*/
|
||||||
public ReferenceCacheEntryImpl(Object reference, String subclass) {
|
public ReferenceCacheEntryImpl(Object reference, EntityPersister subclassPersister) {
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
this.subclass = subclass;
|
this.subclassPersister = subclassPersister;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +64,11 @@ public class ReferenceCacheEntryImpl implements CacheEntry {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSubclass() {
|
public String getSubclass() {
|
||||||
return subclass;
|
return subclassPersister.getEntityName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPersister getSubclassPersister() {
|
||||||
|
return subclassPersister;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -636,7 +636,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
||||||
|
|
||||||
final EventSource session = event.getSession();
|
final EventSource session = event.getSession();
|
||||||
final SessionFactoryImplementor factory = session.getFactory();
|
final SessionFactoryImplementor factory = session.getFactory();
|
||||||
final EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
|
final EntityPersister subclassPersister;
|
||||||
|
|
||||||
if ( LOG.isTraceEnabled() ) {
|
if ( LOG.isTraceEnabled() ) {
|
||||||
LOG.tracef(
|
LOG.tracef(
|
||||||
|
@ -659,7 +659,8 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
entity = ( (ReferenceCacheEntryImpl) entry ).getReference();
|
ReferenceCacheEntryImpl referenceCacheEntry = (ReferenceCacheEntryImpl) entry;
|
||||||
|
entity = referenceCacheEntry.getReference();
|
||||||
if ( entity == null ) {
|
if ( entity == null ) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Reference cache entry contained null : " + MessageHelper.infoString(
|
"Reference cache entry contained null : " + MessageHelper.infoString(
|
||||||
|
@ -669,8 +670,10 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
subclassPersister = referenceCacheEntry.getSubclassPersister();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
subclassPersister = factory.getEntityPersister( entry.getSubclass() );
|
||||||
final Object optionalObject = event.getInstanceToLoad();
|
final Object optionalObject = event.getInstanceToLoad();
|
||||||
entity = optionalObject == null
|
entity = optionalObject == null
|
||||||
? session.instantiate( subclassPersister, entityId )
|
? session.instantiate( subclassPersister, entityId )
|
||||||
|
|
|
@ -5267,7 +5267,7 @@ public abstract class AbstractEntityPersister
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CacheEntry buildCacheEntry(Object entity, Object[] state, Object version, SessionImplementor session) {
|
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