diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java index ea474a3aeb..2b74ab5a0c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java @@ -105,7 +105,7 @@ public class TemporaryTable implements Exportable, Contributable { else { tableNameIdentifier = new Identifier( temporaryTableName, nameParts.getObjectName().isQuoted() ); } - this.qualifiedTableName = creationContext.getSessionFactory().getSqlStringGenerationContext().format( + this.qualifiedTableName = creationContext.getSqlStringGenerationContext().format( new QualifiedTableName( adjustedNameParts.getCatalogName() != null ? adjustedNameParts.getCatalogName() diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index bf1976a9cc..ccd91260d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -108,6 +108,7 @@ import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; +import org.hibernate.service.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.SessionFactoryServiceRegistry; import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory; @@ -321,6 +322,16 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { public JdbcServices getJdbcServices() { return jdbcServices; } + + @Override + public SqlStringGenerationContext getSqlStringGenerationContext() { + return sqlStringGenerationContext; + } + + @Override + public ServiceRegistry getServiceRegistry() { + return serviceRegistry; + } }; // this needs to happen after persisters are all ready to go... diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java index 76596c8a20..0b642a3300 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java @@ -498,12 +498,12 @@ public class Property implements Serializable, MetaAttributable { @Override public String getDefaultCatalog() { - return context.getSessionFactory().getSessionFactoryOptions().getDefaultCatalog(); + return context.getSessionFactoryOptions().getDefaultCatalog(); } @Override public String getDefaultSchema() { - return context.getSessionFactory().getSessionFactoryOptions().getDefaultSchema(); + return context.getSessionFactoryOptions().getDefaultSchema(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java index 392cec8d10..f306f70cbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java @@ -62,18 +62,9 @@ public class EmbeddableRepresentationStrategyPojo extends AbstractEmbeddableRepr assert bootDescriptor.getComponentClass() != null; - this.strategySelector = creationContext.getSessionFactory() - .getServiceRegistry() - .getService( StrategySelector.class ); + this.strategySelector = creationContext.getServiceRegistry().getService( StrategySelector.class ); this.reflectionOptimizer = buildReflectionOptimizer( bootDescriptor, creationContext ); - final ConfigurationService configurationService = creationContext.getMetadata().getMetadataBuildingOptions().getServiceRegistry() - .getService(ConfigurationService.class); - boolean createEmptyCompositesEnabled = ConfigurationHelper.getBoolean( - Environment.CREATE_EMPTY_COMPOSITES_ENABLED, - configurationService.getSettings(), - false - ); this.instantiator = customInstantiator != null ? customInstantiator @@ -108,13 +99,12 @@ public class EmbeddableRepresentationStrategyPojo extends AbstractEmbeddableRepr } if ( bootDescriptor.isEmbedded() && ReflectHelper.isAbstractClass( bootDescriptor.getComponentClass() ) ) { - final ProxyFactoryFactory proxyFactoryFactory = creationContext.getSessionFactory() - .getServiceRegistry() - .getService( ProxyFactoryFactory.class ); return new EmbeddableInstantiatorProxied( bootDescriptor.getComponentClass(), runtimeDescriptorAccess, - proxyFactoryFactory.buildBasicProxyFactory( bootDescriptor.getComponentClass() ) + creationContext.getServiceRegistry() + .getService( ProxyFactoryFactory.class ) + .buildBasicProxyFactory( bootDescriptor.getComponentClass() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java index f6114acd37..4e479ed48e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java @@ -80,9 +80,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent PersistentClass bootDescriptor, EntityPersister runtimeDescriptor, RuntimeModelCreationContext creationContext) { - final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); - final JavaTypeRegistry jtdRegistry = creationContext.getTypeConfiguration() - .getJavaTypeRegistry(); + final JavaTypeRegistry jtdRegistry = creationContext.getTypeConfiguration().getJavaTypeRegistry(); final Class mappedJavaType = bootDescriptor.getMappedClass(); this.mappedJtd = jtdRegistry.resolveEntityTypeDescriptor( mappedJavaType ); @@ -156,13 +154,13 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent this.proxyFactory = proxyFactory; // resolveReflectionOptimizer may lead to a makePropertyAccess call which requires strategySelector - this.strategySelector = sessionFactory.getServiceRegistry().getService( StrategySelector.class ); + this.strategySelector = creationContext.getServiceRegistry().getService( StrategySelector.class ); final Map propertyAccessMap = new LinkedHashMap<>(); for ( Property property : bootDescriptor.getPropertyClosure() ) { propertyAccessMap.put( property.getName(), makePropertyAccess( property ) ); } this.propertyAccessMap = propertyAccessMap; - this.reflectionOptimizer = resolveReflectionOptimizer( bootDescriptor, bytecodeProvider, sessionFactory ); + this.reflectionOptimizer = resolveReflectionOptimizer( bytecodeProvider ); this.instantiator = determineInstantiator( bootDescriptor, entityMetamodel ); } @@ -268,9 +266,10 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent ? null : ReflectHelper.getMethod( proxyInterface, idSetterMethod ); - ProxyFactory pf = bytecodeProvider.getProxyFactoryFactory().buildProxyFactory( creationContext.getSessionFactory() ); + final ProxyFactory proxyFactory = bytecodeProvider.getProxyFactoryFactory() + .buildProxyFactory( creationContext.getSessionFactory() ); try { - pf.postInstantiate( + proxyFactory.postInstantiate( bootDescriptor.getEntityName(), mappedClass, proxyInterfaces, @@ -281,7 +280,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent null ); - return pf; + return proxyFactory; } catch (HibernateException he) { LOG.unableToCreateProxyFactory( bootDescriptor.getEntityName(), he ); @@ -289,10 +288,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent } } - private ReflectionOptimizer resolveReflectionOptimizer( - PersistentClass bootType, - BytecodeProvider bytecodeProvider, - SessionFactoryImplementor sessionFactory) { + private ReflectionOptimizer resolveReflectionOptimizer(BytecodeProvider bytecodeProvider) { if ( ! Environment.useReflectionOptimizer() ) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java index 49956adde9..2a35eb9753 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java @@ -18,7 +18,6 @@ import org.hibernate.engine.FetchTiming; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.mapping.Any; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Column; @@ -223,9 +222,8 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType Consumer attributeConsumer, SuccessfulCompletionCallback completionCallback, MappingModelCreationProcess creationProcess) { - final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); - final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration(); - final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); + final TypeConfiguration typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration(); + final JdbcServices jdbcServices = creationProcess.getCreationContext().getJdbcServices(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); final Dialect dialect = jdbcEnvironment.getDialect(); @@ -332,42 +330,10 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType final boolean updateable = value.isColumnUpdateable( 0 ); final boolean includeInOptimisticLocking = bootPropertyDescriptor.isOptimisticLocked(); final CascadeStyle cascadeStyle = compositeType.getCascadeStyle( attributeIndex ); - final MutabilityPlan mutabilityPlan; - - if ( updateable ) { - mutabilityPlan = new MutabilityPlan<>() { - @Override - public boolean isMutable() { - return true; - } - - @Override - public Object deepCopy(Object value) { - if ( value == null ) { - return null; - } - - return anyType.deepCopy( value, creationProcess.getCreationContext().getSessionFactory() ); - } - - @Override - public Serializable disassemble(Object value, SharedSessionContract session) { - throw new UnsupportedOperationException(); - } - - @Override - public Object assemble(Serializable cached, SharedSessionContract session) { - throw new UnsupportedOperationException(); - } - }; - } - else { - mutabilityPlan = ImmutableMutabilityPlan.INSTANCE; - } SimpleAttributeMetadata attributeMetadataAccess = new SimpleAttributeMetadata( propertyAccess, - mutabilityPlan, + getMutabilityPlan( updateable ), nullable, insertable, updateable, @@ -392,7 +358,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType } else if ( subtype instanceof CompositeType ) { final CompositeType subCompositeType = (CompositeType) subtype; - final int columnSpan = subCompositeType.getColumnSpan( sessionFactory ); + final int columnSpan = subCompositeType.getColumnSpan( creationProcess.getCreationContext().getMetadata() ); final String subTableExpression; final String[] subRootTableKeyColumnNames; if ( rootTableKeyColumnNames == null ) { @@ -476,4 +442,33 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType return true; } + + private static MutabilityPlan getMutabilityPlan(boolean updateable) { + if ( updateable ) { + return new MutabilityPlan<>() { + @Override + public boolean isMutable() { + return true; + } + + @Override + public Object deepCopy(Object value) { + return value; + } + + @Override + public Serializable disassemble(Object value, SharedSessionContract session) { + throw new UnsupportedOperationException(); + } + + @Override + public Object assemble(Serializable cached, SharedSessionContract session) { + throw new UnsupportedOperationException(); + } + }; + } + else { + return ImmutableMutabilityPlan.INSTANCE; + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java index 7a233ff7d0..964a208663 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedAssociationMapping.java @@ -63,9 +63,8 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption AnyType anyType, Any bootValueMapping, MappingModelCreationProcess creationProcess) { - final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); - final Dialect dialect = sessionFactory.getSqlStringGenerationContext().getDialect(); + final Dialect dialect = creationProcess.getCreationContext().getDialect(); final String tableName = MappingModelCreationHelper.getTableIdentifierExpression( bootValueMapping.getTable(), creationProcess @@ -126,7 +125,7 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption ? FetchTiming.DELAYED : FetchTiming.IMMEDIATE, bootValueMapping.getMetaValues(), - sessionFactory + creationProcess.getCreationContext().getSessionFactory() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedCollectionPart.java index 4cf112f658..52c2d51024 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/DiscriminatedCollectionPart.java @@ -10,7 +10,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import org.hibernate.engine.FetchTiming; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.mapping.Any; import org.hibernate.mapping.IndexedConsumer; @@ -50,7 +49,6 @@ import org.hibernate.type.descriptor.java.JavaType; */ public class DiscriminatedCollectionPart implements DiscriminatedAssociationModelPart, CollectionPart { private final Nature nature; - private final SessionFactoryImplementor sessionFactory; private final NavigableRole partRole; private final CollectionPersister collectionDescriptor; @@ -75,8 +73,6 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode bootValueMapping, creationProcess ); - - sessionFactory = creationProcess.getCreationContext().getSessionFactory(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java index 9584cb2b2c..600c7a64b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java @@ -22,7 +22,6 @@ import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.mapping.AggregateColumn; @@ -168,20 +167,14 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme this.embeddableJtd = representationStrategy.getMappedJavaType(); this.valueMapping = embeddedPartBuilder.apply( this ); - final ConfigurationService cs = creationContext.getSessionFactory().getServiceRegistry() - .getService(ConfigurationService.class); - this.createEmptyCompositesEnabled = ConfigurationHelper.getBoolean( Environment.CREATE_EMPTY_COMPOSITES_ENABLED, - cs.getSettings(), + creationContext.getServiceRegistry().getService( ConfigurationService.class ).getSettings(), false ); final AggregateColumn aggregateColumn = bootDescriptor.getAggregateColumn(); if ( aggregateColumn != null ) { - final Dialect dialect = creationContext.getBootstrapContext() - .getServiceRegistry() - .getService( JdbcServices.class ) - .getDialect(); + final Dialect dialect = creationContext.getDialect(); final boolean insertable; final boolean updatable; if ( componentProperty == null ) { @@ -330,9 +323,8 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme // ); // todo (6.0) - get this ^^ to work, or drop the comment - final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); - final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration(); - final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); + final TypeConfiguration typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration(); + final JdbcServices jdbcServices = creationProcess.getCreationContext().getJdbcServices(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); final Dialect dialect = jdbcEnvironment.getDialect(); @@ -442,42 +434,10 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme final boolean updateable = updateability[columnPosition]; final boolean includeInOptimisticLocking = bootPropertyDescriptor.isOptimisticLocked(); final CascadeStyle cascadeStyle = compositeType.getCascadeStyle( attributeIndex ); - final MutabilityPlan mutabilityPlan; - - if ( updateable ) { - mutabilityPlan = new MutabilityPlan<>() { - @Override - public boolean isMutable() { - return true; - } - - @Override - public Object deepCopy(Object value) { - if ( value == null ) { - return null; - } - - return anyType.deepCopy( value, creationProcess.getCreationContext().getSessionFactory() ); - } - - @Override - public Serializable disassemble(Object value, SharedSessionContract session) { - throw new UnsupportedOperationException(); - } - - @Override - public Object assemble(Serializable cached, SharedSessionContract session) { - throw new UnsupportedOperationException(); - } - }; - } - else { - mutabilityPlan = ImmutableMutabilityPlan.INSTANCE; - } SimpleAttributeMetadata attributeMetadataAccess = new SimpleAttributeMetadata( propertyAccess, - mutabilityPlan, + getMutabilityPlan( updateable ), nullable, insertable, updateable, @@ -502,7 +462,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme } else if ( subtype instanceof CompositeType ) { final CompositeType subCompositeType = (CompositeType) subtype; - final int columnSpan = subCompositeType.getColumnSpan( sessionFactory ); + final int columnSpan = subCompositeType.getColumnSpan( creationProcess.getCreationContext().getMetadata() ); final String subTableExpression; final String[] subRootTableKeyColumnNames; if ( rootTableKeyColumnNames == null ) { @@ -589,6 +549,35 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme return true; } + private static MutabilityPlan getMutabilityPlan(boolean updateable) { + if ( updateable ) { + return new MutabilityPlan<>() { + @Override + public boolean isMutable() { + return true; + } + + @Override + public Object deepCopy(Object value) { + return value; + } + + @Override + public Serializable disassemble(Object value, SharedSessionContract session) { + throw new UnsupportedOperationException(); + } + + @Override + public Object assemble(Serializable cached, SharedSessionContract session) { + throw new UnsupportedOperationException(); + } + }; + } + else { + return ImmutableMutabilityPlan.INSTANCE; + } + } + private boolean initColumnMappings() { this.selectableMappings = SelectableMappingsImpl.from( this ); return true; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java index c721aaa88c..a0f60fc1d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java @@ -82,7 +82,7 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden this.idMapping = idMapping; this.virtualIdEmbeddable = virtualIdEmbeddable; - this.javaType = creationProcess.getCreationContext().getSessionFactory().getTypeConfiguration() + this.javaType = creationProcess.getCreationContext().getTypeConfiguration() .getJavaTypeRegistry() .resolveManagedTypeDescriptor( idClassSource.getComponentClass() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ManyToManyCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ManyToManyCollectionPart.java index cb7b3ba1af..4391f9a07c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ManyToManyCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ManyToManyCollectionPart.java @@ -471,7 +471,7 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple true, false, false, - creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect(), + creationProcess.getCreationContext().getJdbcServices().getDialect(), creationProcess.getSqmFunctionRegistry() ); @@ -503,11 +503,11 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple collectionTableName, elementBootDescriptor, getPropertyOrder( elementBootDescriptor, creationProcess ), - creationProcess.getCreationContext().getSessionFactory(), + creationProcess.getCreationContext().getMetadata(), creationProcess.getCreationContext().getTypeConfiguration(), elementBootDescriptor.getColumnInsertability(), elementBootDescriptor.getColumnUpdateability(), - creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect(), + creationProcess.getCreationContext().getDialect(), creationProcess.getSqmFunctionRegistry() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 23b7188f9c..098d0c587c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -322,12 +322,27 @@ public class MappingModelCreationHelper { PropertyAccess propertyAccess, CascadeStyle cascadeStyle, MappingModelCreationProcess creationProcess) { - final MutabilityPlan mutabilityPlan; - if ( bootProperty.isUpdateable() ) { - mutabilityPlan = new MutabilityPlan() { + final MutabilityPlan mutabilityPlan = getMutabilityPlan( bootProperty, attrType, creationProcess ); + return new SimpleAttributeMetadata( + propertyAccess, + mutabilityPlan, + bootProperty.getValue().isNullable(), + bootProperty.isInsertable(), + bootProperty.isUpdateable(), + bootProperty.isOptimisticLocked(), + cascadeStyle + ); + } - final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext() - .getSessionFactory(); + private static MutabilityPlan getMutabilityPlan( + Property bootProperty, + Type attrType, + MappingModelCreationProcess creationProcess) { + if ( bootProperty.isUpdateable() ) { + return new MutabilityPlan() { + + final SessionFactoryImplementor sessionFactory = + creationProcess.getCreationContext().getSessionFactory(); @Override public boolean isMutable() { @@ -355,16 +370,8 @@ public class MappingModelCreationHelper { }; } else { - mutabilityPlan = ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.INSTANCE; } - SimpleAttributeMetadata basicAttributeMetadataAccess = new SimpleAttributeMetadata( propertyAccess, - mutabilityPlan, - bootProperty.getValue().isNullable(), - bootProperty.isInsertable(), - bootProperty.isUpdateable(), - bootProperty.isOptimisticLocked(), - cascadeStyle ); - return basicAttributeMetadataAccess; } @SuppressWarnings("rawtypes") @@ -387,8 +394,7 @@ public class MappingModelCreationHelper { final Collection bootValueMapping = (Collection) bootProperty.getValue(); final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); - final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); - final Dialect dialect = sessionFactory.getSqlStringGenerationContext().getDialect(); + final Dialect dialect = creationContext.getDialect(); final MappingMetamodel domainModel = creationContext.getDomainModel(); final CollectionPersister collectionDescriptor = domainModel.findCollectionDescriptor( bootValueMapping.getRole() ); @@ -562,6 +568,7 @@ public class MappingModelCreationHelper { cascadeStyle ); + final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); final FetchStyle style = FetchOptionsHelper.determineFetchStyleByMetadata( fetchMode, collectionDescriptor.getCollectionType(), @@ -996,7 +1003,7 @@ public class MappingModelCreationHelper { keyTableExpression, collectionBootValueMapping.getKey(), getPropertyOrder( bootValueMapping, creationProcess ), - creationProcess.getCreationContext().getSessionFactory(), + creationProcess.getCreationContext().getMetadata(), creationProcess.getCreationContext().getTypeConfiguration(), insertable, updateable, @@ -1020,7 +1027,7 @@ public class MappingModelCreationHelper { keyTableExpression, bootValueMapping, getPropertyOrder( bootValueMapping, creationProcess ), - creationProcess.getCreationContext().getSessionFactory(), + creationProcess.getCreationContext().getMetadata(), creationProcess.getCreationContext().getTypeConfiguration(), insertable, updateable, @@ -1078,7 +1085,7 @@ public class MappingModelCreationHelper { else { final EntityType entityType = (EntityType) bootValueMapping.getType(); final Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType( - creationProcess.getCreationContext().getSessionFactory() + creationProcess.getCreationContext().getMetadata() ); if ( identifierOrUniqueKeyType instanceof ComponentType ) { componentType = (ComponentType) identifierOrUniqueKeyType; @@ -1142,7 +1149,12 @@ public class MappingModelCreationHelper { } public static String getTableIdentifierExpression(Table table, MappingModelCreationProcess creationProcess) { - return getTableIdentifierExpression( table, creationProcess.getCreationContext().getSessionFactory() ); + if ( table.getSubselect() != null ) { + return "( " + table.getSubselect() + " )"; + } + + return creationProcess.getCreationContext().getSqlStringGenerationContext() + .format( table.getQualifiedTableName() ); } public static String getTableIdentifierExpression(Table table, SessionFactoryImplementor sessionFactory) { @@ -1150,7 +1162,8 @@ public class MappingModelCreationHelper { return "( " + table.getSubselect() + " )"; } - return sessionFactory.getSqlStringGenerationContext().format( table.getQualifiedTableName() ); + return sessionFactory.getSqlStringGenerationContext() + .format( table.getQualifiedTableName() ); } private static CollectionPart interpretMapKey( @@ -1225,10 +1238,6 @@ public class MappingModelCreationHelper { final EntityType indexEntityType = (EntityType) collectionDescriptor.getIndexType(); final EntityPersister associatedEntity = creationProcess.getEntityPersister( indexEntityType.getAssociatedEntityName() ); - final EntityCollectionPart.Cardinality partCardinality = bootMapKeyDescriptor instanceof OneToMany - ? EntityCollectionPart.Cardinality.ONE_TO_MANY - : EntityCollectionPart.Cardinality.MANY_TO_MANY; - final EntityCollectionPart indexDescriptor; if ( bootMapKeyDescriptor instanceof OneToMany ) { indexDescriptor = new OneToManyCollectionPart( @@ -1324,8 +1333,7 @@ public class MappingModelCreationHelper { if ( element instanceof Any ) { final Any anyBootMapping = (Any) element; - final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); - final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration(); + final TypeConfiguration typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration(); final JavaTypeRegistry jtdRegistry = typeConfiguration.getJavaTypeRegistry(); final JavaType baseJtd = jtdRegistry.getDescriptor(Object.class); @@ -1521,7 +1529,7 @@ public class MappingModelCreationHelper { cascadeStyle, creationProcess ); - SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); + final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); final AssociationType type = (AssociationType) bootProperty.getType(); final FetchStyle fetchStyle = FetchOptionsHelper @@ -1571,21 +1579,14 @@ public class MappingModelCreationHelper { creationProcess.registerForeignKeyPostInitCallbacks( "To-one key - " + navigableRole, - () -> { - final Dialect dialect = creationProcess.getCreationContext() - .getSessionFactory() - .getJdbcServices() - .getDialect(); - - return MappingModelCreationHelper.interpretToOneKeyDescriptor( - attributeMapping, - bootProperty, - (ToOne) bootProperty.getValue(), - null, - dialect, - creationProcess - ); - } + () -> MappingModelCreationHelper.interpretToOneKeyDescriptor( + attributeMapping, + bootProperty, + (ToOne) bootProperty.getValue(), + null, + creationProcess.getCreationContext().getDialect(), + creationProcess + ) ); return attributeMapping; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java index 530cc64b25..148abb26ed 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java @@ -52,9 +52,7 @@ public class SimpleNaturalIdMapping extends AbstractNaturalIdMapping implements ); this.attribute = attribute; - typeConfiguration = creationProcess.getCreationContext() - .getSessionFactory() - .getTypeConfiguration(); + typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java index d983607950..3289e22f23 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java @@ -38,13 +38,12 @@ public class VirtualIdRepresentationStrategy implements EmbeddableRepresentation RuntimeModelCreationContext creationContext) { this.entityMappingType = entityMappingType; if ( bootDescriptor.getComponentClassName() != null && ReflectHelper.isAbstractClass( bootDescriptor.getComponentClass() ) ) { - final ProxyFactoryFactory proxyFactoryFactory = creationContext.getSessionFactory() - .getServiceRegistry() - .getService( ProxyFactoryFactory.class ); this.instantiator = new EmbeddableInstantiatorProxied( bootDescriptor.getComponentClass(), () -> virtualIdEmbeddable, - proxyFactoryFactory.buildBasicProxyFactory( bootDescriptor.getComponentClass() ) + creationContext.getServiceRegistry() + .getService( ProxyFactoryFactory.class ) + .buildBasicProxyFactory( bootDescriptor.getComponentClass() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java index e3da815e3e..9bea05bd6e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java @@ -6,6 +6,7 @@ */ package org.hibernate.metamodel.spi; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; @@ -15,6 +16,7 @@ import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.query.sqm.function.SqmFunctionRegistry; +import org.hibernate.service.ServiceRegistry; import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; import org.hibernate.type.spi.TypeConfiguration; @@ -56,4 +58,8 @@ public interface RuntimeModelCreationContext extends PersisterCreationContext { SessionFactoryOptions getSessionFactoryOptions(); JdbcServices getJdbcServices(); + + SqlStringGenerationContext getSqlStringGenerationContext(); + + ServiceRegistry getServiceRegistry(); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index ec9f48ee88..825c92d36e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -272,7 +272,7 @@ public abstract class AbstractCollectionPersister this.factory = creationContext.getSessionFactory(); this.cacheAccessStrategy = cacheAccessStrategy; - if ( factory.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() ) { + if ( creationContext.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() ) { cacheEntryStructure = collectionBootDescriptor.isMap() ? StructuredMapCacheEntry.INSTANCE : StructuredCollectionCacheEntry.INSTANCE; @@ -281,8 +281,8 @@ public abstract class AbstractCollectionPersister cacheEntryStructure = UnstructuredCacheEntry.INSTANCE; } - dialect = factory.getJdbcServices().getDialect(); - sqlExceptionHelper = factory.getJdbcServices().getSqlExceptionHelper(); + dialect = creationContext.getDialect(); + sqlExceptionHelper = creationContext.getJdbcServices().getSqlExceptionHelper(); collectionType = collectionBootDescriptor.getCollectionType(); navigableRole = new NavigableRole( collectionBootDescriptor.getRole() ); entityName = collectionBootDescriptor.getOwnerEntityName(); @@ -316,8 +316,8 @@ public abstract class AbstractCollectionPersister sqlWhereStringTemplate = Template.renderWhereStringTemplate( sqlWhereString, dialect, - factory.getTypeConfiguration(), - factory.getQueryEngine().getSqmFunctionRegistry() + creationContext.getTypeConfiguration(), + creationContext.getFunctionRegistry() ); } else { @@ -330,7 +330,7 @@ public abstract class AbstractCollectionPersister int batch = collectionBootDescriptor.getBatchSize(); if ( batch == -1 ) { - batch = factory.getSessionFactoryOptions().getDefaultBatchFetchSize(); + batch = creationContext.getSessionFactoryOptions().getDefaultBatchFetchSize(); } batchSize = batch; @@ -389,8 +389,8 @@ public abstract class AbstractCollectionPersister Formula form = (Formula) selectable; elementFormulaTemplates[j] = form.getTemplate( dialect, - factory.getTypeConfiguration(), - factory.getQueryEngine().getSqmFunctionRegistry() + creationContext.getTypeConfiguration(), + creationContext.getFunctionRegistry() ); elementFormulas[j] = form.getFormula(); } @@ -401,8 +401,8 @@ public abstract class AbstractCollectionPersister elementColumnReaders[j] = col.getReadExpr( dialect ); elementColumnReaderTemplates[j] = col.getTemplate( dialect, - factory.getTypeConfiguration(), - factory.getQueryEngine().getSqmFunctionRegistry() + creationContext.getTypeConfiguration(), + creationContext.getFunctionRegistry() ); elementColumnIsGettable[j] = true; if ( elementType.isComponentType() ) { @@ -454,8 +454,8 @@ public abstract class AbstractCollectionPersister Formula indexForm = (Formula) s; indexFormulaTemplates[i] = indexForm.getTemplate( dialect, - factory.getTypeConfiguration(), - factory.getQueryEngine().getSqmFunctionRegistry() + creationContext.getTypeConfiguration(), + creationContext.getFunctionRegistry() ); indexFormulas[i] = indexForm.getFormula(); hasFormula = true; @@ -548,10 +548,7 @@ public abstract class AbstractCollectionPersister ); } else if ( !elementType.isEntityType() ) { - elementPropertyMapping = new ElementPropertyMapping( - elementColumnNames, - elementType - ); + elementPropertyMapping = new ElementPropertyMapping( elementColumnNames, elementType ); } else { // not all entity-persisters implement PropertyMapping! @@ -590,9 +587,9 @@ public abstract class AbstractCollectionPersister manyToManyWhereString = "( " + collectionBootDescriptor.getManyToManyWhere() + ")"; manyToManyWhereTemplate = Template.renderWhereStringTemplate( manyToManyWhereString, - factory.getJdbcServices().getDialect(), - factory.getTypeConfiguration(), - factory.getQueryEngine().getSqmFunctionRegistry() + creationContext.getDialect(), + creationContext.getTypeConfiguration(), + creationContext.getFunctionRegistry() ); } @@ -624,14 +621,14 @@ public abstract class AbstractCollectionPersister private BeforeExecutionGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) { final Generator generator = collection.getIdentifier().createGenerator( context.getBootstrapContext().getIdentifierGeneratorFactory(), - factory.getJdbcServices().getDialect(), + context.getDialect(), null ); if ( generator.generatedOnExecution() ) { throw new MappingException("must be an BeforeExecutionGenerator"); //TODO fix message } if ( generator instanceof IdentifierGenerator ) { - ( (IdentifierGenerator) generator ).initialize( context.getSessionFactory().getSqlStringGenerationContext() ); + ( (IdentifierGenerator) generator ).initialize( context.getSqlStringGenerationContext() ); } return (BeforeExecutionGenerator) generator; } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java index af3ffbe983..9b6be4b168 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/OneToManyPersister.java @@ -113,7 +113,7 @@ public class OneToManyPersister extends AbstractCollectionPersister { RuntimeModelCreationContext creationContext) throws MappingException, CacheException { super( collectionBinding, cacheAccessStrategy, creationContext ); cascadeDeleteEnabled = collectionBinding.getKey().isCascadeDeleteEnabled() - && creationContext.getSessionFactory().getJdbcServices().getDialect().supportsCascadeDelete(); + && creationContext.getDialect().supportsCascadeDelete(); keyIsNullable = collectionBinding.getKey().isNullable(); keyIsUpdateable = collectionBinding.getKey().isUpdateable(); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index a71a79f9c6..95c07b5e52 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -275,6 +275,7 @@ import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter; +import org.hibernate.type.spi.TypeConfiguration; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; @@ -525,12 +526,11 @@ public abstract class AbstractEntityPersister javaType = representationStrategy.getLoadJavaType(); assert javaType != null; - final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class ); - final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect(); + final Dialect dialect = creationContext.getDialect(); int batch = persistentClass.getBatchSize(); if ( batch == -1 ) { - batch = factory.getSessionFactoryOptions().getDefaultBatchFetchSize(); + batch = creationContext.getSessionFactoryOptions().getDefaultBatchFetchSize(); } batchSize = batch; hasSubselectLoadableCollections = persistentClass.hasSubselectLoadableCollections(); @@ -568,16 +568,17 @@ public abstract class AbstractEntityPersister multiIdEntityLoader = new MultiIdLoaderStandard<>( this, persistentClass, factory ); - SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry(); + final TypeConfiguration typeConfiguration = creationContext.getTypeConfiguration(); + final SqmFunctionRegistry functionRegistry = creationContext.getFunctionRegistry(); List columns = persistentClass.getIdentifier().getColumns(); - for ( int i = 0; i < columns.size(); i++ ) { + for (int i = 0; i < columns.size(); i++ ) { Column column = columns.get(i); rootTableKeyColumnNames[i] = column.getQuotedName( dialect ); rootTableKeyColumnReaders[i] = column.getReadExpr( dialect ); rootTableKeyColumnReaderTemplates[i] = column.getTemplate( dialect, - factory.getTypeConfiguration(), + typeConfiguration, functionRegistry ); identifierAliases[i] = column.getAlias( dialect, persistentClass.getRootTable() ); @@ -608,7 +609,7 @@ public abstract class AbstractEntityPersister sqlWhereStringTemplate = Template.renderWhereStringTemplate( "(" + persistentClass.getWhere() + ")", dialect, - factory.getTypeConfiguration(), + typeConfiguration, functionRegistry ); } @@ -654,7 +655,7 @@ public abstract class AbstractEntityPersister formula.setFormula( substituteBrackets( formula.getFormula() ) ); formulaTemplates[k] = selectable.getTemplate( dialect, - factory.getTypeConfiguration(), + typeConfiguration, functionRegistry ); } @@ -738,7 +739,7 @@ public abstract class AbstractEntityPersister if ( selectable.isFormula() ) { final String template = selectable.getTemplate( dialect, - factory.getTypeConfiguration(), + typeConfiguration, functionRegistry ); forms[i] = template; @@ -759,7 +760,7 @@ public abstract class AbstractEntityPersister readers[i] = column.getReadExpr( dialect ); readerTemplates[i] = column.getTemplate( dialect, - factory.getTypeConfiguration(), + typeConfiguration, functionRegistry ); } @@ -801,8 +802,8 @@ public abstract class AbstractEntityPersister ? new FilterHelper( persistentClass.getFilters(), factory ) : null; - useReferenceCacheEntries = shouldUseReferenceCacheEntries(); - cacheEntryHelper = buildCacheEntryHelper(); + useReferenceCacheEntries = shouldUseReferenceCacheEntries( creationContext.getSessionFactoryOptions() ); + cacheEntryHelper = buildCacheEntryHelper( creationContext.getSessionFactoryOptions() ); invalidateCache = sessionFactoryOptions.isSecondLevelCacheEnabled() && canWriteToCache && shouldInvalidateCache( persistentClass, creationContext ); @@ -852,10 +853,10 @@ public abstract class AbstractEntityPersister : knownAbstract; } - private boolean shouldUseReferenceCacheEntries() { + private boolean shouldUseReferenceCacheEntries(SessionFactoryOptions options) { // Check if we can use Reference Cached entities in 2lc // todo : should really validate that the cache access type is read-only - if ( !factory.getSessionFactoryOptions().isDirectReferenceCacheEntriesEnabled() ) { + if ( !options.isDirectReferenceCacheEntriesEnabled() ) { return false; } // for now, limit this to just entities that: @@ -1097,7 +1098,7 @@ public abstract class AbstractEntityPersister } } - protected CacheEntryHelper buildCacheEntryHelper() { + protected CacheEntryHelper buildCacheEntryHelper(SessionFactoryOptions options) { if ( cacheAccessStrategy == null ) { // the entity defined no caching... return NoopCacheEntryHelper.INSTANCE; @@ -1108,7 +1109,7 @@ public abstract class AbstractEntityPersister return new ReferenceCacheEntryHelper( this ); } else { - return factory.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() + return options.isStructuredCacheEntriesEnabled() ? new StructuredCacheEntryHelper( this ) : new StandardCacheEntryHelper( this ); } @@ -4828,10 +4829,8 @@ public abstract class AbstractEntityPersister templateInstanceCreator = null; } else { - final LazyValue templateCreator = new LazyValue<>( - () -> instantiator.instantiate( creationProcess.getCreationContext().getSessionFactory() ) - ); - templateInstanceCreator = templateCreator::getValue; + final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); + templateInstanceCreator = new LazyValue<>( () -> instantiator.instantiate( sessionFactory ) )::getValue; } identifierMapping = creationProcess.processSubPart( @@ -5015,12 +5014,11 @@ public abstract class AbstractEntityPersister protected Map buildDiscriminatorValueMappings( MappingModelCreationProcess modelCreationProcess) { final MappingMetamodelImplementor mappingModel = - modelCreationProcess.getCreationContext().getSessionFactory().getMappingMetamodel(); + modelCreationProcess.getCreationContext().getDomainModel(); //noinspection unchecked final JdbcLiteralFormatter jdbcLiteralFormatter = (JdbcLiteralFormatter) getDiscriminatorType().getJdbcLiteralFormatter(); - final Dialect dialect = modelCreationProcess.getCreationContext() - .getSessionFactory().getJdbcServices().getDialect(); + final Dialect dialect = modelCreationProcess.getCreationContext().getDialect(); final Map valueMappings = new ConcurrentHashMap<>(); getSubclassByDiscriminatorValue().forEach( (value, entityName) -> { @@ -5233,7 +5231,7 @@ public abstract class AbstractEntityPersister final BasicValue.Resolution basicTypeResolution = bootModelVersionValue.resolve(); final Column column = (Column) bootModelVersionValue.getColumn(); - final Dialect dialect = creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect(); + final Dialect dialect = creationProcess.getCreationContext().getDialect(); return new EntityVersionMappingImpl( bootModelRootEntityDescriptor.getRootClass(), @@ -5257,10 +5255,9 @@ public abstract class AbstractEntityPersister int stateArrayPosition, int fetchableIndex, MappingModelCreationProcess creationProcess) { - final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); - final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); - final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); - final Dialect dialect = jdbcEnvironment.getDialect(); + final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); + final JdbcServices jdbcServices = creationContext.getJdbcServices(); + final Dialect dialect = creationContext.getDialect(); final String attrName = tupleAttrDefinition.getName(); final Type attrType = tupleAttrDefinition.getType(); @@ -5336,12 +5333,12 @@ public abstract class AbstractEntityPersister assert !selectables.isEmpty(); final Selectable selectable = selectables.get(0); - assert attrColumnExpression.equals( selectable.getText(sessionFactory.getJdbcServices().getDialect()) ); + assert attrColumnExpression.equals( selectable.getText( creationContext.getDialect() ) ); customReadExpr = selectable.getTemplate( dialect, - sessionFactory.getTypeConfiguration(), - sessionFactory.getQueryEngine().getSqmFunctionRegistry() + creationContext.getTypeConfiguration(), + creationContext.getFunctionRegistry() ); customWriteExpr = selectable.getCustomWriteExpression(); Column column = value.getColumns().get( 0 ); @@ -5392,10 +5389,9 @@ public abstract class AbstractEntityPersister ); } else if ( attrType instanceof AnyType ) { - final JavaType baseAssociationJtd = sessionFactory - .getTypeConfiguration() - .getJavaTypeRegistry() - .getDescriptor( Object.class ); + final JavaType baseAssociationJtd = + creationContext.getTypeConfiguration().getJavaTypeRegistry() + .getDescriptor( Object.class ); final AnyType anyType = (AnyType) attrType; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index 2bde4ffbb0..f63be28ec0 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -19,10 +19,10 @@ import java.util.function.Supplier; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.MappingException; +import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.DynamicFilterAliasGenerator; @@ -188,12 +188,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext ); - final SessionFactoryImplementor factory = creationContext.getSessionFactory(); - final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class ); - final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect(); - final SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry(); - final TypeConfiguration typeConfiguration = factory.getTypeConfiguration(); - final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); + final Dialect dialect = creationContext.getDialect(); + final SqmFunctionRegistry functionRegistry = creationContext.getFunctionRegistry(); + final TypeConfiguration typeConfiguration = creationContext.getTypeConfiguration(); + final BasicTypeRegistry basicTypeRegistry = creationContext.getTypeConfiguration().getBasicTypeRegistry(); // DISCRIMINATOR @@ -479,7 +477,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { for ( int i = 0; i < propertyClosure.size(); i++ ) { final String tableName = propertyClosure.get(i).getValue().getTable() - .getQualifiedName( factory.getSqlStringGenerationContext() ); + .getQualifiedName( creationContext.getSqlStringGenerationContext() ); // propertyTableNumbers[i] = getTableId( tableName, this.tableNames ); naturalOrderPropertyTableNumbers[i] = getTableId( tableName, naturalOrderTableNames ); } @@ -495,7 +493,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { for ( Property property : persistentClass.getSubclassPropertyClosure() ) { final String tableName = property.getValue().getTable(). - getQualifiedName( factory.getSqlStringGenerationContext() ); + getQualifiedName( creationContext.getSqlStringGenerationContext() ); final Integer tableNumber = getTableId( tableName, subclassTableNameClosure ); propTableNumbers.add( tableNumber ); @@ -545,7 +543,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { notNullColumnTableNumbers = new int[subclassSpan]; final int id = getTableId( - table.getQualifiedName( factory.getSqlStringGenerationContext() ), + table.getQualifiedName( creationContext.getSqlStringGenerationContext() ), subclassTableNameClosure ); notNullColumnTableNumbers[subclassSpanMinusOne] = id; @@ -568,7 +566,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { initDiscriminatorProperties( dialect, k, subclassTable, discriminatorValue, isAbstract( subclass ) ); subclassesByDiscriminatorValue.put( discriminatorValue, subclass.getEntityName() ); final int tableId = getTableId( - subclassTable.getQualifiedName( factory.getSqlStringGenerationContext() ), + subclassTable.getQualifiedName( creationContext.getSqlStringGenerationContext() ), subclassTableNameClosure ); notNullColumnTableNumbers[k] = tableId; @@ -577,7 +575,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } } - subclassNamesBySubclassTable = buildSubclassNamesBySubclassTableMapping( persistentClass, factory ); + subclassNamesBySubclassTable = buildSubclassNamesBySubclassTableMapping( + persistentClass, + creationContext.getSqlStringGenerationContext() + ); initSubclassPropertyAliasesMap( persistentClass ); @@ -643,7 +644,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { */ private String[][] buildSubclassNamesBySubclassTableMapping( PersistentClass persistentClass, - SessionFactoryImplementor factory) { + SqlStringGenerationContext context) { // this value represents the number of subclasses (and not the class itself) final int numberOfSubclassTables = subclassTableNameClosure.length - coreTableSpan; if ( numberOfSubclassTables == 0 ) { @@ -651,15 +652,15 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } final String[][] mapping = new String[numberOfSubclassTables][]; - processPersistentClassHierarchy( persistentClass, true, factory, mapping ); + processPersistentClassHierarchy( persistentClass, true, mapping, context ); return mapping; } private Set processPersistentClassHierarchy( PersistentClass persistentClass, boolean isBase, - SessionFactoryImplementor factory, - String[][] mapping) { + String[][] mapping, + SqlStringGenerationContext context) { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // collect all the class names that indicate that the "main table" of the given PersistentClass should be @@ -668,7 +669,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { for ( Subclass subclass : persistentClass.getDirectSubclasses() ) { final Set subclassSubclassNames = - processPersistentClassHierarchy( subclass, false, factory, mapping ); + processPersistentClassHierarchy( subclass, false, mapping, context ); classNames.addAll( subclassSubclassNames ); } @@ -681,7 +682,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { msc = msc.getSuperMappedSuperclass(); } - associateSubclassNamesToSubclassTableIndexes( persistentClass, classNames, mapping, factory ); + associateSubclassNamesToSubclassTableIndexes( persistentClass, classNames, mapping, context ); } return classNames; @@ -691,15 +692,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { PersistentClass persistentClass, Set classNames, String[][] mapping, - SessionFactoryImplementor factory) { + SqlStringGenerationContext context) { - final String tableName = persistentClass.getTable() - .getQualifiedName( factory.getSqlStringGenerationContext() ); + final String tableName = persistentClass.getTable().getQualifiedName( context ); associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping ); for ( Join join : persistentClass.getJoins() ) { - final String secondaryTableName = join.getTable() - .getQualifiedName( factory.getSqlStringGenerationContext() ); + final String secondaryTableName = join.getTable().getQualifiedName( context ); associateSubclassNamesToSubclassTableIndex( secondaryTableName, classNames, mapping ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index 1540823ef4..777b0911ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -20,7 +20,6 @@ import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.DynamicFilterAliasGenerator; import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.util.collections.ArrayHelper; @@ -143,10 +142,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext ); - final SessionFactoryImplementor factory = creationContext.getSessionFactory(); - final Dialect dialect = factory.getJdbcServices().getDialect(); - final SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry(); - final TypeConfiguration typeConfiguration = factory.getTypeConfiguration(); + final Dialect dialect = creationContext.getDialect(); + final SqmFunctionRegistry functionRegistry = creationContext.getFunctionRegistry(); + final TypeConfiguration typeConfiguration = creationContext.getTypeConfiguration(); // CLASS + TABLE diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index dfc43389e9..a5acf495c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -28,7 +28,6 @@ import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; -import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.id.IdentityGenerator; import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.StaticFilterAliasGenerator; @@ -115,8 +114,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { validateGenerator(); - final SessionFactoryImplementor factory = creationContext.getSessionFactory(); - final Dialect dialect = factory.getJdbcServices().getDialect(); + final Dialect dialect = creationContext.getDialect(); // TABLE @@ -162,7 +160,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { discriminatorValue = persistentClass.getSubclassId(); discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() ); - discriminatorType = factory.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ); + discriminatorType = creationContext.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ); // PROPERTIES diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java index 32c8b566bd..6f0c6516ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmMutationStrategyHelper.java @@ -10,10 +10,8 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import org.hibernate.boot.spi.SessionFactoryOptions; -import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.internal.FastSessionServices; import org.hibernate.mapping.RootClass; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.PluralAttributeMapping; @@ -50,8 +48,7 @@ public class SqmMutationStrategyHelper { EntityMappingType rootEntityDescriptor, MappingModelCreationProcess creationProcess) { final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); - final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); - final SessionFactoryOptions options = sessionFactory.getSessionFactoryOptions(); + final SessionFactoryOptions options = creationContext.getSessionFactoryOptions(); final SqmMultiTableMutationStrategy specifiedStrategy = options.getCustomSqmMultiTableMutationStrategy(); if ( specifiedStrategy != null ) { @@ -60,10 +57,7 @@ public class SqmMutationStrategyHelper { // todo (6.0) : add capability define strategy per-hierarchy - return sessionFactory.getJdbcServices() - .getJdbcEnvironment() - .getDialect() - .getFallbackSqmMutationStrategy( rootEntityDescriptor, creationContext ); + return creationContext.getDialect().getFallbackSqmMutationStrategy( rootEntityDescriptor, creationContext ); } /** @@ -75,8 +69,7 @@ public class SqmMutationStrategyHelper { EntityMappingType rootEntityDescriptor, MappingModelCreationProcess creationProcess) { final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); - final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); - final SessionFactoryOptions options = sessionFactory.getSessionFactoryOptions(); + final SessionFactoryOptions options = creationContext.getSessionFactoryOptions(); final SqmMultiTableInsertStrategy specifiedStrategy = options.getCustomSqmMultiTableInsertStrategy(); if ( specifiedStrategy != null ) { @@ -84,7 +77,7 @@ public class SqmMutationStrategyHelper { } // todo (6.0) : add capability define strategy per-hierarchy - return sessionFactory.getJdbcServices().getDialect().getFallbackSqmInsertStrategy( rootEntityDescriptor, creationContext ); + return creationContext.getDialect().getFallbackSqmInsertStrategy( rootEntityDescriptor, creationContext ); } public static void visitCollectionTables( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertStrategy.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertStrategy.java index aca6e8bbf0..79ad2b1cf0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertStrategy.java @@ -112,7 +112,7 @@ public class CteInsertStrategy implements SqmMultiTableInsertStrategy { this.rootDescriptor = rootDescriptor; this.sessionFactory = runtimeModelCreationContext.getSessionFactory(); - final Dialect dialect = sessionFactory.getJdbcServices().getDialect(); + final Dialect dialect = runtimeModelCreationContext.getDialect(); if ( !dialect.supportsNonQueryWithCTE() ) { throw new UnsupportedOperationException( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteMutationStrategy.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteMutationStrategy.java index 9ddec150fa..a1c9c97948 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteMutationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteMutationStrategy.java @@ -9,7 +9,6 @@ package org.hibernate.query.sqm.mutation.internal.cte; import java.util.Locale; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; @@ -70,7 +69,7 @@ public class CteMutationStrategy implements SqmMultiTableMutationStrategy { this.rootDescriptor = rootDescriptor; this.sessionFactory = runtimeModelCreationContext.getSessionFactory(); - final Dialect dialect = sessionFactory.getJdbcServices().getDialect(); + final Dialect dialect = runtimeModelCreationContext.getDialect(); if ( !dialect.supportsNonQueryWithCTE() ) { throw new UnsupportedOperationException( diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index 8ae3f6cddd..673c316b6a 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -9,7 +9,6 @@ package org.hibernate.tuple.entity; import java.io.Serializable; import java.util.ArrayList; import java.util.BitSet; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -19,7 +18,6 @@ import java.util.Set; import org.hibernate.HibernateException; import org.hibernate.MappingException; import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementHelper; import org.hibernate.bytecode.internal.BytecodeEnhancementMetadataNonPojoImpl; import org.hibernate.bytecode.internal.BytecodeEnhancementMetadataPojoImpl; @@ -55,6 +53,7 @@ import org.hibernate.type.EntityType; import org.hibernate.type.ManyToOneType; import org.hibernate.type.Type; +import static java.util.Collections.singleton; import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.util.ReflectHelper.isAbstractClass; import static org.hibernate.internal.util.ReflectHelper.isFinalClass; @@ -170,7 +169,8 @@ public class EntityMetamodel implements Serializable { versioned = persistentClass.isVersioned(); - SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions(); + final boolean collectionsInDefaultFetchGroupEnabled = + creationContext.getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled(); if ( persistentClass.hasPojoRepresentation() ) { final Component identifierMapperComponent = persistentClass.getIdentifierMapper(); @@ -186,14 +186,14 @@ public class EntityMetamodel implements Serializable { } else { nonAggregatedCidMapper = null; - idAttributeNames = Collections.singleton( identifierAttribute.getName() ); + idAttributeNames = singleton( identifierAttribute.getName() ); } bytecodeEnhancementMetadata = BytecodeEnhancementMetadataPojoImpl.from( persistentClass, idAttributeNames, nonAggregatedCidMapper, - sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled(), + collectionsInDefaultFetchGroupEnabled, creationContext.getMetadata() ); } @@ -285,7 +285,7 @@ public class EntityMetamodel implements Serializable { assert entityBinding != null; return entityBinding.hasSubclasses(); }, - sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled() + collectionsInDefaultFetchGroupEnabled ); if ( lazy ) { @@ -479,7 +479,7 @@ public class EntityMetamodel implements Serializable { } } if ( mappingProperty.getValue() instanceof Component ) { - final Dialect dialect = context.getSessionFactory().getJdbcServices().getDialect(); + final Dialect dialect = context.getDialect(); final CompositeGeneratorBuilder builder = new CompositeGeneratorBuilder( mappingProperty, dialect ); final Component component = (Component) mappingProperty.getValue(); for ( Property property : component.getProperties() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/Type.java b/hibernate-core/src/main/java/org/hibernate/type/Type.java index 9cd3529e63..57c7239348 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/Type.java +++ b/hibernate-core/src/main/java/org/hibernate/type/Type.java @@ -339,7 +339,7 @@ public interface Type extends Serializable { * @throws HibernateException An error from Hibernate */ Object deepCopy(Object value, SessionFactoryImplementor factory) - throws HibernateException; + throws HibernateException; /** * Are objects of this type mutable with respect to the referencing object?