HHH-4737 : Cache the EntityKey in EntityEntry when id is non-null

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18528 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Gail Badner 2010-01-13 06:02:14 +00:00
parent cc382233c5
commit 94415151f7
5 changed files with 23 additions and 13 deletions

View File

@ -108,9 +108,8 @@ public final class EntityDeleteAction extends EntityAction {
} }
entry.postDelete(); entry.postDelete();
EntityKey key = new EntityKey( entry.getId(), entry.getPersister(), session.getEntityMode() ); persistenceContext.removeEntity( entry.getEntityKey() );
persistenceContext.removeEntity(key); persistenceContext.removeProxy( entry.getEntityKey() );
persistenceContext.removeProxy(key);
if ( persister.hasCache() ) { if ( persister.hasCache() ) {
persister.getCacheAccessStrategy().remove( ck ); persister.getCacheAccessStrategy().remove( ck );

View File

@ -56,6 +56,7 @@ public final class EntityEntry implements Serializable {
private transient EntityPersister persister; // for convenience to save some lookups private transient EntityPersister persister; // for convenience to save some lookups
private final EntityMode entityMode; private final EntityMode entityMode;
private final String entityName; private final String entityName;
private transient EntityKey cachedEntityKey; // cached EntityKey (lazy-initialized)
private boolean isBeingReplicated; private boolean isBeingReplicated;
private boolean loadedWithLazyPropertiesUnfetched; //NOTE: this is not updated when properties are fetched lazily! private boolean loadedWithLazyPropertiesUnfetched; //NOTE: this is not updated when properties are fetched lazily!
private final transient Object rowId; private final transient Object rowId;
@ -165,6 +166,21 @@ public final class EntityEntry implements Serializable {
return persister; return persister;
} }
/**
* Get the EntityKey based on this EntityEntry.
* @return the EntityKey
* @throws IllegalStateException if getId() is null
*/
public EntityKey getEntityKey() {
if ( cachedEntityKey == null ) {
if ( getId() == null ) {
throw new IllegalStateException( "cannot generate an EntityKey when id is null.");
}
cachedEntityKey = new EntityKey( getId(), getPersister(), entityMode );
}
return cachedEntityKey;
}
void afterDeserialize(SessionFactoryImplementor factory) { void afterDeserialize(SessionFactoryImplementor factory) {
persister = factory.getEntityPersister( entityName ); persister = factory.getEntityPersister( entityName );
} }
@ -225,7 +241,7 @@ public final class EntityEntry implements Serializable {
earlyInsert ? earlyInsert ?
!isExistsInDatabase() : !isExistsInDatabase() :
session.getPersistenceContext().getNullifiableEntityKeys() session.getPersistenceContext().getNullifiableEntityKeys()
.contains( new EntityKey( getId(), getPersister(), entityMode ) ) .contains( getEntityKey() )
); );
} }

View File

@ -698,8 +698,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
*/ */
public Object proxyFor(Object impl) throws HibernateException { public Object proxyFor(Object impl) throws HibernateException {
EntityEntry e = getEntry(impl); EntityEntry e = getEntry(impl);
EntityPersister p = e.getPersister(); return proxyFor( e.getPersister(), e.getEntityKey(), impl );
return proxyFor( p, new EntityKey( e.getId(), p, session.getEntityMode() ), impl );
} }
/** /**

View File

@ -191,10 +191,7 @@ public final class TwoPhaseLoad {
} }
boolean isReallyReadOnly = readOnly || !persister.isMutable(); boolean isReallyReadOnly = readOnly || !persister.isMutable();
Object proxy = persistenceContext.getProxy( Object proxy = persistenceContext.getProxy( entityEntry.getEntityKey() );
new EntityKey(entityEntry.getId(), entityEntry.getPersister(), session.getEntityMode()
)
);
if ( proxy != null ) { if ( proxy != null ) {
// there is already a proxy for this impl // there is already a proxy for this impl
// only set the status to read-only if the proxy is read-only // only set the status to read-only if the proxy is read-only

View File

@ -88,9 +88,8 @@ public class DefaultEvictEventListener implements EvictEventListener {
else { else {
EntityEntry e = persistenceContext.removeEntry( object ); EntityEntry e = persistenceContext.removeEntry( object );
if ( e != null ) { if ( e != null ) {
EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode() ); persistenceContext.removeEntity( e.getEntityKey() );
persistenceContext.removeEntity( key ); doEvict( object, e.getEntityKey(), e.getPersister(), source );
doEvict( object, key, e.getPersister(), source );
} }
} }
} }