> {
boolean isEntity();
/**
- * Returns the component type of the type if it is a {@link Collection}. Will return the type of the key if the
- * property is a {@link Map}.
+ * Returns the component type of the type if it is a {@link java.util.Collection}. Will return the type of the key if the
+ * property is a {@link java.util.Map}.
*
- * @return the component type, the map's key type or {@literal null} if neither {@link Collection} nor {@link Map}.
+ * @return the component type, the map's key type or {@literal null} if neither {@link java.util.Collection} nor {@link java.util.Map}.
*/
Class> getComponentType();
@@ -76,9 +74,9 @@ public interface PersistentProperty
> {
Class> getRawType();
/**
- * Returns the type of the values if the property is a {@link Map}.
+ * Returns the type of the values if the property is a {@link java.util.Map}.
*
- * @return the map's value type or {@literal null} if no {@link Map}
+ * @return the map's value type or {@literal null} if no {@link java.util.Map}
*/
Class> getMapValueType();
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java
index 52b6edb99..d9cf0538c 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java
@@ -241,35 +241,7 @@ public abstract class AbstractMappingContext nestedType = getNestedTypeToAdd(property, entity);
- if (nestedType != null) {
- addPersistentEntity(nestedType);
- }
- }
- }, new ReflectionUtils.FieldFilter() {
+ ReflectionUtils.doWithFields(type, new PersistentPropertyCreator(entity, descriptors), new ReflectionUtils.FieldFilter() {
public boolean matches(Field field) {
return !Modifier.isStatic(field.getModifiers()) && !UNMAPPED_FIELDS.contains(field.getName());
}
@@ -372,4 +344,54 @@ public abstract class AbstractMappingContext descriptors;
+
+ /**
+ * Creates a new {@link PersistentPropertyCreator} for the given {@link PersistentEntity} and
+ * {@link PropertyDescriptor}s.
+ *
+ * @param entity
+ * @param descriptors
+ */
+ private PersistentPropertyCreator(E entity, Map descriptors) {
+ this.entity = entity;
+ this.descriptors = descriptors;
+ }
+
+ public void doWith(Field field) {
+
+ PropertyDescriptor descriptor = descriptors.get(field.getName());
+
+ ReflectionUtils.makeAccessible(field);
+ P property = createPersistentProperty(field, descriptor, entity, simpleTypeHolder);
+
+ if (property.isTransient()) {
+ return;
+ }
+
+ entity.addPersistentProperty(property);
+
+ if (property.isAssociation()) {
+ entity.addAssociation(property.getAssociation());
+ }
+
+ if (property.isIdProperty()) {
+ entity.setIdProperty(property);
+ }
+
+ TypeInformation> nestedType = getNestedTypeToAdd(property, entity);
+ if (nestedType != null) {
+ addPersistentEntity(nestedType);
+ }
+ }
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java
deleted file mode 100644
index b3c5980d1..000000000
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAware.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2011 by the original author(s).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.data.mapping.context;
-
-/**
- * An interface to make beans aware of the active MappingContext in the current ApplicationContext.
- *
- * @author Jon Brisbin
- */
-public interface MappingContextAware {
-
- /**
- * The active MappingContext for the environment.
- *
- * @param mappingContext
- */
- void setMappingContext(MappingContext, ?> mappingContext);
-
-}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java
deleted file mode 100644
index dee4e921a..000000000
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/context/MappingContextAwareBeanPostProcessor.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2011 by the original author(s).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.data.mapping.context;
-
-import java.util.Map;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-/**
- * BeanPostProcessor to make Spring beans aware of the current MappingContext. If a MappingContext exists with the
- * default bean name ("mappingContext"), then that bean is used. If there is no MappingContext registered under the
- * default bean name, then the first MappingContext it finds is the one it chooses.
- *
- * @author Jon Brisbin
- */
-public class MappingContextAwareBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware {
-
- private ApplicationContext applicationContext;
- private String mappingContextBeanName = "mappingContext";
- private MappingContext, ?> mappingContext;
-
- public MappingContextAwareBeanPostProcessor() {
- }
-
- public MappingContextAwareBeanPostProcessor(MappingContext, ?> mappingContext) {
- this.mappingContext = mappingContext;
- }
-
- public String getMappingContextBeanName() {
- return mappingContextBeanName;
- }
-
- public void setMappingContextBeanName(String mappingContextBeanName) {
- this.mappingContextBeanName = mappingContextBeanName;
- }
-
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- this.applicationContext = applicationContext;
- }
-
- public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
- return bean;
- }
-
- @SuppressWarnings("rawtypes")
- public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
- if (bean instanceof MappingContextAware) {
- if (null == mappingContext) {
- Map mappingContexts = applicationContext.getBeansOfType(MappingContext.class);
- if (mappingContexts.containsKey(mappingContextBeanName)) {
- this.mappingContext = mappingContexts.get(mappingContextBeanName);
- } else {
- String firstBean = mappingContexts.keySet().iterator().next();
- this.mappingContext = applicationContext.getBean(firstBean, MappingContext.class);
- }
- }
- ((MappingContextAware) bean).setMappingContext(mappingContext);
- }
- return bean;
- }
-}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java
index 6f844a906..f4cddc226 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java
@@ -15,6 +15,7 @@
*/
package org.springframework.data.mapping.model;
+import java.io.Serializable;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
@@ -186,8 +187,9 @@ public class BasicPersistentEntity> implement
* @author Oliver Gierke
*/
private static final class AssociationComparator
> implements
- Comparator> {
+ Comparator>, Serializable {
+ private static final long serialVersionUID = 4508054194886854513L;
private final Comparator
delegate;
public AssociationComparator(Comparator
delegate) {
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java
index cb8e9813c..06d80c4b6 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/BeanWrapper.java
@@ -104,6 +104,9 @@ public class BeanWrapper, T> {
} catch (BeanInstantiationException e) {
throw new MappingInstantiationException(e.getMessage(), e);
}
+
+ this.bean = bean;
+ return;
}
List