HHH-15746 Beans Helper doesn't need to be a singleton, convert to static helpers

This commit is contained in:
Sanne Grinovero 2022-11-23 14:38:37 +00:00 committed by Sanne Grinovero
parent ed52dba650
commit 7081d31647
4 changed files with 9 additions and 13 deletions

View File

@ -276,7 +276,7 @@ public class TypeDefinition implements Serializable {
private static Object instantiateType(StandardServiceRegistry serviceRegistry, private static Object instantiateType(StandardServiceRegistry serviceRegistry,
String name, Class<?> typeImplementorClass, String name, Class<?> typeImplementorClass,
BeanInstanceProducer instanceProducer) { BeanInstanceProducer instanceProducer) {
if ( Helper.INSTANCE.shouldIgnoreBeanContainer( serviceRegistry ) ) { if ( Helper.shouldIgnoreBeanContainer( serviceRegistry ) ) {
return name != null return name != null
? instanceProducer.produceBeanInstance( name, typeImplementorClass ) ? instanceProducer.produceBeanInstance( name, typeImplementorClass )
: instanceProducer.produceBeanInstance( typeImplementorClass ); : instanceProducer.produceBeanInstance( typeImplementorClass );

View File

@ -73,7 +73,7 @@ public class StandardIdentifierGeneratorFactory
* Constructs a new factory * Constructs a new factory
*/ */
public StandardIdentifierGeneratorFactory(ServiceRegistry serviceRegistry) { public StandardIdentifierGeneratorFactory(ServiceRegistry serviceRegistry) {
this( serviceRegistry, Helper.INSTANCE.shouldIgnoreBeanContainer( serviceRegistry ) ); this( serviceRegistry, Helper.shouldIgnoreBeanContainer( serviceRegistry ) );
} }
/** /**

View File

@ -44,7 +44,7 @@ public abstract class AbstractCdiBeanContainer implements CdiBasedBeanContainer
Class<B> beanType, Class<B> beanType,
LifecycleOptions lifecycleOptions, LifecycleOptions lifecycleOptions,
BeanInstanceProducer fallbackProducer) { BeanInstanceProducer fallbackProducer) {
final String beanCacheKey = Helper.INSTANCE.determineBeanCacheKey( beanType ); final String beanCacheKey = Helper.determineBeanCacheKey( beanType );
final ContainedBeanImplementor existing = beanCache.get( beanCacheKey ); final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
if ( existing != null ) { if ( existing != null ) {
@ -97,7 +97,7 @@ public abstract class AbstractCdiBeanContainer implements CdiBasedBeanContainer
Class<B> beanType, Class<B> beanType,
LifecycleOptions lifecycleOptions, LifecycleOptions lifecycleOptions,
BeanInstanceProducer fallbackProducer) { BeanInstanceProducer fallbackProducer) {
final String beanCacheKey = Helper.INSTANCE.determineBeanCacheKey( beanName, beanType ); final String beanCacheKey = Helper.determineBeanCacheKey( beanName, beanType );
final ContainedBeanImplementor existing = beanCache.get( beanCacheKey ); final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
if ( existing != null ) { if ( existing != null ) {

View File

@ -18,24 +18,20 @@ import org.hibernate.service.ServiceRegistry;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class Helper { public final class Helper {
/**
* Singleton access
*/
public static final Helper INSTANCE = new Helper();
private Helper() { private Helper() {
} }
public String determineBeanCacheKey(Class<?> beanType) { public static String determineBeanCacheKey(Class<?> beanType) {
return beanType.getName(); return beanType.getName();
} }
public String determineBeanCacheKey(String name, Class<?> beanType) { public static String determineBeanCacheKey(String name, Class<?> beanType) {
return beanType.getName() + ':' + name; return beanType.getName() + ':' + name;
} }
public boolean shouldIgnoreBeanContainer(ServiceRegistry serviceRegistry) { public static boolean shouldIgnoreBeanContainer(ServiceRegistry serviceRegistry) {
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class ); final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
final Object beanManagerRef = configService.getSettings().get( AvailableSettings.JAKARTA_CDI_BEAN_MANAGER ); final Object beanManagerRef = configService.getSettings().get( AvailableSettings.JAKARTA_CDI_BEAN_MANAGER );
@ -51,7 +47,7 @@ public class Helper {
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
public BeanLifecycleStrategy getLifecycleStrategy(boolean shouldRegistryManageLifecycle) { public static BeanLifecycleStrategy getLifecycleStrategy(boolean shouldRegistryManageLifecycle) {
return shouldRegistryManageLifecycle return shouldRegistryManageLifecycle
? JpaCompliantLifecycleStrategy.INSTANCE ? JpaCompliantLifecycleStrategy.INSTANCE
: ContainerManagedLifecycleStrategy.INSTANCE; : ContainerManagedLifecycleStrategy.INSTANCE;