DATACMNS-1116 - AbstractMappingContext now caches PersistentPropertyPaths.

As the calculation of a PersistentPropertyPath instances is rather expensive and they're heavily used in downstream mapping operations (e.g. query and fields mapping in MongoDB) we now cache the instances created per base type and property path.
This commit is contained in:
Oliver Gierke
2017-07-19 13:45:41 +02:00
parent d692702663
commit dfcb9f77a4
2 changed files with 26 additions and 5 deletions

View File

@@ -31,10 +31,10 @@ import org.mockito.Mockito;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
@@ -155,7 +155,7 @@ public class AbstractMappingContextUnitTests {
assertThat(entity.getPersistentProperty("persons"))
.satisfies(it -> assertThat(mappingContext.getPersistentEntity(it))
.satisfies(inner -> assertThat(((PersistentEntity)inner).getType()).isEqualTo(Person.class)));
.satisfies(inner -> assertThat(((PersistentEntity) inner).getType()).isEqualTo(Person.class)));
}
@Test // DATACMNS-380
@@ -226,6 +226,13 @@ public class AbstractMappingContextUnitTests {
.matches(e -> context.getPersistentPropertyPath(e) != null);
}
@Test // DATACMNS-1116
public void cachesPersistentPropertyPaths() {
assertThat(context.getPersistentPropertyPath("persons.name", Sample.class)) //
.isSameAs(context.getPersistentPropertyPath("persons.name", Sample.class));
}
private static void assertHasEntityFor(Class<?> type, SampleMappingContext context, boolean expected) {
boolean found = false;