Skip to content

Commit

Permalink
HHH-15746 Beans Helper doesn't need to be a singleton, convert to sta…
Browse files Browse the repository at this point in the history
…tic helpers
  • Loading branch information
Sanne committed Nov 28, 2022
1 parent ed52dba commit 7081d31
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public MutabilityPlan getMutabilityPlan() {
private static Object instantiateType(StandardServiceRegistry serviceRegistry,
String name, Class<?> typeImplementorClass,
BeanInstanceProducer instanceProducer) {
if ( Helper.INSTANCE.shouldIgnoreBeanContainer( serviceRegistry ) ) {
if ( Helper.shouldIgnoreBeanContainer( serviceRegistry ) ) {
return name != null
? instanceProducer.produceBeanInstance( name, typeImplementorClass )
: instanceProducer.produceBeanInstance( typeImplementorClass );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class StandardIdentifierGeneratorFactory
* Constructs a new factory
*/
public StandardIdentifierGeneratorFactory(ServiceRegistry serviceRegistry) {
this( serviceRegistry, Helper.INSTANCE.shouldIgnoreBeanContainer( serviceRegistry ) );
this( serviceRegistry, Helper.shouldIgnoreBeanContainer( serviceRegistry ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private <B> ContainedBean<B> getCacheableBean(
Class<B> beanType,
LifecycleOptions lifecycleOptions,
BeanInstanceProducer fallbackProducer) {
final String beanCacheKey = Helper.INSTANCE.determineBeanCacheKey( beanType );
final String beanCacheKey = Helper.determineBeanCacheKey( beanType );

final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
if ( existing != null ) {
Expand Down Expand Up @@ -97,7 +97,7 @@ private <B> ContainedBeanImplementor<B> getCacheableBean(
Class<B> beanType,
LifecycleOptions lifecycleOptions,
BeanInstanceProducer fallbackProducer) {
final String beanCacheKey = Helper.INSTANCE.determineBeanCacheKey( beanName, beanType );
final String beanCacheKey = Helper.determineBeanCacheKey( beanName, beanType );

final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
if ( existing != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@
/**
* @author Steve Ebersole
*/
public class Helper {
/**
* Singleton access
*/
public static final Helper INSTANCE = new Helper();
public final class Helper {

private Helper() {
}

public String determineBeanCacheKey(Class<?> beanType) {
public static String determineBeanCacheKey(Class<?> beanType) {
return beanType.getName();
}

public String determineBeanCacheKey(String name, Class<?> beanType) {
public static String determineBeanCacheKey(String name, Class<?> beanType) {
return beanType.getName() + ':' + name;
}

public boolean shouldIgnoreBeanContainer(ServiceRegistry serviceRegistry) {
public static boolean shouldIgnoreBeanContainer(ServiceRegistry serviceRegistry) {
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
final Object beanManagerRef = configService.getSettings().get( AvailableSettings.JAKARTA_CDI_BEAN_MANAGER );

Expand All @@ -51,7 +47,7 @@ public boolean shouldIgnoreBeanContainer(ServiceRegistry serviceRegistry) {
}

@SuppressWarnings("unused")
public BeanLifecycleStrategy getLifecycleStrategy(boolean shouldRegistryManageLifecycle) {
public static BeanLifecycleStrategy getLifecycleStrategy(boolean shouldRegistryManageLifecycle) {
return shouldRegistryManageLifecycle
? JpaCompliantLifecycleStrategy.INSTANCE
: ContainerManagedLifecycleStrategy.INSTANCE;
Expand Down

0 comments on commit 7081d31

Please sign in to comment.