DATACMNS-867 - Introduced PersistentEntity.getRequiredPersistentProperty().

This commit is contained in:
Oliver Gierke
2016-10-11 15:43:42 +02:00
parent d4811e29d9
commit db4bf10ebb
2 changed files with 14 additions and 1 deletions

View File

@@ -97,6 +97,8 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> {
*/
Optional<P> getPersistentProperty(String name);
P getRequiredPersistentProperty(String name);
/**
* Returns the property equipped with an annotation of the given type.
*

View File

@@ -107,7 +107,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
this.properties = new ArrayList<>();
this.comparator = comparator;
this.constructor = new PreferredConstructorDiscoverer<>(this).getConstructor();
this.associations = comparator.<Set<Association<P>>>map(it -> new TreeSet<>(new AssociationComparator<>(it)))
this.associations = comparator.<Set<Association<P>>> map(it -> new TreeSet<>(new AssociationComparator<>(it)))
.orElseGet(() -> new HashSet<>());
this.propertyCache = new HashMap<>();
@@ -273,6 +273,17 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
return Optional.ofNullable(propertyCache.get(name));
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentEntity#getRequiredPersistentProperty(java.lang.String)
*/
@Override
public P getRequiredPersistentProperty(String name) {
return getPersistentProperty(name).orElseThrow(
() -> new IllegalArgumentException(String.format("No property %s found for type %s!", name, getType())));
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentEntity#getPersistentProperty(java.lang.Class)