55package org .hibernate .boot .model ;
66
77import java .io .Serializable ;
8- import java .lang .annotation .Annotation ;
9- import java .lang .reflect .Constructor ;
10- import java .lang .reflect .InvocationTargetException ;
118import java .sql .Types ;
129import java .util .Arrays ;
1310import java .util .Collections ;
4239import org .hibernate .type .spi .TypeConfigurationAware ;
4340import org .hibernate .usertype .UserType ;
4441
42+ import static java .util .Collections .emptyMap ;
4543import static org .hibernate .boot .model .process .internal .InferredBasicValueResolver .resolveSqlTypeIndicators ;
4644import static org .hibernate .mapping .MappingHelper .injectParameters ;
4745
@@ -101,35 +99,32 @@ public Map<String,String> getParameters() {
10199
102100 public BasicValue .Resolution <?> resolve (
103101 Map <?,?> localConfigParameters ,
104- Annotation typeAnnotation ,
105102 MutabilityPlan <?> explicitMutabilityPlan ,
106103 MetadataBuildingContext context ,
107104 JdbcTypeIndicators indicators ) {
108105 if ( CollectionHelper .isEmpty ( localConfigParameters ) ) {
109106 // we can use the re-usable resolution...
110107 if ( reusableResolution == null ) {
111- reusableResolution = createResolution ( name , Collections . emptyMap (), typeAnnotation , indicators , context );
108+ reusableResolution = createResolution ( name , emptyMap (), indicators , context );
112109 }
113110 return reusableResolution ;
114111 }
115112 else {
116113 final String name = this .name + ":" + NAME_COUNTER .getAndIncrement ();
117- return createResolution ( name , localConfigParameters , typeAnnotation , indicators , context );
114+ return createResolution ( name , localConfigParameters , indicators , context );
118115 }
119116 }
120117
121118 private BasicValue .Resolution <?> createResolution (
122119 String name ,
123120 Map <?,?> usageSiteProperties ,
124- Annotation typeAnnotation ,
125121 JdbcTypeIndicators indicators ,
126122 MetadataBuildingContext context ) {
127123 return createResolution (
128124 name ,
129125 typeImplementorClass ,
130126 parameters ,
131127 usageSiteProperties ,
132- typeAnnotation ,
133128 indicators ,
134129 context
135130 );
@@ -140,7 +135,6 @@ private static <T> BasicValue.Resolution<T> createResolution(
140135 Class <T > typeImplementorClass ,
141136 Map <?,?> parameters ,
142137 Map <?,?> usageSiteProperties ,
143- Annotation typeAnnotation ,
144138 JdbcTypeIndicators indicators ,
145139 MetadataBuildingContext context ) {
146140 final BootstrapContext bootstrapContext = context .getBootstrapContext ();
@@ -154,7 +148,8 @@ private static <T> BasicValue.Resolution<T> createResolution(
154148 if ( isKnownType ) {
155149
156150 final T typeInstance =
157- instantiateType ( name , typeImplementorClass , typeAnnotation , context , bootstrapContext );
151+ instantiateType ( bootstrapContext .getServiceRegistry (), context .getBuildingOptions (),
152+ name , typeImplementorClass , bootstrapContext .getCustomTypeProducer () );
158153
159154 if ( typeInstance instanceof TypeConfigurationAware configurationAware ) {
160155 configurationAware .setTypeConfiguration ( typeConfiguration );
@@ -174,7 +169,7 @@ private static <T> BasicValue.Resolution<T> createResolution(
174169 @ SuppressWarnings ("unchecked" )
175170 final UserType <T > userType = (UserType <T >) typeInstance ;
176171 final CustomType <T > customType = new CustomType <>( userType , typeConfiguration );
177- return new UserTypeResolution <>( customType , null , combinedTypeParameters , typeAnnotation );
172+ return new UserTypeResolution <>( customType , null , combinedTypeParameters );
178173 }
179174
180175 if ( typeInstance instanceof BasicType ) {
@@ -231,28 +226,6 @@ public MutabilityPlan<T> getMutabilityPlan() {
231226 return resolveLegacyCases ( typeImplementorClass , indicators , typeConfiguration );
232227 }
233228
234- private static <T > T instantiateType (
235- String name , Class <T > typeImplementorClass , Annotation typeAnnotation ,
236- MetadataBuildingContext context , BootstrapContext bootstrapContext ) {
237- if ( typeAnnotation != null ) {
238- // attempt to instantiate it with the annotation as a constructor argument
239- try {
240- final Constructor <T > constructor = typeImplementorClass .getConstructor ( typeAnnotation .annotationType () );
241- constructor .setAccessible ( true );
242- return constructor .newInstance ( typeAnnotation );
243- }
244- catch ( NoSuchMethodException ignored ) {
245- // no such constructor, instantiate it the old way
246- }
247- catch (InvocationTargetException |InstantiationException |IllegalAccessException e ) {
248- throw new org .hibernate .InstantiationException ( "Could not instantiate custom type" , typeImplementorClass , e );
249- }
250- }
251-
252- return instantiateType ( bootstrapContext .getServiceRegistry (), context .getBuildingOptions (),
253- name , typeImplementorClass , bootstrapContext .getCustomTypeProducer () );
254- }
255-
256229 private static <T > BasicValue .Resolution <T > resolveLegacyCases (
257230 Class <T > typeImplementorClass , JdbcTypeIndicators indicators , TypeConfiguration typeConfiguration ) {
258231 final BasicType <T > legacyType ;
@@ -345,14 +318,12 @@ public static BasicValue.Resolution<?> createLocalResolution(
345318 String name ,
346319 Class <?> typeImplementorClass ,
347320 Map <?,?> localTypeParams ,
348- Annotation typeAnnotation ,
349321 MetadataBuildingContext buildingContext ) {
350322 return createResolution (
351323 name + ':' + NAME_COUNTER .getAndIncrement (),
352324 typeImplementorClass ,
353325 localTypeParams ,
354326 null ,
355- typeAnnotation ,
356327 buildingContext .getBootstrapContext ().getTypeConfiguration ().getCurrentBaseSqlTypeIndicators (),
357328 buildingContext
358329 );
0 commit comments