diff --git a/src/main/java/org/springframework/data/repository/support/Repositories.java b/src/main/java/org/springframework/data/repository/support/Repositories.java index 3ed318879..f15c49c87 100644 --- a/src/main/java/org/springframework/data/repository/support/Repositories.java +++ b/src/main/java/org/springframework/data/repository/support/Repositories.java @@ -94,8 +94,8 @@ public class Repositories implements Iterable> { RepositoryFactoryInformation repositoryFactoryInformation = beanFactory.getBean(name, RepositoryFactoryInformation.class); - Class domainType = ClassUtils.getUserClass(repositoryFactoryInformation.getRepositoryInformation() - .getDomainType()); + Class domainType = ClassUtils + .getUserClass(repositoryFactoryInformation.getRepositoryInformation().getDomainType()); RepositoryInformation information = repositoryFactoryInformation.getRepositoryInformation(); Set> alternativeDomainTypes = information.getAlternativeDomainTypes(); @@ -193,6 +193,28 @@ public class Repositories implements Iterable> { return information == EMPTY_REPOSITORY_FACTORY_INFO ? null : information.getRepositoryInformation(); } + /** + * Returns the {@link RepositoryInformation} for the given repository interface. + * + * @param repositoryInterface must not be {@literal null}. + * @return the {@link RepositoryInformation} for the given repository interface or {@literal null} there's no + * repository instance registered for the given interface. + * @since 1.12 + */ + public RepositoryInformation getRepositoryInformation(Class repositoryInterface) { + + for (RepositoryFactoryInformation factoryInformation : repositoryFactoryInfos.values()) { + + RepositoryInformation information = factoryInformation.getRepositoryInformation(); + + if (information.getRepositoryInterface().equals(repositoryInterface)) { + return information; + } + } + + return null; + } + /** * Returns the {@link PersistentEntity} for the given domain class. Might return {@literal null} in case the module * storing the given domain class does not support the mapping subsystem. diff --git a/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java b/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java index 643fd630c..7b32bc57d 100644 --- a/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java +++ b/src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java @@ -17,7 +17,7 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat */ package org.springframework.data.repository.support; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import java.io.Serializable; @@ -139,6 +139,18 @@ public class RepositoriesUnitTests { context.close(); } + /** + * @see DATACMNS-794 + */ + @Test + public void exposesRepositoryFactoryInformationForRepository() { + + RepositoryInformation information = new Repositories(context).getRepositoryInformation(PersonRepository.class); + + assertThat(information, is(notNullValue())); + assertThat(information.getRepositoryInterface(), is(typeCompatibleWith(PersonRepository.class))); + } + class Person {} class Address {}