Skip to content

Conversation

sebersole
Copy link
Member

@sebersole sebersole commented Jan 20, 2023

This form circumvents CDI hosting of UserType impls when extended or delayed strategies are used.

Alternative to #5992

@sebersole sebersole mentioned this pull request Jan 20, 2023
Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. A few comments below.

I'm mainly concerned about changing the behavior of getBean in BeanContainer, since Hibernate Search relies on that.

* @implNote Defaulted for backwards compatibility
*/
<T> ManagedBean<T> getBean(String beanName, Class<T> beanContract);
default <T> ManagedBean<T> getBean(Class<T> beanClass, boolean cdiRequiredIfAvailable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to use an enum instead of a boolean, both for more explicit code on call sites and to be free to add other behavior later if need be?

if ( usableBeanManager == null ) {
BeanInstanceProducer fallbackProducer,
boolean cdiRequiredIfAvailable) {
if ( !cdiRequiredIfAvailable ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the cdiRequiredIfAvailable flag be ignored if usableBeanManager is non-null (and thus CDI is already available)?

E.g.:

Suggested change
if ( !cdiRequiredIfAvailable ) {
if ( !cdiRequiredIfAvailable && usableBeanManager == null ) {

That way if the caller is lucky and CDI was already initialized, they can get a CDI bean.

Class<B> beanType,
LifecycleOptions lifecycleOptions,
BeanInstanceProducer fallbackProducer) {
return getBean( beanType, lifecycleOptions, fallbackProducer, false );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the default behavior, though... Including for Hibernate Search in the "delayed" case. I'm not sure of the implications.

Since you're (likely) always going to call getBean() with the explicit cdiRequiredIfAvailable flag yourself, can you please preserve the legacy behavior for this method? Just for backwards compatibility of integrations?

Class<B> beanType,
LifecycleOptions lifecycleOptions,
BeanInstanceProducer fallbackProducer,
boolean cdiRequiredIfAvailable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another name would be better, since BeanContainer can be used for non-CDI implementations? E.g. beanContainerRequiredIfAvailable or something like that.

Comment on lines +72 to +73
fallbackBeanInstanceProducer,
true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can say for sure that existing integrators using this API (i.e. Hibernate Search) do not, at the moment, use true.

Since these tests are specifically about checking compatibility with Hibernate Search, it's probably better to keep calling the old method without the cdiRequiredIfAvailable flag?

@sebersole sebersole closed this Jan 26, 2023
@sebersole sebersole deleted the cdi-usertype2 branch January 26, 2023 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants