Browse Source

DATACMNS-1767 - Polishing.

Reformat code. Use reflection for property access when running within a native image.

Original pull request: #456.
pull/457/head
Mark Paluch 6 years ago
parent
commit
00d77d03cd
No known key found for this signature in database
GPG Key ID: 51A00FA751B91849
  1. 6
      src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java
  2. 2
      src/main/java/org/springframework/data/mapping/model/BeanWrapperPropertyAccessorFactory.java
  3. 4
      src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java

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

@ -44,6 +44,7 @@ import org.springframework.data.mapping.PersistentProperty; @@ -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; @@ -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<? @@ -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);

2
src/main/java/org/springframework/data/mapping/model/BeanWrapperPropertyAccessorFactory.java

@ -23,7 +23,7 @@ import org.springframework.data.mapping.PersistentPropertyAccessor; @@ -23,7 +23,7 @@ import org.springframework.data.mapping.PersistentPropertyAccessor;
*
* @author Oliver Gierke
*/
enum BeanWrapperPropertyAccessorFactory implements PersistentPropertyAccessorFactory {
public enum BeanWrapperPropertyAccessorFactory implements PersistentPropertyAccessorFactory {
INSTANCE;

4
src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java

@ -142,9 +142,9 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -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()));
}

Loading…
Cancel
Save