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();
EntityKey key = new EntityKey( entry.getId(), entry.getPersister(), session.getEntityMode() );
persistenceContext.removeEntity(key);
persistenceContext.removeProxy(key);
persistenceContext.removeEntity( entry.getEntityKey() );
persistenceContext.removeProxy( entry.getEntityKey() );
if ( persister.hasCache() ) {
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 final EntityMode entityMode;
private final String entityName;
private transient EntityKey cachedEntityKey; // cached EntityKey (lazy-initialized)
private boolean isBeingReplicated;
private boolean loadedWithLazyPropertiesUnfetched; //NOTE: this is not updated when properties are fetched lazily!
private final transient Object rowId;
@ -165,6 +166,21 @@ public final class EntityEntry implements Serializable {
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) {
persister = factory.getEntityPersister( entityName );
}
@ -225,7 +241,7 @@ public final class EntityEntry implements Serializable {
earlyInsert ?
!isExistsInDatabase() :
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 {
EntityEntry e = getEntry(impl);
EntityPersister p = e.getPersister();
return proxyFor( p, new EntityKey( e.getId(), p, session.getEntityMode() ), impl );
return proxyFor( e.getPersister(), e.getEntityKey(), impl );
}
/**

View File

@ -191,10 +191,7 @@ public final class TwoPhaseLoad {
}
boolean isReallyReadOnly = readOnly || !persister.isMutable();
Object proxy = persistenceContext.getProxy(
new EntityKey(entityEntry.getId(), entityEntry.getPersister(), session.getEntityMode()
)
);
Object proxy = persistenceContext.getProxy( entityEntry.getEntityKey() );
if ( proxy != null ) {
// there is already a proxy for this impl
// 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 {
EntityEntry e = persistenceContext.removeEntry( object );
if ( e != null ) {
EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode() );
persistenceContext.removeEntity( key );
doEvict( object, key, e.getPersister(), source );
persistenceContext.removeEntity( e.getEntityKey() );
doEvict( object, e.getEntityKey(), e.getPersister(), source );
}
}
}