further reduce direct use of SessionFactory during metamodel building

This commit is contained in:
Gavin 2023-01-02 14:56:35 +01:00 committed by Gavin King
parent 102ef2f469
commit 822153948c
26 changed files with 245 additions and 285 deletions

View File

@ -105,7 +105,7 @@ public class TemporaryTable implements Exportable, Contributable {
else { else {
tableNameIdentifier = new Identifier( temporaryTableName, nameParts.getObjectName().isQuoted() ); tableNameIdentifier = new Identifier( temporaryTableName, nameParts.getObjectName().isQuoted() );
} }
this.qualifiedTableName = creationContext.getSessionFactory().getSqlStringGenerationContext().format( this.qualifiedTableName = creationContext.getSqlStringGenerationContext().format(
new QualifiedTableName( new QualifiedTableName(
adjustedNameParts.getCatalogName() != null adjustedNameParts.getCatalogName() != null
? adjustedNameParts.getCatalogName() ? adjustedNameParts.getCatalogName()

View File

@ -108,6 +108,7 @@ import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper; import org.hibernate.resource.transaction.backend.jta.internal.synchronization.ExceptionMapper;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry; import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory; import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
@ -321,6 +322,16 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
public JdbcServices getJdbcServices() { public JdbcServices getJdbcServices() {
return jdbcServices; 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... // this needs to happen after persisters are all ready to go...

View File

@ -498,12 +498,12 @@ public class Property implements Serializable, MetaAttributable {
@Override @Override
public String getDefaultCatalog() { public String getDefaultCatalog() {
return context.getSessionFactory().getSessionFactoryOptions().getDefaultCatalog(); return context.getSessionFactoryOptions().getDefaultCatalog();
} }
@Override @Override
public String getDefaultSchema() { public String getDefaultSchema() {
return context.getSessionFactory().getSessionFactoryOptions().getDefaultSchema(); return context.getSessionFactoryOptions().getDefaultSchema();
} }
@Override @Override

View File

@ -62,18 +62,9 @@ public class EmbeddableRepresentationStrategyPojo extends AbstractEmbeddableRepr
assert bootDescriptor.getComponentClass() != null; assert bootDescriptor.getComponentClass() != null;
this.strategySelector = creationContext.getSessionFactory() this.strategySelector = creationContext.getServiceRegistry().getService( StrategySelector.class );
.getServiceRegistry()
.getService( StrategySelector.class );
this.reflectionOptimizer = buildReflectionOptimizer( bootDescriptor, creationContext ); 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 this.instantiator = customInstantiator != null
? customInstantiator ? customInstantiator
@ -108,13 +99,12 @@ public class EmbeddableRepresentationStrategyPojo extends AbstractEmbeddableRepr
} }
if ( bootDescriptor.isEmbedded() && ReflectHelper.isAbstractClass( bootDescriptor.getComponentClass() ) ) { if ( bootDescriptor.isEmbedded() && ReflectHelper.isAbstractClass( bootDescriptor.getComponentClass() ) ) {
final ProxyFactoryFactory proxyFactoryFactory = creationContext.getSessionFactory()
.getServiceRegistry()
.getService( ProxyFactoryFactory.class );
return new EmbeddableInstantiatorProxied( return new EmbeddableInstantiatorProxied(
bootDescriptor.getComponentClass(), bootDescriptor.getComponentClass(),
runtimeDescriptorAccess, runtimeDescriptorAccess,
proxyFactoryFactory.buildBasicProxyFactory( bootDescriptor.getComponentClass() ) creationContext.getServiceRegistry()
.getService( ProxyFactoryFactory.class )
.buildBasicProxyFactory( bootDescriptor.getComponentClass() )
); );
} }

View File

@ -80,9 +80,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
PersistentClass bootDescriptor, PersistentClass bootDescriptor,
EntityPersister runtimeDescriptor, EntityPersister runtimeDescriptor,
RuntimeModelCreationContext creationContext) { RuntimeModelCreationContext creationContext) {
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); final JavaTypeRegistry jtdRegistry = creationContext.getTypeConfiguration().getJavaTypeRegistry();
final JavaTypeRegistry jtdRegistry = creationContext.getTypeConfiguration()
.getJavaTypeRegistry();
final Class<?> mappedJavaType = bootDescriptor.getMappedClass(); final Class<?> mappedJavaType = bootDescriptor.getMappedClass();
this.mappedJtd = jtdRegistry.resolveEntityTypeDescriptor( mappedJavaType ); this.mappedJtd = jtdRegistry.resolveEntityTypeDescriptor( mappedJavaType );
@ -156,13 +154,13 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
this.proxyFactory = proxyFactory; this.proxyFactory = proxyFactory;
// resolveReflectionOptimizer may lead to a makePropertyAccess call which requires strategySelector // 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<String, PropertyAccess> propertyAccessMap = new LinkedHashMap<>(); final Map<String, PropertyAccess> propertyAccessMap = new LinkedHashMap<>();
for ( Property property : bootDescriptor.getPropertyClosure() ) { for ( Property property : bootDescriptor.getPropertyClosure() ) {
propertyAccessMap.put( property.getName(), makePropertyAccess( property ) ); propertyAccessMap.put( property.getName(), makePropertyAccess( property ) );
} }
this.propertyAccessMap = propertyAccessMap; this.propertyAccessMap = propertyAccessMap;
this.reflectionOptimizer = resolveReflectionOptimizer( bootDescriptor, bytecodeProvider, sessionFactory ); this.reflectionOptimizer = resolveReflectionOptimizer( bytecodeProvider );
this.instantiator = determineInstantiator( bootDescriptor, entityMetamodel ); this.instantiator = determineInstantiator( bootDescriptor, entityMetamodel );
} }
@ -268,9 +266,10 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
? null ? null
: ReflectHelper.getMethod( proxyInterface, idSetterMethod ); : ReflectHelper.getMethod( proxyInterface, idSetterMethod );
ProxyFactory pf = bytecodeProvider.getProxyFactoryFactory().buildProxyFactory( creationContext.getSessionFactory() ); final ProxyFactory proxyFactory = bytecodeProvider.getProxyFactoryFactory()
.buildProxyFactory( creationContext.getSessionFactory() );
try { try {
pf.postInstantiate( proxyFactory.postInstantiate(
bootDescriptor.getEntityName(), bootDescriptor.getEntityName(),
mappedClass, mappedClass,
proxyInterfaces, proxyInterfaces,
@ -281,7 +280,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
null null
); );
return pf; return proxyFactory;
} }
catch (HibernateException he) { catch (HibernateException he) {
LOG.unableToCreateProxyFactory( bootDescriptor.getEntityName(), he ); LOG.unableToCreateProxyFactory( bootDescriptor.getEntityName(), he );
@ -289,10 +288,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
} }
} }
private ReflectionOptimizer resolveReflectionOptimizer( private ReflectionOptimizer resolveReflectionOptimizer(BytecodeProvider bytecodeProvider) {
PersistentClass bootType,
BytecodeProvider bytecodeProvider,
SessionFactoryImplementor sessionFactory) {
if ( ! Environment.useReflectionOptimizer() ) { if ( ! Environment.useReflectionOptimizer() ) {
return null; return null;
} }

View File

@ -18,7 +18,6 @@ import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.Any; import org.hibernate.mapping.Any;
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
@ -223,9 +222,8 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
Consumer<AttributeMapping> attributeConsumer, Consumer<AttributeMapping> attributeConsumer,
SuccessfulCompletionCallback completionCallback, SuccessfulCompletionCallback completionCallback,
MappingModelCreationProcess creationProcess) { MappingModelCreationProcess creationProcess) {
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); final TypeConfiguration typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration();
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration(); final JdbcServices jdbcServices = creationProcess.getCreationContext().getJdbcServices();
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect(); final Dialect dialect = jdbcEnvironment.getDialect();
@ -332,42 +330,10 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
final boolean updateable = value.isColumnUpdateable( 0 ); final boolean updateable = value.isColumnUpdateable( 0 );
final boolean includeInOptimisticLocking = bootPropertyDescriptor.isOptimisticLocked(); final boolean includeInOptimisticLocking = bootPropertyDescriptor.isOptimisticLocked();
final CascadeStyle cascadeStyle = compositeType.getCascadeStyle( attributeIndex ); 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( SimpleAttributeMetadata attributeMetadataAccess = new SimpleAttributeMetadata(
propertyAccess, propertyAccess,
mutabilityPlan, getMutabilityPlan( updateable ),
nullable, nullable,
insertable, insertable,
updateable, updateable,
@ -392,7 +358,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
} }
else if ( subtype instanceof CompositeType ) { else if ( subtype instanceof CompositeType ) {
final CompositeType subCompositeType = (CompositeType) subtype; final CompositeType subCompositeType = (CompositeType) subtype;
final int columnSpan = subCompositeType.getColumnSpan( sessionFactory ); final int columnSpan = subCompositeType.getColumnSpan( creationProcess.getCreationContext().getMetadata() );
final String subTableExpression; final String subTableExpression;
final String[] subRootTableKeyColumnNames; final String[] subRootTableKeyColumnNames;
if ( rootTableKeyColumnNames == null ) { if ( rootTableKeyColumnNames == null ) {
@ -476,4 +442,33 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
return true; 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;
}
}
} }

View File

@ -63,9 +63,8 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
AnyType anyType, AnyType anyType,
Any bootValueMapping, Any bootValueMapping,
MappingModelCreationProcess creationProcess) { 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( final String tableName = MappingModelCreationHelper.getTableIdentifierExpression(
bootValueMapping.getTable(), bootValueMapping.getTable(),
creationProcess creationProcess
@ -126,7 +125,7 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
? FetchTiming.DELAYED ? FetchTiming.DELAYED
: FetchTiming.IMMEDIATE, : FetchTiming.IMMEDIATE,
bootValueMapping.getMetaValues(), bootValueMapping.getMetaValues(),
sessionFactory creationProcess.getCreationContext().getSessionFactory()
); );
} }

