HHH-12444 - Introduce BootstrapContext

HHH-12443 - Introduce TypeConfiguration
This commit is contained in:
Andrea Boriero 2018-03-23 13:41:09 +00:00 committed by Steve Ebersole
parent 170caf0076
commit 6f798598a2
6 changed files with 61 additions and 17 deletions

View File

@ -37,6 +37,11 @@ public interface MetadataImplementor extends Metadata, Mapping {
*/ */
MetadataBuildingOptions getMetadataBuildingOptions(); MetadataBuildingOptions getMetadataBuildingOptions();
/**
* Access to the TypeConfiguration
*
* @return Access to the TypeConfiguration
*/
TypeConfiguration getTypeConfiguration(); TypeConfiguration getTypeConfiguration();
/** /**

View File

@ -125,7 +125,6 @@ import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
import org.hibernate.type.SerializableType; import org.hibernate.type.SerializableType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.TypeResolver; import org.hibernate.type.TypeResolver;
import org.hibernate.type.spi.TypeConfiguration;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -173,7 +172,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
// todo : org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor too? // todo : org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor too?
private final transient MetamodelImpl metamodel; private final transient MetamodelImplementor metamodel;
private final transient CriteriaBuilderImpl criteriaBuilder; private final transient CriteriaBuilderImpl criteriaBuilder;
private final PersistenceUnitUtil jpaPersistenceUnitUtil; private final PersistenceUnitUtil jpaPersistenceUnitUtil;
private final transient CacheImplementor cacheAccess; private final transient CacheImplementor cacheAccess;
@ -189,7 +188,6 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
private final transient Map<String, FilterDefinition> filters; private final transient Map<String, FilterDefinition> filters;
private final transient Map<String, FetchProfile> fetchProfiles; private final transient Map<String, FetchProfile> fetchProfiles;
private final transient TypeResolver typeResolver;
private final transient TypeHelper typeHelper; private final transient TypeHelper typeHelper;
public SessionFactoryImpl( public SessionFactoryImpl(
@ -245,10 +243,8 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
for ( SessionFactoryObserver sessionFactoryObserver : options.getSessionFactoryObservers() ) { for ( SessionFactoryObserver sessionFactoryObserver : options.getSessionFactoryObservers() ) {
this.observer.addObserver( sessionFactoryObserver ); this.observer.addObserver( sessionFactoryObserver );
} }
TypeConfiguration typeConfiguration = metadata.getTypeConfiguration();
typeConfiguration.scope( this ); this.typeHelper = new TypeLocatorImpl( metadata.getTypeConfiguration().getTypeResolver() );
this.typeResolver = typeConfiguration.getTypeResolver();
this.typeHelper = new TypeLocatorImpl( typeResolver );
this.filters = new HashMap<>(); this.filters = new HashMap<>();
this.filters.putAll( metadata.getFilterDefinitions() ); this.filters.putAll( metadata.getFilterDefinitions() );
@ -295,8 +291,11 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
LOG.debug( "Instantiated session factory" ); LOG.debug( "Instantiated session factory" );
this.metamodel = new MetamodelImpl( this ); this.metamodel = metadata.getTypeConfiguration().scope( this , bootstrapContext);
this.metamodel.initialize( metadata, determineJpaMetaModelPopulationSetting( properties ) ); ( (MetamodelImpl) this.metamodel ).initialize(
metadata,
determineJpaMetaModelPopulationSetting( properties )
);
//Named Queries: //Named Queries:
this.namedQueryRepository = metadata.buildNamedQueryRepository( this ); this.namedQueryRepository = metadata.buildNamedQueryRepository( this );
@ -563,7 +562,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
*/ */
@Deprecated @Deprecated
public TypeResolver getTypeResolver() { public TypeResolver getTypeResolver() {
return typeResolver; return metamodel.getTypeConfiguration().getTypeResolver();
} }
public QueryPlanCache getQueryPlanCache() { public QueryPlanCache getQueryPlanCache() {

View File

@ -65,6 +65,7 @@ import org.hibernate.persister.spi.PersisterFactory;
import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;
/** /**
* Hibernate implementation of the JPA {@link javax.persistence.metamodel.Metamodel} contract. * Hibernate implementation of the JPA {@link javax.persistence.metamodel.Metamodel} contract.
@ -94,8 +95,11 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
private final transient Map<String,EntityGraph> entityGraphMap = new ConcurrentHashMap<>(); private final transient Map<String,EntityGraph> entityGraphMap = new ConcurrentHashMap<>();
public MetamodelImpl(SessionFactoryImplementor sessionFactory) { private final TypeConfiguration typeConfiguration;
public MetamodelImpl(SessionFactoryImplementor sessionFactory, TypeConfiguration typeConfiguration) {
this.sessionFactory = sessionFactory; this.sessionFactory = sessionFactory;
this.typeConfiguration = typeConfiguration;
} }
/** /**
@ -493,6 +497,11 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
// this.entityTypesByEntityName = entityTypesByEntityName; // this.entityTypesByEntityName = entityTypesByEntityName;
// } // }
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}
@Override @Override
public SessionFactoryImplementor getSessionFactory() { public SessionFactoryImplementor getSessionFactory() {
return sessionFactory; return sessionFactory;

View File

@ -18,11 +18,19 @@ import org.hibernate.Metamodel;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.spi.TypeConfiguration;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface MetamodelImplementor extends Metamodel { public interface MetamodelImplementor extends Metamodel {
/**
* Access to the TypeConfiguration in effect for this SessionFactory/Metamodel
*
* @return Access to the TypeConfiguration
*/
TypeConfiguration getTypeConfiguration();
@Override @Override
SessionFactoryImplementor getSessionFactory(); SessionFactoryImplementor getSessionFactory();

View File

@ -7,25 +7,27 @@
package org.hibernate.type.spi; package org.hibernate.type.spi;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Incubating; import org.hibernate.Incubating;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver; import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService; import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.internal.SessionFactoryRegistry; import org.hibernate.internal.SessionFactoryRegistry;
import org.hibernate.metamodel.internal.MetamodelImpl;
import org.hibernate.metamodel.spi.MetamodelImplementor;
import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.TypeFactory; import org.hibernate.type.TypeFactory;
import org.hibernate.type.TypeResolver; import org.hibernate.type.TypeResolver;
import org.jboss.logging.Logger;
import static org.hibernate.internal.CoreLogging.logger;
import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.CoreLogging.messageLogger;
/** /**
@ -57,6 +59,9 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
private final BasicTypeRegistry basicTypeRegistry; private final BasicTypeRegistry basicTypeRegistry;
private final Map<String,String> importMap = new ConcurrentHashMap<>();
// temporarily needed to support deprecations // temporarily needed to support deprecations
private final TypeResolver typeResolver; private final TypeResolver typeResolver;
@ -86,6 +91,10 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
return basicTypeRegistry; return basicTypeRegistry;
} }
public Map<String, String> getImportMap() {
return Collections.unmodifiableMap( importMap );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Scoping // Scoping
@ -108,10 +117,24 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
scope.setMetadataBuildingContext( metadataBuildingContext ); scope.setMetadataBuildingContext( metadataBuildingContext );
} }
public void scope(SessionFactoryImpl sessionFactory) { public MetamodelImplementor scope(SessionFactoryImplementor sessionFactory, BootstrapContext bootstrapContext) {
log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImpl [%s]", this, sessionFactory ); log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImpl [%s]", this, sessionFactory );
scope.setSessionFactory( sessionFactory ); scope.setSessionFactory( sessionFactory );
typeFactory.injectSessionFactory( sessionFactory ); typeFactory.injectSessionFactory( sessionFactory );
log.debugf( "Scoping TypeConfiguration [%s] to SessionFactory [%s]", this, sessionFactory );
for ( Map.Entry<String, String> importEntry : scope.metadataBuildingContext.getMetadataCollector().getImports().entrySet() ) {
if ( importMap.containsKey( importEntry.getKey() ) ) {
continue;
}
importMap.put( importEntry.getKey(), importEntry.getValue() );
}
scope.setSessionFactory( sessionFactory );
sessionFactory.addObserver( this );
MetamodelImpl metamodel = new MetamodelImpl( sessionFactory, this );
return metamodel;
} }
/** /**

View File

@ -94,7 +94,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
.addAnnotatedClass( WithGenericCollection.class ) .addAnnotatedClass( WithGenericCollection.class )
.buildMetadata(); .buildMetadata();
SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory(); SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory();
MetamodelImpl metamodel = new MetamodelImpl( sfi ); MetamodelImpl metamodel = new MetamodelImpl( sfi, ( (MetadataImplementor) metadata ).getTypeConfiguration() );
metamodel.initialize( (MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED ); metamodel.initialize( (MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED );
sfi.close(); sfi.close();
} }