1515import java .util .Properties ;
1616import java .util .concurrent .atomic .AtomicInteger ;
1717
18- import org .hibernate .boot .model .process .internal .InferredBasicValueResolver ;
1918import org .hibernate .boot .model .process .internal .UserTypeResolution ;
2019import org .hibernate .boot .registry .StandardServiceRegistry ;
2120import org .hibernate .boot .spi .BootstrapContext ;
4241import org .hibernate .type .spi .TypeConfigurationAware ;
4342import org .hibernate .usertype .UserType ;
4443
44+ import static org .hibernate .boot .model .process .internal .InferredBasicValueResolver .resolveSqlTypeIndicators ;
4545import static org .hibernate .mapping .MappingHelper .injectParameters ;
4646
4747/**
@@ -131,26 +131,28 @@ private BasicValue.Resolution<?> createResolution(
131131 );
132132 }
133133
134- private static BasicValue .Resolution <? > createResolution (
134+ private static < T > BasicValue .Resolution <T > createResolution (
135135 String name ,
136- Class <? > typeImplementorClass ,
136+ Class <T > typeImplementorClass ,
137137 Map <?,?> parameters ,
138138 Map <?,?> usageSiteProperties ,
139139 JdbcTypeIndicators indicators ,
140140 MetadataBuildingContext context ) {
141141 final BootstrapContext bootstrapContext = context .getBootstrapContext ();
142142 final TypeConfiguration typeConfiguration = bootstrapContext .getTypeConfiguration ();
143143 final BeanInstanceProducer instanceProducer = bootstrapContext .getCustomTypeProducer ();
144- final boolean isKnownType = Type .class .isAssignableFrom ( typeImplementorClass )
144+ final boolean isKnownType =
145+ Type .class .isAssignableFrom ( typeImplementorClass )
145146 || UserType .class .isAssignableFrom ( typeImplementorClass );
146147
147148 // support for AttributeConverter would be nice too
148149 if ( isKnownType ) {
149- final Object typeInstance = instantiateType ( bootstrapContext .getServiceRegistry (),
150+ final T typeInstance = instantiateType ( bootstrapContext .getServiceRegistry (),
150151 context .getBuildingOptions (), name , typeImplementorClass , instanceProducer );
151152
152153 if ( typeInstance instanceof TypeConfigurationAware ) {
153- ( (TypeConfigurationAware ) typeInstance ).setTypeConfiguration ( typeConfiguration );
154+ final TypeConfigurationAware configurationAware = (TypeConfigurationAware ) typeInstance ;
155+ configurationAware .setTypeConfiguration ( typeConfiguration );
154156 }
155157
156158 final Properties combinedTypeParameters = new Properties ();
@@ -164,22 +166,23 @@ private static BasicValue.Resolution<?> createResolution(
164166 injectParameters ( typeInstance , combinedTypeParameters );
165167
166168 if ( typeInstance instanceof UserType ) {
167- final UserType <?> userType = ( UserType <?>) typeInstance ;
168- final CustomType <?> customType = new CustomType <>( userType , typeConfiguration ) ;
169-
170- return new UserTypeResolution ( customType , null , combinedTypeParameters );
169+ @ SuppressWarnings ( "unchecked" )
170+ final UserType < T > userType = ( UserType < T >) typeInstance ;
171+ final CustomType < T > customType = new CustomType <>( userType , typeConfiguration );
172+ return new UserTypeResolution <> ( customType , null , combinedTypeParameters );
171173 }
172174
173175 if ( typeInstance instanceof BasicType ) {
174- final BasicType <?> resolvedBasicType = (BasicType <?>) typeInstance ;
176+ @ SuppressWarnings ("unchecked" )
177+ final BasicType <T > resolvedBasicType = (BasicType <T >) typeInstance ;
175178 return new BasicValue .Resolution <>() {
176179 @ Override
177180 public JdbcMapping getJdbcMapping () {
178181 return resolvedBasicType ;
179182 }
180183
181- @ Override @ SuppressWarnings ({ "rawtypes" , "unchecked" })
182- public BasicType getLegacyResolvedBasicType () {
184+ @ Override
185+ public BasicType < T > getLegacyResolvedBasicType () {
183186 return resolvedBasicType ;
184187 }
185188
@@ -188,8 +191,8 @@ public Properties getCombinedTypeParameters() {
188191 return combinedTypeParameters ;
189192 }
190193
191- @ Override @ SuppressWarnings ({ "rawtypes" , "unchecked" })
192- public JavaType getDomainJavaType () {
194+ @ Override
195+ public JavaType < T > getDomainJavaType () {
193196 return resolvedBasicType .getMappedJavaType ();
194197 }
195198
@@ -204,12 +207,12 @@ public JdbcType getJdbcType() {
204207 }
205208
206209 @ Override
207- public BasicValueConverter getValueConverter () {
210+ public BasicValueConverter < T ,?> getValueConverter () {
208211 return resolvedBasicType .getValueConverter ();
209212 }
210213
211- @ Override @ SuppressWarnings ({ "rawtypes" , "unchecked" })
212- public MutabilityPlan getMutabilityPlan () {
214+ @ Override
215+ public MutabilityPlan < T > getMutabilityPlan () {
213216 // a TypeDefinition does not explicitly provide a MutabilityPlan (yet?)
214217 return resolvedBasicType .isMutable ()
215218 ? getDomainJavaType ().getMutabilityPlan ()
@@ -220,37 +223,35 @@ public MutabilityPlan getMutabilityPlan() {
220223 }
221224
222225 // Series of backward compatible special cases
226+ return resolveLegacyCases ( typeImplementorClass , indicators , typeConfiguration );
227+ }
223228
229+ private static <T > BasicValue .Resolution <T > resolveLegacyCases (
230+ Class <T > typeImplementorClass , JdbcTypeIndicators indicators , TypeConfiguration typeConfiguration ) {
231+ final BasicType <T > legacyType ;
224232 if ( Serializable .class .isAssignableFrom ( typeImplementorClass ) ) {
225- @ SuppressWarnings ({"rawtypes" , "unchecked" })
226- final SerializableType legacyType = new SerializableType ( typeImplementorClass );
227- return createBasicTypeResolution ( legacyType , typeImplementorClass , indicators , typeConfiguration );
233+ legacyType = new SerializableType ( typeImplementorClass );
228234 }
229-
230- if ( typeImplementorClass .isInterface () ) {
231- return createBasicTypeResolution ( new JavaObjectType (), typeImplementorClass , indicators , typeConfiguration );
235+ else if ( typeImplementorClass .isInterface () ) {
236+ legacyType = (BasicType <T >) new JavaObjectType ();
237+ }
238+ else {
239+ throw new IllegalArgumentException ( "Named type [" + typeImplementorClass
240+ + "] did not implement BasicType nor UserType" );
232241 }
233242
234- throw new IllegalArgumentException (
235- "Named type [" + typeImplementorClass + "] did not implement BasicType nor UserType"
236- );
243+ return createBasicTypeResolution ( legacyType , typeImplementorClass , indicators , typeConfiguration );
237244 }
238245
239- private static BasicValue .Resolution <Object > createBasicTypeResolution (
240- BasicType <? > type ,
241- Class <?> typeImplementorClass ,
246+ private static < T > BasicValue .Resolution <T > createBasicTypeResolution (
247+ BasicType <T > type ,
248+ Class <? extends T > typeImplementorClass ,
242249 JdbcTypeIndicators indicators ,
243- TypeConfiguration typeConfiguration
244- ) {
245- final JavaType <Serializable > jtd = typeConfiguration
246- .getJavaTypeRegistry ()
247- .resolveDescriptor ( typeImplementorClass );
250+ TypeConfiguration typeConfiguration ) {
251+ final JavaType <T > jtd = typeConfiguration .getJavaTypeRegistry ().resolveDescriptor ( typeImplementorClass );
248252 final JdbcType jdbcType = typeConfiguration .getJdbcTypeRegistry ().getDescriptor ( Types .VARBINARY );
249- final BasicType <Serializable > resolved = InferredBasicValueResolver .resolveSqlTypeIndicators (
250- indicators ,
251- typeConfiguration .getBasicTypeRegistry ().resolve ( jtd , jdbcType ),
252- jtd
253- );
253+ final BasicType <T > basicType = typeConfiguration .getBasicTypeRegistry ().resolve ( jtd , jdbcType );
254+ final BasicType <T > resolved = resolveSqlTypeIndicators ( indicators , basicType , jtd );
254255
255256 return new BasicValue .Resolution <>() {
256257 @ Override
@@ -259,14 +260,12 @@ public JdbcMapping getJdbcMapping() {
259260 }
260261
261262 @ Override
262- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
263- public BasicType getLegacyResolvedBasicType () {
263+ public BasicType <T > getLegacyResolvedBasicType () {
264264 return type ;
265265 }
266266
267267 @ Override
268- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
269- public JavaType getDomainJavaType () {
268+ public JavaType <T > getDomainJavaType () {
270269 return resolved .getMappedJavaType ();
271270 }
272271
@@ -281,13 +280,12 @@ public JdbcType getJdbcType() {
281280 }
282281
283282 @ Override
284- public BasicValueConverter getValueConverter () {
283+ public BasicValueConverter < T ,?> getValueConverter () {
285284 return resolved .getValueConverter ();
286285 }
287286
288287 @ Override
289- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
290- public MutabilityPlan getMutabilityPlan () {
288+ public MutabilityPlan <T > getMutabilityPlan () {
291289 // a TypeDefinition does not explicitly provide a MutabilityPlan (yet?)
292290 return resolved .isMutable ()
293291 ? getDomainJavaType ().getMutabilityPlan ()
@@ -296,20 +294,20 @@ public MutabilityPlan getMutabilityPlan() {
296294 };
297295 }
298296
299- private static Object instantiateType (
297+ private static < T > T instantiateType (
300298 StandardServiceRegistry serviceRegistry ,
301299 MetadataBuildingOptions buildingOptions ,
302300 String name ,
303- Class <? > typeImplementorClass ,
301+ Class <T > typeImplementorClass ,
304302 BeanInstanceProducer instanceProducer ) {
305303 if ( buildingOptions .disallowExtensionsInCdi () ) {
306304 return name != null
307305 ? instanceProducer .produceBeanInstance ( name , typeImplementorClass )
308306 : instanceProducer .produceBeanInstance ( typeImplementorClass );
309307 }
310308 else {
311- final ManagedBeanRegistry beanRegistry = serviceRegistry .getService ( ManagedBeanRegistry .class );
312- final ManagedBean <? > typeBean = name != null
309+ final ManagedBeanRegistry beanRegistry = serviceRegistry .requireService ( ManagedBeanRegistry .class );
310+ final ManagedBean <T > typeBean = name != null
313311 ? beanRegistry .getBean ( name , typeImplementorClass , instanceProducer )
314312 : beanRegistry .getBean ( typeImplementorClass , instanceProducer );
315313 return typeBean .getBeanInstance ();
0 commit comments