Skip to content

Commit 3b73a4f

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 7ed72ff commit 3b73a4f

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
@@ -48,6 +48,7 @@
4848
import org.springframework.data.mapping.PersistentPropertyPath;
4949
import org.springframework.data.mapping.PersistentPropertyPaths;
5050
import org.springframework.data.mapping.PropertyPath;
51+
import org.springframework.data.mapping.model.BeanWrapperPropertyAccessorFactory;
5152
import org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory;
5253
import org.springframework.data.mapping.model.EntityInstantiators;
5354
import org.springframework.data.mapping.model.InstantiationAwarePropertyAccessorFactory;
@@ -89,6 +90,8 @@
8990
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
9091
implements MappingContext<E, P>, ApplicationEventPublisherAware, ApplicationContextAware, InitializingBean {
9192

93+
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
94+
9295
private final Optional<E> NONE = Optional.empty();
9396
private final Map<TypeInformation<?>, Optional<E>> persistentEntities = new HashMap<>();
9497
private final PersistentPropertyAccessorFactory persistentPropertyAccessorFactory;
@@ -110,7 +113,8 @@ protected AbstractMappingContext() {
110113
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
111114

112115
EntityInstantiators instantiators = new EntityInstantiators();
113-
ClassGeneratingPropertyAccessorFactory accessorFactory = new ClassGeneratingPropertyAccessorFactory();
116+
PersistentPropertyAccessorFactory accessorFactory = IN_NATIVE_IMAGE ? BeanWrapperPropertyAccessorFactory.INSTANCE
117+
: new ClassGeneratingPropertyAccessorFactory();
114118

115119
this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory,
116120
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)