HHH-6974 - Add caching to new "load access" api for natural id loading

This commit is contained in:
Steve Ebersole 2012-01-21 08:39:37 -06:00
parent bbac2fd220
commit b0ba04d09b
2 changed files with 12 additions and 7 deletions

View File

@ -1600,7 +1600,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
rtn.entityEntries = IdentityMap.instantiateSequenced( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
for ( int i = 0; i < count; i++ ) {
Object entity = ois.readObject();
EntityEntry entry = EntityEntry.deserialize( ois, session );
EntityEntry entry = EntityEntry.deserialize( ois, rtn );
rtn.entityEntries.put( entity, entry );
}
@ -1766,6 +1766,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
this.persister = persister;
}
public EntityPersister getPersister() {
return persister;
}
private Map<Serializable,NaturalId> pkToNaturalIdMap = new ConcurrentHashMap<Serializable, NaturalId>();
private Map<NaturalId,Serializable> naturalIdToPkMap = new ConcurrentHashMap<NaturalId,Serializable>();
}

View File

@ -338,7 +338,7 @@ public final class EntityEntry implements Serializable {
private void notifyLoadedStateUpdated() {
if ( persistenceContext == null ) {
throw new HibernateException( "PersistenceContext was null on an empty to update loaded state; indicates mis-use of EntityEntry as non-flushed change handling" );
throw new HibernateException( "PersistenceContext was null on attempt to update loaded state" );
}
persistenceContext.loadedStateUpdatedNotification( this );
@ -374,7 +374,7 @@ public final class EntityEntry implements Serializable {
* Session/PersistenceContext for increased performance.
*
* @param ois The stream from which to read the entry.
* @param session The session being deserialized.
* @param persistenceContext The context being deserialized.
*
* @return The deserialized EntityEntry
*
@ -384,10 +384,11 @@ public final class EntityEntry implements Serializable {
*/
public static EntityEntry deserialize(
ObjectInputStream ois,
SessionImplementor session) throws IOException, ClassNotFoundException {
String previousStatusString = null;
PersistenceContext persistenceContext) throws IOException, ClassNotFoundException {
String previousStatusString;
return new EntityEntry(
( session == null ? null : session.getFactory() ),
// this complexity comes from non-flushed changes, should really look at how that reattaches entries
( persistenceContext.getSession() == null ? null : persistenceContext.getSession().getFactory() ),
(String) ois.readObject(),
( Serializable ) ois.readObject(),
EntityMode.parse( (String) ois.readObject() ),
@ -404,7 +405,7 @@ public final class EntityEntry implements Serializable {
ois.readBoolean(),
ois.readBoolean(),
ois.readBoolean(),
( session == null ? null : session.getPersistenceContext() ) // ugh, need to redo how this particular bit works for non-flushed changes
persistenceContext
);
}
}