Skip to content

Commit 9d7d735

Browse files
arefbehboudichristophstrobl
authored andcommitted
Polishing JpaMetamodel.
Closes: #3555 Original Pull Request: #3559
1 parent a389415 commit 9d7d735

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/util/JpaMetamodel.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Collection;
1919
import java.util.Map;
20+
import java.util.Objects;
2021
import java.util.Optional;
2122
import java.util.concurrent.ConcurrentHashMap;
2223

@@ -38,15 +39,16 @@
3839
* @author Oliver Gierke
3940
* @author Mark Paluch
4041
* @author Sylvère Richard
42+
* @author Aref Behboodi
4143
*/
4244
public class JpaMetamodel {
4345

4446
private static final Map<Metamodel, JpaMetamodel> CACHE = new ConcurrentHashMap<>(4);
4547

4648
private final Metamodel metamodel;
4749

48-
private Lazy<Collection<Class<?>>> managedTypes;
49-
private Lazy<Collection<Class<?>>> jpaEmbeddables;
50+
private final Lazy<Collection<Class<?>>> managedTypes;
51+
private final Lazy<Collection<Class<?>>> jpaEmbeddables;
5052

5153
/**
5254
* Creates a new {@link JpaMetamodel} for the given JPA {@link Metamodel}.
@@ -61,12 +63,12 @@ private JpaMetamodel(Metamodel metamodel) {
6163

6264
this.managedTypes = Lazy.of(() -> metamodel.getManagedTypes().stream() //
6365
.map(ManagedType::getJavaType) //
64-
.filter(it -> it != null) //
66+
.filter(Objects::nonNull) //
6567
.collect(StreamUtils.toUnmodifiableSet()));
6668

6769
this.jpaEmbeddables = Lazy.of(() -> metamodel.getEmbeddables().stream() //
6870
.map(ManagedType::getJavaType)
69-
.filter(it -> it != null)
71+
.filter(Objects::nonNull)
7072
.filter(it -> AnnotatedElementUtils.isAnnotated(it, Embeddable.class))
7173
.collect(StreamUtils.toUnmodifiableSet()));
7274
}
@@ -101,7 +103,7 @@ public boolean isSingleIdAttribute(Class<?> entity, String name, Class<?> attrib
101103
return metamodel.getEntities().stream() //
102104
.filter(it -> entity.equals(it.getJavaType())) //
103105
.findFirst() //
104-
.flatMap(it -> getSingularIdAttribute(it)) //
106+
.flatMap(JpaMetamodel::getSingularIdAttribute) //
105107
.filter(it -> it.getJavaType().equals(attributeType)) //
106108
.map(it -> it.getName().equals(name)) //
107109
.orElse(false);

0 commit comments

Comments
 (0)