HHH-12591 - Remove second call to Scope#setSessionFactory(SessionFactoryImplementor) from TypeConfiguration#scope(SessionFactoryImplementor,BootstrapContext)

This commit is contained in:
Andrea Boriero 2018-05-16 22:03:46 +01:00
parent 9b00aaf9a5
commit 99d630bcc2
1 changed files with 19 additions and 7 deletions

View File

@ -138,14 +138,20 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
} }
public void scope(MetadataBuildingContext metadataBuildingContext) { public void scope(MetadataBuildingContext metadataBuildingContext) {
log.debugf( "Scoping TypeConfiguration [%s] to MetadataBuildingContext [%s]", this, metadataBuildingContext ); if ( log.isDebugEnabled() ) {
log.debugf(
"Scoping TypeConfiguration [%s] to MetadataBuildingContext [%s]",
this,
metadataBuildingContext
);
}
scope.setMetadataBuildingContext( metadataBuildingContext ); scope.setMetadataBuildingContext( metadataBuildingContext );
} }
public MetamodelImplementor scope(SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext) { public MetamodelImplementor scope(SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext) {
if ( log.isDebugEnabled() ) {
log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImpl [%s]", this, sessionFactory ); log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImpl [%s]", this, sessionFactory );
scope.setSessionFactory( sessionFactory ); }
log.debugf( "Scoping TypeConfiguration [%s] to SessionFactory [%s]", this, sessionFactory );
for ( Map.Entry<String, String> importEntry : scope.metadataBuildingContext.getMetadataCollector().getImports().entrySet() ) { for ( Map.Entry<String, String> importEntry : scope.metadataBuildingContext.getMetadataCollector().getImports().entrySet() ) {
if ( importMap.containsKey( importEntry.getKey() ) ) { if ( importMap.containsKey( importEntry.getKey() ) ) {
@ -181,13 +187,17 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
// Instead of allowing scope#setSessionFactory to influence this, we use the SessionFactoryObserver callback // Instead of allowing scope#setSessionFactory to influence this, we use the SessionFactoryObserver callback
// to handle this, allowing any SessionFactory constructor code to be able to continue to have access to the // to handle this, allowing any SessionFactory constructor code to be able to continue to have access to the
// MetadataBuildingContext through TypeConfiguration until this callback is fired. // MetadataBuildingContext through TypeConfiguration until this callback is fired.
if ( log.isDebugEnabled() ) {
log.tracef( "Handling #sessionFactoryCreated from [%s] for TypeConfiguration", factory ); log.tracef( "Handling #sessionFactoryCreated from [%s] for TypeConfiguration", factory );
}
scope.setMetadataBuildingContext( null ); scope.setMetadataBuildingContext( null );
} }
@Override @Override
public void sessionFactoryClosed(SessionFactory factory) { public void sessionFactoryClosed(SessionFactory factory) {
if ( log.isDebugEnabled() ) {
log.tracef( "Handling #sessionFactoryClosed from [%s] for TypeConfiguration", factory ); log.tracef( "Handling #sessionFactoryClosed from [%s] for TypeConfiguration", factory );
}
TypeConfigurationRegistry.INSTANCE.deregisterTypeConfiguration( this ); TypeConfigurationRegistry.INSTANCE.deregisterTypeConfiguration( this );
@ -288,7 +298,9 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
} }
public void unsetSessionFactory(SessionFactory factory) { public void unsetSessionFactory(SessionFactory factory) {
if ( log.isDebugEnabled() ) {
log.debugf( "Un-scoping TypeConfiguration [%s] from SessionFactory [%s]", this, factory ); log.debugf( "Un-scoping TypeConfiguration [%s] from SessionFactory [%s]", this, factory );
}
this.sessionFactory = null; this.sessionFactory = null;
} }