HHH-3515 : EntityNameResolver defensiveness

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15273 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2008-10-08 04:39:11 +00:00
parent ff128ca6f8
commit 4c110150e4
2 changed files with 30 additions and 27 deletions

View File

@ -468,6 +468,9 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
} }
private void registerEntityNameResolvers(EntityPersister persister) { private void registerEntityNameResolvers(EntityPersister persister) {
if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizerMapping() == null ) {
return;
}
Iterator itr = persister.getEntityMetamodel().getTuplizerMapping().iterateTuplizers(); Iterator itr = persister.getEntityMetamodel().getTuplizerMapping().iterateTuplizers();
while ( itr.hasNext() ) { while ( itr.hasNext() ) {
final EntityTuplizer tuplizer = ( EntityTuplizer ) itr.next(); final EntityTuplizer tuplizer = ( EntityTuplizer ) itr.next();

View File

@ -39,7 +39,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.dom4j.Element;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -73,7 +72,6 @@ import org.hibernate.engine.ActionQueue;
import org.hibernate.engine.CollectionEntry; import org.hibernate.engine.CollectionEntry;
import org.hibernate.engine.EntityEntry; import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.EntityKey; import org.hibernate.engine.EntityKey;
import org.hibernate.engine.FilterDefinition;
import org.hibernate.engine.PersistenceContext; import org.hibernate.engine.PersistenceContext;
import org.hibernate.engine.QueryParameters; import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.StatefulPersistenceContext; import org.hibernate.engine.StatefulPersistenceContext;
@ -127,8 +125,6 @@ import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.stat.SessionStatistics; import org.hibernate.stat.SessionStatistics;
import org.hibernate.stat.SessionStatisticsImpl; import org.hibernate.stat.SessionStatisticsImpl;
import org.hibernate.tuple.DynamicMapInstantiator;
import org.hibernate.tuple.entity.PojoEntityTuplizer;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.util.ArrayHelper; import org.hibernate.util.ArrayHelper;
import org.hibernate.util.CollectionHelper; import org.hibernate.util.CollectionHelper;
@ -177,29 +173,7 @@ public final class SessionImpl extends AbstractSessionImpl
private transient Session rootSession; private transient Session rootSession;
private transient Map childSessionsByEntityMode; private transient Map childSessionsByEntityMode;
private EntityNameResolver entityNameResolver = new EntityNameResolver() { private EntityNameResolver entityNameResolver = new CoordinatingEntityNameResolver();
public String resolveEntityName(Object entity) {
String entityName = interceptor.getEntityName( entity );
if ( entityName != null ) {
return entityName;
}
Iterator itr = factory.iterateEntityNameResolvers( entityMode );
while ( itr.hasNext() ) {
final EntityNameResolver resolver = ( EntityNameResolver ) itr.next();
entityName = resolver.resolveEntityName( entity );
if ( entityName != null ) {
break;
}
}
if ( entityName != null ) {
return entityName;
}
// the old-time stand-by...
return entity.getClass().getName();
}
};
/** /**
* Constructor used in building "child sessions". * Constructor used in building "child sessions".
@ -1944,6 +1918,8 @@ public final class SessionImpl extends AbstractSessionImpl
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
log.trace( "deserializing session" ); log.trace( "deserializing session" );
entityNameResolver = new CoordinatingEntityNameResolver();
boolean isRootSession = ois.readBoolean(); boolean isRootSession = ois.readBoolean();
connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() ); connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() );
entityMode = EntityMode.parse( ( String ) ois.readObject() ); entityMode = EntityMode.parse( ( String ) ois.readObject() );
@ -2020,4 +1996,28 @@ public final class SessionImpl extends AbstractSessionImpl
oos.writeObject( loadQueryInfluencers ); oos.writeObject( loadQueryInfluencers );
oos.writeObject( childSessionsByEntityMode ); oos.writeObject( childSessionsByEntityMode );
} }
private class CoordinatingEntityNameResolver implements EntityNameResolver {
public String resolveEntityName(Object entity) {
String entityName = interceptor.getEntityName( entity );
if ( entityName != null ) {
return entityName;
}
Iterator itr = factory.iterateEntityNameResolvers( entityMode );
while ( itr.hasNext() ) {
final EntityNameResolver resolver = ( EntityNameResolver ) itr.next();
entityName = resolver.resolveEntityName( entity );
if ( entityName != null ) {
break;
}
}
if ( entityName != null ) {
return entityName;
}
// the old-time stand-by...
return entity.getClass().getName();
}
}
} }