Introduce PersistentEntity.doWithAll(…).

To let a PropertyHandler operate on all properties *and* the inverse property of associations.

Fixes #2325.
This commit is contained in:
Oliver Drotbohm
2021-03-11 10:14:52 +01:00
parent 6b0292cc66
commit d03bfb877a
2 changed files with 38 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import java.util.Iterator;
import org.springframework.data.annotation.Immutable;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* Represents a persistent entity.
@@ -240,6 +241,22 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> extends It
void doWithAssociations(SimpleAssociationHandler handler);
/**
* Applies the given {@link PropertyHandler} to both all {@link PersistentProperty}s as well as all inverse properties
* of all {@link Association}s.
*
* @param handler must not be {@literal null}.
* @since 2.5
*/
default void doWithAll(PropertyHandler<P> handler) {
Assert.notNull(handler, "PropertyHandler must not be null!");
doWithProperties(handler);
doWithAssociations(
(AssociationHandler<P>) association -> handler.doWithPersistentProperty(association.getInverse()));
}
/**
* Looks up the annotation of the given type on the {@link PersistentEntity}.
*