DATACMNS-867 - Introduced PersistentEntity.getRequiredPersistentProperty().
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user