Skip to content

Commit

Permalink
avoid the use of TypeConfiguration.getServiceRegistry()
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jan 3, 2023
1 parent e8f899f commit b7b5fb7
Show file tree
Hide file tree
Showing 31 changed files with 155 additions and 131 deletions.
Expand Up @@ -56,7 +56,7 @@ public void verifyMappings(SessionFactoryScope scope) {
final JdbcType realType;
if (intervalType instanceof AdjustableJdbcType) {
realType = ((AdjustableJdbcType) intervalType).resolveIndicatedType(
() -> mappingMetamodel.getTypeConfiguration(),
mappingMetamodel.getTypeConfiguration().getCurrentBaseSqlTypeIndicators(),
jdbcMapping.getJavaTypeDescriptor()
);
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -46,6 +47,7 @@ public void verifyMappings(SessionFactoryScope scope) {
.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();
Expand All @@ -64,6 +66,11 @@ public TypeConfiguration getTypeConfiguration() {
public int getColumnScale() {
return duration.getScale() == null ? JdbcTypeIndicators.NO_COLUMN_SCALE : duration.getScale();
}

@Override
public Dialect getDialect() {
return dialect;
}
},
jdbcMapping.getJavaTypeDescriptor()
);
Expand Down
Expand Up @@ -53,7 +53,7 @@ public void verifyMappings(SessionFactoryScope scope) throws Exception {
final JdbcType realType;
if (intervalType instanceof AdjustableJdbcType) {
realType = ((AdjustableJdbcType) intervalType).resolveIndicatedType(
() -> mappingMetamodel.getTypeConfiguration(),
mappingMetamodel.getTypeConfiguration().getCurrentBaseSqlTypeIndicators(),
jdbcMapping.getJavaTypeDescriptor()
);
}
Expand Down
Expand Up @@ -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(
Expand Down
Expand Up @@ -107,7 +107,7 @@ public BootstrapContextImpl(
this.representationStrategySelector = ManagedTypeRepresentationResolverStandard.INSTANCE;

this.typeConfiguration = new TypeConfiguration();
this.beanInstanceProducer = new TypeBeanInstanceProducer( typeConfiguration );
this.beanInstanceProducer = new TypeBeanInstanceProducer( configService );
}

@Override
Expand Down
Expand Up @@ -15,7 +15,6 @@
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.
Expand All @@ -24,29 +23,27 @@
*/
@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 );
}
}
Expand All @@ -58,6 +55,6 @@ public <B> B produceBeanInstance(String name, Class<B> beanType) {

@Override
public Map<String, Object> getConfigurationSettings() {
return typeConfiguration.getServiceRegistry().getService( ConfigurationService.class ).getSettings();
return configurationService.getSettings();
}
}
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -685,6 +686,11 @@ public int getPreferredSqlTypeCodeForInstant() {
public int getPreferredSqlTypeCodeForArray() {
return context.getPreferredSqlTypeCodeForArray();
}

@Override
public Dialect getDialect() {
return context.getMetadataCollector().getDatabase().getDialect();
}
}
);
return typeConfiguration.getBasicTypeRegistry().resolve( jtd, jdbcType );
Expand Down
Expand Up @@ -1023,11 +1023,9 @@ private java.lang.reflect.Type resolveJavaType(XClass returnedClassOrElement) {
.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) {
Expand Down
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -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;
Expand Down Expand Up @@ -90,6 +89,11 @@ public int getPreferredSqlTypeCodeForInstant() {
public int getPreferredSqlTypeCodeForArray() {
return context.getPreferredSqlTypeCodeForArray();
}

@Override
public Dialect getDialect() {
return context.getMetadataCollector().getDatabase().getDialect();
}
}
);

Expand Down
Expand Up @@ -8,8 +8,6 @@

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;
Expand Down Expand Up @@ -156,7 +154,7 @@ public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabase
}

public Collection<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjects() {
return auxiliaryDatabaseObjects == null ? emptyList() : auxiliaryDatabaseObjects.values();
return auxiliaryDatabaseObjects.values();
}

public Collection<InitCommand> getInitCommands() {
Expand Down
Expand Up @@ -17,7 +17,6 @@
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;
Expand Down Expand Up @@ -107,10 +106,7 @@ public JdbcType resolveIndicatedType(JdbcTypeIndicators indicators, JavaType<?>
final int scale;
if ( indicators.getColumnScale() == JdbcTypeIndicators.NO_COLUMN_SCALE ) {
scale = domainJtd.getDefaultSqlScale(
indicators.getTypeConfiguration()
.getServiceRegistry()
.getService( JdbcServices.class )
.getDialect(),
indicators.getDialect(),
this
);
}
Expand Down

0 comments on commit b7b5fb7

Please sign in to comment.