|
37 | 37 | import org.hibernate.generator.GeneratorCreationContext; |
38 | 38 | import org.hibernate.internal.CoreLogging; |
39 | 39 | import org.hibernate.internal.CoreMessageLogger; |
40 | | -import org.hibernate.internal.util.ReflectHelper; |
41 | 40 | import org.hibernate.models.spi.MemberDetails; |
42 | 41 | import org.hibernate.models.spi.TypeDetails; |
43 | 42 | import org.hibernate.resource.beans.spi.ManagedBeanRegistry; |
|
63 | 62 | import static org.hibernate.boot.model.internal.GeneratorBinder.ASSIGNED_GENERATOR_NAME; |
64 | 63 | import static org.hibernate.boot.model.internal.GeneratorBinder.ASSIGNED_IDENTIFIER_GENERATOR_CREATOR; |
65 | 64 | import static org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl.fromExplicit; |
| 65 | +import static org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass; |
66 | 66 | import static org.hibernate.internal.util.collections.ArrayHelper.toBooleanArray; |
67 | 67 |
|
68 | 68 | /** |
@@ -208,7 +208,7 @@ protected void justAddColumn(Column column) { |
208 | 208 | } |
209 | 209 |
|
210 | 210 | protected void justAddColumn(Column column, boolean insertable, boolean updatable) { |
211 | | - int index = columns.indexOf( column ); |
| 211 | + final int index = columns.indexOf( column ); |
212 | 212 | if ( index == -1 ) { |
213 | 213 | columns.add( column ); |
214 | 214 | insertability.add( insertable ); |
@@ -289,26 +289,23 @@ public String getTypeName() { |
289 | 289 |
|
290 | 290 | public void setTypeName(String typeName) { |
291 | 291 | if ( typeName != null && typeName.startsWith( TYPE_NAME_PREFIX ) ) { |
292 | | - final String converterClassName = typeName.substring( TYPE_NAME_PREFIX.length() ); |
293 | | - final ClassLoaderService cls = getMetadata() |
294 | | - .getMetadataBuildingOptions() |
295 | | - .getServiceRegistry() |
296 | | - .requireService( ClassLoaderService.class ); |
297 | | - try { |
298 | | - final Class<? extends AttributeConverter<?,?>> converterClass = cls.classForName( converterClassName ); |
299 | | - this.attributeConverterDescriptor = new ClassBasedConverterDescriptor( |
300 | | - converterClass, |
301 | | - false, |
302 | | - ( (InFlightMetadataCollector) getMetadata() ).getBootstrapContext().getClassmateContext() |
303 | | - ); |
304 | | - return; |
305 | | - } |
306 | | - catch (Exception e) { |
307 | | - log.logBadHbmAttributeConverterType( typeName, e.getMessage() ); |
308 | | - } |
| 292 | + setAttributeConverterDescriptor( typeName ); |
| 293 | + } |
| 294 | + else { |
| 295 | + this.typeName = typeName; |
309 | 296 | } |
| 297 | + } |
310 | 298 |
|
311 | | - this.typeName = typeName; |
| 299 | + void setAttributeConverterDescriptor(String typeName) { |
| 300 | + final String converterClassName = typeName.substring( TYPE_NAME_PREFIX.length() ); |
| 301 | + this.attributeConverterDescriptor = |
| 302 | + new ClassBasedConverterDescriptor( classLoaderService().classForName( converterClassName ), |
| 303 | + false, getBuildingContext().getBootstrapContext().getClassmateContext() ); |
| 304 | + } |
| 305 | + |
| 306 | + ClassLoaderService classLoaderService() { |
| 307 | + return getMetadata().getMetadataBuildingOptions().getServiceRegistry() |
| 308 | + .requireService( ClassLoaderService.class ); |
312 | 309 | } |
313 | 310 |
|
314 | 311 | public void makeVersion() { |
@@ -675,14 +672,7 @@ public void setTypeUsingReflection(String className, String propertyName) throws |
675 | 672 | } |
676 | 673 |
|
677 | 674 | private Class<?> getClass(String className, String propertyName) { |
678 | | - return ReflectHelper.reflectedPropertyClass( |
679 | | - className, |
680 | | - propertyName, |
681 | | - getMetadata() |
682 | | - .getMetadataBuildingOptions() |
683 | | - .getServiceRegistry() |
684 | | - .requireService( ClassLoaderService.class ) |
685 | | - ); |
| 675 | + return reflectedPropertyClass( className, propertyName, classLoaderService() ); |
686 | 676 | } |
687 | 677 |
|
688 | 678 | /** |
@@ -738,8 +728,8 @@ public TypeConfiguration getTypeConfiguration() { |
738 | 728 |
|
739 | 729 | private <T> Type buildAttributeConverterTypeAdapter( |
740 | 730 | JpaAttributeConverter<T, ?> jpaAttributeConverter) { |
741 | | - JavaType<T> domainJavaType = jpaAttributeConverter.getDomainJavaType(); |
742 | | - JavaType<?> relationalJavaType = jpaAttributeConverter.getRelationalJavaType(); |
| 731 | + final JavaType<T> domainJavaType = jpaAttributeConverter.getDomainJavaType(); |
| 732 | + final JavaType<?> relationalJavaType = jpaAttributeConverter.getRelationalJavaType(); |
743 | 733 |
|
744 | 734 | // build the SqlTypeDescriptor adapter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
745 | 735 | // Going back to the illustration, this should be a SqlTypeDescriptor that handles the Integer <-> String |
@@ -951,16 +941,11 @@ protected void createParameterImpl() { |
951 | 941 | final MemberDetails attributeMember = (MemberDetails) typeParameters.get( DynamicParameterizedType.XPROPERTY ); |
952 | 942 | // todo : not sure this works for handling @MapKeyEnumerated |
953 | 943 | final Annotation[] annotations = getAnnotations( attributeMember ); |
954 | | - |
955 | | - final ClassLoaderService classLoaderService = |
956 | | - getMetadata().getMetadataBuildingOptions().getServiceRegistry() |
957 | | - .requireService( ClassLoaderService.class ); |
958 | 944 | typeParameters.put( |
959 | 945 | DynamicParameterizedType.PARAMETER_TYPE, |
960 | 946 | new ParameterTypeImpl( |
961 | | - classLoaderService.classForTypeName( |
962 | | - typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) |
963 | | - ), |
| 947 | + classLoaderService() |
| 948 | + .classForTypeName( typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ), |
964 | 949 | attributeMember != null ? attributeMember.getType() : null, |
965 | 950 | annotations, |
966 | 951 | table.getCatalog(), |
@@ -1003,13 +988,9 @@ public DynamicParameterizedType.ParameterType makeParameterImpl() { |
1003 | 988 | final MemberDetails attributeMember = (MemberDetails) typeParameters.get( DynamicParameterizedType.XPROPERTY ); |
1004 | 989 | // todo : not sure this works for handling @MapKeyEnumerated |
1005 | 990 | final Annotation[] annotations = getAnnotations( attributeMember ); |
1006 | | - |
1007 | | - final ClassLoaderService classLoaderService = |
1008 | | - getMetadata().getMetadataBuildingOptions().getServiceRegistry() |
1009 | | - .requireService( ClassLoaderService.class ); |
1010 | | - |
1011 | 991 | return new ParameterTypeImpl( |
1012 | | - classLoaderService.classForTypeName( typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ), |
| 992 | + classLoaderService() |
| 993 | + .classForTypeName( typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ), |
1013 | 994 | attributeMember != null ? attributeMember.getType() : null, |
1014 | 995 | annotations, |
1015 | 996 | table.getCatalog(), |
|
0 commit comments