DATACMNS-809 - Refactor BasicPersistentEntity to set PersistentPropertyAccessorFactory.

PersistentPropertyAccessorFactory can be set on a BasicPersistentEntity. This is done by AbstractMappingContext once the entity is verified. This change reduces the count of PersistentPropertyAccessorFactory instances and performs the isSupported check only once, when initializing the entity.

Original pull request: #159.
This commit is contained in:
Mark Paluch
2016-05-03 09:27:21 +02:00
committed by Oliver Gierke
parent 41fe89743b
commit defc3c7874
8 changed files with 123 additions and 42 deletions

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.mapping.model;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
@@ -131,6 +131,18 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
assertThat(persistentPropertyAccessor.getProperty(property), is(equalTo((Object) value)));
}
/**
* @see DATACMNS-809
*/
@Test
public void shouldUseClassPropertyAccessorFactory() throws Exception {
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
.getPersistentEntity(bean.getClass());
assertThat(persistentEntity.getPropertyAccessorFactory(), is(instanceOf(DefaultPersistentPropertyAccessorFactory.class)));
}
private PersistentPropertyAccessor getPersistentPropertyAccessor(Object bean) {
return factory.getPropertyAccessor(mappingContext.getPersistentEntity(bean.getClass()), bean);
}

View File

@@ -16,7 +16,7 @@
package org.springframework.data.mapping.model;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
@@ -156,6 +156,18 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
persistentPropertyAccessor.setProperty(property, null);
}
/**
* @see DATACMNS-809
*/
@Test
public void shouldUseClassPropertyAccessorFactory() throws Exception {
BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = mappingContext
.getPersistentEntity(bean.getClass());
assertThat(persistentEntity.getPropertyAccessorFactory(), is(instanceOf(DefaultPersistentPropertyAccessorFactory.class)));
}
private PersistentPropertyAccessor getPersistentPropertyAccessor(Object bean) {
return factory.getPropertyAccessor(mappingContext.getPersistentEntity(bean.getClass()), bean);
}