DATACMNS-526 - Added type matching to strict repository scanning.
Repository interfaces are now also considered strict matches if they are assignable to one of the types returned by getIdentifyingTypes().
This commit is contained in:
@@ -157,6 +157,16 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the types that indicate a store match when inspecting repositories for strict matches.
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*/
|
||||
protected Collection<Class<?>> getIdentifyingTypes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given source on the given {@link AbstractBeanDefinition} and registers it inside the given
|
||||
* {@link BeanDefinitionRegistry}.
|
||||
@@ -219,8 +229,16 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
|
||||
protected boolean isStrictRepositoryCandidate(Class<?> repositoryInterface) {
|
||||
|
||||
RepositoryMetadata metadata = AbstractRepositoryMetadata.getMetadata(repositoryInterface);
|
||||
Class<?> domainType = metadata.getDomainType();
|
||||
|
||||
Collection<Class<?>> types = getIdentifyingTypes();
|
||||
|
||||
for (Class<?> type : types) {
|
||||
if (type.isAssignableFrom(repositoryInterface)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Class<?> domainType = metadata.getDomainType();
|
||||
Collection<Class<? extends Annotation>> annotations = getIdentifyingAnnotations();
|
||||
|
||||
if (annotations.isEmpty()) {
|
||||
|
||||
@@ -52,34 +52,35 @@ public class RepositoryConfigurationExtensionSupportUnitTests {
|
||||
assertThat(extension.isStrictRepositoryCandidate(AnnotatedTypeRepository.class), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-526
|
||||
*/
|
||||
@Test
|
||||
public void considersRepositoryInterfaceExtendingStoreInterfaceStrictMatch() {
|
||||
assertThat(extension.isStrictRepositoryCandidate(ExtendingInterface.class), is(true));
|
||||
}
|
||||
|
||||
static class SampleRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix()
|
||||
*/
|
||||
@Override
|
||||
protected String getModulePrefix() {
|
||||
return "core";
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryClassName()
|
||||
*/
|
||||
@Override
|
||||
public String getRepositoryFactoryClassName() {
|
||||
return RepositoryFactorySupport.class.getName();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingAnnotations()
|
||||
*/
|
||||
@Override
|
||||
protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations() {
|
||||
return Collections.<Class<? extends Annotation>> singleton(Primary.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<?>> getIdentifyingTypes() {
|
||||
return Collections.<Class<?>> singleton(StoreInterface.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Primary
|
||||
@@ -90,4 +91,8 @@ public class RepositoryConfigurationExtensionSupportUnitTests {
|
||||
interface AnnotatedTypeRepository extends Repository<AnnotatedType, Long> {}
|
||||
|
||||
interface PlainTypeRepository extends Repository<PlainType, Long> {}
|
||||
|
||||
interface StoreInterface {}
|
||||
|
||||
interface ExtendingInterface extends StoreInterface, Repository<PlainType, Long> {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user