Skip to content

DATACMNS-809 — Investigate use of method handles for property access #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.13.0.BUILD-SNAPSHOT</version>
<version>1.13.0.DATACMNS-809-SNAPSHOT</version>

<name>Spring Data Core</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.mapping.model.DefaultPersistentPropertyAccessorFactory;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.mapping.model.MutablePersistentEntity;
import org.springframework.data.mapping.model.SimpleTypeHolder;
Expand All @@ -54,19 +55,21 @@
* <p>
* The implementation uses a {@link ReentrantReadWriteLock} to make sure {@link PersistentEntity} are completely
* populated before accessing them from outside.
*
*
* @param E the concrete {@link PersistentEntity} type the {@link MappingContext} implementation creates
* @param P the concrete {@link PersistentProperty} type the {@link MappingContext} implementation creates
* @author Jon Brisbin
* @author Oliver Gierke
* @author Michael Hunger
* @author Thomas Darimont
* @author Tomasz Wysocki
* @author Mark Paluch
*/
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
implements MappingContext<E, P>, ApplicationEventPublisherAware, InitializingBean {

private final Map<TypeInformation<?>, E> persistentEntities = new HashMap<TypeInformation<?>, E>();
private final DefaultPersistentPropertyAccessorFactory persistentPropertyAccessorFactory = new DefaultPersistentPropertyAccessorFactory();

private ApplicationEventPublisher applicationEventPublisher;

Expand All @@ -78,7 +81,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
private final Lock read = lock.readLock();
private final Lock write = lock.writeLock();

/*
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
*/
Expand All @@ -88,7 +91,7 @@ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEv

/**
* Sets the {@link Set} of types to populate the context initially.
*
*
* @param initialEntitySet
*/
public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet) {
Expand All @@ -100,7 +103,7 @@ public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet) {
* {@link MappingException}s in case one tries to lookup a {@link PersistentEntity} not already in the context. This
* defaults to {@literal false} so that unknown types will be transparently added to the MappingContext if not known
* in advance.
*
*
* @param strict
*/
public void setStrict(boolean strict) {
Expand All @@ -111,7 +114,7 @@ public void setStrict(boolean strict) {
* Configures the {@link SimpleTypeHolder} to be used by the {@link MappingContext}. Allows customization of what
* types will be regarded as simple types and thus not recursively analysed. Setting this to {@literal null} will
* reset the context to use the default {@link SimpleTypeHolder}.
*
*
* @param simpleTypes
*/
public void setSimpleTypeHolder(SimpleTypeHolder simpleTypes) {
Expand Down Expand Up @@ -139,7 +142,7 @@ public E getPersistentEntity(Class<?> type) {
return getPersistentEntity(ClassTypeInformation.from(type));
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.MappingContext#hasPersistentEntityFor(java.lang.Class)
*/
Expand Down Expand Up @@ -216,7 +219,7 @@ public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath,
return getPersistentPropertyPath(propertyPath, ClassTypeInformation.from(type));
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.MappingContext#getPersistentPropertyPath(org.springframework.data.mapping.context.InvalidPersistentPropertyPath)
*/
Expand All @@ -231,7 +234,7 @@ private PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath,

/**
* Creates a {@link PersistentPropertyPath} for the given parts and {@link TypeInformation}.
*
*
* @param parts must not be {@literal null} or empty.
* @param type must not be {@literal null}.
* @return
Expand Down Expand Up @@ -268,7 +271,7 @@ private PersistentPropertyPath<P> getPersistentPropertyPath(Collection<String> p

/**
* Adds the given type to the {@link MappingContext}.
*
*
* @param type
* @return
*/
Expand All @@ -278,7 +281,7 @@ protected E addPersistentEntity(Class<?> type) {

/**
* Adds the given {@link TypeInformation} to the {@link MappingContext}.
*
*
* @param typeInformation
* @return
*/
Expand Down Expand Up @@ -316,6 +319,9 @@ protected E addPersistentEntity(TypeInformation<?> typeInformation) {

entity.verify();

if (persistentPropertyAccessorFactory.isSupported(entity)) {
entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory);
}
} catch (MappingException e) {
persistentEntities.remove(typeInformation);
throw e;
Expand All @@ -335,7 +341,7 @@ protected E addPersistentEntity(TypeInformation<?> typeInformation) {
}
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.PersistentEntityAware#getManagedTypes()
*/
Expand All @@ -354,7 +360,7 @@ public Collection<TypeInformation<?>> getManagedTypes() {

/**
* Creates the concrete {@link PersistentEntity} instance.
*
*
* @param <T>
* @param typeInformation
* @return
Expand All @@ -363,7 +369,7 @@ public Collection<TypeInformation<?>> getManagedTypes() {

/**
* Creates the concrete instance of {@link PersistentProperty}.
*
*
* @param field
* @param descriptor
* @param owner
Expand All @@ -373,7 +379,7 @@ public Collection<TypeInformation<?>> getManagedTypes() {
protected abstract P createPersistentProperty(Field field, PropertyDescriptor descriptor, E owner,
SimpleTypeHolder simpleTypeHolder);

/*
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
Expand All @@ -398,7 +404,7 @@ public void initialize() {
* default this will reject this for all types considered simple, but it might be necessary to tweak that in case you
* have registered custom converters for top level types (which renders them to be considered simple) but still need
* meta-information about them.
*
*
* @param type will never be {@literal null}.
* @return
*/
Expand All @@ -408,7 +414,7 @@ protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {

/**
* {@link FieldCallback} to create {@link PersistentProperty} instances.
*
*
* @author Oliver Gierke
*/
private final class PersistentPropertyCreator implements FieldCallback {
Expand All @@ -420,7 +426,7 @@ private final class PersistentPropertyCreator implements FieldCallback {
/**
* Creates a new {@link PersistentPropertyCreator} for the given {@link PersistentEntity} and
* {@link PropertyDescriptor}s.
*
*
* @param entity must not be {@literal null}.
* @param descriptors must not be {@literal null}.
*/
Expand Down Expand Up @@ -451,7 +457,7 @@ public void doWith(Field field) {
/**
* Adds {@link PersistentProperty} instances for all suitable {@link PropertyDescriptor}s without a backing
* {@link Field}.
*
*
* @see PersistentPropertyFilter
*/
public void addPropertiesForRemainingDescriptors() {
Expand Down Expand Up @@ -494,7 +500,7 @@ private void createAndRegisterProperty(Field field, PropertyDescriptor descripto
/**
* Filter rejecting static fields as well as artifically introduced ones. See
* {@link PersistentPropertyFilter#UNMAPPED_PROPERTIES} for details.
*
*
* @author Oliver Gierke
*/
static enum PersistentPropertyFilter implements FieldFilter {
Expand All @@ -513,7 +519,7 @@ static enum PersistentPropertyFilter implements FieldFilter {
UNMAPPED_PROPERTIES = Collections.unmodifiableCollection(matches);
}

/*
/*
* (non-Javadoc)
* @see org.springframework.util.ReflectionUtils.FieldFilter#matches(java.lang.reflect.Field)
*/
Expand All @@ -534,7 +540,7 @@ public boolean matches(Field field) {

/**
* Returns whether the given {@link PropertyDescriptor} is one to create a {@link PersistentProperty} for.
*
*
* @param descriptor must not be {@literal null}.
* @return
*/
Expand All @@ -557,7 +563,7 @@ public boolean matches(PropertyDescriptor descriptor) {

/**
* Value object to help defining property exclusion based on name patterns and types.
*
*
* @since 1.4
* @author Oliver Gierke
*/
Expand All @@ -569,7 +575,7 @@ static class PropertyMatch {
/**
* Creates a new {@link PropertyMatch} for the given name pattern and type name. At least one of the paramters
* must not be {@literal null}.
*
*
* @param namePattern a regex pattern to match field names, can be {@literal null}.
* @param typeName the name of the type to exclude, can be {@literal null}.
*/
Expand All @@ -583,7 +589,7 @@ public PropertyMatch(String namePattern, String typeName) {

/**
* Returns whether the given {@link Field} matches the defined {@link PropertyMatch}.
*
*
* @param field must not be {@literal null}.
* @return
*/
Expand Down
Loading