Skip to content

Commit

Permalink
HHH-18998 remove added code which is probably not necessary
Browse files Browse the repository at this point in the history
(need to check with @sebersole)
  • Loading branch information
gavinking committed Jan 23, 2025
1 parent 322b67f commit 182f0ad
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
package org.hibernate.boot.model;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Types;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
Expand Down Expand Up @@ -42,6 +38,7 @@
import org.hibernate.type.spi.TypeConfigurationAware;
import org.hibernate.usertype.UserType;

import static java.util.Collections.emptyMap;
import static org.hibernate.boot.model.process.internal.InferredBasicValueResolver.resolveSqlTypeIndicators;
import static org.hibernate.mapping.MappingHelper.injectParameters;

Expand Down Expand Up @@ -101,35 +98,32 @@ public Map<String,String> getParameters() {

public BasicValue.Resolution<?> resolve(
Map<?,?> localConfigParameters,
Annotation typeAnnotation,
MutabilityPlan<?> explicitMutabilityPlan,
MetadataBuildingContext context,
JdbcTypeIndicators indicators) {
if ( CollectionHelper.isEmpty( localConfigParameters ) ) {
// we can use the re-usable resolution...
if ( reusableResolution == null ) {
reusableResolution = createResolution( name, Collections.emptyMap(), typeAnnotation, indicators, context );
reusableResolution = createResolution( name, emptyMap(), indicators, context );
}
return reusableResolution;
}
else {
final String name = this.name + ":" + NAME_COUNTER.getAndIncrement();
return createResolution( name, localConfigParameters, typeAnnotation, indicators, context );
return createResolution( name, localConfigParameters, indicators, context );
}
}

private BasicValue.Resolution<?> createResolution(
String name,
Map<?,?> usageSiteProperties,
Annotation typeAnnotation,
JdbcTypeIndicators indicators,
MetadataBuildingContext context) {
return createResolution(
name,
typeImplementorClass,
parameters,
usageSiteProperties,
typeAnnotation,
indicators,
context
);
Expand All @@ -140,7 +134,6 @@ private static <T> BasicValue.Resolution<T> createResolution(
Class<T> typeImplementorClass,
Map<?,?> parameters,
Map<?,?> usageSiteProperties,
Annotation typeAnnotation,
JdbcTypeIndicators indicators,
MetadataBuildingContext context) {
final BootstrapContext bootstrapContext = context.getBootstrapContext();
Expand All @@ -154,7 +147,8 @@ private static <T> BasicValue.Resolution<T> createResolution(
if ( isKnownType ) {

final T typeInstance =
instantiateType( name, typeImplementorClass, typeAnnotation, context, bootstrapContext );
instantiateType( bootstrapContext.getServiceRegistry(), context.getBuildingOptions(),
name, typeImplementorClass, bootstrapContext.getCustomTypeProducer() );

if ( typeInstance instanceof TypeConfigurationAware configurationAware ) {
configurationAware.setTypeConfiguration( typeConfiguration );
Expand All @@ -174,7 +168,7 @@ private static <T> BasicValue.Resolution<T> createResolution(
@SuppressWarnings("unchecked")
final UserType<T> userType = (UserType<T>) typeInstance;
final CustomType<T> customType = new CustomType<>( userType, typeConfiguration );
return new UserTypeResolution<>( customType, null, combinedTypeParameters, typeAnnotation );
return new UserTypeResolution<>( customType, null, combinedTypeParameters );
}

if ( typeInstance instanceof BasicType ) {
Expand Down Expand Up @@ -231,28 +225,6 @@ public MutabilityPlan<T> getMutabilityPlan() {
return resolveLegacyCases( typeImplementorClass, indicators, typeConfiguration );
}

private static <T> T instantiateType(
String name, Class<T> typeImplementorClass, Annotation typeAnnotation,
MetadataBuildingContext context, BootstrapContext bootstrapContext) {
if ( typeAnnotation != null ) {
// attempt to instantiate it with the annotation as a constructor argument
try {
final Constructor<T> constructor = typeImplementorClass.getConstructor( typeAnnotation.annotationType() );
constructor.setAccessible( true );
return constructor.newInstance( typeAnnotation );
}
catch ( NoSuchMethodException ignored ) {
// no such constructor, instantiate it the old way
}
catch (InvocationTargetException|InstantiationException|IllegalAccessException e) {
throw new org.hibernate.InstantiationException( "Could not instantiate custom type", typeImplementorClass, e );
}
}

return instantiateType( bootstrapContext.getServiceRegistry(), context.getBuildingOptions(),
name, typeImplementorClass, bootstrapContext.getCustomTypeProducer() );
}

private static <T> BasicValue.Resolution<T> resolveLegacyCases(
Class<T> typeImplementorClass, JdbcTypeIndicators indicators, TypeConfiguration typeConfiguration) {
final BasicType<T> legacyType;
Expand Down Expand Up @@ -345,14 +317,12 @@ public static BasicValue.Resolution<?> createLocalResolution(
String name,
Class<?> typeImplementorClass,
Map<?,?> localTypeParams,
Annotation typeAnnotation,
MetadataBuildingContext buildingContext) {
return createResolution(
name + ':' + NAME_COUNTER.getAndIncrement(),
typeImplementorClass,
localTypeParams,
null,
typeAnnotation,
buildingContext.getBootstrapContext().getTypeConfiguration().getCurrentBaseSqlTypeIndicators(),
buildingContext
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package org.hibernate.boot.model.process.internal;

import java.lang.annotation.Annotation;
import java.util.Properties;

import org.hibernate.mapping.BasicValue;
Expand All @@ -28,16 +27,13 @@ public class UserTypeResolution<T> implements BasicValue.Resolution<T> {
* and builds its own :(
*/
private final Properties combinedTypeParameters;
private final Annotation typeAnnotation;

public UserTypeResolution(
CustomType<T> userTypeAdapter,
MutabilityPlan<T> explicitMutabilityPlan,
Properties combinedTypeParameters,
Annotation typeAnnotation) {
Properties combinedTypeParameters) {
this.userTypeAdapter = userTypeAdapter;
this.combinedTypeParameters = combinedTypeParameters;
this.typeAnnotation = typeAnnotation;
this.mutabilityPlan = explicitMutabilityPlan != null
? explicitMutabilityPlan
: new UserTypeMutabilityPlanAdapter<>( userTypeAdapter.getUserType() );
Expand Down Expand Up @@ -81,10 +77,6 @@ public Properties getCombinedTypeParameters() {
return combinedTypeParameters;
}

public Annotation getTypeAnnotation() {
return typeAnnotation;
}

@Override
public JdbcMapping getJdbcMapping() {
return userTypeAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,6 @@ private BasicType<?> resolveExplicitlyNamedAnyDiscriminatorType(
final BasicValue.Resolution<?> resolution = typeDefinition.resolve(
parameters,
null,
null,
metadataBuildingContext,
typeConfiguration.getCurrentBaseSqlTypeIndicators()
);
Expand Down
18 changes: 3 additions & 15 deletions hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,7 @@ private Resolution<?> buildResolution(Properties typeParameters) {
explicitMutabilityPlanAccess,
getAttributeConverterDescriptor(),
typeParameters,
getTypeAnnotation(),
this::setTypeParameters,
this::setTypeAnnotation,
this,
getBuildingContext()
);
Expand Down Expand Up @@ -644,7 +642,7 @@ private Resolution<?> resolution(BasicJavaType explicitJavaType, JavaType<?> jav
context.getTypeDefinitionRegistry().resolveAutoApplied( castType );
if ( autoAppliedTypeDef != null ) {
log.debug("BasicValue resolution matched auto-applied type-definition");
return autoAppliedTypeDef.resolve( getTypeParameters(), null, null, context, this );
return autoAppliedTypeDef.resolve( getTypeParameters(), null, context, this );
}
}

Expand Down Expand Up @@ -812,9 +810,7 @@ private static Resolution<?> interpretExplicitlyNamedType(
Function<TypeConfiguration, MutabilityPlan> explicitMutabilityPlanAccess,
ConverterDescriptor converterDescriptor,
Map<Object,Object> localTypeParams,
Annotation typeAnnotation,
Consumer<Properties> combinedParameterConsumer,
Consumer<Annotation> annotationConsumer,
JdbcTypeIndicators stdIndicators,
MetadataBuildingContext context) {

Expand Down Expand Up @@ -897,14 +893,12 @@ public TypeConfiguration getTypeConfiguration() {
if ( typeDefinition != null ) {
final Resolution<?> resolution = typeDefinition.resolve(
localTypeParams,
typeAnnotation,
explicitMutabilityPlanAccess != null
? explicitMutabilityPlanAccess.apply( typeConfiguration )
: null,
context,
stdIndicators
);
annotationConsumer.accept( resolution.getTypeAnnotation() );
combinedParameterConsumer.accept( resolution.getCombinedTypeParameters() );
return resolution;
}
Expand All @@ -920,7 +914,6 @@ public TypeConfiguration getTypeConfiguration() {
context.getTypeDefinitionRegistry().register( implicitDefinition );
return implicitDefinition.resolve(
localTypeParams,
typeAnnotation,
explicitMutabilityPlanAccess != null
? explicitMutabilityPlanAccess.apply( typeConfiguration )
: null,
Expand All @@ -929,7 +922,7 @@ public TypeConfiguration getTypeConfiguration() {
);
}

return TypeDefinition.createLocalResolution( name, typeNamedClass, localTypeParams, typeAnnotation, context );
return TypeDefinition.createLocalResolution( name, typeNamedClass, localTypeParams, context );
}
catch (ClassLoadingException e) {
// allow the exception below to trigger
Expand Down Expand Up @@ -1039,8 +1032,7 @@ public void setExplicitCustomType(Class<? extends UserType<?>> explicitCustomTyp
getTypeConfiguration()
),
null,
typeProperties,
typeAnnotation
typeProperties
);
}
}
Expand Down Expand Up @@ -1179,10 +1171,6 @@ default Properties getCombinedTypeParameters() {
return null;
}

default Annotation getTypeAnnotation() {
return null;
}

JdbcMapping getJdbcMapping();

/**
Expand Down

0 comments on commit 182f0ad

Please sign in to comment.