Search 6 groundwork - Make bean references easier to use in configuration properties

Description

The idea would be to allow to define a configuration property of type "BeanReference", so that we can get rid of some of the complexity we currently face each time a bean can be passed to a configuration property. Ideally, the property should accept these values:

  • a String representing the bean name

  • a Class<? extends TheExpectedType> (requires HSEARCH-3174)

  • an instance of TheExpectedType (requires HSEARCH-3174)

One solution would be to allow this:

private static final ConfigurationProperty<Optional<BeanReference>> MY_PROPERTY = ConfigurationProperty.forKey( "myKey ) .asBeanReference() .build(); ... public void someMethod(BeanProvider beanProvider, ConfigurationPropertySource source) { MyBean myBean = MY_KEY.get(source).orElseThrow( () -> new IllegalStateException() ) .get( beanProvider, MyBean.class ); }

This would require to:

  • Move the reponsibility of passing the beanreference data (name, class, ...) to the beanreference itself: instead of writing beanProvider.get(beanRef.getName(), beanRef.getType()), we would write beanRef.get(beanProvider) and the beanreference would pass whatever information is necessary. That encapsulation of the bean retrieval would allow to seamlessly introduce bean references that already contain the bean, so that we can more easily support the case where the bean was provided as a property value.

  • As a consequence, introduce one factory method per "reference type", which could return different implementations: BeanReference.of(Class<?>), BeanReference.of(String), BeanReference.of(Class<?>, String), BeanReference.ofInstance(Object)

  • Add a method PropertyKeyContext.asBeanReference() to the property key definition DSL, which would define a converter that calls the appropriate BeanReference.of method depending on the property value type.

As a second step, we could try to introduce a generic parameter in BeanReference, so that we can write this kind of code:

private static final ConfigurationProperty<Optional<BeanReference<MyBean>>> MY_PROPERTY = ConfigurationProperty.forKey( "myKey ) .asBeanReference( MyBean.class ) .build(); ... public void someMethod(BeanProvider beanProvider, ConfigurationPropertySource source) { MyBean myBean = MY_KEY.get(source).orElseThrow( () -> new IllegalStateException() ) .get( beanProvider ); }

Activity

Show:
Steve Ebersole
updated the workflowSeptember 14, 2023 at 4:58 PM
Expanded Workflow with pull request
Expanded Workflow
Yoann Rodière
changed the statusJanuary 31, 2019 at 3:08 PM
Resolved
Closed
Yoann Rodière
made 4 changes
December 4, 2018 at 3:55 PM
Status
Pull Request Sent
Resolved
Fix versions
None
6.0.0.Alpha2
Resolution
None
Fixed
Yoann Rodière
updated the SprintDecember 3, 2018 at 8:34 AM
HSEARCH - 2018-07
HSEARCH - 2018-07, HSEARCH - 2018-08
Yoann Rodière
made 2 changes
November 30, 2018 at 2:47 PM
Status
In Progress
Pull Request Sent
Pull Request
None
https://github.com/hibernate/hibernate-search/pull/1826
Yoann Rodière
made 4 changes
November 30, 2018 at 8:48 AM
Status
Open
In Progress
Assignee
Unassigned
Yoann Rodière
Rank
None
Ranked lower
Yoann Rodière
made 4 changes
October 16, 2018 at 3:16 PM
Rank
None
Ranked higher
Rank
None
Ranked higher
Sprint
None
HSEARCH - New contributors - 2
Yoann Rodière
updated the linkOctober 3, 2018 at 7:33 AM
None
This issue depends on HSEARCH-3174
Yoann Rodière
created the IssueOctober 3, 2018 at 7:33 AM
Fixed

Details

Assignee

Reporter

Components

Sprint

Fix versions

Priority

Created October 3, 2018 at 7:33 AM
Updated January 31, 2019 at 3:08 PM
Resolved December 4, 2018 at 3:55 PM

Flag notifications