View File

@ -10,7 +10,6 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.hibernate.engine.FetchTiming; import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.Any; import org.hibernate.mapping.Any;
import org.hibernate.mapping.IndexedConsumer; import org.hibernate.mapping.IndexedConsumer;
@ -50,7 +49,6 @@ import org.hibernate.type.descriptor.java.JavaType;
*/ */
public class DiscriminatedCollectionPart implements DiscriminatedAssociationModelPart, CollectionPart { public class DiscriminatedCollectionPart implements DiscriminatedAssociationModelPart, CollectionPart {
private final Nature nature; private final Nature nature;
private final SessionFactoryImplementor sessionFactory;
private final NavigableRole partRole; private final NavigableRole partRole;
private final CollectionPersister collectionDescriptor; private final CollectionPersister collectionDescriptor;
@ -75,8 +73,6 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode
bootValueMapping, bootValueMapping,
creationProcess creationProcess
); );
sessionFactory = creationProcess.getCreationContext().getSessionFactory();
} }
@Override @Override

View File

@ -22,7 +22,6 @@ import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.mapping.AggregateColumn; import org.hibernate.mapping.AggregateColumn;
@ -168,20 +167,14 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
this.embeddableJtd = representationStrategy.getMappedJavaType(); this.embeddableJtd = representationStrategy.getMappedJavaType();
this.valueMapping = embeddedPartBuilder.apply( this ); this.valueMapping = embeddedPartBuilder.apply( this );
final ConfigurationService cs = creationContext.getSessionFactory().getServiceRegistry()
.getService(ConfigurationService.class);
this.createEmptyCompositesEnabled = ConfigurationHelper.getBoolean( this.createEmptyCompositesEnabled = ConfigurationHelper.getBoolean(
Environment.CREATE_EMPTY_COMPOSITES_ENABLED, Environment.CREATE_EMPTY_COMPOSITES_ENABLED,
cs.getSettings(), creationContext.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
false false
); );
final AggregateColumn aggregateColumn = bootDescriptor.getAggregateColumn(); final AggregateColumn aggregateColumn = bootDescriptor.getAggregateColumn();
if ( aggregateColumn != null ) { if ( aggregateColumn != null ) {
final Dialect dialect = creationContext.getBootstrapContext() final Dialect dialect = creationContext.getDialect();
.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect();
final boolean insertable; final boolean insertable;
final boolean updatable; final boolean updatable;
if ( componentProperty == null ) { if ( componentProperty == null ) {
@ -330,9 +323,8 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
// ); // );
// todo (6.0) - get this ^^ to work, or drop the comment // todo (6.0) - get this ^^ to work, or drop the comment
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); final TypeConfiguration typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration();
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration(); final JdbcServices jdbcServices = creationProcess.getCreationContext().getJdbcServices();
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect(); final Dialect dialect = jdbcEnvironment.getDialect();
@ -442,42 +434,10 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
final boolean updateable = updateability[columnPosition]; final boolean updateable = updateability[columnPosition];
final boolean includeInOptimisticLocking = bootPropertyDescriptor.isOptimisticLocked(); final boolean includeInOptimisticLocking = bootPropertyDescriptor.isOptimisticLocked();
final CascadeStyle cascadeStyle = compositeType.getCascadeStyle( attributeIndex ); 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( SimpleAttributeMetadata attributeMetadataAccess = new SimpleAttributeMetadata(
propertyAccess, propertyAccess,
mutabilityPlan, getMutabilityPlan( updateable ),
nullable, nullable,
insertable, insertable,
updateable, updateable,
@ -502,7 +462,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
} }
else if ( subtype instanceof CompositeType ) { else if ( subtype instanceof CompositeType ) {
final CompositeType subCompositeType = (CompositeType) subtype; final CompositeType subCompositeType = (CompositeType) subtype;
final int columnSpan = subCompositeType.getColumnSpan( sessionFactory ); final int columnSpan = subCompositeType.getColumnSpan( creationProcess.getCreationContext().getMetadata() );
final String subTableExpression; final String subTableExpression;
final String[] subRootTableKeyColumnNames; final String[] subRootTableKeyColumnNames;
if ( rootTableKeyColumnNames == null ) { if ( rootTableKeyColumnNames == null ) {
@ -589,6 +549,35 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
return true; 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() { private boolean initColumnMappings() {
this.selectableMappings = SelectableMappingsImpl.from( this ); this.selectableMappings = SelectableMappingsImpl.from( this );
return true; return true;

View File

@ -82,7 +82,7 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden
this.idMapping = idMapping; this.idMapping = idMapping;
this.virtualIdEmbeddable = virtualIdEmbeddable; this.virtualIdEmbeddable = virtualIdEmbeddable;
this.javaType = creationProcess.getCreationContext().getSessionFactory().getTypeConfiguration() this.javaType = creationProcess.getCreationContext().getTypeConfiguration()
.getJavaTypeRegistry() .getJavaTypeRegistry()
.resolveManagedTypeDescriptor( idClassSource.getComponentClass() ); .resolveManagedTypeDescriptor( idClassSource.getComponentClass() );

View File

@ -471,7 +471,7 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
true, true,
false, false,
false, false,
creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect(), creationProcess.getCreationContext().getJdbcServices().getDialect(),
creationProcess.getSqmFunctionRegistry() creationProcess.getSqmFunctionRegistry()
); );
@ -503,11 +503,11 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
collectionTableName, collectionTableName,
elementBootDescriptor, elementBootDescriptor,
getPropertyOrder( elementBootDescriptor, creationProcess ), getPropertyOrder( elementBootDescriptor, creationProcess ),
creationProcess.getCreationContext().getSessionFactory(), creationProcess.getCreationContext().getMetadata(),
creationProcess.getCreationContext().getTypeConfiguration(), creationProcess.getCreationContext().getTypeConfiguration(),
elementBootDescriptor.getColumnInsertability(), elementBootDescriptor.getColumnInsertability(),
elementBootDescriptor.getColumnUpdateability(), elementBootDescriptor.getColumnUpdateability(),
creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect(), creationProcess.getCreationContext().getDialect(),
creationProcess.getSqmFunctionRegistry() creationProcess.getSqmFunctionRegistry()
); );

View File

@ -322,12 +322,27 @@ public class MappingModelCreationHelper {
PropertyAccess propertyAccess, PropertyAccess propertyAccess,
CascadeStyle cascadeStyle, CascadeStyle cascadeStyle,
MappingModelCreationProcess creationProcess) { MappingModelCreationProcess creationProcess) {
final MutabilityPlan mutabilityPlan; final MutabilityPlan mutabilityPlan = getMutabilityPlan( bootProperty, attrType, creationProcess );
if ( bootProperty.isUpdateable() ) { return new SimpleAttributeMetadata(
mutabilityPlan = new MutabilityPlan() { propertyAccess,
mutabilityPlan,
bootProperty.getValue().isNullable(),
bootProperty.isInsertable(),
bootProperty.isUpdateable(),
bootProperty.isOptimisticLocked(),
cascadeStyle
);
}
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext() private static MutabilityPlan getMutabilityPlan(
.getSessionFactory(); Property bootProperty,
Type attrType,
MappingModelCreationProcess creationProcess) {
if ( bootProperty.isUpdateable() ) {
return new MutabilityPlan() {
final SessionFactoryImplementor sessionFactory =
creationProcess.getCreationContext().getSessionFactory();
@Override @Override
public boolean isMutable() { public boolean isMutable() {
@ -355,16 +370,8 @@ public class MappingModelCreationHelper {
}; };
} }
else { 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") @SuppressWarnings("rawtypes")
@ -387,8 +394,7 @@ public class MappingModelCreationHelper {
final Collection bootValueMapping = (Collection) bootProperty.getValue(); final Collection bootValueMapping = (Collection) bootProperty.getValue();
final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext();
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); final Dialect dialect = creationContext.getDialect();
final Dialect dialect = sessionFactory.getSqlStringGenerationContext().getDialect();
final MappingMetamodel domainModel = creationContext.getDomainModel(); final MappingMetamodel domainModel = creationContext.getDomainModel();
final CollectionPersister collectionDescriptor = domainModel.findCollectionDescriptor( bootValueMapping.getRole() ); final CollectionPersister collectionDescriptor = domainModel.findCollectionDescriptor( bootValueMapping.getRole() );
@ -562,6 +568,7 @@ public class MappingModelCreationHelper {
cascadeStyle cascadeStyle
); );
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory();
final FetchStyle style = FetchOptionsHelper.determineFetchStyleByMetadata( final FetchStyle style = FetchOptionsHelper.determineFetchStyleByMetadata(
fetchMode, fetchMode,
collectionDescriptor.getCollectionType(), collectionDescriptor.getCollectionType(),
@ -996,7 +1003,7 @@ public class MappingModelCreationHelper {
keyTableExpression, keyTableExpression,
collectionBootValueMapping.getKey(), collectionBootValueMapping.getKey(),
getPropertyOrder( bootValueMapping, creationProcess ), getPropertyOrder( bootValueMapping, creationProcess ),
creationProcess.getCreationContext().getSessionFactory(), creationProcess.getCreationContext().getMetadata(),
creationProcess.getCreationContext().getTypeConfiguration(), creationProcess.getCreationContext().getTypeConfiguration(),
insertable, insertable,
updateable, updateable,
@ -1020,7 +1027,7 @@ public class MappingModelCreationHelper {
keyTableExpression, keyTableExpression,
bootValueMapping, bootValueMapping,
getPropertyOrder( bootValueMapping, creationProcess ), getPropertyOrder( bootValueMapping, creationProcess ),
creationProcess.getCreationContext().getSessionFactory(), creationProcess.getCreationContext().getMetadata(),
creationProcess.getCreationContext().getTypeConfiguration(), creationProcess.getCreationContext().getTypeConfiguration(),
insertable, insertable,
updateable, updateable,
@ -1078,7 +1085,7 @@ public class MappingModelCreationHelper {
else { else {
final EntityType entityType = (EntityType) bootValueMapping.getType(); final EntityType entityType = (EntityType) bootValueMapping.getType();
final Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType( final Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType(
creationProcess.getCreationContext().getSessionFactory() creationProcess.getCreationContext().getMetadata()
); );
if ( identifierOrUniqueKeyType instanceof ComponentType ) { if ( identifierOrUniqueKeyType instanceof ComponentType ) {
componentType = (ComponentType) identifierOrUniqueKeyType; componentType = (ComponentType) identifierOrUniqueKeyType;
@ -1142,7 +1149,12 @@ public class MappingModelCreationHelper {
} }
public static String getTableIdentifierExpression(Table table, MappingModelCreationProcess creationProcess) { 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) { public static String getTableIdentifierExpression(Table table, SessionFactoryImplementor sessionFactory) {
@ -1150,7 +1162,8 @@ public class MappingModelCreationHelper {
return "( " + table.getSubselect() + " )"; return "( " + table.getSubselect() + " )";
} }
return sessionFactory.getSqlStringGenerationContext().format( table.getQualifiedTableName() ); return sessionFactory.getSqlStringGenerationContext()
.format( table.getQualifiedTableName() );
} }
private static CollectionPart interpretMapKey( private static CollectionPart interpretMapKey(
@ -1225,10 +1238,6 @@ public class MappingModelCreationHelper {
final EntityType indexEntityType = (EntityType) collectionDescriptor.getIndexType(); final EntityType indexEntityType = (EntityType) collectionDescriptor.getIndexType();
final EntityPersister associatedEntity = creationProcess.getEntityPersister( indexEntityType.getAssociatedEntityName() ); 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; final EntityCollectionPart indexDescriptor;
if ( bootMapKeyDescriptor instanceof OneToMany ) { if ( bootMapKeyDescriptor instanceof OneToMany ) {
indexDescriptor = new OneToManyCollectionPart( indexDescriptor = new OneToManyCollectionPart(
@ -1324,8 +1333,7 @@ public class MappingModelCreationHelper {
if ( element instanceof Any ) { if ( element instanceof Any ) {
final Any anyBootMapping = (Any) element; final Any anyBootMapping = (Any) element;
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); final TypeConfiguration typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration();
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration();
final JavaTypeRegistry jtdRegistry = typeConfiguration.getJavaTypeRegistry(); final JavaTypeRegistry jtdRegistry = typeConfiguration.getJavaTypeRegistry();
final JavaType<Object> baseJtd = jtdRegistry.getDescriptor(Object.class); final JavaType<Object> baseJtd = jtdRegistry.getDescriptor(Object.class);
@ -1521,7 +1529,7 @@ public class MappingModelCreationHelper {
cascadeStyle, cascadeStyle,
creationProcess creationProcess
); );
SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory();
final AssociationType type = (AssociationType) bootProperty.getType(); final AssociationType type = (AssociationType) bootProperty.getType();
final FetchStyle fetchStyle = FetchOptionsHelper final FetchStyle fetchStyle = FetchOptionsHelper
@ -1571,21 +1579,14 @@ public class MappingModelCreationHelper {
creationProcess.registerForeignKeyPostInitCallbacks( creationProcess.registerForeignKeyPostInitCallbacks(
"To-one key - " + navigableRole, "To-one key - " + navigableRole,
() -> { () -> MappingModelCreationHelper.interpretToOneKeyDescriptor(
final Dialect dialect = creationProcess.getCreationContext() attributeMapping,
.getSessionFactory() bootProperty,
.getJdbcServices() (ToOne) bootProperty.getValue(),
.getDialect(); null,
creationProcess.getCreationContext().getDialect(),
return MappingModelCreationHelper.interpretToOneKeyDescriptor( creationProcess
attributeMapping, )
bootProperty,
(ToOne) bootProperty.getValue(),
null,
dialect,
creationProcess
);
}
); );
return attributeMapping; return attributeMapping;
} }

View File

@ -52,9 +52,7 @@ public class SimpleNaturalIdMapping extends AbstractNaturalIdMapping implements
); );
this.attribute = attribute; this.attribute = attribute;
typeConfiguration = creationProcess.getCreationContext() typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration();
.getSessionFactory()
.getTypeConfiguration();
} }

View File

@ -38,13 +38,12 @@ public class VirtualIdRepresentationStrategy implements EmbeddableRepresentation
RuntimeModelCreationContext creationContext) { RuntimeModelCreationContext creationContext) {
this.entityMappingType = entityMappingType; this.entityMappingType = entityMappingType;
if ( bootDescriptor.getComponentClassName() != null && ReflectHelper.isAbstractClass( bootDescriptor.getComponentClass() ) ) { if ( bootDescriptor.getComponentClassName() != null && ReflectHelper.isAbstractClass( bootDescriptor.getComponentClass() ) ) {
final ProxyFactoryFactory proxyFactoryFactory = creationContext.getSessionFactory()
.getServiceRegistry()
.getService( ProxyFactoryFactory.class );
this.instantiator = new EmbeddableInstantiatorProxied( this.instantiator = new EmbeddableInstantiatorProxied(
bootDescriptor.getComponentClass(), bootDescriptor.getComponentClass(),
() -> virtualIdEmbeddable, () -> virtualIdEmbeddable,
proxyFactoryFactory.buildBasicProxyFactory( bootDescriptor.getComponentClass() ) creationContext.getServiceRegistry()
.getService( ProxyFactoryFactory.class )
.buildBasicProxyFactory( bootDescriptor.getComponentClass() )
); );
} }

View File

@ -6,6 +6,7 @@
*/ */
package org.hibernate.metamodel.spi; package org.hibernate.metamodel.spi;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.SessionFactoryOptions; 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.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.persister.spi.PersisterCreationContext;
import org.hibernate.query.sqm.function.SqmFunctionRegistry; import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.type.spi.TypeConfiguration;
@ -56,4 +58,8 @@ public interface RuntimeModelCreationContext extends PersisterCreationContext {
SessionFactoryOptions getSessionFactoryOptions(); SessionFactoryOptions getSessionFactoryOptions();
JdbcServices getJdbcServices(); JdbcServices getJdbcServices();
SqlStringGenerationContext getSqlStringGenerationContext();
ServiceRegistry getServiceRegistry();
} }

View File

@ -272,7 +272,7 @@ public abstract class AbstractCollectionPersister
this.factory = creationContext.getSessionFactory(); this.factory = creationContext.getSessionFactory();
this.cacheAccessStrategy = cacheAccessStrategy; this.cacheAccessStrategy = cacheAccessStrategy;
if ( factory.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() ) { if ( creationContext.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() ) {
cacheEntryStructure = collectionBootDescriptor.isMap() cacheEntryStructure = collectionBootDescriptor.isMap()
? StructuredMapCacheEntry.INSTANCE ? StructuredMapCacheEntry.INSTANCE
: StructuredCollectionCacheEntry.INSTANCE; : StructuredCollectionCacheEntry.INSTANCE;
@ -281,8 +281,8 @@ public abstract class AbstractCollectionPersister
cacheEntryStructure = UnstructuredCacheEntry.INSTANCE; cacheEntryStructure = UnstructuredCacheEntry.INSTANCE;
} }
dialect = factory.getJdbcServices().getDialect(); dialect = creationContext.getDialect();
sqlExceptionHelper = factory.getJdbcServices().getSqlExceptionHelper(); sqlExceptionHelper = creationContext.getJdbcServices().getSqlExceptionHelper();
collectionType = collectionBootDescriptor.getCollectionType(); collectionType = collectionBootDescriptor.getCollectionType();
navigableRole = new NavigableRole( collectionBootDescriptor.getRole() ); navigableRole = new NavigableRole( collectionBootDescriptor.getRole() );
entityName = collectionBootDescriptor.getOwnerEntityName(); entityName = collectionBootDescriptor.getOwnerEntityName();
@ -316,8 +316,8 @@ public abstract class AbstractCollectionPersister
sqlWhereStringTemplate = Template.renderWhereStringTemplate( sqlWhereStringTemplate = Template.renderWhereStringTemplate(
sqlWhereString, sqlWhereString,
dialect, dialect,
factory.getTypeConfiguration(), creationContext.getTypeConfiguration(),
factory.getQueryEngine().getSqmFunctionRegistry() creationContext.getFunctionRegistry()
); );
} }
else { else {
@ -330,7 +330,7 @@ public abstract class AbstractCollectionPersister
int batch = collectionBootDescriptor.getBatchSize(); int batch = collectionBootDescriptor.getBatchSize();
if ( batch == -1 ) { if ( batch == -1 ) {
batch = factory.getSessionFactoryOptions().getDefaultBatchFetchSize(); batch = creationContext.getSessionFactoryOptions().getDefaultBatchFetchSize();
} }
batchSize = batch; batchSize = batch;
@ -389,8 +389,8 @@ public abstract class AbstractCollectionPersister
Formula form = (Formula) selectable; Formula form = (Formula) selectable;
elementFormulaTemplates[j] = form.getTemplate( elementFormulaTemplates[j] = form.getTemplate(
dialect, dialect,
factory.getTypeConfiguration(), creationContext.getTypeConfiguration(),
factory.getQueryEngine().getSqmFunctionRegistry() creationContext.getFunctionRegistry()
); );
elementFormulas[j] = form.getFormula(); elementFormulas[j] = form.getFormula();
} }
@ -401,8 +401,8 @@ public abstract class AbstractCollectionPersister
elementColumnReaders[j] = col.getReadExpr( dialect ); elementColumnReaders[j] = col.getReadExpr( dialect );
elementColumnReaderTemplates[j] = col.getTemplate( elementColumnReaderTemplates[j] = col.getTemplate(
dialect, dialect,
factory.getTypeConfiguration(), creationContext.getTypeConfiguration(),
factory.getQueryEngine().getSqmFunctionRegistry() creationContext.getFunctionRegistry()
); );
elementColumnIsGettable[j] = true; elementColumnIsGettable[j] = true;
if ( elementType.isComponentType() ) { if ( elementType.isComponentType() ) {
@ -454,8 +454,8 @@ public abstract class AbstractCollectionPersister
Formula indexForm = (Formula) s; Formula indexForm = (Formula) s;
indexFormulaTemplates[i] = indexForm.getTemplate( indexFormulaTemplates[i] = indexForm.getTemplate(
dialect, dialect,
factory.getTypeConfiguration(), creationContext.getTypeConfiguration(),
factory.getQueryEngine().getSqmFunctionRegistry() creationContext.getFunctionRegistry()
); );
indexFormulas[i] = indexForm.getFormula(); indexFormulas[i] = indexForm.getFormula();
hasFormula = true; hasFormula = true;
@ -548,10 +548,7 @@ public abstract class AbstractCollectionPersister
); );
} }
else if ( !elementType.isEntityType() ) { else if ( !elementType.isEntityType() ) {
elementPropertyMapping = new ElementPropertyMapping( elementPropertyMapping = new ElementPropertyMapping( elementColumnNames, elementType );
elementColumnNames,
elementType
);
} }
else { else {
// not all entity-persisters implement PropertyMapping! // not all entity-persisters implement PropertyMapping!
@ -590,9 +587,9 @@ public abstract class AbstractCollectionPersister
manyToManyWhereString = "( " + collectionBootDescriptor.getManyToManyWhere() + ")"; manyToManyWhereString = "( " + collectionBootDescriptor.getManyToManyWhere() + ")";
manyToManyWhereTemplate = Template.renderWhereStringTemplate( manyToManyWhereTemplate = Template.renderWhereStringTemplate(
manyToManyWhereString, manyToManyWhereString,
factory.getJdbcServices().getDialect(), creationContext.getDialect(),
factory.getTypeConfiguration(), creationContext.getTypeConfiguration(),
factory.getQueryEngine().getSqmFunctionRegistry() creationContext.getFunctionRegistry()
); );
} }
@ -624,14 +621,14 @@ public abstract class AbstractCollectionPersister
private BeforeExecutionGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) { private BeforeExecutionGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) {
final Generator generator = collection.getIdentifier().createGenerator( final Generator generator = collection.getIdentifier().createGenerator(
context.getBootstrapContext().getIdentifierGeneratorFactory(), context.getBootstrapContext().getIdentifierGeneratorFactory(),
factory.getJdbcServices().getDialect(), context.getDialect(),
null null
); );
if ( generator.generatedOnExecution() ) { if ( generator.generatedOnExecution() ) {
throw new MappingException("must be an BeforeExecutionGenerator"); //TODO fix message throw new MappingException("must be an BeforeExecutionGenerator"); //TODO fix message
} }
if ( generator instanceof IdentifierGenerator ) { if ( generator instanceof IdentifierGenerator ) {
( (IdentifierGenerator) generator ).initialize( context.getSessionFactory().getSqlStringGenerationContext() ); ( (IdentifierGenerator) generator ).initialize( context.getSqlStringGenerationContext() );
} }
return (BeforeExecutionGenerator) generator; return (BeforeExecutionGenerator) generator;
} }

View File

@ -113,7 +113,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
RuntimeModelCreationContext creationContext) throws MappingException, CacheException { RuntimeModelCreationContext creationContext) throws MappingException, CacheException {
super( collectionBinding, cacheAccessStrategy, creationContext ); super( collectionBinding, cacheAccessStrategy, creationContext );
cascadeDeleteEnabled = collectionBinding.getKey().isCascadeDeleteEnabled() cascadeDeleteEnabled = collectionBinding.getKey().isCascadeDeleteEnabled()
&& creationContext.getSessionFactory().getJdbcServices().getDialect().supportsCascadeDelete(); && creationContext.getDialect().supportsCascadeDelete();
keyIsNullable = collectionBinding.getKey().isNullable(); keyIsNullable = collectionBinding.getKey().isNullable();
keyIsUpdateable = collectionBinding.getKey().isUpdateable(); keyIsUpdateable = collectionBinding.getKey().isUpdateable();

View File

@ -275,6 +275,7 @@ import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.descriptor.java.MutabilityPlan;
import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter; import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter;
import org.hibernate.type.spi.TypeConfiguration;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
@ -525,12 +526,11 @@ public abstract class AbstractEntityPersister
javaType = representationStrategy.getLoadJavaType(); javaType = representationStrategy.getLoadJavaType();
assert javaType != null; assert javaType != null;
final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class ); final Dialect dialect = creationContext.getDialect();
final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect();
int batch = persistentClass.getBatchSize(); int batch = persistentClass.getBatchSize();
if ( batch == -1 ) { if ( batch == -1 ) {
batch = factory.getSessionFactoryOptions().getDefaultBatchFetchSize(); batch = creationContext.getSessionFactoryOptions().getDefaultBatchFetchSize();
} }
batchSize = batch; batchSize = batch;
hasSubselectLoadableCollections = persistentClass.hasSubselectLoadableCollections(); hasSubselectLoadableCollections = persistentClass.hasSubselectLoadableCollections();
@ -568,16 +568,17 @@ public abstract class AbstractEntityPersister
multiIdEntityLoader = new MultiIdLoaderStandard<>( this, persistentClass, factory ); multiIdEntityLoader = new MultiIdLoaderStandard<>( this, persistentClass, factory );
SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry(); final TypeConfiguration typeConfiguration = creationContext.getTypeConfiguration();
final SqmFunctionRegistry functionRegistry = creationContext.getFunctionRegistry();
List<Column> columns = persistentClass.getIdentifier().getColumns(); List<Column> 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); Column column = columns.get(i);
rootTableKeyColumnNames[i] = column.getQuotedName( dialect ); rootTableKeyColumnNames[i] = column.getQuotedName( dialect );
rootTableKeyColumnReaders[i] = column.getReadExpr( dialect ); rootTableKeyColumnReaders[i] = column.getReadExpr( dialect );
rootTableKeyColumnReaderTemplates[i] = column.getTemplate( rootTableKeyColumnReaderTemplates[i] = column.getTemplate(
dialect, dialect,
factory.getTypeConfiguration(), typeConfiguration,
functionRegistry functionRegistry
); );
identifierAliases[i] = column.getAlias( dialect, persistentClass.getRootTable() ); identifierAliases[i] = column.getAlias( dialect, persistentClass.getRootTable() );
@ -608,7 +609,7 @@ public abstract class AbstractEntityPersister
sqlWhereStringTemplate = Template.renderWhereStringTemplate( sqlWhereStringTemplate = Template.renderWhereStringTemplate(
"(" + persistentClass.getWhere() + ")", "(" + persistentClass.getWhere() + ")",
dialect, dialect,
factory.getTypeConfiguration(), typeConfiguration,
functionRegistry functionRegistry
); );
} }
@ -654,7 +655,7 @@ public abstract class AbstractEntityPersister
formula.setFormula( substituteBrackets( formula.getFormula() ) ); formula.setFormula( substituteBrackets( formula.getFormula() ) );
formulaTemplates[k] = selectable.getTemplate( formulaTemplates[k] = selectable.getTemplate(
dialect, dialect,
factory.getTypeConfiguration(), typeConfiguration,
functionRegistry functionRegistry
); );
} }
@ -738,7 +739,7 @@ public abstract class AbstractEntityPersister
if ( selectable.isFormula() ) { if ( selectable.isFormula() ) {
final String template = selectable.getTemplate( final String template = selectable.getTemplate(
dialect, dialect,
factory.getTypeConfiguration(), typeConfiguration,
functionRegistry functionRegistry
); );
forms[i] = template; forms[i] = template;
@ -759,7 +760,7 @@ public abstract class AbstractEntityPersister
readers[i] = column.getReadExpr( dialect ); readers[i] = column.getReadExpr( dialect );
readerTemplates[i] = column.getTemplate( readerTemplates[i] = column.getTemplate(
dialect, dialect,
factory.getTypeConfiguration(), typeConfiguration,
functionRegistry functionRegistry
); );
} }
@ -801,8 +802,8 @@ public abstract class AbstractEntityPersister
? new FilterHelper( persistentClass.getFilters(), factory ) ? new FilterHelper( persistentClass.getFilters(), factory )
: null; : null;
useReferenceCacheEntries = shouldUseReferenceCacheEntries(); useReferenceCacheEntries = shouldUseReferenceCacheEntries( creationContext.getSessionFactoryOptions() );
cacheEntryHelper = buildCacheEntryHelper(); cacheEntryHelper = buildCacheEntryHelper( creationContext.getSessionFactoryOptions() );
invalidateCache = sessionFactoryOptions.isSecondLevelCacheEnabled() invalidateCache = sessionFactoryOptions.isSecondLevelCacheEnabled()
&& canWriteToCache && canWriteToCache
&& shouldInvalidateCache( persistentClass, creationContext ); && shouldInvalidateCache( persistentClass, creationContext );
@ -852,10 +853,10 @@ public abstract class AbstractEntityPersister
: knownAbstract; : knownAbstract;
} }
private boolean shouldUseReferenceCacheEntries() { private boolean shouldUseReferenceCacheEntries(SessionFactoryOptions options) {
// Check if we can use Reference Cached entities in 2lc // Check if we can use Reference Cached entities in 2lc
// todo : should really validate that the cache access type is read-only // todo : should really validate that the cache access type is read-only
if ( !factory.getSessionFactoryOptions().isDirectReferenceCacheEntriesEnabled() ) { if ( !options.isDirectReferenceCacheEntriesEnabled() ) {
return false; return false;
} }
// for now, limit this to just entities that: // 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 ) { if ( cacheAccessStrategy == null ) {
// the entity defined no caching... // the entity defined no caching...
return NoopCacheEntryHelper.INSTANCE; return NoopCacheEntryHelper.INSTANCE;
@ -1108,7 +1109,7 @@ public abstract class AbstractEntityPersister
return new ReferenceCacheEntryHelper( this ); return new ReferenceCacheEntryHelper( this );
} }
else { else {
return factory.getSessionFactoryOptions().isStructuredCacheEntriesEnabled() return options.isStructuredCacheEntriesEnabled()
? new StructuredCacheEntryHelper( this ) ? new StructuredCacheEntryHelper( this )
: new StandardCacheEntryHelper( this ); : new StandardCacheEntryHelper( this );
} }
@ -4828,10 +4829,8 @@ public abstract class AbstractEntityPersister
templateInstanceCreator = null; templateInstanceCreator = null;
} }
else { else {
final LazyValue<?> templateCreator = new LazyValue<>( final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory();
() -> instantiator.instantiate( creationProcess.getCreationContext().getSessionFactory() ) templateInstanceCreator = new LazyValue<>( () -> instantiator.instantiate( sessionFactory ) )::getValue;
);
templateInstanceCreator = templateCreator::getValue;
} }
identifierMapping = creationProcess.processSubPart( identifierMapping = creationProcess.processSubPart(
@ -5015,12 +5014,11 @@ public abstract class AbstractEntityPersister
protected Map<Object, DiscriminatorValueDetails> buildDiscriminatorValueMappings( protected Map<Object, DiscriminatorValueDetails> buildDiscriminatorValueMappings(
MappingModelCreationProcess modelCreationProcess) { MappingModelCreationProcess modelCreationProcess) {
final MappingMetamodelImplementor mappingModel = final MappingMetamodelImplementor mappingModel =
modelCreationProcess.getCreationContext().getSessionFactory().getMappingMetamodel(); modelCreationProcess.getCreationContext().getDomainModel();
//noinspection unchecked //noinspection unchecked
final JdbcLiteralFormatter<Object> jdbcLiteralFormatter = final JdbcLiteralFormatter<Object> jdbcLiteralFormatter =
(JdbcLiteralFormatter<Object>) getDiscriminatorType().getJdbcLiteralFormatter(); (JdbcLiteralFormatter<Object>) getDiscriminatorType().getJdbcLiteralFormatter();
final Dialect dialect = modelCreationProcess.getCreationContext() final Dialect dialect = modelCreationProcess.getCreationContext().getDialect();
.getSessionFactory().getJdbcServices().getDialect();
final Map<Object, DiscriminatorValueDetails> valueMappings = new ConcurrentHashMap<>(); final Map<Object, DiscriminatorValueDetails> valueMappings = new ConcurrentHashMap<>();
getSubclassByDiscriminatorValue().forEach( (value, entityName) -> { getSubclassByDiscriminatorValue().forEach( (value, entityName) -> {
@ -5233,7 +5231,7 @@ public abstract class AbstractEntityPersister
final BasicValue.Resolution<?> basicTypeResolution = bootModelVersionValue.resolve(); final BasicValue.Resolution<?> basicTypeResolution = bootModelVersionValue.resolve();
final Column column = (Column) bootModelVersionValue.getColumn(); final Column column = (Column) bootModelVersionValue.getColumn();
final Dialect dialect = creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = creationProcess.getCreationContext().getDialect();
return new EntityVersionMappingImpl( return new EntityVersionMappingImpl(
bootModelRootEntityDescriptor.getRootClass(), bootModelRootEntityDescriptor.getRootClass(),
@ -5257,10 +5255,9 @@ public abstract class AbstractEntityPersister
int stateArrayPosition, int stateArrayPosition,
int fetchableIndex, int fetchableIndex,
MappingModelCreationProcess creationProcess) { MappingModelCreationProcess creationProcess) {
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext();
final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); final JdbcServices jdbcServices = creationContext.getJdbcServices();
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); final Dialect dialect = creationContext.getDialect();
final Dialect dialect = jdbcEnvironment.getDialect();
final String attrName = tupleAttrDefinition.getName(); final String attrName = tupleAttrDefinition.getName();
final Type attrType = tupleAttrDefinition.getType(); final Type attrType = tupleAttrDefinition.getType();
@ -5336,12 +5333,12 @@ public abstract class AbstractEntityPersister
assert !selectables.isEmpty(); assert !selectables.isEmpty();
final Selectable selectable = selectables.get(0); final Selectable selectable = selectables.get(0);
assert attrColumnExpression.equals( selectable.getText(sessionFactory.getJdbcServices().getDialect()) ); assert attrColumnExpression.equals( selectable.getText( creationContext.getDialect() ) );
customReadExpr = selectable.getTemplate( customReadExpr = selectable.getTemplate(
dialect, dialect,
sessionFactory.getTypeConfiguration(), creationContext.getTypeConfiguration(),
sessionFactory.getQueryEngine().getSqmFunctionRegistry() creationContext.getFunctionRegistry()
); );
customWriteExpr = selectable.getCustomWriteExpression(); customWriteExpr = selectable.getCustomWriteExpression();
Column column = value.getColumns().get( 0 ); Column column = value.getColumns().get( 0 );
@ -5392,10 +5389,9 @@ public abstract class AbstractEntityPersister
); );
} }
else if ( attrType instanceof AnyType ) { else if ( attrType instanceof AnyType ) {
final JavaType<Object> baseAssociationJtd = sessionFactory final JavaType<Object> baseAssociationJtd =
.getTypeConfiguration() creationContext.getTypeConfiguration().getJavaTypeRegistry()
.getJavaTypeRegistry() .getDescriptor( Object.class );
.getDescriptor( Object.class );
final AnyType anyType = (AnyType) attrType; final AnyType anyType = (AnyType) attrType;

View File

@ -19,10 +19,10 @@ import java.util.function.Supplier;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.DynamicFilterAliasGenerator; import org.hibernate.internal.DynamicFilterAliasGenerator;
@ -188,12 +188,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext ); super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext );
final SessionFactoryImplementor factory = creationContext.getSessionFactory(); final Dialect dialect = creationContext.getDialect();
final JdbcServices jdbcServices = factory.getServiceRegistry().getService( JdbcServices.class ); final SqmFunctionRegistry functionRegistry = creationContext.getFunctionRegistry();
final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect(); final TypeConfiguration typeConfiguration = creationContext.getTypeConfiguration();
final SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry(); final BasicTypeRegistry basicTypeRegistry = creationContext.getTypeConfiguration().getBasicTypeRegistry();
final TypeConfiguration typeConfiguration = factory.getTypeConfiguration();
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
// DISCRIMINATOR // DISCRIMINATOR
@ -479,7 +477,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
for ( int i = 0; i < propertyClosure.size(); i++ ) { for ( int i = 0; i < propertyClosure.size(); i++ ) {
final String tableName = final String tableName =
propertyClosure.get(i).getValue().getTable() propertyClosure.get(i).getValue().getTable()
.getQualifiedName( factory.getSqlStringGenerationContext() ); .getQualifiedName( creationContext.getSqlStringGenerationContext() );
// propertyTableNumbers[i] = getTableId( tableName, this.tableNames ); // propertyTableNumbers[i] = getTableId( tableName, this.tableNames );
naturalOrderPropertyTableNumbers[i] = getTableId( tableName, naturalOrderTableNames ); naturalOrderPropertyTableNumbers[i] = getTableId( tableName, naturalOrderTableNames );
} }
@ -495,7 +493,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
for ( Property property : persistentClass.getSubclassPropertyClosure() ) { for ( Property property : persistentClass.getSubclassPropertyClosure() ) {
final String tableName = property.getValue().getTable(). final String tableName = property.getValue().getTable().
getQualifiedName( factory.getSqlStringGenerationContext() ); getQualifiedName( creationContext.getSqlStringGenerationContext() );
final Integer tableNumber = getTableId( tableName, subclassTableNameClosure ); final Integer tableNumber = getTableId( tableName, subclassTableNameClosure );
propTableNumbers.add( tableNumber ); propTableNumbers.add( tableNumber );
@ -545,7 +543,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
notNullColumnTableNumbers = new int[subclassSpan]; notNullColumnTableNumbers = new int[subclassSpan];
final int id = getTableId( final int id = getTableId(
table.getQualifiedName( factory.getSqlStringGenerationContext() ), table.getQualifiedName( creationContext.getSqlStringGenerationContext() ),
subclassTableNameClosure subclassTableNameClosure
); );
notNullColumnTableNumbers[subclassSpanMinusOne] = id; notNullColumnTableNumbers[subclassSpanMinusOne] = id;
@ -568,7 +566,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
initDiscriminatorProperties( dialect, k, subclassTable, discriminatorValue, isAbstract( subclass ) ); initDiscriminatorProperties( dialect, k, subclassTable, discriminatorValue, isAbstract( subclass ) );
subclassesByDiscriminatorValue.put( discriminatorValue, subclass.getEntityName() ); subclassesByDiscriminatorValue.put( discriminatorValue, subclass.getEntityName() );
final int tableId = getTableId( final int tableId = getTableId(
subclassTable.getQualifiedName( factory.getSqlStringGenerationContext() ), subclassTable.getQualifiedName( creationContext.getSqlStringGenerationContext() ),
subclassTableNameClosure subclassTableNameClosure
); );
notNullColumnTableNumbers[k] = tableId; notNullColumnTableNumbers[k] = tableId;
@ -577,7 +575,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
} }
} }
subclassNamesBySubclassTable = buildSubclassNamesBySubclassTableMapping( persistentClass, factory ); subclassNamesBySubclassTable = buildSubclassNamesBySubclassTableMapping(
persistentClass,
creationContext.getSqlStringGenerationContext()
);
initSubclassPropertyAliasesMap( persistentClass ); initSubclassPropertyAliasesMap( persistentClass );
@ -643,7 +644,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
*/ */
private String[][] buildSubclassNamesBySubclassTableMapping( private String[][] buildSubclassNamesBySubclassTableMapping(
PersistentClass persistentClass, PersistentClass persistentClass,
SessionFactoryImplementor factory) { SqlStringGenerationContext context) {
// this value represents the number of subclasses (and not the class itself) // this value represents the number of subclasses (and not the class itself)
final int numberOfSubclassTables = subclassTableNameClosure.length - coreTableSpan; final int numberOfSubclassTables = subclassTableNameClosure.length - coreTableSpan;
if ( numberOfSubclassTables == 0 ) { if ( numberOfSubclassTables == 0 ) {
@ -651,15 +652,15 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
} }
final String[][] mapping = new String[numberOfSubclassTables][]; final String[][] mapping = new String[numberOfSubclassTables][];
processPersistentClassHierarchy( persistentClass, true, factory, mapping ); processPersistentClassHierarchy( persistentClass, true, mapping, context );
return mapping; return mapping;
} }
private Set<String> processPersistentClassHierarchy( private Set<String> processPersistentClassHierarchy(
PersistentClass persistentClass, PersistentClass persistentClass,
boolean isBase, 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 // 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() ) { for ( Subclass subclass : persistentClass.getDirectSubclasses() ) {
final Set<String> subclassSubclassNames = final Set<String> subclassSubclassNames =
processPersistentClassHierarchy( subclass, false, factory, mapping ); processPersistentClassHierarchy( subclass, false, mapping, context );
classNames.addAll( subclassSubclassNames ); classNames.addAll( subclassSubclassNames );
} }
@ -681,7 +682,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
msc = msc.getSuperMappedSuperclass(); msc = msc.getSuperMappedSuperclass();
} }
associateSubclassNamesToSubclassTableIndexes( persistentClass, classNames, mapping, factory ); associateSubclassNamesToSubclassTableIndexes( persistentClass, classNames, mapping, context );
} }
return classNames; return classNames;
@ -691,15 +692,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
PersistentClass persistentClass, PersistentClass persistentClass,
Set<String> classNames, Set<String> classNames,
String[][] mapping, String[][] mapping,
SessionFactoryImplementor factory) { SqlStringGenerationContext context) {
final String tableName = persistentClass.getTable() final String tableName = persistentClass.getTable().getQualifiedName( context );
.getQualifiedName( factory.getSqlStringGenerationContext() );
associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping ); associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping );
for ( Join join : persistentClass.getJoins() ) { for ( Join join : persistentClass.getJoins() ) {
final String secondaryTableName = join.getTable() final String secondaryTableName = join.getTable().getQualifiedName( context );
.getQualifiedName( factory.getSqlStringGenerationContext() );
associateSubclassNamesToSubclassTableIndex( secondaryTableName, classNames, mapping ); associateSubclassNamesToSubclassTableIndex( secondaryTableName, classNames, mapping );
} }
} }

