Skip to content

Commit d8cea8b

Browse files
committed
DATACMNS-1208 - AbstractMappingContext.hasPersistentEntityFor(…) now properly considers cached absence.
AbstractMappingContext.hasPersistentEntityFor(…) now also properly consideres the empty Optional as non-presence as that is held to allow to distinguish between a type completely unkown to the context, or already known but not considered a persistent entity. Related pull request: #258.
1 parent 5d0cd54 commit d8cea8b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ public boolean hasPersistentEntityFor(Class<?> type) {
181181

182182
Assert.notNull(type, "Type must not be null!");
183183

184-
return persistentEntities.containsKey(ClassTypeInformation.from(type));
184+
Optional<E> entity = persistentEntities.get(ClassTypeInformation.from(type));
185+
186+
return entity == null ? false : entity.isPresent();
185187
}
186188

187189
/*

src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ public void cachesPersistentPropertyPaths() {
244244
.isSameAs(context.getPersistentPropertyPath("persons.name", Sample.class));
245245
}
246246

247+
@Test // DATACMNS-1208
248+
public void ensureHasPersistentEntityReportsFalseForTypesThatShouldntBeCreated() {
249+
250+
SampleMappingContext context = new SampleMappingContext();
251+
252+
assertThat(context.hasPersistentEntityFor(String.class)).isFalse();
253+
assertThat(context.getPersistentEntity(String.class)).isNull();
254+
assertThat(context.hasPersistentEntityFor(String.class)).isFalse();
255+
}
256+
247257
private static void assertHasEntityFor(Class<?> type, SampleMappingContext context, boolean expected) {
248258

249259
boolean found = false;

0 commit comments

Comments
 (0)