Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public BootstrapContextImpl(
this.representationStrategySelector = ManagedTypeRepresentationResolverStandard.INSTANCE;

this.typeConfiguration = new TypeConfiguration();
this.beanInstanceProducer = new TypeBeanInstanceProducer( configService );
this.beanInstanceProducer = new TypeBeanInstanceProducer( configService, serviceRegistry );
this.sqmFunctionRegistry = new SqmFunctionRegistry();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
Expand Down Expand Up @@ -126,6 +125,7 @@
import static org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl.fromExplicit;
import static org.hibernate.cfg.MappingSettings.DEFAULT_CATALOG;
import static org.hibernate.cfg.MappingSettings.DEFAULT_SCHEMA;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize;

/**
Expand Down Expand Up @@ -409,7 +409,7 @@ public void addEntityBinding(PersistentClass persistentClass) throws DuplicateMa
throw new DuplicateMappingException( DuplicateMappingException.Type.ENTITY, entityName );
}

PersistentClass matchingPersistentClass = entityBindingMap.values()
final PersistentClass matchingPersistentClass = entityBindingMap.values()
.stream()
.filter( existingPersistentClass -> existingPersistentClass.getJpaEntityName().equals( jpaEntityName ) )
.findFirst()
Expand Down Expand Up @@ -503,11 +503,8 @@ public void registerEmbeddableInstantiator(Class<?> embeddableType, Class<? exte

@Override
public Class<? extends EmbeddableInstantiator> findRegisteredEmbeddableInstantiator(Class<?> embeddableType) {
if ( registeredInstantiators == null ) {
return null;
}
return registeredInstantiators == null ? null : registeredInstantiators.get( embeddableType );

return registeredInstantiators.get( embeddableType );
}

private Map<Class<?>, Class<? extends CompositeUserType<?>>> registeredCompositeUserTypes;
Expand All @@ -522,11 +519,8 @@ public void registerCompositeUserType(Class<?> embeddableType, Class<? extends C

@Override
public Class<? extends CompositeUserType<?>> findRegisteredCompositeUserType(Class<?> embeddableType) {
if ( registeredCompositeUserTypes == null ) {
return null;
}
return registeredCompositeUserTypes == null ? null : registeredCompositeUserTypes.get( embeddableType );

return registeredCompositeUserTypes.get( embeddableType );
}

private Map<Class<?>, Class<? extends UserType<?>>> registeredUserTypes;
Expand All @@ -540,11 +534,8 @@ public void registerUserType(Class<?> basicType, Class<? extends UserType<?>> us

@Override
public Class<? extends UserType<?>> findRegisteredUserType(Class<?> basicType) {
if ( registeredUserTypes == null ) {
return null;
}
return registeredUserTypes == null ? null : registeredUserTypes.get( basicType );

return registeredUserTypes.get( basicType );
}

private Map<CollectionClassification, CollectionTypeRegistrationDescriptor> collectionTypeRegistrations;
Expand Down Expand Up @@ -582,15 +573,16 @@ private CollectionTypeRegistrationDescriptor toDescriptor(CollectionTypeRegistra
}

private Map<String,String> extractParameters(Parameter[] annotationUsages) {
if ( CollectionHelper.isEmpty( annotationUsages ) ) {
if ( isEmpty( annotationUsages ) ) {
return null;
}

final Map<String,String> result = mapOfSize( annotationUsages.length );
for ( Parameter parameter : annotationUsages ) {
result.put( parameter.name(), parameter.value() );
else {
final Map<String, String> result = mapOfSize( annotationUsages.length );
for ( Parameter parameter : annotationUsages ) {
result.put( parameter.name(), parameter.value() );
}
return result;
}
return result;
}


Expand Down Expand Up @@ -703,7 +695,7 @@ public IdentifierGeneratorDefinition getIdentifierGenerator(String name) {

@Override
public java.util.Collection<Table> collectTableMappings() {
ArrayList<Table> tables = new ArrayList<>();
final ArrayList<Table> tables = new ArrayList<>();
for ( Namespace namespace : getDatabase().getNamespaces() ) {
tables.addAll( namespace.getTables() );
}
Expand All @@ -715,29 +707,27 @@ public void addIdentifierGenerator(IdentifierGeneratorDefinition generator) {
if ( generator == null || generator.getName() == null ) {
throw new IllegalArgumentException( "ID generator object or name is null." );
}

if ( generator.getName().isEmpty() ) {
return;
}

if ( defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {
return;
}

final IdentifierGeneratorDefinition old = idGeneratorDefinitionMap.put( generator.getName(), generator );
if ( old != null && !old.equals( generator ) ) {
if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
throw new IllegalArgumentException( "Duplicate generator name " + old.getName() + "; you will likely want to set the property " + AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE + " to false " );
}
else {
log.duplicateGeneratorName( old.getName() );
else if ( !generator.getName().isEmpty()
&& !defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {
final IdentifierGeneratorDefinition old =
idGeneratorDefinitionMap.put( generator.getName(), generator );
if ( old != null && !old.equals( generator ) ) {
if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
throw new IllegalArgumentException( "Duplicate generator name " + old.getName()
+ "; you will likely want to set the property "
+ AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE + " to false " );
}
else {
log.duplicateGeneratorName( old.getName() );
}
}
}

}

@Override
public void addDefaultIdentifierGenerator(IdentifierGeneratorDefinition generator) {
this.addIdentifierGenerator( generator );
addIdentifierGenerator( generator );
defaultIdentifierGeneratorNames.add( generator.getName() );
}

Expand All @@ -761,8 +751,7 @@ public void addNamedEntityGraph(NamedEntityGraphDefinition definition) {
final String name = definition.getRegisteredName();
final NamedEntityGraphDefinition previous = namedEntityGraphMap.put( name, definition );
if ( previous != null ) {
throw new DuplicateMappingException(
DuplicateMappingException.Type.NAMED_ENTITY_GRAPH, name );
throw new DuplicateMappingException( DuplicateMappingException.Type.NAMED_ENTITY_GRAPH, name );
}
}

Expand Down Expand Up @@ -790,12 +779,9 @@ public void addNamedQuery(NamedHqlQueryDefinition<?> def) {
else if ( def.getRegistrationName() == null ) {
throw new IllegalArgumentException( "Named query definition name is null: " + def.getHqlString() );
}

if ( defaultNamedQueryNames.contains( def.getRegistrationName() ) ) {
return;
else if ( !defaultNamedQueryNames.contains( def.getRegistrationName() ) ) {
applyNamedQuery( def.getRegistrationName(), def );
}

applyNamedQuery( def.getRegistrationName(), def );
}

private void applyNamedQuery(String name, NamedHqlQueryDefinition<?> query) {
Expand Down Expand Up @@ -833,15 +819,12 @@ public void addNamedNativeQuery(NamedNativeQueryDefinition<?> def) {
if ( def == null ) {
throw new IllegalArgumentException( "Named native query definition object is null" );
}
if ( def.getRegistrationName() == null ) {
else if ( def.getRegistrationName() == null ) {
throw new IllegalArgumentException( "Named native query definition name is null: " + def.getSqlQueryString() );
}

if ( defaultNamedNativeQueryNames.contains( def.getRegistrationName() ) ) {
return;
else if ( !defaultNamedNativeQueryNames.contains( def.getRegistrationName() ) ) {
applyNamedNativeQuery( def.getRegistrationName(), def );
}

applyNamedNativeQuery( def.getRegistrationName(), def );
}

private void applyNamedNativeQuery(String name, NamedNativeQueryDefinition<?> query) {
Expand Down Expand Up @@ -877,14 +860,11 @@ public void addNamedProcedureCallDefinition(NamedProcedureCallDefinition definit
}

final String name = definition.getRegistrationName();

if ( defaultNamedProcedureNames.contains( name ) ) {
return;
}

final NamedProcedureCallDefinition previous = namedProcedureCallMap.put( name, definition );
if ( previous != null ) {
throw new DuplicateMappingException( DuplicateMappingException.Type.PROCEDURE, name );
if ( !defaultNamedProcedureNames.contains( name ) ) {
final NamedProcedureCallDefinition previous = namedProcedureCallMap.put( name, definition );
if ( previous != null ) {
throw new DuplicateMappingException( DuplicateMappingException.Type.PROCEDURE, name );
}
}
}

Expand Down Expand Up @@ -918,12 +898,9 @@ public void addResultSetMapping(NamedResultSetMappingDescriptor resultSetMapping
if ( name == null ) {
throw new IllegalArgumentException( "Result-set mapping name is null: " + resultSetMappingDescriptor );
}

if ( defaultSqlResultSetMappingNames.contains( name ) ) {
return;
else if ( !defaultSqlResultSetMappingNames.contains( name ) ) {
applyResultSetMapping( resultSetMappingDescriptor );
}

applyResultSetMapping( resultSetMappingDescriptor );
}

public void applyResultSetMapping(NamedResultSetMappingDescriptor resultSetMappingDescriptor) {
Expand Down Expand Up @@ -1879,32 +1856,26 @@ public void processSecondPasses(MetadataBuildingContext buildingContext) {
}

private void processValueResolvers(MetadataBuildingContext buildingContext) {
if ( valueResolvers == null ) {
return;
}


while ( ! valueResolvers.isEmpty() ) {
final boolean anyRemoved = valueResolvers.removeIf(
resolver -> resolver.apply( buildingContext )
);
if ( valueResolvers != null ) {
while ( !valueResolvers.isEmpty() ) {
final boolean anyRemoved = valueResolvers.removeIf(
resolver -> resolver.apply( buildingContext )
);

if ( ! anyRemoved ) {
throw new MappingException( "Unable to complete initialization of boot meta-model" );
if ( !anyRemoved ) {
throw new MappingException( "Unable to complete initialization of boot meta-model" );
}
}
}
}

private void processSecondPasses(ArrayList<? extends SecondPass> secondPasses) {
if ( secondPasses == null ) {
return;
}

for ( SecondPass secondPass : secondPasses ) {
secondPass.doSecondPass( getEntityBindingMap() );
if ( secondPasses != null ) {
for ( SecondPass secondPass : secondPasses ) {
secondPass.doSecondPass( getEntityBindingMap() );
}
secondPasses.clear();
}

secondPasses.clear();
}

private void processFkSecondPassesInOrder() {
Expand All @@ -1915,8 +1886,8 @@ private void processFkSecondPassesInOrder() {

// split FkSecondPass instances into primary key and non primary key FKs.
// While doing so build a map of class names to FkSecondPass instances depending on this class.
Map<String, Set<FkSecondPass>> isADependencyOf = new HashMap<>();
List<FkSecondPass> endOfQueueFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
final Map<String, Set<FkSecondPass>> isADependencyOf = new HashMap<>();
final List<FkSecondPass> endOfQueueFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
for ( FkSecondPass sp : fkSecondPassList ) {
if ( sp.isInPrimaryKey() ) {
final String referenceEntityName = sp.getReferencedEntityName();
Expand All @@ -1933,7 +1904,7 @@ private void processFkSecondPassesInOrder() {
}

// using the isADependencyOf map we order the FkSecondPass recursively instances into the right order for processing
List<FkSecondPass> orderedFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
final List<FkSecondPass> orderedFkSecondPasses = new ArrayList<>( fkSecondPassList.size() );
for ( String tableName : isADependencyOf.keySet() ) {
buildRecursiveOrderedFkSecondPasses( orderedFkSecondPasses, isADependencyOf, tableName, tableName );
}
Expand Down Expand Up @@ -1968,7 +1939,7 @@ private void buildRecursiveOrderedFkSecondPasses(
Map<String, Set<FkSecondPass>> isADependencyOf,
String startTable,
String currentTable) {
Set<FkSecondPass> dependencies = isADependencyOf.get( currentTable );
final Set<FkSecondPass> dependencies = isADependencyOf.get( currentTable );
if ( dependencies != null ) {
for ( FkSecondPass pass : dependencies ) {
String dependentTable = pass.getValue().getTable().getQualifiedTableName().render();
Expand Down Expand Up @@ -2016,7 +1987,7 @@ private void processEndOfQueue(List<FkSecondPass> endOfQueueFkSecondPasses) {

private void secondPassCompileForeignKeys(MetadataBuildingContext buildingContext) {
int uniqueInteger = 0;
Set<ForeignKey> done = new HashSet<>();
final Set<ForeignKey> done = new HashSet<>();
for ( Table table : collectTableMappings() ) {
table.setUniqueInteger( uniqueInteger++ );
secondPassCompileForeignKeys( table, done, buildingContext );
Expand Down Expand Up @@ -2052,26 +2023,22 @@ protected void secondPassCompileForeignKeys(Table table, Set<ForeignKey> done, M
}

private void processPropertyReferences() {
if ( delayedPropertyReferenceHandlers == null ) {
return;
}
log.debug( "Processing association property references" );
if ( delayedPropertyReferenceHandlers != null ) {
log.debug( "Processing association property references" );

for ( DelayedPropertyReferenceHandler delayedPropertyReferenceHandler : delayedPropertyReferenceHandlers ) {
delayedPropertyReferenceHandler.process( this );
}
for ( DelayedPropertyReferenceHandler delayedPropertyReferenceHandler : delayedPropertyReferenceHandlers ) {
delayedPropertyReferenceHandler.process( this );
}

delayedPropertyReferenceHandlers.clear();
delayedPropertyReferenceHandlers.clear();
}
}

private Map<String,NaturalIdUniqueKeyBinder> naturalIdUniqueKeyBinderMap;

@Override
public NaturalIdUniqueKeyBinder locateNaturalIdUniqueKeyBinder(String entityName) {
if ( naturalIdUniqueKeyBinderMap == null ) {
return null;
}
return naturalIdUniqueKeyBinderMap.get( entityName );
return naturalIdUniqueKeyBinderMap == null ? null : naturalIdUniqueKeyBinderMap.get( entityName );
}

@Override
Expand All @@ -2086,15 +2053,12 @@ public void registerNaturalIdUniqueKeyBinder(String entityName, NaturalIdUniqueK
}

private void processNaturalIdUniqueKeyBinders() {
if ( naturalIdUniqueKeyBinderMap == null ) {
return;
}

for ( NaturalIdUniqueKeyBinder naturalIdUniqueKeyBinder : naturalIdUniqueKeyBinderMap.values() ) {
naturalIdUniqueKeyBinder.process();
if ( naturalIdUniqueKeyBinderMap != null ) {
for ( NaturalIdUniqueKeyBinder naturalIdUniqueKeyBinder : naturalIdUniqueKeyBinderMap.values() ) {
naturalIdUniqueKeyBinder.process();
}
naturalIdUniqueKeyBinderMap.clear();
}

naturalIdUniqueKeyBinderMap.clear();
}

private void processCachingOverrides() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.type.spi.TypeBootstrapContext;
import org.hibernate.service.ServiceRegistry;

import java.lang.reflect.Constructor;
import java.util.Map;
Expand All @@ -22,9 +23,11 @@
@Internal
public class TypeBeanInstanceProducer implements BeanInstanceProducer, TypeBootstrapContext {
private final ConfigurationService configurationService;
private final ServiceRegistry serviceRegistry;

public TypeBeanInstanceProducer(ConfigurationService configurationService) {
public TypeBeanInstanceProducer(ConfigurationService configurationService, ServiceRegistry serviceRegistry) {
this.configurationService = configurationService;
this.serviceRegistry = serviceRegistry;
}

@Override
Expand Down Expand Up @@ -64,4 +67,9 @@ public <B> B produceBeanInstance(String name, Class<B> beanType) {
public Map<String, Object> getConfigurationSettings() {
return configurationService.getSettings();
}

@Override
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
}
Loading
Loading