Browse Source

Use NativeDetector.inNativeImage() instead of manual property check.

Closes: #2298
Original pull request: #2299.
Relates to: spring-projects/spring-framework#25795
2.4.x
Christoph Strobl 5 years ago committed by Mark Paluch
parent
commit
08e408bea2
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 5
      src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java
  2. 4
      src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java

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

@ -38,6 +38,7 @@ import org.springframework.context.ApplicationContextAware; @@ -38,6 +38,7 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.core.KotlinDetector;
import org.springframework.core.NativeDetector;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
@ -86,8 +87,6 @@ import org.springframework.util.ReflectionUtils.FieldFilter; @@ -86,8 +87,6 @@ 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;
@ -109,7 +108,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -109,7 +108,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
EntityInstantiators instantiators = new EntityInstantiators();
PersistentPropertyAccessorFactory accessorFactory = IN_NATIVE_IMAGE ? BeanWrapperPropertyAccessorFactory.INSTANCE
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage() ? BeanWrapperPropertyAccessorFactory.INSTANCE
: new ClassGeneratingPropertyAccessorFactory();
this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory,

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

@ -31,6 +31,7 @@ import org.springframework.asm.MethodVisitor; @@ -31,6 +31,7 @@ import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Opcodes;
import org.springframework.asm.Type;
import org.springframework.cglib.core.ReflectUtils;
import org.springframework.core.NativeDetector;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PreferredConstructor;
@ -55,7 +56,6 @@ import org.springframework.util.ClassUtils; @@ -55,7 +56,6 @@ import org.springframework.util.ClassUtils;
class ClassGeneratingEntityInstantiator implements EntityInstantiator {
private static final Log LOGGER = LogFactory.getLog(ClassGeneratingEntityInstantiator.class);
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
private static final Object[] EMPTY_ARGS = new Object[0];
@ -142,7 +142,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { @@ -142,7 +142,7 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator {
*/
boolean shouldUseReflectionEntityInstantiator(PersistentEntity<?, ?> entity) {
if (IN_NATIVE_IMAGE) {
if (NativeDetector.inNativeImage()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("graalvm.nativeimage - fall back to reflection for %s.", entity.getName()));

Loading…
Cancel
Save