Browse Source

DATACMNS-794 - Repositories now exposes RepositoryInformation for repository interfaces.

pull/109/merge
Oliver Gierke 10 years ago
parent
commit
c60cd647cc
  1. 26
      src/main/java/org/springframework/data/repository/support/Repositories.java
  2. 14
      src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java

26
src/main/java/org/springframework/data/repository/support/Repositories.java

@ -94,8 +94,8 @@ public class Repositories implements Iterable<Class<?>> { @@ -94,8 +94,8 @@ public class Repositories implements Iterable<Class<?>> {
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<Class<?>> alternativeDomainTypes = information.getAlternativeDomainTypes();
@ -193,6 +193,28 @@ public class Repositories implements Iterable<Class<?>> { @@ -193,6 +193,28 @@ public class Repositories implements Iterable<Class<?>> {
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<Object, Serializable> 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.

14
src/test/java/org/springframework/data/repository/support/RepositoriesUnitTests.java

@ -17,7 +17,7 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat @@ -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 { @@ -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 {}

Loading…
Cancel
Save