View File

@ -20,7 +20,6 @@ import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.DynamicFilterAliasGenerator; import org.hibernate.internal.DynamicFilterAliasGenerator;
import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
@ -143,10 +142,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext ); super( persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext );
final SessionFactoryImplementor factory = creationContext.getSessionFactory(); final Dialect dialect = creationContext.getDialect();
final Dialect dialect = factory.getJdbcServices().getDialect(); final SqmFunctionRegistry functionRegistry = creationContext.getFunctionRegistry();
final SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry(); final TypeConfiguration typeConfiguration = creationContext.getTypeConfiguration();
final TypeConfiguration typeConfiguration = factory.getTypeConfiguration();
// CLASS + TABLE // CLASS + TABLE

View File

@ -28,7 +28,6 @@ import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.id.IdentityGenerator; import org.hibernate.id.IdentityGenerator;
import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.StaticFilterAliasGenerator; import org.hibernate.internal.StaticFilterAliasGenerator;
@ -115,8 +114,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
validateGenerator(); validateGenerator();
final SessionFactoryImplementor factory = creationContext.getSessionFactory(); final Dialect dialect = creationContext.getDialect();
final Dialect dialect = factory.getJdbcServices().getDialect();
// TABLE // TABLE
@ -162,7 +160,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
discriminatorValue = persistentClass.getSubclassId(); discriminatorValue = persistentClass.getSubclassId();
discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() ); discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() );
discriminatorType = factory.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER ); discriminatorType = creationContext.getTypeConfiguration().getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER );
// PROPERTIES // PROPERTIES

