DATACMNS-1767 - Polishing.
Reformat code. Use reflection for property access when running within a native image. Original pull request: #456.
This commit is contained in:
@@ -44,6 +44,7 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyPath;
|
||||
import org.springframework.data.mapping.PersistentPropertyPaths;
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.mapping.model.BeanWrapperPropertyAccessorFactory;
|
||||
import org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory;
|
||||
import org.springframework.data.mapping.model.EntityInstantiators;
|
||||
import org.springframework.data.mapping.model.InstantiationAwarePropertyAccessorFactory;
|
||||
@@ -85,6 +86,8 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
|
||||
implements MappingContext<E, P>, ApplicationEventPublisherAware, ApplicationContextAware, InitializingBean {
|
||||
|
||||
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
|
||||
|
||||
private final Optional<E> NONE = Optional.empty();
|
||||
private final Map<TypeInformation<?>, Optional<E>> persistentEntities = new HashMap<>();
|
||||
private final PersistentPropertyAccessorFactory persistentPropertyAccessorFactory;
|
||||
@@ -106,7 +109,8 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
|
||||
|
||||
EntityInstantiators instantiators = new EntityInstantiators();
|
||||
ClassGeneratingPropertyAccessorFactory accessorFactory = new ClassGeneratingPropertyAccessorFactory();
|
||||
PersistentPropertyAccessorFactory accessorFactory = IN_NATIVE_IMAGE ? BeanWrapperPropertyAccessorFactory.INSTANCE
|
||||
: new ClassGeneratingPropertyAccessorFactory();
|
||||
|
||||
this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory,
|
||||
instantiators);
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
enum BeanWrapperPropertyAccessorFactory implements PersistentPropertyAccessorFactory {
|
||||
public enum BeanWrapperPropertyAccessorFactory implements PersistentPropertyAccessorFactory {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
|
||||
@@ -142,9 +142,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
|
||||
*/
|
||||
boolean shouldUseReflectionEntityInstantiator(PersistentEntity<?, ?> entity) {
|
||||
|
||||
if(IN_NATIVE_IMAGE) {
|
||||
if (IN_NATIVE_IMAGE) {
|
||||
|
||||
if(LOGGER.isDebugEnabled()) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("graalvm.nativeimage - fall back to reflection for %s.", entity.getName()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user