Interface BeanResolver
Depending on the integration, beans may be instantiated using reflection (expecting a no-argument constructor), or provided by a more advanced dependency injection context (CDI, Spring DI).
Regardless of the underlying implementation, this interface is used to resolve beans,
referenced either
resolve(Class, BeanRetrieval)
by their type},
or by their type and name
.
It also offers ways to get references to configured beans of a given type
.
This interface is API,
but should only be implemented by Hibernate Search itself;
if you are looking to provide beans from a different source,
you should implement BeanProvider
instead.
-
Method Summary
Modifier and TypeMethodDescription<T> List<BeanReference<T>>
allConfiguredForRole
(Class<T> role) Return all the bean references configured for the given role.<T> Map<String,
BeanReference<T>> namedConfiguredForRole
(Class<T> role) Return named bean references configured for the given role.<T> BeanHolder<T>
resolve
(Class<T> typeReference, String nameReference, BeanRetrieval retrieval) Resolve a bean by its name.<T> BeanHolder<T>
resolve
(Class<T> typeReference, BeanRetrieval retrieval) Resolve a bean by its type.default <T> BeanHolder<List<T>>
resolve
(List<? extends BeanReference<? extends T>> references) Resolve a list ofBeanReference
s.default <T> BeanHolder<T>
resolve
(BeanReference<T> reference) Resolve aBeanReference
.
-
Method Details
-
resolve
Resolve a bean by its type.- Type Parameters:
T
- The expected return type.- Parameters:
typeReference
- The type used as a reference to the bean to resolve. Must be non-null.retrieval
- How to retrieve the bean. SeeBeanRetrieval
.- Returns:
- A
BeanHolder
containing the resolved bean. - Throws:
SearchException
- if the reference is invalid (null) or the bean cannot be resolved.
-
resolve
Resolve a bean by its name.- Type Parameters:
T
- The expected return type.- Parameters:
typeReference
- The type used as a reference to the bean to resolve. Must be non-null.nameReference
- The name used as a reference to the bean to resolve. Must be non-null and non-empty.retrieval
- How to retrieve the bean. SeeBeanRetrieval
.- Returns:
- A
BeanHolder
containing the resolved bean. - Throws:
SearchException
- if a reference is invalid (null or empty) or the bean cannot be resolved.
-
resolve
Resolve aBeanReference
.This method is just syntactic sugar to allow writing
bridgeProvider::resolve
and getting aFunction<BeanReference<T>, T>
that can be used inOptional.map(Function)
for instance.- Type Parameters:
T
- The expected return type.- Parameters:
reference
- The reference to the bean to resolve. Must be non-null.- Returns:
- A
BeanHolder
containing the resolved bean. - Throws:
SearchException
- if the reference is invalid (null or empty) or the bean cannot be resolved.
-
resolve
Resolve a list ofBeanReference
s.The main advantage of calling this method over looping and calling
resolve(BeanReference)
repeatedly is that errors are handled correctly: if a bean was already instantiated, and getting the next one fails, then the first bean will be properlyclosed
before the exception is propagated. Also, this method returns aBeanHolder<List<T>>
instead of aList<BeanHolder<T>>
, so its result is easier to use in a try-with-resources.This method is also syntactic sugar to allow writing
bridgeProvider::resolve
and getting aFunction<BeanReference<T>, T>
that can be used inOptional.map(Function)
for instance.- Type Parameters:
T
- The expected bean type.- Parameters:
references
- The references to the beans to retrieve. Must be non-null.- Returns:
- A
BeanHolder
containing aList
containing the resolved beans, in the same order as thereferences
. - Throws:
SearchException
- if one reference is invalid (null or empty) or the corresponding bean cannot be resolved.
-
allConfiguredForRole
Return all the bean references configured for the given role.WARNING: this does not just return references to all the beans that implement
role
. Only beans registered duringbean configuration
are taken into account.- Type Parameters:
T
- The expected bean type.- Parameters:
role
- The role that must have been assigned to the retrieved beans. Must be non-null and non-empty.- Returns:
- A
List
of bean references, possibly empty.
-
namedConfiguredForRole
Return named bean references configured for the given role.WARNING: this does not just return references to all the beans that implement
role
. Only beans registered duringbean configuration
are taken into account.- Type Parameters:
T
- The expected bean type.- Parameters:
role
- The role that must have been assigned to the retrieved beans. Must be non-null and non-empty.- Returns:
- A
Map
from name to bean reference, possibly empty.
-