View File

@ -10,10 +10,8 @@ import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.FastSessionServices;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.mapping.PluralAttributeMapping;
@ -50,8 +48,7 @@ public class SqmMutationStrategyHelper {
EntityMappingType rootEntityDescriptor, EntityMappingType rootEntityDescriptor,
MappingModelCreationProcess creationProcess) { MappingModelCreationProcess creationProcess) {
final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext();
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); final SessionFactoryOptions options = creationContext.getSessionFactoryOptions();
final SessionFactoryOptions options = sessionFactory.getSessionFactoryOptions();
final SqmMultiTableMutationStrategy specifiedStrategy = options.getCustomSqmMultiTableMutationStrategy(); final SqmMultiTableMutationStrategy specifiedStrategy = options.getCustomSqmMultiTableMutationStrategy();
if ( specifiedStrategy != null ) { if ( specifiedStrategy != null ) {
@ -60,10 +57,7 @@ public class SqmMutationStrategyHelper {
// todo (6.0) : add capability define strategy per-hierarchy // todo (6.0) : add capability define strategy per-hierarchy
return sessionFactory.getJdbcServices() return creationContext.getDialect().getFallbackSqmMutationStrategy( rootEntityDescriptor, creationContext );
.getJdbcEnvironment()
.getDialect()
.getFallbackSqmMutationStrategy( rootEntityDescriptor, creationContext );
} }
/** /**
@ -75,8 +69,7 @@ public class SqmMutationStrategyHelper {
EntityMappingType rootEntityDescriptor, EntityMappingType rootEntityDescriptor,
MappingModelCreationProcess creationProcess) { MappingModelCreationProcess creationProcess) {
final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext();
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); final SessionFactoryOptions options = creationContext.getSessionFactoryOptions();
final SessionFactoryOptions options = sessionFactory.getSessionFactoryOptions();
final SqmMultiTableInsertStrategy specifiedStrategy = options.getCustomSqmMultiTableInsertStrategy(); final SqmMultiTableInsertStrategy specifiedStrategy = options.getCustomSqmMultiTableInsertStrategy();
if ( specifiedStrategy != null ) { if ( specifiedStrategy != null ) {
@ -84,7 +77,7 @@ public class SqmMutationStrategyHelper {
} }
// todo (6.0) : add capability define strategy per-hierarchy // 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( public static void visitCollectionTables(

View File

@ -112,7 +112,7 @@ public class CteInsertStrategy implements SqmMultiTableInsertStrategy {
this.rootDescriptor = rootDescriptor; this.rootDescriptor = rootDescriptor;
this.sessionFactory = runtimeModelCreationContext.getSessionFactory(); this.sessionFactory = runtimeModelCreationContext.getSessionFactory();
final Dialect dialect = sessionFactory.getJdbcServices().getDialect(); final Dialect dialect = runtimeModelCreationContext.getDialect();
if ( !dialect.supportsNonQueryWithCTE() ) { if ( !dialect.supportsNonQueryWithCTE() ) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(

View File

@ -9,7 +9,6 @@ package org.hibernate.query.sqm.mutation.internal.cte;
import java.util.Locale; import java.util.Locale;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
@ -70,7 +69,7 @@ public class CteMutationStrategy implements SqmMultiTableMutationStrategy {
this.rootDescriptor = rootDescriptor; this.rootDescriptor = rootDescriptor;
this.sessionFactory = runtimeModelCreationContext.getSessionFactory(); this.sessionFactory = runtimeModelCreationContext.getSessionFactory();
final Dialect dialect = sessionFactory.getJdbcServices().getDialect(); final Dialect dialect = runtimeModelCreationContext.getDialect();
if ( !dialect.supportsNonQueryWithCTE() ) { if ( !dialect.supportsNonQueryWithCTE() ) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(

View File

@ -9,7 +9,6 @@ package org.hibernate.tuple.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -19,7 +18,6 @@ import java.util.Set;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementHelper; import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementHelper;
import org.hibernate.bytecode.internal.BytecodeEnhancementMetadataNonPojoImpl; import org.hibernate.bytecode.internal.BytecodeEnhancementMetadataNonPojoImpl;
import org.hibernate.bytecode.internal.BytecodeEnhancementMetadataPojoImpl; import org.hibernate.bytecode.internal.BytecodeEnhancementMetadataPojoImpl;
@ -55,6 +53,7 @@ import org.hibernate.type.EntityType;
import org.hibernate.type.ManyToOneType; import org.hibernate.type.ManyToOneType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import static java.util.Collections.singleton;
import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.CoreLogging.messageLogger;
import static org.hibernate.internal.util.ReflectHelper.isAbstractClass; import static org.hibernate.internal.util.ReflectHelper.isAbstractClass;
import static org.hibernate.internal.util.ReflectHelper.isFinalClass; import static org.hibernate.internal.util.ReflectHelper.isFinalClass;
@ -170,7 +169,8 @@ public class EntityMetamodel implements Serializable {
versioned = persistentClass.isVersioned(); versioned = persistentClass.isVersioned();
SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions(); final boolean collectionsInDefaultFetchGroupEnabled =
creationContext.getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled();
if ( persistentClass.hasPojoRepresentation() ) { if ( persistentClass.hasPojoRepresentation() ) {
final Component identifierMapperComponent = persistentClass.getIdentifierMapper(); final Component identifierMapperComponent = persistentClass.getIdentifierMapper();
@ -186,14 +186,14 @@ public class EntityMetamodel implements Serializable {
} }
else { else {
nonAggregatedCidMapper = null; nonAggregatedCidMapper = null;
idAttributeNames = Collections.singleton( identifierAttribute.getName() ); idAttributeNames = singleton( identifierAttribute.getName() );
} }
bytecodeEnhancementMetadata = BytecodeEnhancementMetadataPojoImpl.from( bytecodeEnhancementMetadata = BytecodeEnhancementMetadataPojoImpl.from(
persistentClass, persistentClass,
idAttributeNames, idAttributeNames,
nonAggregatedCidMapper, nonAggregatedCidMapper,
sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled(), collectionsInDefaultFetchGroupEnabled,
creationContext.getMetadata() creationContext.getMetadata()
); );
} }
@ -285,7 +285,7 @@ public class EntityMetamodel implements Serializable {
assert entityBinding != null; assert entityBinding != null;
return entityBinding.hasSubclasses(); return entityBinding.hasSubclasses();
}, },
sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled() collectionsInDefaultFetchGroupEnabled
); );
if ( lazy ) { if ( lazy ) {
@ -479,7 +479,7 @@ public class EntityMetamodel implements Serializable {
} }
} }
if ( mappingProperty.getValue() instanceof Component ) { 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 CompositeGeneratorBuilder builder = new CompositeGeneratorBuilder( mappingProperty, dialect );
final Component component = (Component) mappingProperty.getValue(); final Component component = (Component) mappingProperty.getValue();
for ( Property property : component.getProperties() ) { for ( Property property : component.getProperties() ) {

View File

@ -339,7 +339,7 @@ public interface Type extends Serializable {
* @throws HibernateException An error from Hibernate * @throws HibernateException An error from Hibernate
*/ */
Object deepCopy(Object value, SessionFactoryImplementor factory) Object deepCopy(Object value, SessionFactoryImplementor factory)
throws HibernateException; throws HibernateException;
/** /**
* Are objects of this type mutable with respect to the referencing object? * Are objects of this type mutable with respect to the referencing object?