avoid the use of TypeConfiguration.getServiceRegistry()

This commit is contained in:
Gavin 2023-01-03 17:24:58 +01:00 committed by Gavin King
parent e8f899ffbc
commit b7b5fb7559
31 changed files with 155 additions and 131 deletions

View File

@ -56,7 +56,7 @@ public class DurationMappingLegacyTests {
final JdbcType realType;
if (intervalType instanceof AdjustableJdbcType) {
realType = ((AdjustableJdbcType) intervalType).resolveIndicatedType(
() -> mappingMetamodel.getTypeConfiguration(),
mappingMetamodel.getTypeConfiguration().getCurrentBaseSqlTypeIndicators(),
jdbcMapping.getJavaTypeDescriptor()
);
}

View File

@ -12,6 +12,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.dialect.Dialect;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
@ -46,6 +47,7 @@ public class DurationMappingTests {
.getMappingMetamodel();
final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(EntityWithDuration.class);
final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("duration");
final JdbcMapping jdbcMapping = duration.getJdbcMapping();
@ -64,6 +66,11 @@ public class DurationMappingTests {
public int getColumnScale() {
return duration.getScale() == null ? JdbcTypeIndicators.NO_COLUMN_SCALE : duration.getScale();
}
@Override
public Dialect getDialect() {
return dialect;
}
},
jdbcMapping.getJavaTypeDescriptor()
);

View File

@ -53,7 +53,7 @@ public class InetAddressMappingTests {
final JdbcType realType;
if (intervalType instanceof AdjustableJdbcType) {
realType = ((AdjustableJdbcType) intervalType).resolveIndicatedType(
() -> mappingMetamodel.getTypeConfiguration(),
mappingMetamodel.getTypeConfiguration().getCurrentBaseSqlTypeIndicators(),
jdbcMapping.getJavaTypeDescriptor()
);
}

View File

@ -49,7 +49,7 @@ public class InformixDialectTestCase extends BaseUnitTestCase {
@BeforeClass
public static void init() {
TypeConfiguration typeConfiguration = new TypeConfiguration();
final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl(typeConfiguration, new MappingMetamodelImpl( typeConfiguration, ssr ) );
final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl( typeConfiguration, new MappingMetamodelImpl( typeConfiguration, ssr ), ssr );
ssr = new StandardServiceRegistryBuilder().build();
queryEngine = new QueryEngine(

View File

@ -107,7 +107,7 @@ public class BootstrapContextImpl implements BootstrapContext {
this.representationStrategySelector = ManagedTypeRepresentationResolverStandard.INSTANCE;
this.typeConfiguration = new TypeConfiguration();
this.beanInstanceProducer = new TypeBeanInstanceProducer( typeConfiguration );
this.beanInstanceProducer = new TypeBeanInstanceProducer( configService );
}
@Override

View File

@ -15,7 +15,6 @@ import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.type.spi.TypeBootstrapContext;
import org.hibernate.type.spi.TypeConfiguration;
/**
* {@link BeanInstanceProducer} implementation for building beans related to custom types.
@ -24,29 +23,27 @@ import org.hibernate.type.spi.TypeConfiguration;
*/
@Internal //TODO: move this to org.hibernate.boot.internal, where its only usage is
public class TypeBeanInstanceProducer implements BeanInstanceProducer, TypeBootstrapContext {
private final TypeConfiguration typeConfiguration;
private final ConfigurationService configurationService;
public TypeBeanInstanceProducer(TypeConfiguration typeConfiguration) {
this.typeConfiguration = typeConfiguration;
public TypeBeanInstanceProducer(ConfigurationService configurationService) {
this.configurationService = configurationService;
}
@Override
public <B> B produceBeanInstance(Class<B> beanType) {
try {
final B type;
final Constructor<B> bootstrapContextAwareTypeConstructor = ReflectHelper.getConstructor(
beanType,
TypeBootstrapContext.class
);
if ( bootstrapContextAwareTypeConstructor != null ) {
type = bootstrapContextAwareTypeConstructor.newInstance( this );
return bootstrapContextAwareTypeConstructor.newInstance( this );
}
else {
type = beanType.newInstance();
return beanType.newInstance();
}
return type;
}
catch (Exception e) {
catch ( Exception e ) {
throw new MappingException( "Could not instantiate Type: " + beanType.getName(), e );
}
}
@ -58,6 +55,6 @@ public class TypeBeanInstanceProducer implements BeanInstanceProducer, TypeBoots
@Override
public Map<String, Object> getConfigurationSettings() {
return typeConfiguration.getServiceRegistry().getService( ConfigurationService.class ).getSettings();
return configurationService.getSettings();
}
}

View File

@ -31,6 +31,7 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.GenericsHelper;
@ -685,6 +686,11 @@ public final class AnnotationBinder {
public int getPreferredSqlTypeCodeForArray() {
return context.getPreferredSqlTypeCodeForArray();
}
@Override
public Dialect getDialect() {
return context.getMetadataCollector().getDatabase().getDialect();
}
}
);
return typeConfiguration.getBasicTypeRegistry().resolve( jtd, jdbcType );

View File

@ -1023,11 +1023,9 @@ public class BasicValueBinder implements JdbcTypeIndicators {
.toType( returnedClassOrElement );
}
private Dialect getDialect() {
return buildingContext.getBuildingOptions()
.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect();
@Override
public Dialect getDialect() {
return buildingContext.getMetadataCollector().getDatabase().getDialect();
}
private void applyJpaConverter(XProperty property, ConverterDescriptor attributeConverterDescriptor) {

View File

@ -12,6 +12,7 @@ import jakarta.persistence.TemporalType;
import org.hibernate.TimeZoneStorageStrategy;
import org.hibernate.annotations.TimeZoneStorageType;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.mapping.BasicValue;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
@ -36,14 +37,12 @@ public class VersionResolution<E> implements BasicValue.Resolution<E> {
@SuppressWarnings({"rawtypes", "unchecked"})
public static <E> VersionResolution<E> from(
Function<TypeConfiguration, java.lang.reflect.Type> implicitJavaTypeAccess,
Function<TypeConfiguration, BasicJavaType> explicitJtdAccess,
Function<TypeConfiguration, JdbcType> explicitStdAccess,
TimeZoneStorageType timeZoneStorageType,
TypeConfiguration typeConfiguration,
@SuppressWarnings("unused") MetadataBuildingContext context) {
// todo (6.0) : add support for Dialect-specific interpretation?
final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final java.lang.reflect.Type implicitJavaType = implicitJavaTypeAccess.apply( typeConfiguration );
final JavaType registered = typeConfiguration.getJavaTypeRegistry().resolveDescriptor( implicitJavaType );
final BasicJavaType jtd = (BasicJavaType) registered;
@ -90,6 +89,11 @@ public class VersionResolution<E> implements BasicValue.Resolution<E> {
public int getPreferredSqlTypeCodeForArray() {
return context.getPreferredSqlTypeCodeForArray();
}
@Override
public Dialect getDialect() {
return context.getMetadataCollector().getDatabase().getDialect();
}
}
);

View File

@ -8,8 +8,6 @@ package org.hibernate.boot.model.relational;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -156,7 +154,7 @@ public class Database {
}
public Collection<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjects() {
return auxiliaryDatabaseObjects == null ? emptyList() : auxiliaryDatabaseObjects.values();
return auxiliaryDatabaseObjects.values();
}
public Collection<InitCommand> getInitCommands() {

View File

@ -17,7 +17,6 @@ import java.sql.Types;
import java.time.Duration;
import org.hibernate.HibernateException;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.ValueBinder;
@ -107,10 +106,7 @@ public class PostgreSQLIntervalSecondJdbcType implements AdjustableJdbcType {
final int scale;
if ( indicators.getColumnScale() == JdbcTypeIndicators.NO_COLUMN_SCALE ) {
scale = domainJtd.getDefaultSqlScale(
indicators.getTypeConfiguration()
.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect(),
indicators.getDialect(),
this
);
}

View File

@ -29,10 +29,8 @@ import org.hibernate.boot.model.process.internal.VersionResolution;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
@ -44,7 +42,6 @@ import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.resource.beans.spi.ManagedBean;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation;
import org.hibernate.type.BasicType;
import org.hibernate.type.CustomType;
@ -73,8 +70,6 @@ import static org.hibernate.mapping.MappingHelper.injectParameters;
public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resolvable {
private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class );
private final TypeConfiguration typeConfiguration;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// incoming "configuration" values
@ -107,15 +102,11 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
public BasicValue(MetadataBuildingContext buildingContext, Table table) {
super( buildingContext, table );
this.typeConfiguration = buildingContext.getBootstrapContext().getTypeConfiguration();
buildingContext.getMetadataCollector().registerValueMappingResolver( this::resolve );
}
public BasicValue(BasicValue original) {
super( original );
this.typeConfiguration = original.typeConfiguration;
this.explicitTypeName = original.explicitTypeName;
this.explicitLocalTypeParams = original.explicitLocalTypeParams == null
? null
@ -321,12 +312,17 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
final Selectable selectable = getColumn();
if ( selectable instanceof Column ) {
resolveColumn( (Column) selectable, getServiceRegistry().getService( JdbcServices.class ).getDialect() );
resolveColumn( (Column) selectable, getDialect() );
}
return resolution;
}
@Override
public Dialect getDialect() {
return getMetadata().getDatabase().getDialect();
}
private void resolveColumn(Column column, Dialect dialect) {
if ( column.getSqlTypeCode() == null ) {
@ -381,7 +377,6 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
typeParameters,
this::setTypeParameters,
this,
typeConfiguration,
getBuildingContext()
);
}
@ -390,10 +385,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
if ( isVersion() ) {
return VersionResolution.from(
implicitJavaTypeAccess,
explicitJavaTypeAccess,
explicitJdbcTypeAccess,
timeZoneStorageType,
typeConfiguration,
getBuildingContext()
);
}
@ -402,16 +394,14 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
// determine JavaType if we can
final BasicJavaType explicitJavaType = explicitJavaTypeAccess == null ? null
: explicitJavaTypeAccess.apply( typeConfiguration );
: explicitJavaTypeAccess.apply( getTypeConfiguration() );
final JavaType<?> javaType = determineJavaType( explicitJavaType );
final ConverterDescriptor attributeConverterDescriptor = getAttributeConverterDescriptor();
final Selectable column = getColumn();
if ( attributeConverterDescriptor != null ) {
final ManagedBeanRegistry managedBeanRegistry = getBuildingContext().getBootstrapContext()
.getServiceRegistry()
.getService( ManagedBeanRegistry.class );
final ManagedBeanRegistry managedBeanRegistry = getServiceRegistry().getService( ManagedBeanRegistry.class );
final NamedConverterResolution<?> converterResolution = NamedConverterResolution.from(
attributeConverterDescriptor,
@ -426,7 +416,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
}
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
return BasicValue.this.getTypeConfiguration();
}
},
getBuildingContext()
@ -441,13 +431,13 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
final BasicType registeredElementType = converterResolution.getLegacyResolvedBasicType();
final BasicType<?> registeredType = registeredElementType == null ? null
: containerJtd.resolveType(
typeConfiguration,
getMetadata().getDatabase().getDialect(),
getTypeConfiguration(),
getDialect(),
registeredElementType,
column instanceof ColumnTypeInformation ? (ColumnTypeInformation) column : null
);
if ( registeredType != null ) {
typeConfiguration.getBasicTypeRegistry().register( registeredType );
getTypeConfiguration().getBasicTypeRegistry().register( registeredType );
return new InferredBasicValueResolution(
registeredType,
@ -464,11 +454,11 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
}
final JdbcType jdbcType = explicitJdbcTypeAccess != null
? explicitJdbcTypeAccess.apply( typeConfiguration )
? explicitJdbcTypeAccess.apply( getTypeConfiguration() )
: null;
final JavaType<?> basicJavaType = javaType == null && jdbcType != null
? jdbcType.getJdbcRecommendedJavaTypeMapping( null, null, typeConfiguration )
? jdbcType.getJdbcRecommendedJavaTypeMapping( null, null, getTypeConfiguration() )
: javaType;
if ( basicJavaType == null ) {
throw new MappingException( "Unable to determine JavaType to use : " + this );
@ -493,8 +483,8 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
column,
ownerName,
propertyName,
getMetadata().getDatabase().getDialect(),
typeConfiguration
getDialect(),
getTypeConfiguration()
);
}
}
@ -504,9 +494,9 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
if ( javaType == null ) {
if ( implicitJavaTypeAccess != null ) {
final java.lang.reflect.Type implicitJtd = implicitJavaTypeAccess.apply( typeConfiguration );
final java.lang.reflect.Type implicitJtd = implicitJavaTypeAccess.apply( getTypeConfiguration() );
if ( implicitJtd != null ) {
javaType = typeConfiguration.getJavaTypeRegistry().getDescriptor( implicitJtd );
javaType = getTypeConfiguration().getJavaTypeRegistry().getDescriptor( implicitJtd );
}
}
}
@ -528,16 +518,13 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
impliedJavaType = resolvedJavaType;
}
else if ( implicitJavaTypeAccess != null ) {
impliedJavaType = implicitJavaTypeAccess.apply( typeConfiguration );
impliedJavaType = implicitJavaTypeAccess.apply( getTypeConfiguration() );
}
else if ( ownerName != null && propertyName != null ) {
final ServiceRegistry serviceRegistry = typeConfiguration.getServiceRegistry();
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
impliedJavaType = ReflectHelper.reflectedPropertyType(
ownerName,
propertyName,
classLoaderService
getServiceRegistry().getService( ClassLoaderService.class )
);
}
else {
@ -550,10 +537,9 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
return null;
}
return typeConfiguration.getJavaTypeRegistry().resolveDescriptor( impliedJavaType );
return getTypeConfiguration().getJavaTypeRegistry().resolveDescriptor( impliedJavaType );
}
private static Resolution<?> interpretExplicitlyNamedType(
String name,
Function<TypeConfiguration, BasicJavaType> explicitJtdAccess,
@ -563,11 +549,11 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
Map<Object,Object> localTypeParams,
Consumer<Properties> combinedParameterConsumer,
JdbcTypeIndicators stdIndicators,
TypeConfiguration typeConfiguration,
MetadataBuildingContext context) {
final StandardServiceRegistry serviceRegistry = context.getBootstrapContext().getServiceRegistry();
final ManagedBeanRegistry managedBeanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class );
final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final JpaAttributeConverterCreationContext converterCreationContext = new JpaAttributeConverterCreationContext() {
@Override
@ -653,7 +639,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
// see if the name is a UserType or BasicType implementor class name
final ClassLoaderService cls = typeConfiguration.getServiceRegistry().getService( ClassLoaderService.class );
final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class );
try {
final Class<?> typeNamedClass = cls.classForName( name );
@ -726,7 +712,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
public int resolveJdbcTypeCode(int jdbcTypeCode) {
return aggregateColumn == null
? jdbcTypeCode
: getMetadata().getDatabase().getDialect().getAggregateSupport()
: getDialect().getAggregateSupport()
.aggregateComponentSqlTypeCode( aggregateColumn.getSqlTypeCode(), jdbcTypeCode );
}
@ -754,11 +740,6 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
return buildingContext.getBuildingOptions().getDefaultTimeZoneStorage();
}
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}
public void setExplicitTypeParams(Map<String,String> explicitLocalTypeParams) {
this.explicitLocalTypeParams = explicitLocalTypeParams;
}
@ -771,11 +752,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
if ( StringHelper.isNotEmpty( typeName ) ) {
if ( typeName.startsWith( ConverterDescriptor.TYPE_NAME_PREFIX ) ) {
final String converterClassName = typeName.substring( ConverterDescriptor.TYPE_NAME_PREFIX.length() );
final ClassLoaderService cls = getBuildingContext()
.getMetadataCollector()
.getMetadataBuildingOptions()
.getServiceRegistry()
.getService( ClassLoaderService.class );
final ClassLoaderService cls = getServiceRegistry().getService( ClassLoaderService.class );
try {
final Class<AttributeConverter<?,?>> converterClass = cls.classForName( converterClassName );
setAttributeConverterDescriptor( new ClassBasedConverterDescriptor(
@ -805,8 +782,8 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
throw new UnsupportedOperationException( "Unsupported attempt to set an explicit-custom-type when value is already resolved" );
}
final BootstrapContext bootstrapContext = getBuildingContext().getBootstrapContext();
final BeanInstanceProducer instanceProducer = bootstrapContext.getCustomTypeProducer();
final BeanInstanceProducer instanceProducer =
getBuildingContext().getBootstrapContext().getCustomTypeProducer();
final Properties properties = new Properties();
if ( CollectionHelper.isNotEmpty( getTypeParameters() ) ) {
@ -818,23 +795,19 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
final ManagedBean<T> typeBean;
if ( properties.isEmpty() ) {
typeBean = bootstrapContext
.getServiceRegistry()
.getService( ManagedBeanRegistry.class )
typeBean = getServiceRegistry().getService( ManagedBeanRegistry.class )
.getBean( explicitCustomType, instanceProducer );
}
else {
final String name = explicitCustomType.getName() + COUNTER++;
typeBean = bootstrapContext
.getServiceRegistry()
.getService( ManagedBeanRegistry.class )
typeBean = getServiceRegistry().getService( ManagedBeanRegistry.class )
.getBean( name, explicitCustomType, instanceProducer );
}
final T typeInstance = typeBean.getBeanInstance();
if ( typeInstance instanceof TypeConfigurationAware ) {
( (TypeConfigurationAware) typeInstance ).setTypeConfiguration( typeConfiguration );
( (TypeConfigurationAware) typeInstance ).setTypeConfiguration( getTypeConfiguration() );
}
if ( typeInstance instanceof DynamicParameterizedType ) {
@ -851,7 +824,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
setTypeParameters( properties );
this.resolution = new UserTypeResolution(
new CustomType<>( (UserType<?>) typeInstance, typeConfiguration ),
new CustomType<>( (UserType<?>) typeInstance, getTypeConfiguration() ),
null,
properties
);

View File

@ -155,6 +155,10 @@ public abstract class SimpleValue implements KeyValue {
return getMetadata().getMetadataBuildingOptions().getServiceRegistry();
}
public TypeConfiguration getTypeConfiguration() {
return getBuildingContext().getBootstrapContext().getTypeConfiguration();
}
public void setOnDeleteAction(OnDeleteAction onDeleteAction) {
this.onDeleteAction = onDeleteAction;
}
@ -730,6 +734,11 @@ public abstract class SimpleValue implements KeyValue {
public TimeZoneStorageStrategy getDefaultTimeZoneStorageStrategy() {
return buildingContext.getBuildingOptions().getDefaultTimeZoneStorage();
}
@Override
public Dialect getDialect() {
return buildingContext.getMetadataCollector().getDatabase().getDialect();
}
}
);
int jdbcTypeCode = recommendedJdbcType.getDdlTypeCode();

View File

@ -41,9 +41,7 @@ public interface JpaMetamodel extends Metamodel {
*/
TypeConfiguration getTypeConfiguration();
default ServiceRegistry getServiceRegistry() {
return getTypeConfiguration().getServiceRegistry();
}
ServiceRegistry getServiceRegistry();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -51,6 +51,7 @@ import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.spi.DynamicModelJavaType;
import org.hibernate.type.descriptor.java.spi.EntityJavaType;
@ -85,6 +86,7 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
private final TypeConfiguration typeConfiguration;
private final MappingMetamodel mappingMetamodel;
private final ServiceRegistry serviceRegistry;
private final Map<String, EntityDomainType<?>> jpaEntityTypeMap = new TreeMap<>(); // Need ordering for deterministic implementers list in SqmPolymorphicRootDescriptor
private final Map<Class<?>, ManagedDomainType<?>> jpaManagedTypeMap = new HashMap<>();
@ -102,9 +104,13 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
private final Map<String,Object> knownInvalidnameToImportMap = new ConcurrentHashMap<>();
public JpaMetamodelImpl(TypeConfiguration typeConfiguration, MappingMetamodel mappingMetamodel) {
public JpaMetamodelImpl(
TypeConfiguration typeConfiguration,
MappingMetamodel mappingMetamodel,
ServiceRegistry serviceRegistry) {
this.typeConfiguration = typeConfiguration;
this.mappingMetamodel = mappingMetamodel;
this.serviceRegistry = serviceRegistry;
}
@Override
@ -112,6 +118,11 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
return typeConfiguration;
}
@Override
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
@Override
public JpaCompliance getJpaCompliance() {
return typeConfiguration.getJpaCompliance();

View File

@ -165,7 +165,7 @@ public class MappingMetamodelImpl implements MappingMetamodelImplementor, Metamo
public MappingMetamodelImpl(TypeConfiguration typeConfiguration, ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
this.typeConfiguration = typeConfiguration;
this.jpaMetamodel = new JpaMetamodelImpl( typeConfiguration, this );
this.jpaMetamodel = new JpaMetamodelImpl( typeConfiguration, this, serviceRegistry );
}
public JpaMetamodelImplementor getJpaMetamodel() {
@ -361,6 +361,11 @@ public class MappingMetamodelImpl implements MappingMetamodelImplementor, Metamo
return typeConfiguration;
}
@Override
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
@Override
public void forEachEntityDescriptor(Consumer<EntityPersister> action) {
entityPersisterMap.values().forEach( action );

View File

@ -105,7 +105,7 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
return;
}
if ( ! getTypeConfiguration().getJpaCompliance().isLoadByIdComplianceEnabled() ) {
if ( ! sessionFactory.getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled() ) {
try {
if ( bindType != null ) {
value = coerce( value, bindType );
@ -211,7 +211,7 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
bindType = queryParameter.getHibernateType();
}
if ( ! getTypeConfiguration().getJpaCompliance().isLoadByIdComplianceEnabled() ) {
if ( ! sessionFactory.getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled() ) {
if ( bindType != null ) {
try {
value = coerce( value, bindType );

View File

@ -34,6 +34,7 @@ import org.hibernate.Internal;
import org.hibernate.LockMode;
import org.hibernate.QueryException;
import org.hibernate.boot.model.process.internal.InferredBasicValueResolver;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.TimestampaddFunction;
import org.hibernate.dialect.function.TimestampdiffFunction;
import org.hibernate.engine.FetchTiming;
@ -611,6 +612,11 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
return statement;
}
@Override
public Dialect getDialect() {
return creationContext.getSessionFactory().getJdbcServices().getDialect();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SqlTypeDescriptorIndicators

View File

@ -128,6 +128,11 @@ public interface ResultSetAccess extends JdbcValuesMetadata {
public EnumType getEnumeratedType() {
return resolvedJdbcType.isNumber() ? EnumType.ORDINAL : EnumType.STRING;
}
@Override
public Dialect getDialect() {
return getFactory().getJdbcServices().getDialect();
}
}
);
}

View File

@ -19,6 +19,7 @@ import jakarta.persistence.MapKeyEnumerated;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.annotations.Nationalized;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.CoreLogging;
@ -508,5 +509,10 @@ public class EnumType<T extends Enum<T>>
public long getColumnLength() {
return columnLength == null ? NO_COLUMN_LENGTH : columnLength;
}
@Override
public Dialect getDialect() {
return typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect();
}
}
}

View File

@ -48,9 +48,7 @@ public abstract class AbstractArrayJavaType<T, E> extends AbstractClassJavaType<
if ( jdbcType instanceof ArrayJdbcType ) {
return ( (ArrayJdbcType) jdbcType ).resolveType(
typeConfiguration,
typeConfiguration.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect(),
indicators.getDialect(),
recommendedComponentJdbcType,
ColumnTypeInformation.EMPTY
);

View File

@ -20,7 +20,6 @@ import org.hibernate.internal.util.CharSequenceHelper;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.compare.ComparableComparator;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;

View File

@ -74,9 +74,7 @@ public class BasicCollectionJavaType<C extends Collection<E>, E> extends Abstrac
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
return ( (ArrayJdbcType) jdbcType ).resolveType(
typeConfiguration,
typeConfiguration.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect(),
indicators.getDialect(),
recommendedComponentJdbcType,
ColumnTypeInformation.EMPTY
);

View File

@ -61,12 +61,7 @@ public class RegistryHelper {
if ( javaTypeClass.isAnnotationPresent( Mutability.class ) ) {
final Mutability annotation = javaTypeClass.getAnnotation( Mutability.class );
final Class<? extends MutabilityPlan<?>> planClass = annotation.value();
final ManagedBeanRegistry managedBeanRegistry = typeConfiguration
.getServiceRegistry()
.getService( ManagedBeanRegistry.class );
final ManagedBean<? extends MutabilityPlan<?>> planBean = managedBeanRegistry.getBean( planClass );
return (MutabilityPlan<J>) planBean.getBeanInstance();
return typeConfiguration.createMutabilityPlan( annotation.value() );
}
if ( javaTypeClass.isEnum() ) {

View File

@ -12,11 +12,9 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.BasicJavaType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterNumericData;
import org.hibernate.type.spi.TypeConfiguration;
@ -52,8 +50,11 @@ public class FloatJdbcType implements JdbcType {
Integer length,
Integer scale,
TypeConfiguration typeConfiguration) {
if ( length != null && length <= typeConfiguration.getServiceRegistry().getService( JdbcServices.class ).getDialect().getFloatPrecision() ) {
return typeConfiguration.getJavaTypeRegistry().getDescriptor( Float.class );
if ( length != null ) {
int floatPrecision = typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect().getFloatPrecision();
if ( length <= floatPrecision ) {
return typeConfiguration.getJavaTypeRegistry().getDescriptor( Float.class );
}
}
return typeConfiguration.getJavaTypeRegistry().getDescriptor( Double.class );
}

View File

@ -11,6 +11,7 @@ import jakarta.persistence.TemporalType;
import org.hibernate.AssertionFailure;
import org.hibernate.TimeZoneStorageStrategy;
import org.hibernate.dialect.Dialect;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.java.BasicJavaType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
@ -237,4 +238,6 @@ public interface JdbcTypeIndicators {
throw new IllegalArgumentException( "Unexpected jakarta.persistence.TemporalType : " + temporalPrecision);
}
}
Dialect getDialect();
}

View File

@ -91,10 +91,7 @@ public class NVarcharJdbcType implements AdjustableJdbcType {
}
protected boolean shouldUseMaterializedLob(JdbcTypeIndicators indicators) {
final Dialect dialect = indicators.getTypeConfiguration()
.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect();
final Dialect dialect = indicators.getDialect();
final long length = indicators.getColumnLength();
final long maxLength = indicators.isNationalized() ?
dialect.getMaxNVarcharCapacity() :

View File

@ -88,10 +88,7 @@ public class VarbinaryJdbcType implements AdjustableJdbcType {
}
protected boolean shouldUseMaterializedLob(JdbcTypeIndicators indicators) {
final Dialect dialect = indicators.getTypeConfiguration()
.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect();
final Dialect dialect = indicators.getDialect();
final long length = indicators.getColumnLength();
final long maxLength = dialect.getMaxVarbinaryCapacity();
return length > maxLength && dialect.useMaterializedLobWhenCapacityExceeded();

View File

@ -89,10 +89,7 @@ public class VarcharJdbcType implements AdjustableJdbcType {
}
protected boolean shouldUseMaterializedLob(JdbcTypeIndicators indicators) {
final Dialect dialect = indicators.getTypeConfiguration()
.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect();
final Dialect dialect = indicators.getDialect();
final long length = indicators.getColumnLength();
final long maxLength = indicators.isNationalized() ?
dialect.getMaxNVarcharCapacity() :

View File

@ -41,6 +41,7 @@ import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.BasicTypeRegistration;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.id.uuid.LocalObjectUuidHelper;
import org.hibernate.internal.CoreMessageLogger;
@ -56,12 +57,15 @@ import org.hibernate.query.sqm.IntervalType;
import org.hibernate.query.internal.QueryHelper;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.tree.SqmTypedNode;
import org.hibernate.resource.beans.spi.ManagedBean;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.MutabilityPlan;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
@ -231,7 +235,10 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
* is obtained.
*
* @return The {@link ServiceRegistry} for the current scope
*
* @deprecated This simply isn't a very sensible place to hang the {@link ServiceRegistry}
*/
@Deprecated(since = "6.2")
public ServiceRegistry getServiceRegistry() {
return scope.getServiceRegistry();
}
@ -345,14 +352,14 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
}
try {
final ClassLoaderService cls = getServiceRegistry().getService( ClassLoaderService.class );
final Class<?> javaTypeClass = cls.classForName( name );
final Class<?> javaTypeClass =
scope.getServiceRegistry().getService( ClassLoaderService.class )
.classForName( name );
final JavaType<?> jtd = javaTypeRegistry.resolveDescriptor( javaTypeClass );
final JdbcType jdbcType = jtd.getRecommendedJdbcType( getCurrentBaseSqlTypeIndicators() );
return basicTypeRegistry.resolve( jtd, jdbcType );
}
catch (Exception ignore) {
catch ( Exception ignore ) {
}
throw new HibernateException( "unrecognized cast target type: " + name );
@ -444,6 +451,13 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
: sessionFactory.getSessionFactoryOptions().getPreferredSqlTypeCodeForArray();
}
@Override
public Dialect getDialect() {
return sessionFactory == null
? metadataBuildingContext.getMetadataCollector().getDatabase().getDialect()
: sessionFactory.getJdbcServices().getDialect();
}
private Scope(TypeConfiguration typeConfiguration) {
this.typeConfiguration = typeConfiguration;
}
@ -789,4 +803,12 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
return matchesJavaType( type, Duration.class );
}
@Internal @SuppressWarnings("unchecked")
public <J> MutabilityPlan<J> createMutabilityPlan(Class<? extends MutabilityPlan<?>> planClass) {
final ManagedBean<? extends MutabilityPlan<?>> planBean =
scope.getServiceRegistry()
.getService( ManagedBeanRegistry.class )
.getBean( planClass );
return (MutabilityPlan<J>) planBean.getBeanInstance();
}
}

View File

@ -47,9 +47,7 @@ public class DomainModelTesting {
}
private void settingAssertions(DomainModelScope scope) {
final org.hibernate.service.ServiceRegistry serviceRegistry = ( (MetadataImplementor) scope.getDomainModel() )
.getTypeConfiguration()
.getServiceRegistry();
final org.hibernate.service.ServiceRegistry serviceRegistry = scope.getDomainModel().getDatabase().getServiceRegistry();
final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
assertThat( configurationService.getSettings().get( "simple" ) ).isEqualTo( "simple-value" );
}