Author: stliu
Date: 2010-07-08 04:59:06 -0400 (Thu, 08 Jul 2010)
New Revision: 19915
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityDeleteAction.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/EntityEntry.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/event/def/DefaultEvictEventListener.java
Log:
JBPAPP-4580 HHH-4737 Cache the EntityKey in EntityEntry when id is non-null
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityDeleteAction.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityDeleteAction.java 2010-07-08
08:51:15 UTC (rev 19914)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityDeleteAction.java 2010-07-08
08:59:06 UTC (rev 19915)
@@ -108,9 +108,8 @@
}
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 );
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/EntityEntry.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/EntityEntry.java 2010-07-08
08:51:15 UTC (rev 19914)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/EntityEntry.java 2010-07-08
08:59:06 UTC (rev 19915)
@@ -56,6 +56,7 @@
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 @@
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 @@
earlyInsert ?
!isExistsInDatabase() :
session.getPersistenceContext().getNullifiableEntityKeys()
- .contains( new EntityKey( getId(), getPersister(), entityMode ) )
+ .contains( getEntityKey() )
);
}
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2010-07-08
08:51:15 UTC (rev 19914)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2010-07-08
08:59:06 UTC (rev 19915)
@@ -687,8 +687,7 @@
*/
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 );
}
/**
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/event/def/DefaultEvictEventListener.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/event/def/DefaultEvictEventListener.java 2010-07-08
08:51:15 UTC (rev 19914)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/event/def/DefaultEvictEventListener.java 2010-07-08
08:59:06 UTC (rev 19915)
@@ -88,9 +88,8 @@
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 );
}
}
}
Show replies by date