Skip to content

Commit

Permalink
HHH-12444 - Introduce BootstrapContext
Browse files Browse the repository at this point in the history
HHH-12443 - Introduce TypeConfiguration
  • Loading branch information
dreab8 authored and sebersole committed Mar 28, 2018
1 parent 55e73c7 commit 9229514
Show file tree
Hide file tree
Showing 59 changed files with 814 additions and 412 deletions.
Expand Up @@ -24,7 +24,6 @@


import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.boot.archive.spi.InputStreamAccess; import org.hibernate.boot.archive.spi.InputStreamAccess;
import org.hibernate.boot.internal.ClassmateContext;
import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.internal.MetadataBuilderImpl;
import org.hibernate.boot.jaxb.Origin; import org.hibernate.boot.jaxb.Origin;
import org.hibernate.boot.jaxb.SourceType; import org.hibernate.boot.jaxb.SourceType;
Expand Down Expand Up @@ -61,10 +60,10 @@ public class MetadataSources implements Serializable {


private XmlMappingBinderAccess xmlMappingBinderAccess; private XmlMappingBinderAccess xmlMappingBinderAccess;


private List<Binding> xmlBindings = new ArrayList<Binding>(); private List<Binding> xmlBindings = new ArrayList<>();
private LinkedHashSet<Class<?>> annotatedClasses = new LinkedHashSet<Class<?>>(); private LinkedHashSet<Class<?>> annotatedClasses = new LinkedHashSet<>();
private LinkedHashSet<String> annotatedClassNames = new LinkedHashSet<String>(); private LinkedHashSet<String> annotatedClassNames = new LinkedHashSet<>();
private LinkedHashSet<String> annotatedPackages = new LinkedHashSet<String>(); private LinkedHashSet<String> annotatedPackages = new LinkedHashSet<>();


public MetadataSources() { public MetadataSources() {
this( new BootstrapServiceRegistryBuilder().build() ); this( new BootstrapServiceRegistryBuilder().build() );
Expand Down Expand Up @@ -127,16 +126,6 @@ public MetadataBuilder getMetadataBuilder() {
return getCustomBuilderOrDefault( defaultBuilder ); return getCustomBuilderOrDefault( defaultBuilder );
} }


/**
* Get a builder for metadata where non-default options can be specified.
*
* @return The built metadata.
*/
public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry, ClassmateContext classmateContext) {
MetadataBuilderImpl defaultBuilder = new MetadataBuilderImpl( this, serviceRegistry, classmateContext );
return getCustomBuilderOrDefault( defaultBuilder );
}

/** /**
* Get a builder for metadata where non-default options can be specified. * Get a builder for metadata where non-default options can be specified.
* *
Expand All @@ -145,7 +134,8 @@ public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistr
*/ */
@Deprecated @Deprecated
public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry) { public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry) {
return getMetadataBuilder( serviceRegistry, new ClassmateContext() ); MetadataBuilderImpl defaultBuilder = new MetadataBuilderImpl( this, serviceRegistry );
return getCustomBuilderOrDefault( defaultBuilder );
} }


