DATALDAP-64 - Export composable repositories via CDI.
We now export composable repositories through our CDI extension. Repositories can now be customized either by a single custom implementation (as it was before) and by providing fragment interfaces along their fragment implementation. This change aligns CDI support with the existing RepositoryFactory support we provide within a Spring application context.
This commit is contained in:
@@ -63,13 +63,19 @@ public class LdapRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType,
|
||||
Optional<Object> customImplementation) {
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
|
||||
|
||||
LdapOperations ldapOperations = getDependencyInstance(operations, LdapOperations.class);
|
||||
LdapRepositoryFactory factory = new LdapRepositoryFactory(ldapOperations);
|
||||
|
||||
return customImplementation.map(o -> factory.getRepository(repositoryType, o))
|
||||
.orElseGet(() -> factory.getRepository(repositoryType));
|
||||
return create(() -> new LdapRepositoryFactory(ldapOperations), repositoryType);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#getScope()
|
||||
*/
|
||||
@Override
|
||||
public Class<? extends Annotation> getScope() {
|
||||
return operations.getScope();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.ldap.repository.cdi;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
interface SampleRepositoryCustom {
|
||||
interface SampleFragment {
|
||||
|
||||
int returnOne();
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.ldap.repository.cdi;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class SampleRepositoryImpl implements SampleRepositoryCustom {
|
||||
class SampleFragmentImpl implements SampleFragment {
|
||||
|
||||
@Override
|
||||
public int returnOne() {
|
||||
@@ -23,4 +23,4 @@ import org.springframework.data.repository.CrudRepository;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public interface SampleRepository extends CrudRepository<DummyEntity, Name>, SampleRepositoryCustom {}
|
||||
public interface SampleRepository extends CrudRepository<DummyEntity, Name>, SampleFragment {}
|
||||
|
||||
Reference in New Issue
Block a user