DATACMNS-867 - Introduced Stream-based alternatives for PersistentEntity.doWith… methods.

This commit is contained in:
Oliver Gierke
2016-10-11 15:44:15 +02:00
parent db4bf10ebb
commit 49575fd4ce
2 changed files with 29 additions and 7 deletions

View File

@@ -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}.
*

View File

@@ -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)