Skip to content

Commit 00d77d0

Browse files
committed
DATACMNS-1767 - Polishing.
Reformat code. Use reflection for property access when running within a native image. Original pull request: #456.
1 parent ff0a8f7 commit 00d77d0

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.springframework.data.mapping.PersistentPropertyPath;
4545
import org.springframework.data.mapping.PersistentPropertyPaths;
4646
import org.springframework.data.mapping.PropertyPath;
47+
import org.springframework.data.mapping.model.BeanWrapperPropertyAccessorFactory;
4748
import org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory;
4849
import org.springframework.data.mapping.model.EntityInstantiators;
4950
import org.springframework.data.mapping.model.InstantiationAwarePropertyAccessorFactory;
@@ -85,6 +86,8 @@
8586
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
8687
implements MappingContext<E, P>, ApplicationEventPublisherAware, ApplicationContextAware, InitializingBean {
8788

89+
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
90+
8891
private final Optional<E> NONE = Optional.empty();
8992
private final Map<TypeInformation<?>, Optional<E>> persistentEntities = new HashMap<>();
9093
private final PersistentPropertyAccessorFactory persistentPropertyAccessorFactory;
@@ -106,7 +109,8 @@ protected AbstractMappingContext() {
106109
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
107110

108111
EntityInstantiators instantiators = new EntityInstantiators();
109-
ClassGeneratingPropertyAccessorFactory accessorFactory = new ClassGeneratingPropertyAccessorFactory();
112+
PersistentPropertyAccessorFactory accessorFactory = IN_NATIVE_IMAGE ? BeanWrapperPropertyAccessorFactory.INSTANCE
113+
: new ClassGeneratingPropertyAccessorFactory();
110114

111115
this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory,
112116
instantiators);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Oliver Gierke
2525
*/
26-
enum BeanWrapperPropertyAccessorFactory implements PersistentPropertyAccessorFactory {
26+
public enum BeanWrapperPropertyAccessorFactory implements PersistentPropertyAccessorFactory {
2727

2828
INSTANCE;
2929

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> e
142142
*/
143143
boolean shouldUseReflectionEntityInstantiator(PersistentEntity<?, ?> entity) {
144144

145-
if(IN_NATIVE_IMAGE) {
145+
if (IN_NATIVE_IMAGE) {
146146

147-
if(LOGGER.isDebugEnabled()) {
147+
if (LOGGER.isDebugEnabled()) {
148148
LOGGER.debug(String.format("graalvm.nativeimage - fall back to reflection for %s.", entity.getName()));
149149
}
150150

0 commit comments

Comments
 (0)