/** /**
Expand All @@ -163,7 +153,7 @@ private MetadataBuilder getCustomBuilderOrDefault(MetadataBuilderImpl defaultBui
final MetadataBuilder returnedBuilder = discoveredBuilderFactory.getMetadataBuilder( this, defaultBuilder ); final MetadataBuilder returnedBuilder = discoveredBuilderFactory.getMetadataBuilder( this, defaultBuilder );
if ( returnedBuilder != null ) { if ( returnedBuilder != null ) {
if ( activeFactoryNames == null ) { if ( activeFactoryNames == null ) {
activeFactoryNames = new ArrayList<String>(); activeFactoryNames = new ArrayList<>();
} }
activeFactoryNames.add( discoveredBuilderFactory.getClass().getName() ); activeFactoryNames.add( discoveredBuilderFactory.getClass().getName() );
builder = returnedBuilder; builder = returnedBuilder;
Expand Down
Expand Up @@ -32,7 +32,6 @@
import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.ClassLoaderAccess; import org.hibernate.boot.spi.ClassLoaderAccess;
import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider; import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunction;
Expand Down Expand Up @@ -73,10 +72,9 @@ public class BootstrapContextImpl implements BootstrapContext {


public BootstrapContextImpl( public BootstrapContextImpl(
StandardServiceRegistry serviceRegistry, StandardServiceRegistry serviceRegistry,
ClassmateContext classmateContext,
MetadataBuildingOptions metadataBuildingOptions) { MetadataBuildingOptions metadataBuildingOptions) {
this.serviceRegistry = serviceRegistry; this.serviceRegistry = serviceRegistry;
this.classmateContext = classmateContext; this.classmateContext = new ClassmateContext();
this.metadataBuildingOptions = metadataBuildingOptions; this.metadataBuildingOptions = metadataBuildingOptions;


final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
Expand Down
Expand Up @@ -377,6 +377,12 @@ private void addTypeDefinition(String registrationKey, TypeDefinition typeDefini
} }
} }


@Override
public ClassmateContext getClassmateContext() {
return bootstrapContext.getClassmateContext();
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// attribute converters // attribute converters


Expand Down Expand Up @@ -2219,7 +2225,7 @@ public boolean isInSecondPass() {
*/ */
public MetadataImpl buildMetadataInstance(MetadataBuildingContext buildingContext) { public MetadataImpl buildMetadataInstance(MetadataBuildingContext buildingContext) {
processSecondPasses( buildingContext ); processSecondPasses( buildingContext );
processExportableProducers( buildingContext ); processExportableProducers( );


try { try {
return new MetadataImpl( return new MetadataImpl(
Expand Down Expand Up @@ -2251,7 +2257,7 @@ public MetadataImpl buildMetadataInstance(MetadataBuildingContext buildingContex
} }
} }


private void processExportableProducers(MetadataBuildingContext buildingContext) { private void processExportableProducers() {
// for now we only handle id generators as ExportableProducers // for now we only handle id generators as ExportableProducers


final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect(); final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
Expand Down
Expand Up @@ -9,13 +9,15 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import javax.persistence.AttributeConverter; import javax.persistence.AttributeConverter;
import javax.persistence.SharedCacheMode; import javax.persistence.SharedCacheMode;


import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MultiTenancyStrategy; import org.hibernate.MultiTenancyStrategy;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.boot.AttributeConverterInfo; import org.hibernate.boot.AttributeConverterInfo;
import org.hibernate.boot.CacheRegionDefinition; import org.hibernate.boot.CacheRegionDefinition;
import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.MetadataBuilder;
Expand Down Expand Up @@ -84,11 +86,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
private final MetadataBuildingOptionsImpl options; private final MetadataBuildingOptionsImpl options;


public MetadataBuilderImpl(MetadataSources sources) { public MetadataBuilderImpl(MetadataSources sources) {
this( this( sources, getStandardServiceRegistry( sources.getServiceRegistry() ) );
sources,
getStandardServiceRegistry( sources.getServiceRegistry() ),
new ClassmateContext()
);
} }


private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) { private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
Expand Down Expand Up @@ -116,10 +114,12 @@ else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
} }
} }


public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry, ClassmateContext classmateContext) { public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry) {
this.sources = sources; this.sources = sources;
this.options = new MetadataBuildingOptionsImpl( serviceRegistry ); this.options = new MetadataBuildingOptionsImpl( serviceRegistry );
this.bootstrapContext = new BootstrapContextImpl( serviceRegistry, classmateContext, options ); this.bootstrapContext = new BootstrapContextImpl( serviceRegistry, options );
//this is needed only fro implementig deprecated method
options.setBootstrapContext( bootstrapContext );


for ( MetadataSourcesContributor contributor : for ( MetadataSourcesContributor contributor :
sources.getServiceRegistry() sources.getServiceRegistry()
Expand Down Expand Up @@ -312,7 +312,6 @@ public MetadataBuilder allowSpecjSyntax() {
return this; return this;
} }



@Override @Override
public MetadataBuilder applySqlFunction(String functionName, SQLFunction function) { public MetadataBuilder applySqlFunction(String functionName, SQLFunction function) {
this.bootstrapContext.addSqlFunction( functionName, function ); this.bootstrapContext.addSqlFunction( functionName, function );
Expand Down Expand Up @@ -436,11 +435,6 @@ public MetadataBuilder applyIdGenerationTypeInterpreter(IdGeneratorStrategyInter
return this; return this;
} }


// public MetadataBuilder with(PersistentAttributeMemberResolver resolver) {
// options.persistentAttributeMemberResolver = resolver;
// return this;
// }

@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends MetadataBuilder> T unwrap(Class<T> type) { public <T extends MetadataBuilder> T unwrap(Class<T> type) {
Expand Down Expand Up @@ -582,6 +576,8 @@ public static class MetadataBuildingOptionsImpl
implements MetadataBuildingOptions, JpaOrmXmlPersistenceUnitDefaultAware { implements MetadataBuildingOptions, JpaOrmXmlPersistenceUnitDefaultAware {
private final StandardServiceRegistry serviceRegistry; private final StandardServiceRegistry serviceRegistry;
private final MappingDefaultsImpl mappingDefaults; private final MappingDefaultsImpl mappingDefaults;
// todo (6.0) : remove bootstrapContext property along with the deprecated methods
private BootstrapContext bootstrapContext;


private ArrayList<BasicTypeRegistration> basicTypeRegistrations = new ArrayList<>(); private ArrayList<BasicTypeRegistration> basicTypeRegistrations = new ArrayList<>();


Expand All @@ -602,9 +598,6 @@ public static class MetadataBuildingOptionsImpl


private String schemaCharset; private String schemaCharset;


// private PersistentAttributeMemberResolver persistentAttributeMemberResolver =
// StandardPersistentAttributeMemberResolver.INSTANCE;

public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) { public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry; this.serviceRegistry = serviceRegistry;


Expand Down Expand Up @@ -769,6 +762,41 @@ public List<BasicTypeRegistration> getBasicTypeRegistrations() {
return basicTypeRegistrations; return basicTypeRegistrations;
} }


@Override
public ReflectionManager getReflectionManager() {
return bootstrapContext.getReflectionManager();
}

@Override
public IndexView getJandexView() {
return bootstrapContext.getJandexView();
}

@Override
public ScanOptions getScanOptions() {
return bootstrapContext.getScanOptions();
}

@Override
public ScanEnvironment getScanEnvironment() {
return bootstrapContext.getScanEnvironment();
}

@Override
public Object getScanner() {
return bootstrapContext.getScanner();
}

@Override
public ArchiveDescriptorFactory getArchiveDescriptorFactory() {
return bootstrapContext.getArchiveDescriptorFactory();
}

@Override
public ClassLoader getTempClassLoader() {
return bootstrapContext.getJpaTempClassLoader();
}

@Override @Override
public ImplicitNamingStrategy getImplicitNamingStrategy() { public ImplicitNamingStrategy getImplicitNamingStrategy() {
return implicitNamingStrategy; return implicitNamingStrategy;
Expand Down Expand Up @@ -799,6 +827,11 @@ public IdGeneratorStrategyInterpreter getIdGenerationTypeInterpreter() {
return idGenerationTypeInterpreter; return idGenerationTypeInterpreter;
} }


@Override
public List<CacheRegionDefinition> getCacheRegionDefinitions() {
return new ArrayList<>( bootstrapContext.getCacheRegionDefinitions() );
}

@Override @Override
public boolean ignoreExplicitDiscriminatorsForJoinedInheritance() { public boolean ignoreExplicitDiscriminatorsForJoinedInheritance() {
return !explicitDiscriminatorsForJoinedInheritanceSupported; return !explicitDiscriminatorsForJoinedInheritanceSupported;
Expand Down Expand Up @@ -829,6 +862,22 @@ public List<MetadataSourceType> getSourceProcessOrdering() {
return sourceProcessOrdering; return sourceProcessOrdering;
} }


@Override
public Map<String, SQLFunction> getSqlFunctions() {
return bootstrapContext.getSqlFunctions();
}

@Override
public List<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjectList() {
return new ArrayList<>( bootstrapContext.getAuxiliaryDatabaseObjectList());
}

@Override
public List<AttributeConverterInfo> getAttributeConverters() {
return new ArrayList<>( bootstrapContext.getAttributeConverters() );
}

@Override
public String getSchemaCharset() { public String getSchemaCharset() {
return schemaCharset; return schemaCharset;
} }
Expand Down Expand Up @@ -856,9 +905,8 @@ public void apply(JpaOrmXmlPersistenceUnitDefaults jpaOrmXmlPersistenceUnitDefau
} }
} }


// @Override public void setBootstrapContext(BootstrapContextImpl bootstrapContext) {
// public PersistentAttributeMemberResolver getPersistentAttributeMemberResolver() { this.bootstrapContext = bootstrapContext;
// return persistentAttributeMemberResolver; }
// }
} }
} }
Expand Up @@ -8,6 +8,7 @@


import org.hibernate.boot.model.naming.ObjectNameNormalizer; import org.hibernate.boot.model.naming.ObjectNameNormalizer;
import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.ClassLoaderAccess;
import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MappingDefaults; import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
Expand Down Expand Up @@ -59,6 +60,11 @@ public InFlightMetadataCollector getMetadataCollector() {
return metadataCollector; return metadataCollector;
} }


