DATACMNS-867 - Introduced Stream-based alternatives for PersistentEntity.doWith… methods.
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.data.mapping;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.convert.EntityInstantiator;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
@@ -156,6 +157,8 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> {
|
||||
|
||||
void doWithProperties(SimplePropertyHandler handler);
|
||||
|
||||
Stream<P> getPersistentProperties();
|
||||
|
||||
/**
|
||||
* Applies the given {@link AssociationHandler} to all {@link Association} contained in this {@link PersistentEntity}.
|
||||
*
|
||||
@@ -165,6 +168,8 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> {
|
||||
|
||||
void doWithAssociations(SimpleAssociationHandler handler);
|
||||
|
||||
Stream<Association<P>> getAssociations();
|
||||
|
||||
/**
|
||||
* Looks up the annotation of the given type on the {@link PersistentEntity}.
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -335,11 +336,9 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
*/
|
||||
public void doWithProperties(PropertyHandler<P> handler) {
|
||||
|
||||
Assert.notNull(handler, "Handler must not be null!");
|
||||
Assert.notNull(handler, "PropertyHandler must not be null!");
|
||||
|
||||
properties.stream()//
|
||||
.filter(it -> !it.isTransient() && !it.isAssociation())//
|
||||
.forEach(it -> handler.doWithPersistentProperty(it));
|
||||
getPersistentProperties().forEach(it -> handler.doWithPersistentProperty(it));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -351,9 +350,18 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
|
||||
Assert.notNull(handler, "Handler must not be null!");
|
||||
|
||||
properties.stream()//
|
||||
.filter(it -> !it.isTransient() && !it.isAssociation())//
|
||||
.forEach(it -> handler.doWithPersistentProperty(it));
|
||||
getPersistentProperties().forEach(it -> handler.doWithPersistentProperty(it));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.PersistentEntity#getPersistentProperties()
|
||||
*/
|
||||
@Override
|
||||
public Stream<P> getPersistentProperties() {
|
||||
|
||||
return properties.stream()//
|
||||
.filter(it -> !it.isTransient() && !it.isAssociation());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -382,6 +390,15 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.PersistentEntity#getAssociations()
|
||||
*/
|
||||
@Override
|
||||
public Stream<Association<P>> getAssociations() {
|
||||
return associations.stream();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.PersistentEntity#findAnnotation(java.lang.Class)
|
||||
|
||||
Reference in New Issue
Block a user