Class CdiRepositoryBean<T>
java.lang.Object
org.springframework.data.repository.cdi.CdiRepositoryBean<T>
- All Implemented Interfaces:
jakarta.enterprise.context.spi.Contextual<T>
,jakarta.enterprise.inject.spi.Bean<T>
,jakarta.enterprise.inject.spi.BeanAttributes<T>
,jakarta.enterprise.inject.spi.PassivationCapable
public abstract class CdiRepositoryBean<T>
extends Object
implements jakarta.enterprise.inject.spi.Bean<T>, jakarta.enterprise.inject.spi.PassivationCapable
Base class for
Bean
wrappers.- Author:
- Dirk Mahler, Oliver Gierke, Mark Paluchs, Peter Rietzler, Jens Schauder, Christoph Strobl, Ariel Carrera, Xeno Amess, Johannes Englmeier
-
Constructor Summary
ConstructorDescriptionCdiRepositoryBean
(Set<Annotation> qualifiers, Class<T> repositoryType, jakarta.enterprise.inject.spi.BeanManager beanManager) Creates a newCdiRepositoryBean
.CdiRepositoryBean
(Set<Annotation> qualifiers, Class<T> repositoryType, jakarta.enterprise.inject.spi.BeanManager beanManager, Optional<CustomRepositoryImplementationDetector> detector) Creates a newCdiRepositoryBean
.CdiRepositoryBean
(Set<Annotation> qualifiers, Class<T> repositoryType, jakarta.enterprise.inject.spi.BeanManager beanManager, CdiRepositoryContext context) Creates a newCdiRepositoryBean
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyConfiguration
(RepositoryFactorySupport repositoryFactory) Applies the configuration fromCdiRepositoryConfiguration
toRepositoryFactorySupport
by looking up the actual configuration.protected static void
applyConfiguration
(RepositoryFactorySupport repositoryFactory, CdiRepositoryConfiguration configuration) Applies the configuration fromCdiRepositoryConfiguration
toRepositoryFactorySupport
by looking up the actual configuration.final T
protected abstract T
create
(jakarta.enterprise.context.spi.CreationalContext<T> creationalContext, Class<T> repositoryType) Creates the actual component instance.protected T
create
(Supplier<? extends RepositoryFactorySupport> factorySupplier, Class<T> repositoryType) Creates the actual component instance given arepository factory supplier
and the repositorytype
.protected static <T> T
create
(RepositoryFactorySupport repositoryFactory, Class<T> repositoryType, RepositoryComposition.RepositoryFragments repositoryFragments) Creates the actual repository instance.void
Class<?>
protected <S> S
getDependencyInstance
(jakarta.enterprise.inject.spi.Bean<S> bean) Returns an instance of an the givenBean
.protected <S> S
getDependencyInstance
(jakarta.enterprise.inject.spi.Bean<S> bean, Class<?> type) Returns an instance of an the givenBean
and allows to be specific about the type that is about to be created.getId()
Set<jakarta.enterprise.inject.spi.InjectionPoint>
getName()
getRepositoryFragments
(Class<T> repositoryType) Lookup repository fragments for arepository interface
.Class<? extends Annotation>
getScope()
Set<Class<? extends Annotation>>
getTypes()
final void
Forces the initialization of bean target.boolean
boolean
protected CdiRepositoryConfiguration
lookupConfiguration
(jakarta.enterprise.inject.spi.BeanManager beanManager, Set<Annotation> qualifiers) Looks up an instance of aCdiRepositoryConfiguration
.toString()
-
Constructor Details
-
CdiRepositoryBean
public CdiRepositoryBean(Set<Annotation> qualifiers, Class<T> repositoryType, jakarta.enterprise.inject.spi.BeanManager beanManager) Creates a newCdiRepositoryBean
.- Parameters:
qualifiers
- must not be null.repositoryType
- has to be an interface must not be null.beanManager
- the CDIBeanManager
, must not be null.
-
CdiRepositoryBean
public CdiRepositoryBean(Set<Annotation> qualifiers, Class<T> repositoryType, jakarta.enterprise.inject.spi.BeanManager beanManager, Optional<CustomRepositoryImplementationDetector> detector) Creates a newCdiRepositoryBean
.- Parameters:
qualifiers
- must not be null.repositoryType
- has to be an interface must not be null.beanManager
- the CDIBeanManager
, must not be null.detector
- detector for the custom repository implementationsCustomRepositoryImplementationDetector
.
-
CdiRepositoryBean
public CdiRepositoryBean(Set<Annotation> qualifiers, Class<T> repositoryType, jakarta.enterprise.inject.spi.BeanManager beanManager, CdiRepositoryContext context) Creates a newCdiRepositoryBean
.- Parameters:
qualifiers
- must not be null.repositoryType
- has to be an interface must not be null.beanManager
- the CDIBeanManager
, must not be null.context
- CDI context encapsulating class loader, metadata scanning and fragment detection.- Since:
- 2.1
-
-
Method Details
-
getTypes
- Specified by:
getTypes
in interfacejakarta.enterprise.inject.spi.BeanAttributes<T>
-
getDependencyInstance
protected <S> S getDependencyInstance(jakarta.enterprise.inject.spi.Bean<S> bean) Returns an instance of an the givenBean
.- Parameters:
bean
- theBean
about to create an instance for.- Returns:
- the actual component instance.
- See Also:
-
BeanAttributes.getTypes()
-
getDependencyInstance
Returns an instance of an the givenBean
and allows to be specific about the type that is about to be created.- Parameters:
bean
- theBean
about to create an instance for.type
- the expected type of the component instance created for thatBean
. We need to hand this parameter explicitly as theBean
might carry multiple types but the primary one might not be the first, i.e. the one returned byBean.getBeanClass()
.- Returns:
- the actual component instance.
- See Also:
-
BeanAttributes.getTypes()
-
initialize
public final void initialize()Forces the initialization of bean target. -
create
- Specified by:
create
in interfacejakarta.enterprise.context.spi.Contextual<T>
-
destroy
public void destroy(T instance, jakarta.enterprise.context.spi.CreationalContext<T> creationalContext) - Specified by:
destroy
in interfacejakarta.enterprise.context.spi.Contextual<T>
-
getQualifiers
- Specified by:
getQualifiers
in interfacejakarta.enterprise.inject.spi.BeanAttributes<T>
-
getName
- Specified by:
getName
in interfacejakarta.enterprise.inject.spi.BeanAttributes<T>
-
getStereotypes
- Specified by:
getStereotypes
in interfacejakarta.enterprise.inject.spi.BeanAttributes<T>
-
getBeanClass
- Specified by:
getBeanClass
in interfacejakarta.enterprise.inject.spi.Bean<T>
-
isAlternative
public boolean isAlternative()- Specified by:
isAlternative
in interfacejakarta.enterprise.inject.spi.BeanAttributes<T>
-
isNullable
public boolean isNullable() -
getInjectionPoints
- Specified by:
getInjectionPoints
in interfacejakarta.enterprise.inject.spi.Bean<T>
-
getScope
- Specified by:
getScope
in interfacejakarta.enterprise.inject.spi.BeanAttributes<T>
-
getId
- Specified by:
getId
in interfacejakarta.enterprise.inject.spi.PassivationCapable
-
create
protected abstract T create(jakarta.enterprise.context.spi.CreationalContext<T> creationalContext, Class<T> repositoryType) Creates the actual component instance.- Parameters:
creationalContext
- will never be null.repositoryType
- will never be null.- Returns:
-
create
protected T create(Supplier<? extends RepositoryFactorySupport> factorySupplier, Class<T> repositoryType) Creates the actual component instance given arepository factory supplier
and the repositorytype
. This method is an utility for to create a repository. This method will obtain arepository factory
and configure it withCdiRepositoryConfiguration
.- Parameters:
factorySupplier
- must not be null.repositoryType
- must not be null.- Returns:
- Since:
- 2.1
-
getRepositoryFragments
Lookup repository fragments for arepository interface
.- Parameters:
repositoryType
- must not be null.- Returns:
- the
RepositoryComposition.RepositoryFragments
. - Since:
- 2.1
-
lookupConfiguration
protected CdiRepositoryConfiguration lookupConfiguration(jakarta.enterprise.inject.spi.BeanManager beanManager, Set<Annotation> qualifiers) Looks up an instance of aCdiRepositoryConfiguration
. In case the instance cannot be found within the CDI scope, a default configuration is used.- Returns:
- an available CdiRepositoryConfiguration instance or a default configuration.
-
applyConfiguration
Applies the configuration fromCdiRepositoryConfiguration
toRepositoryFactorySupport
by looking up the actual configuration.- Parameters:
repositoryFactory
- will never be null.- Since:
- 2.1
-
applyConfiguration
protected static void applyConfiguration(RepositoryFactorySupport repositoryFactory, CdiRepositoryConfiguration configuration) Applies the configuration fromCdiRepositoryConfiguration
toRepositoryFactorySupport
by looking up the actual configuration.- Parameters:
repositoryFactory
- will never be null.configuration
- will never be null.- Since:
- 2.1
-
create
protected static <T> T create(RepositoryFactorySupport repositoryFactory, Class<T> repositoryType, RepositoryComposition.RepositoryFragments repositoryFragments) Creates the actual repository instance.- Parameters:
repositoryType
- will never be null.repositoryFragments
- will never be null.- Returns:
-
toString
-