@Override
public ClassLoaderAccess getClassLoaderAccess() {
return bootstrapContext.getClassLoaderAccess();
}

@Override @Override
public ObjectNameNormalizer getObjectNameNormalizer() { public ObjectNameNormalizer getObjectNameNormalizer() {
return objectNameNormalizer; return objectNameNormalizer;
Expand Down
Expand Up @@ -430,6 +430,11 @@ public SessionFactoryBuilder enableJpaClosedCompliance(boolean enabled) {
return this; return this;
} }


@Override
public void markAsJpaBootstrap() {
this.bootstrapContext.markAsJpaBootstrap();
}

@Override @Override
public void disableRefreshDetachedEntity() { public void disableRefreshDetachedEntity() {
this.optionsBuilder.disableRefreshDetachedEntity(); this.optionsBuilder.disableRefreshDetachedEntity();
Expand Down
Expand Up @@ -116,7 +116,7 @@ public static Map<String, String> extractParameters(List<JaxbHbmConfigParameterT
if ( xmlParamElements == null || xmlParamElements.isEmpty() ) { if ( xmlParamElements == null || xmlParamElements.isEmpty() ) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
final HashMap<String,String> params = new HashMap<String, String>(); final HashMap<String,String> params = new HashMap<>();
for ( JaxbHbmConfigParameterType paramElement : xmlParamElements ) { for ( JaxbHbmConfigParameterType paramElement : xmlParamElements ) {
params.put( paramElement.getName(), paramElement.getValue() ); params.put( paramElement.getName(), paramElement.getValue() );
} }
Expand Down Expand Up @@ -200,8 +200,8 @@ public static TableSpecificationSource createTableSource(
return createTableSource( mappingDocument, entityElement, inLineViewNameInferrer, null, null, null ); return createTableSource( mappingDocument, entityElement, inLineViewNameInferrer, null, null, null );
} }


public static interface InLineViewNameInferrer { public interface InLineViewNameInferrer {
public String inferInLineViewName(); String inferInLineViewName();
} }


public static TableSpecificationSource createTableSource( public static TableSpecificationSource createTableSource(
Expand Down Expand Up @@ -270,20 +270,6 @@ public static Class reflectedPropertyClass(
MetadataBuildingContext buildingContext, MetadataBuildingContext buildingContext,
Class attributeOwnerClass, Class attributeOwnerClass,
final String attributeName) { final String attributeName) {
// return BeanInfoHelper.visitBeanInfo(
// attributeOwnerClass,
// new BeanInfoHelper.ReturningBeanInfoDelegate<Class>() {
// @Override
// public Class processBeanInfo(BeanInfo beanInfo) throws Exception {
// for ( PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors() ) {
// if ( propertyDescriptor.getName().equals( attributeName ) ) {
// return propertyDescriptor.getPropertyType();
// }
// }
// return null;
// }
// }
// );
return ReflectHelper.reflectedPropertyClass( attributeOwnerClass, attributeName ); return ReflectHelper.reflectedPropertyClass( attributeOwnerClass, attributeName );
} }
} }
Expand Up @@ -25,6 +25,7 @@
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor; import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
import org.hibernate.boot.model.source.spi.ToolingHintContext; import org.hibernate.boot.model.source.spi.ToolingHintContext;
import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.ClassLoaderAccess;
import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MappingDefaults; import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
Expand Down Expand Up @@ -142,6 +143,11 @@ public InFlightMetadataCollector getMetadataCollector() {
return rootBuildingContext.getMetadataCollector(); return rootBuildingContext.getMetadataCollector();
} }


@Override
public ClassLoaderAccess getClassLoaderAccess() {
return rootBuildingContext.getClassLoaderAccess();
}

@Override @Override
public ObjectNameNormalizer getObjectNameNormalizer() { public ObjectNameNormalizer getObjectNameNormalizer() {
return rootBuildingContext.getObjectNameNormalizer(); return rootBuildingContext.getObjectNameNormalizer();
Expand Down

0 comments on commit 9229514

Please sign in to comment.