6767import jakarta .persistence .TemporalType ;
6868
6969import static java .lang .Boolean .parseBoolean ;
70+ import static org .hibernate .internal .util .collections .CollectionHelper .isNotEmpty ;
7071import static org .hibernate .mapping .MappingHelper .injectParameters ;
7172
7273/**
@@ -803,65 +804,69 @@ public void setTypeName(String typeName) {
803804
804805 private static int COUNTER ;
805806
806- public < T extends UserType <?>> void setExplicitCustomType ( Class < T > explicitCustomType ) {
807+ public void setExplicitCustomType ( Class <? extends UserType <?>> explicitCustomType ) {
807808 if ( explicitCustomType != null ) {
808809 if ( resolution != null ) {
809810 throw new UnsupportedOperationException ( "Unsupported attempt to set an explicit-custom-type when value is already resolved" );
810811 }
811812
812- final BeanInstanceProducer instanceProducer =
813- getBuildingContext (). getBootstrapContext (). getCustomTypeProducer ();
814-
815- final Properties properties = new Properties ();
816- if ( CollectionHelper . isNotEmpty ( getTypeParameters () ) ) {
817- properties . putAll ( getTypeParameters () );
818- }
819- if ( CollectionHelper . isNotEmpty ( explicitLocalTypeParams ) ) {
820- properties . putAll ( explicitLocalTypeParams );
821- }
813+ resolution = new UserTypeResolution (
814+ new CustomType <>(
815+ getConfiguredUserTypeBean ( explicitCustomType , getCustomTypeProperties () ),
816+ getTypeConfiguration ()
817+ ),
818+ null ,
819+ getCustomTypeProperties ()
820+ );
821+ }
822+ }
822823
823- final T typeInstance ;
824- if ( getBuildingContext ().getBuildingOptions ().disallowExtensionsInCdi () ) {
825- typeInstance = FallbackBeanInstanceProducer .INSTANCE .produceBeanInstance ( explicitCustomType );
826- }
827- else {
828- final boolean hasParameters = CollectionHelper .isNotEmpty ( properties );
824+ private Properties getCustomTypeProperties () {
825+ final Properties properties = new Properties ();
826+ if ( isNotEmpty ( getTypeParameters () ) ) {
827+ properties .putAll ( getTypeParameters () );
828+ }
829+ if ( isNotEmpty ( explicitLocalTypeParams ) ) {
830+ properties .putAll ( explicitLocalTypeParams );
831+ }
832+ return properties ;
833+ }
829834
830- final ManagedBean <T > typeBean ;
831- if ( hasParameters ) {
832- final String name = explicitCustomType .getName () + COUNTER ++;
833- typeBean = getServiceRegistry ().getService ( ManagedBeanRegistry .class )
834- .getBean ( name , explicitCustomType , instanceProducer );
835- }
836- else {
837- typeBean = getServiceRegistry ().getService ( ManagedBeanRegistry .class )
838- .getBean ( explicitCustomType , instanceProducer );
839- }
840- typeInstance = typeBean .getBeanInstance ();
841- }
835+ private <T > T getConfiguredUserTypeBean (Class <T > explicitCustomType , Properties properties ) {
836+ final T typeInstance =
837+ getBuildingContext ().getBuildingOptions ().disallowExtensionsInCdi ()
838+ ? FallbackBeanInstanceProducer .INSTANCE .produceBeanInstance ( explicitCustomType )
839+ : getUserTypeBean ( explicitCustomType , properties ).getBeanInstance ();
842840
843- if ( typeInstance instanceof TypeConfigurationAware ) {
844- ( (TypeConfigurationAware ) typeInstance ).setTypeConfiguration ( getTypeConfiguration () );
845- }
841+ if ( typeInstance instanceof TypeConfigurationAware ) {
842+ final TypeConfigurationAware configurationAware = (TypeConfigurationAware ) typeInstance ;
843+ configurationAware .setTypeConfiguration ( getTypeConfiguration () );
844+ }
846845
847- if ( typeInstance instanceof DynamicParameterizedType ) {
848- if (parseBoolean (properties .getProperty (DynamicParameterizedType .IS_DYNAMIC ))) {
849- if (properties .get (DynamicParameterizedType .PARAMETER_TYPE ) == null ) {
850- final DynamicParameterizedType .ParameterType parameterType = makeParameterImpl ();
851- properties .put (DynamicParameterizedType .PARAMETER_TYPE , parameterType );
852- }
846+ if ( typeInstance instanceof DynamicParameterizedType ) {
847+ if ( parseBoolean ( properties .getProperty ( DynamicParameterizedType .IS_DYNAMIC ) ) ) {
848+ if ( properties .get ( DynamicParameterizedType .PARAMETER_TYPE ) == null ) {
849+ properties .put ( DynamicParameterizedType .PARAMETER_TYPE , makeParameterImpl () );
853850 }
854851 }
852+ }
855853
856- injectParameters ( typeInstance , properties );
857- // envers - grr
858- setTypeParameters ( properties );
854+ injectParameters ( typeInstance , properties );
855+ // envers - grr
856+ setTypeParameters ( properties );
859857
860- this .resolution = new UserTypeResolution (
861- new CustomType <>( (UserType <?>) typeInstance , getTypeConfiguration () ),
862- null ,
863- properties
864- );
858+ return typeInstance ;
859+ }
860+
861+ private <T > ManagedBean <T > getUserTypeBean (Class <T > explicitCustomType , Properties properties ) {
862+ final BeanInstanceProducer producer = getBuildingContext ().getBootstrapContext ().getCustomTypeProducer ();
863+ final ManagedBeanRegistry registry = getServiceRegistry ().requireService ( ManagedBeanRegistry .class );
864+ if ( isNotEmpty ( properties ) ) {
865+ final String name = explicitCustomType .getName () + COUNTER ++;
866+ return registry .getBean ( name , explicitCustomType , producer );
867+ }
868+ else {
869+ return registry .getBean ( explicitCustomType , producer );
865870 }
866871 }
867872
@@ -882,9 +887,9 @@ public Object accept(ValueVisitor visitor) {
882887 @ Internal
883888 public boolean isDisallowedWrapperArray () {
884889 return getBuildingContext ().getBuildingOptions ().getWrapperArrayHandling () == WrapperArrayHandling .DISALLOW
885- && !isLob ()
886- && ( explicitJavaTypeAccess == null || explicitJavaTypeAccess .apply ( getTypeConfiguration () ) == null )
887- && isWrapperByteOrCharacterArray ();
890+ && !isLob ()
891+ && ( explicitJavaTypeAccess == null || explicitJavaTypeAccess .apply ( getTypeConfiguration () ) == null )
892+ && isWrapperByteOrCharacterArray ();
888893 }
889894
890895 private boolean isWrapperByteOrCharacterArray () {
0 commit comments