DATACMNS-867 - More required metadata lookup.

Introduced overloads to lookup required RepositoryInformation and PersistentEntity instances to Repositories and PersistentEntities.
This commit is contained in:
Oliver Gierke
2017-02-14 11:34:00 +01:00
parent be347eaaab
commit c84e6c8427
2 changed files with 34 additions and 4 deletions

View File

@@ -47,8 +47,8 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ?>> {
/**
* Returns the {@link PersistentEntity} for the given type. Will consider all {@link MappingContext}s registered but
* return {@literal null} in case none of the registered ones already have a {@link PersistentEntity} registered for
* the given type.
* return {@literal Optional#empty()} in case none of the registered ones already have a {@link PersistentEntity}
* registered for the given type.
*
* @param type can be {@literal null}.
* @return
@@ -60,6 +60,23 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ?>> {
.findFirst().map(it -> it.getRequiredPersistentEntity(type));
}
/**
* Returns the {@link PersistentEntity} for the given type. Will consider all {@link MappingContext}s registered but
* throw an {@link IllegalArgumentException} in case none of the registered ones already have a
* {@link PersistentEntity} registered for the given type.
*
* @param type must not be {@literal null}.
* @return the {@link PersistentEntity} for the given domain type.
* @throws IllegalArgumentException in case no {@link PersistentEntity} can be found for the given type.
*/
public PersistentEntity<?, ?> getRequiredPersistentEntity(Class<?> type) {
Assert.notNull(type, "Domain type must not be null!");
return getPersistentEntity(type).orElseThrow(
() -> new IllegalArgumentException(String.format("Couldn't find PersistentEntity for type %s!", type)));
}
/**
* Returns all {@link TypeInformation} exposed by the registered {@link MappingContext}s.
*
@@ -79,7 +96,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ?>> {
@Override
public Iterator<PersistentEntity<?, ?>> iterator() {
return contexts.stream().<PersistentEntity<?, ?>>flatMap(it -> it.getPersistentEntities().stream())
return contexts.stream().<PersistentEntity<?, ?>> flatMap(it -> it.getPersistentEntities().stream())
.collect(Collectors.toList()).iterator();
}
}

View File

@@ -74,7 +74,7 @@ public class Repositories implements Iterable<Class<?>> {
*/
public Repositories(ListableBeanFactory factory) {
Assert.notNull(factory, "Factory must not be null!");
Assert.notNull(factory, "ListableBeanFactory must not be null!");
this.beanFactory = Optional.of(factory);
this.repositoryFactoryInfos = new HashMap<>();
@@ -196,6 +196,19 @@ public class Repositories implements Iterable<Class<?>> {
: Optional.of(information.getRepositoryInformation());
}
/**
* Returns the {@link RepositoryInformation} for the given domain type.
*
* @param domainType must not be {@literal null}.
* @return the {@link RepositoryInformation} for the given domain type.
* @throws IllegalArgumentException in case no {@link RepositoryInformation} could be found for the given domain type.
*/
public RepositoryInformation getRequiredRepositoryInformation(Class<?> domainType) {
return getRepositoryInformationFor(domainType).orElseThrow(() -> new IllegalArgumentException(
"No required RepositoryInformation found for domain type " + domainType.getName() + "!"));
}
/**
* Returns the {@link RepositoryInformation} for the given repository interface.
*