, P extends PersistentProperty> implements MappingContext, InitializingBean, ApplicationEventPublisherAware {
- private static final Set UNMAPPED_FIELDS = new HashSet(Arrays.asList("class", "this$0"));
+ private static final Set UNMAPPED_FIELDS = new HashSet(Arrays.asList("class", "this$0"));
- private ApplicationEventPublisher applicationEventPublisher;
- private ConcurrentMap, E> persistentEntities = new ConcurrentHashMap, E>();
- private ConcurrentMap> validators = new ConcurrentHashMap>();
- private List> customSimpleTypes = new ArrayList>();
- private Set extends Class>> initialEntitySet = new HashSet>();
- private boolean strict = false;
+ private ApplicationEventPublisher applicationEventPublisher;
+ private ConcurrentMap, E> persistentEntities = new ConcurrentHashMap, E>();
+ private ConcurrentMap> validators = new ConcurrentHashMap>();
+ private List> customSimpleTypes = new ArrayList>();
+ private Set extends Class>> initialEntitySet = new HashSet>();
+ private boolean strict = false;
- /**
- * @param customSimpleTypes the customSimpleTypes to set
- */
- public void setCustomSimpleTypes(List> customSimpleTypes) {
- this.customSimpleTypes = customSimpleTypes;
- }
+ /**
+ * @param customSimpleTypes the customSimpleTypes to set
+ */
+ public void setCustomSimpleTypes(List> customSimpleTypes) {
+ this.customSimpleTypes = customSimpleTypes;
+ }
- /*
- * (non-Javadoc)
- * @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
- */
- public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
- this.applicationEventPublisher = applicationEventPublisher;
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
+ */
+ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
+ this.applicationEventPublisher = applicationEventPublisher;
+ }
- /**
- * Sets the {@link Set} of types to populate the context initially.
- *
- * @param initialEntitySet
- */
- public void setInitialEntitySet(Set extends Class>> initialEntitySet) {
- this.initialEntitySet = initialEntitySet;
- }
+ /**
+ * Sets the {@link Set} of types to populate the context initially.
+ *
+ * @param initialEntitySet
+ */
+ public void setInitialEntitySet(Set extends Class>> initialEntitySet) {
+ this.initialEntitySet = initialEntitySet;
+ }
- /**
- * Configures whether the {@link MappingContext} is in strict mode which means, that it will throw
- * {@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) {
- this.strict = strict;
- }
+ /**
+ * Configures whether the {@link MappingContext} is in strict mode which means, that it will throw
+ * {@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) {
+ this.strict = strict;
+ }
- public Collection getPersistentEntities() {
- return persistentEntities.values();
- }
+ public Collection getPersistentEntities() {
+ return persistentEntities.values();
+ }
- /* (non-Javadoc)
- * @see org.springframework.data.mapping.model.MappingContext#getPersistentEntity(java.lang.Class)
- */
- public E getPersistentEntity(Class> type) {
-
- return getPersistentEntity(ClassTypeInformation.from(type));
- }
+ /* (non-Javadoc)
+ * @see org.springframework.data.mapping.model.MappingContext#getPersistentEntity(java.lang.Class)
+ */
+ public E getPersistentEntity(Class> type) {
- /*
- * (non-Javadoc)
- * @see org.springframework.data.mapping.model.MappingContext#getPersistentEntity(org.springframework.data.util.TypeInformation)
- */
- public E getPersistentEntity(TypeInformation> type) {
-
- E entity = persistentEntities.get(type);
-
- if (entity != null) {
- return entity;
- }
-
- if (strict) {
- throw new MappingException("Unknown persistent entity " + type);
- }
-
- return addPersistentEntity(type);
- }
+ return getPersistentEntity(ClassTypeInformation.from(type));
+ }
- /**
- * Adds the given type to the {@link MappingContext}.
- *
- * @param type
- * @return
- */
- protected E addPersistentEntity(Class> type) {
-
- return addPersistentEntity(ClassTypeInformation.from(type));
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.mapping.model.MappingContext#getPersistentEntity(org.springframework.data.util.TypeInformation)
+ */
+ public E getPersistentEntity(TypeInformation> type) {
- /**
- * Adds the given {@link TypeInformation} to the {@link MappingContext}.
- *
- * @param typeInformation
- * @return
- */
- protected E addPersistentEntity(TypeInformation> typeInformation) {
+ E entity = persistentEntities.get(type);
- E persistentEntity = persistentEntities.get(typeInformation);
+ if (entity != null) {
+ return entity;
+ }
- if (persistentEntity != null) {
- return persistentEntity;
- }
+ if (strict) {
+ throw new MappingException("Unknown persistent entity " + type);
+ }
- Class> type = typeInformation.getType();
+ return addPersistentEntity(type);
+ }
- try {
- final E entity = createPersistentEntity(typeInformation);
- BeanInfo info = Introspector.getBeanInfo(type);
+ /**
+ * Adds the given type to the {@link MappingContext}.
+ *
+ * @param type
+ * @return
+ */
+ protected E addPersistentEntity(Class> type) {
- final Map descriptors = new HashMap();
- for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
- descriptors.put(descriptor.getName(), descriptor);
- }
+ return addPersistentEntity(ClassTypeInformation.from(type));
+ }
- ReflectionUtils.doWithFields(type, new FieldCallback() {
+ /**
+ * Adds the given {@link TypeInformation} to the {@link MappingContext}.
+ *
+ * @param typeInformation
+ * @return
+ */
+ protected E addPersistentEntity(TypeInformation> typeInformation) {
- public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
-
- PropertyDescriptor descriptor = descriptors.get(field.getName());
-
- ReflectionUtils.makeAccessible(field);
- P property = createPersistentProperty(field, descriptor, entity);
+ E persistentEntity = persistentEntities.get(typeInformation);
- if (property.isTransient()) {
- return;
- }
-
- entity.addPersistentProperty(property);
-
- if (property.isAssociation()) {
- entity.addAssociation(property.getAssociation());
- }
+ if (persistentEntity != null) {
+ return persistentEntity;
+ }
- if (property.isIdProperty()) {
- entity.setIdProperty(property);
- }
+ Class> type = typeInformation.getType();
- TypeInformation> nestedType = getNestedTypeToAdd(property, entity);
- if (nestedType != null) {
- addPersistentEntity(nestedType);
- }
-
-
- }
- }, new ReflectionUtils.FieldFilter() {
- public boolean matches(Field field) {
- return !Modifier.isStatic(field.getModifiers()) && !UNMAPPED_FIELDS.contains(field.getName());
- }
- });
-
- entity.verify();
+ try {
+ final E entity = createPersistentEntity(typeInformation);
+ BeanInfo info = Introspector.getBeanInfo(type);
- // Inform listeners
- if (null != applicationEventPublisher) {
- applicationEventPublisher.publishEvent(new MappingContextEvent(entity, typeInformation));
- }
+ final Map descriptors = new HashMap();
+ for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
+ descriptors.put(descriptor.getName(), descriptor);
+ }
- // Cache
- persistentEntities.put(entity.getTypeInformation(), (E) entity);
+ ReflectionUtils.doWithFields(type, new FieldCallback() {
- return entity;
- } catch (IntrospectionException e) {
- throw new MappingException(e.getMessage(), e);
- }
- }
+ public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
- /**
- * Returns a potential nested type tha needs to be added when adding the given property in the course of adding a
- * {@link PersistentEntity}. Will return the property's {@link TypeInformation} directly if it is a potential entity,
- * a collections component type if it's a collection as well as the value type of a {@link Map} if it's a map
- * property.
- *
- * @param property
- * @return the TypeInformation to be added as {@link PersistentEntity} or {@literal
- */
- private TypeInformation> getNestedTypeToAdd(P property, PersistentEntity, P> entity) {
-
- if (entity.getType().equals(property.getRawType())) {
- return null;
- }
+ PropertyDescriptor descriptor = descriptors.get(field.getName());
- TypeInformation> typeInformation = property.getTypeInformation();
+ ReflectionUtils.makeAccessible(field);
+ P property = createPersistentProperty(field, descriptor, entity);
- if (customSimpleTypes.contains(typeInformation.getType())) {
- return null;
- }
+ if (property.isTransient()) {
+ return;
+ }
- if (property.isEntity()) {
- return typeInformation;
- }
+ entity.addPersistentProperty(property);
- if (property.isCollection()) {
- return getTypeInformationIfNotSimpleType(typeInformation.getComponentType());
- }
+ if (property.isAssociation()) {
+ entity.addAssociation(property.getAssociation());
+ }
- if (property.isMap()) {
- return getTypeInformationIfNotSimpleType(typeInformation.getMapValueType());
- }
+ if (property.isIdProperty()) {
+ entity.setIdProperty(property);
+ }
- return null;
- }
-
- private TypeInformation> getTypeInformationIfNotSimpleType(TypeInformation> information) {
- return information == null || MappingBeanHelper.isSimpleType(information.getType()) ? null : information;
- }
-
- public List getEntityValidators(E entity) {
- return validators.get(entity);
- }
-
- protected abstract E createPersistentEntity(TypeInformation typeInformation);
-
- protected abstract P createPersistentProperty(Field field, PropertyDescriptor descriptor, E owner);
+ TypeInformation> nestedType = getNestedTypeToAdd(property, entity);
+ if (nestedType != null) {
+ addPersistentEntity(nestedType);
+ }
+ }
+ }, new ReflectionUtils.FieldFilter() {
+ public boolean matches(Field field) {
+ return !Modifier.isStatic(field.getModifiers()) && !UNMAPPED_FIELDS.contains(field.getName());
+ }
+ });
- public void afterPropertiesSet() throws Exception {
- for (Class> initialEntity : initialEntitySet) {
- addPersistentEntity(initialEntity);
- }
- }
+ entity.verify();
+
+ // Inform listeners
+ if (null != applicationEventPublisher) {
+ applicationEventPublisher.publishEvent(new MappingContextEvent(entity, typeInformation));
+ }
+
+ // Cache
+ persistentEntities.put(entity.getTypeInformation(), (E) entity);
+
+ return entity;
+ } catch (IntrospectionException e) {
+ throw new MappingException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Returns a potential nested type tha needs to be added when adding the given property in the course of adding a
+ * {@link PersistentEntity}. Will return the property's {@link TypeInformation} directly if it is a potential entity,
+ * a collections component type if it's a collection as well as the value type of a {@link Map} if it's a map
+ * property.
+ *
+ * @param property
+ * @return the TypeInformation to be added as {@link PersistentEntity} or {@literal
+ */
+ private TypeInformation> getNestedTypeToAdd(P property, PersistentEntity, P> entity) {
+
+ if (entity.getType().equals(property.getRawType())) {
+ return null;
+ }
+
+ TypeInformation> typeInformation = property.getTypeInformation();
+
+ if (customSimpleTypes.contains(typeInformation.getType())) {
+ return null;
+ }
+
+ if (property.isEntity()) {
+ return typeInformation;
+ }
+
+ if (property.isCollection()) {
+ return getTypeInformationIfNotSimpleType(typeInformation.getComponentType());
+ }
+
+ if (property.isMap()) {
+ return getTypeInformationIfNotSimpleType(typeInformation.getMapValueType());
+ }
+
+ return null;
+ }
+
+ private TypeInformation> getTypeInformationIfNotSimpleType(TypeInformation> information) {
+ return information == null || MappingBeanHelper.isSimpleType(information.getType()) ? null : information;
+ }
+
+ public List getEntityValidators(E entity) {
+ return validators.get(entity);
+ }
+
+ protected abstract E createPersistentEntity(TypeInformation typeInformation);
+
+ protected abstract P createPersistentProperty(Field field, PropertyDescriptor descriptor, E owner);
+
+
+ public void afterPropertiesSet() throws Exception {
+ for (Class> initialEntity : initialEntitySet) {
+ addPersistentEntity(initialEntity);
+ }
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractPersistentProperty.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractPersistentProperty.java
index 9a69ff8c0..91f20c2b5 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractPersistentProperty.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractPersistentProperty.java
@@ -54,7 +54,7 @@ public abstract class AbstractPersistentProperty
this.association = isAssociation() ? createAssociation() : null;
this.owner = owner;
}
-
+
protected abstract Association
createAssociation();
public PersistentEntity, P> getOwner() {
@@ -94,16 +94,16 @@ public abstract class AbstractPersistentProperty
}
public boolean isAssociation() {
- if (field.isAnnotationPresent(Reference.class)) {
- return true;
- }
- for (Annotation annotation : field.getDeclaredAnnotations()) {
- if (annotation.annotationType().isAnnotationPresent(Reference.class)) {
- return true;
- }
- }
-
- return false;
+ if (field.isAnnotationPresent(Reference.class)) {
+ return true;
+ }
+ for (Annotation annotation : field.getDeclaredAnnotations()) {
+ if (annotation.annotationType().isAnnotationPresent(Reference.class)) {
+ return true;
+ }
+ }
+
+ return false;
}
public Association
getAssociation() {
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AnnotationBasedPersistentProperty.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AnnotationBasedPersistentProperty.java
index 198efd87a..a0f15f2ed 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AnnotationBasedPersistentProperty.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AnnotationBasedPersistentProperty.java
@@ -31,78 +31,78 @@ import org.springframework.data.mapping.model.PersistentProperty;
/**
* Special {@link PersistentProperty} that takes annotations at a property into account.
- *
+ *
* @author Oliver Gierke
*/
public abstract class AnnotationBasedPersistentProperty
> extends AbstractPersistentProperty
{
-
- private final Value value;
-
- /**
- * Creates a new {@link AnnotationBasedPersistentProperty}.
- *
- * @param field
- * @param propertyDescriptor
- * @param owner
- */
- public AnnotationBasedPersistentProperty(Field field,
- PropertyDescriptor propertyDescriptor, PersistentEntity, P> owner) {
- super(field, propertyDescriptor, owner);
- this.value = field.getAnnotation(Value.class);
- field.isAnnotationPresent(Autowired.class);
- }
+ private final Value value;
- /**
- * Inspects a potentially available {@link Value} annotation at the property and returns the {@link String} value of
- * it.
- *
- * @see org.springframework.data.mapping.AbstractPersistentProperty#getSpelExpression()
- */
- public String getSpelExpression() {
- return value == null ? null :value.value();
- }
+ /**
+ * Creates a new {@link AnnotationBasedPersistentProperty}.
+ *
+ * @param field
+ * @param propertyDescriptor
+ * @param owner
+ */
+ public AnnotationBasedPersistentProperty(Field field,
+ PropertyDescriptor propertyDescriptor, PersistentEntity, P> owner) {
- /**
- * Considers plain transient fields, fields annotated with {@link Transient}, {@link Value} or {@link Autowired} as
- * transien.
- *
- * @see org.springframework.data.mapping.BasicPersistentProperty#isTransient()
- */
- public boolean isTransient() {
-
- boolean isTransient = super.isTransient() || field.isAnnotationPresent(Transient.class);
-
- return isTransient || field.isAnnotationPresent(Value.class) || field.isAnnotationPresent(Autowired.class);
- }
-
- /**
- * Regards the property as ID if there is an {@link Id} annotation found on it.
- */
- public boolean isIdProperty() {
- return field.isAnnotationPresent(Id.class);
- }
-
- /**
- * Considers the property an {@link Association} if it is annotated with {@link Reference}.
- */
- @Override
- public boolean isAssociation() {
-
- if (isTransient()) {
- return false;
- }
- if (field.isAnnotationPresent(Reference.class)) {
- return true;
- }
-
- // TODO: do we need this? Shouldn't the section above already find that annotation?
- for (Annotation annotation : field.getDeclaredAnnotations()) {
- if (annotation.annotationType().isAnnotationPresent(Reference.class)) {
- return true;
- }
- }
-
- return false;
- }
+ super(field, propertyDescriptor, owner);
+ this.value = field.getAnnotation(Value.class);
+ field.isAnnotationPresent(Autowired.class);
+ }
+
+ /**
+ * Inspects a potentially available {@link Value} annotation at the property and returns the {@link String} value of
+ * it.
+ *
+ * @see org.springframework.data.mapping.AbstractPersistentProperty#getSpelExpression()
+ */
+ public String getSpelExpression() {
+ return value == null ? null : value.value();
+ }
+
+ /**
+ * Considers plain transient fields, fields annotated with {@link Transient}, {@link Value} or {@link Autowired} as
+ * transien.
+ *
+ * @see org.springframework.data.mapping.BasicPersistentProperty#isTransient()
+ */
+ public boolean isTransient() {
+
+ boolean isTransient = super.isTransient() || field.isAnnotationPresent(Transient.class);
+
+ return isTransient || field.isAnnotationPresent(Value.class) || field.isAnnotationPresent(Autowired.class);
+ }
+
+ /**
+ * Regards the property as ID if there is an {@link Id} annotation found on it.
+ */
+ public boolean isIdProperty() {
+ return field.isAnnotationPresent(Id.class);
+ }
+
+ /**
+ * Considers the property an {@link Association} if it is annotated with {@link Reference}.
+ */
+ @Override
+ public boolean isAssociation() {
+
+ if (isTransient()) {
+ return false;
+ }
+ if (field.isAnnotationPresent(Reference.class)) {
+ return true;
+ }
+
+ // TODO: do we need this? Shouldn't the section above already find that annotation?
+ for (Annotation annotation : field.getDeclaredAnnotations()) {
+ if (annotation.annotationType().isAnnotationPresent(Reference.class)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AssociationHandler.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AssociationHandler.java
index c835d2d04..aad45eb34 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AssociationHandler.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AssociationHandler.java
@@ -23,5 +23,5 @@ import org.springframework.data.mapping.model.PersistentProperty;
* @author Jon Brisbin
*/
public interface AssociationHandler> {
- void doWithAssociation(Association
association);
+ void doWithAssociation(Association
association);
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicPersistentEntity.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicPersistentEntity.java
index 2335c32fd..e8db155e9 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicPersistentEntity.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/BasicPersistentEntity.java
@@ -27,103 +27,103 @@ import org.springframework.data.util.TypeInformation;
/**
* Simple value object to capture information of {@link PersistentEntity}s.
- *
+ *
* @author Jon Brisbin
*/
public class BasicPersistentEntity> implements MutablePersistentEntity {
- protected final PreferredConstructor preferredConstructor;
- protected final TypeInformation information;
- protected final Map persistentProperties = new HashMap();
- protected final Map> associations = new HashMap>();
- protected P idProperty;
+ protected final PreferredConstructor preferredConstructor;
+ protected final TypeInformation information;
+ protected final Map persistentProperties = new HashMap();
+ protected final Map> associations = new HashMap>();
+ protected P idProperty;
- /**
- * Creates a new {@link BasicPersistentEntity} from the given {@link TypeInformation}.
- *
- * @param information
- */
- public BasicPersistentEntity(TypeInformation information) {
- this.information = information;
- this.preferredConstructor = new PreferredConstructorDiscoverer(information).getConstructor();
- }
+ /**
+ * Creates a new {@link BasicPersistentEntity} from the given {@link TypeInformation}.
+ *
+ * @param information
+ */
+ public BasicPersistentEntity(TypeInformation information) {
+ this.information = information;
+ this.preferredConstructor = new PreferredConstructorDiscoverer(information).getConstructor();
+ }
- public PreferredConstructor getPreferredConstructor() {
- return preferredConstructor;
- }
+ public PreferredConstructor getPreferredConstructor() {
+ return preferredConstructor;
+ }
- public String getName() {
- return getType().getName();
- }
+ public String getName() {
+ return getType().getName();
+ }
- public P getIdProperty() {
- return idProperty;
- }
+ public P getIdProperty() {
+ return idProperty;
+ }
- /* (non-Javadoc)
- * @see org.springframework.data.mapping.MutablePersistentEntity#setIdProperty(P)
- */
-public void setIdProperty(P property) {
- idProperty = property;
- }
+ /* (non-Javadoc)
+ * @see org.springframework.data.mapping.MutablePersistentEntity#setIdProperty(P)
+ */
+ public void setIdProperty(P property) {
+ idProperty = property;
+ }
- public Collection getPersistentProperties() {
- return persistentProperties.values();
- }
+ public Collection
getPersistentProperties() {
+ return persistentProperties.values();
+ }
- /* (non-Javadoc)
- * @see org.springframework.data.mapping.MutablePersistentEntity#addPersistentProperty(P)
- */
-public void addPersistentProperty(P property) {
- persistentProperties.put(property.getName(), property);
- }
+ /* (non-Javadoc)
+ * @see org.springframework.data.mapping.MutablePersistentEntity#addPersistentProperty(P)
+ */
+ public void addPersistentProperty(P property) {
+ persistentProperties.put(property.getName(), property);
+ }
- public Collection> getAssociations() {
- return associations.values();
- }
+ public Collection> getAssociations() {
+ return associations.values();
+ }
- /* (non-Javadoc)
- * @see org.springframework.data.mapping.MutablePersistentEntity#addAssociation(org.springframework.data.mapping.model.Association)
- */
-public void addAssociation(Association association) {
- associations.put(association.getInverse().getName(), association);
- }
+ /* (non-Javadoc)
+ * @see org.springframework.data.mapping.MutablePersistentEntity#addAssociation(org.springframework.data.mapping.model.Association)
+ */
+ public void addAssociation(Association
association) {
+ associations.put(association.getInverse().getName(), association);
+ }
- public P getPersistentProperty(String name) {
- return persistentProperties.get(name);
- }
+ public P getPersistentProperty(String name) {
+ return persistentProperties.get(name);
+ }
- public Class getType() {
- return information.getType();
- }
+ public Class getType() {
+ return information.getType();
+ }
- public TypeInformation getTypeInformation() {
- return information;
- }
+ public TypeInformation getTypeInformation() {
+ return information;
+ }
- public Collection getPersistentPropertyNames() {
- return persistentProperties.keySet();
- }
+ public Collection getPersistentPropertyNames() {
+ return persistentProperties.keySet();
+ }
- public void doWithProperties(PropertyHandler handler) {
- for (P property : persistentProperties.values()) {
- if (!property.isTransient() && !property.isAssociation()) {
- handler.doWithPersistentProperty(property);
- }
- }
- }
+ public void doWithProperties(PropertyHandler
handler) {
+ for (P property : persistentProperties.values()) {
+ if (!property.isTransient() && !property.isAssociation()) {
+ handler.doWithPersistentProperty(property);
+ }
+ }
+ }
- public void doWithAssociations(AssociationHandler
handler) {
- for (Association
association : associations.values()) {
- handler.doWithAssociation(association);
- }
- }
+ public void doWithAssociations(AssociationHandler
handler) {
+ for (Association
association : associations.values()) {
+ handler.doWithAssociation(association);
+ }
+ }
- /* (non-Javadoc)
- * @see org.springframework.data.mapping.MutablePersistentEntity#verify()
- */
- public void verify() {
+ /* (non-Javadoc)
+ * @see org.springframework.data.mapping.MutablePersistentEntity#verify()
+ */
+ public void verify() {
- }
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MappingBeanHelper.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MappingBeanHelper.java
index f430697ef..c1e7a5142 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MappingBeanHelper.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MappingBeanHelper.java
@@ -174,32 +174,32 @@ public abstract class MappingBeanHelper {
Method setter = property.getPropertyDescriptor() != null ? property.getPropertyDescriptor().getWriteMethod() : null;
- if (fieldAccessOnly || null == setter) {
- Object valueToSet = getPotentiallyConvertedValue(value, property.getType());
- ReflectionUtils.makeAccessible(property.getField());
- ReflectionUtils.setField(property.getField(), on, valueToSet);
- return;
- }
+ if (fieldAccessOnly || null == setter) {
+ Object valueToSet = getPotentiallyConvertedValue(value, property.getType());
+ ReflectionUtils.makeAccessible(property.getField());
+ ReflectionUtils.setField(property.getField(), on, valueToSet);
+ return;
+ }
Class>[] paramTypes = setter.getParameterTypes();
Object valueToSet = getPotentiallyConvertedValue(value, paramTypes[0]);
ReflectionUtils.makeAccessible(setter);
ReflectionUtils.invokeMethod(setter, on, valueToSet);
}
-
+
/**
* Converts the given source value if it is not assignable to the given target type.
- *
+ *
* @param source
* @param targetType
* @return
*/
private static Object getPotentiallyConvertedValue(Object source, Class> targetType) {
- if (source != null && source.getClass().isAssignableFrom(targetType)) {
- return source;
- }
-
- return conversionService.convert(source, targetType);
+ if (source != null && source.getClass().isAssignableFrom(targetType)) {
+ return source;
+ }
+
+ return conversionService.convert(source, targetType);
}
@SuppressWarnings({"unchecked"})
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MutablePersistentEntity.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MutablePersistentEntity.java
index 7c20f232e..aebec6553 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MutablePersistentEntity.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/MutablePersistentEntity.java
@@ -22,37 +22,37 @@ import org.springframework.data.mapping.model.PersistentProperty;
/**
* Interface capturing mutator methods for {@link PersistentEntity}s.
- *
+ *
* @author Oliver Gierke
*/
public interface MutablePersistentEntity>
- extends PersistentEntity {
+ extends PersistentEntity {
- /**
- * Sets the id property for the entity.
- *
- * @param property
- */
- void setIdProperty(P property);
+ /**
+ * Sets the id property for the entity.
+ *
+ * @param property
+ */
+ void setIdProperty(P property);
- /**
- * Adds a {@link PersistentProperty} to the entity.
- *
- * @param property
- */
- void addPersistentProperty(P property);
+ /**
+ * Adds a {@link PersistentProperty} to the entity.
+ *
+ * @param property
+ */
+ void addPersistentProperty(P property);
- /**
- * Adds an {@link Association} to the entity.
- *
- * @param association
- */
- void addAssociation(Association association);
+ /**
+ * Adds an {@link Association} to the entity.
+ *
+ * @param association
+ */
+ void addAssociation(Association
association);
- /**
- * Callback method to trigger validation of the {@link PersistentEntity}. As
- * {@link MutablePersistentEntity} is not immutable there might be some
- * verification steps necessary after the object has reached is final state.
- */
- void verify();
+ /**
+ * Callback method to trigger validation of the {@link PersistentEntity}. As
+ * {@link MutablePersistentEntity} is not immutable there might be some
+ * verification steps necessary after the object has reached is final state.
+ */
+ void verify();
}
\ No newline at end of file
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructorDiscoverer.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructorDiscoverer.java
index 4263fac43..3552636c7 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructorDiscoverer.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructorDiscoverer.java
@@ -34,85 +34,85 @@ import org.springframework.data.util.TypeInformation;
*/
public class PreferredConstructorDiscoverer {
- private final ParameterNameDiscoverer nameDiscoverer =
- new LocalVariableTableParameterNameDiscoverer();
+ private final ParameterNameDiscoverer nameDiscoverer =
+ new LocalVariableTableParameterNameDiscoverer();
- private PreferredConstructor constructor;
-
- public PreferredConstructorDiscoverer(Class type) {
- this(ClassTypeInformation.from(type));
- }
+ private PreferredConstructor constructor;
- /**
- * Creates a new {@link PreferredConstructorDiscoverer} for the given type.
- *
- * @param owningType
- */
- protected PreferredConstructorDiscoverer(TypeInformation owningType) {
-
- boolean noArgConstructorFound = false;
- int numberOfArgConstructors = 0;
- Class> rawOwningType = owningType.getType();
+ public PreferredConstructorDiscoverer(Class type) {
+ this(ClassTypeInformation.from(type));
+ }
- for (Constructor> constructor : rawOwningType.getDeclaredConstructors()) {
+ /**
+ * Creates a new {@link PreferredConstructorDiscoverer} for the given type.
+ *
+ * @param owningType
+ */
+ protected PreferredConstructorDiscoverer(TypeInformation owningType) {
- PreferredConstructor preferredConstructor =
- buildPreferredConstructor(constructor, owningType);
+ boolean noArgConstructorFound = false;
+ int numberOfArgConstructors = 0;
+ Class> rawOwningType = owningType.getType();
- // Explicitly defined constructor trumps all
- if (preferredConstructor.isExplicitlyAnnotated()) {
- this.constructor = preferredConstructor;
- return;
- }
+ for (Constructor> constructor : rawOwningType.getDeclaredConstructors()) {
- // No-arg constructor trumps custom ones
- if (this.constructor == null || preferredConstructor.isNoArgConstructor()) {
- this.constructor = preferredConstructor;
- }
-
- if (preferredConstructor.isNoArgConstructor()) {
- noArgConstructorFound = true;
- } else {
- numberOfArgConstructors++;
- }
- }
-
- if (!noArgConstructorFound && numberOfArgConstructors > 1) {
- throw new IllegalArgumentException(
- "Multiple no-arg constructors found! Annotate one with @PreferedConstructor explicitly to select it to be used in persistence operations.");
- }
- }
+ PreferredConstructor preferredConstructor =
+ buildPreferredConstructor(constructor, owningType);
+
+ // Explicitly defined constructor trumps all
+ if (preferredConstructor.isExplicitlyAnnotated()) {
+ this.constructor = preferredConstructor;
+ return;
+ }
+
+ // No-arg constructor trumps custom ones
+ if (this.constructor == null || preferredConstructor.isNoArgConstructor()) {
+ this.constructor = preferredConstructor;
+ }
+
+ if (preferredConstructor.isNoArgConstructor()) {
+ noArgConstructorFound = true;
+ } else {
+ numberOfArgConstructors++;
+ }
+ }
+
+ if (!noArgConstructorFound && numberOfArgConstructors > 1) {
+ throw new IllegalArgumentException(
+ "Multiple no-arg constructors found! Annotate one with @PreferedConstructor explicitly to select it to be used in persistence operations.");
+ }
+ }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private PreferredConstructor buildPreferredConstructor(
- Constructor> constructor, TypeInformation typeInformation) {
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private PreferredConstructor buildPreferredConstructor(
+ Constructor> constructor, TypeInformation typeInformation) {
- List> parameterTypes = typeInformation.getParameterTypes(constructor);
-
- if (parameterTypes.isEmpty()) {
- return new PreferredConstructor((Constructor) constructor);
- }
-
- String[] parameterNames = nameDiscoverer.getParameterNames(constructor);
- Parameter>[] parameters = new Parameter[parameterTypes.size()];
- Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
+ List> parameterTypes = typeInformation.getParameterTypes(constructor);
- for (int i = 0; i < parameterTypes.size(); i++) {
-
- String name = parameterNames == null ? null : parameterNames[i];
- TypeInformation> type = parameterTypes.get(i);
- Annotation[] annotations = parameterAnnotations[i];
-
- parameters[i] = new Parameter(name, type, annotations);
- }
+ if (parameterTypes.isEmpty()) {
+ return new PreferredConstructor((Constructor) constructor);
+ }
- return new PreferredConstructor((Constructor) constructor,
- parameters);
- }
+ String[] parameterNames = nameDiscoverer.getParameterNames(constructor);
+ Parameter>[] parameters = new Parameter[parameterTypes.size()];
+ Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
+
+ for (int i = 0; i < parameterTypes.size(); i++) {
+
+ String name = parameterNames == null ? null : parameterNames[i];
+ TypeInformation> type = parameterTypes.get(i);
+ Annotation[] annotations = parameterAnnotations[i];
+
+ parameters[i] = new Parameter(name, type, annotations);
+ }
+
+ return new PreferredConstructor((Constructor) constructor,
+ parameters);
+ }
- public PreferredConstructor getConstructor() {
- return constructor;
- }
+ public PreferredConstructor getConstructor() {
+ return constructor;
+ }
}
\ No newline at end of file
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java
index 97dca07a3..7a542ed28 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/PropertyHandler.java
@@ -21,10 +21,10 @@ import org.springframework.data.mapping.model.PersistentProperty;
/**
* Callback interface to do something with all plain {@link PersistentProperty}
* instances except associations, transient properties and the id-property.
- *
+ *
* @author Jon Brisbin
*/
public interface PropertyHandler> {
- void doWithPersistentProperty(P persistentProperty);
+ void doWithPersistentProperty(P persistentProperty);
}
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
index 0ba27f9a5..2d457b295 100644
--- 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
@@ -25,11 +25,11 @@ import org.springframework.data.mapping.model.MappingContext;
*/
public interface MappingContextAware {
- /**
- * The active MappingContext for the environment.
- *
- * @param mappingContext
- */
- void setMappingContext(MappingContext, ?> mappingContext);
+ /**
+ * 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
index 495a95a4b..282089ab1 100644
--- 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
@@ -61,7 +61,7 @@ public class MappingContextAwareBeanPostProcessor implements BeanPostProcessor,
}
@SuppressWarnings("rawtypes")
- public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof MappingContextAware) {
if (null == mappingContext) {
Map mappingContexts = applicationContext.getBeansOfType(MappingContext.class);
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java
index 77c8fd472..89cca9bde 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/event/MappingContextEvent.java
@@ -26,20 +26,20 @@ import org.springframework.data.util.TypeInformation;
*/
public class MappingContextEvent, P extends PersistentProperty> extends ApplicationEvent {
- private static final long serialVersionUID = 1336466833846092490L;
- private TypeInformation> typeInformation;
+ private static final long serialVersionUID = 1336466833846092490L;
+ private TypeInformation> typeInformation;
- public MappingContextEvent(E source, TypeInformation> typeInformation) {
- super(source);
- this.typeInformation = typeInformation;
- }
+ public MappingContextEvent(E source, TypeInformation> typeInformation) {
+ super(source);
+ this.typeInformation = typeInformation;
+ }
- public TypeInformation> getTypeInformation() {
- return typeInformation;
- }
+ public TypeInformation> getTypeInformation() {
+ return typeInformation;
+ }
- @SuppressWarnings("unchecked")
- public E getPersistentEntity() {
- return (E) source;
- }
+ @SuppressWarnings("unchecked")
+ public E getPersistentEntity() {
+ return (E) source;
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/Association.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/Association.java
index e1930000f..4ef40cdc7 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/Association.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/Association.java
@@ -21,19 +21,19 @@ package org.springframework.data.mapping.model;
*/
public class Association
> {
- protected P inverse;
- protected P obverse;
+ protected P inverse;
+ protected P obverse;
- public Association(P inverse, P obverse) {
- this.inverse = inverse;
- this.obverse = obverse;
- }
+ public Association(P inverse, P obverse) {
+ this.inverse = inverse;
+ this.obverse = obverse;
+ }
- public P getInverse() {
- return inverse;
- }
+ public P getInverse() {
+ return inverse;
+ }
- public P getObverse() {
- return obverse;
- }
+ public P getObverse() {
+ return obverse;
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java
index eacae59f7..bd96b96dc 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/IllegalMappingException.java
@@ -22,16 +22,16 @@ package org.springframework.data.mapping.model;
*/
public class IllegalMappingException extends RuntimeException {
- /**
- *
- */
+ /**
+ *
+ */
private static final long serialVersionUID = 1L;
-public IllegalMappingException(String s, Throwable throwable) {
- super(s, throwable);
- }
+ public IllegalMappingException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
- public IllegalMappingException(String s) {
- super(s);
- }
+ public IllegalMappingException(String s) {
+ super(s);
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java
index e8253dcb8..e79450169 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingConfigurationException.java
@@ -20,16 +20,16 @@ package org.springframework.data.mapping.model;
* @author Jon Brisbin
*/
public class MappingConfigurationException extends Throwable {
- /**
- *
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
-public MappingConfigurationException(String s) {
- super(s);
- }
+ public MappingConfigurationException(String s) {
+ super(s);
+ }
- public MappingConfigurationException(String s, Throwable throwable) {
- super(s, throwable);
- }
+ public MappingConfigurationException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingContext.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingContext.java
index eddf1463b..e79b337b8 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingContext.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingContext.java
@@ -36,24 +36,24 @@ import org.springframework.validation.Validator;
* @author Oliver Gierke
*/
public interface MappingContext, P extends PersistentProperty> {
-
- /**
- * Obtains a list of PersistentEntity instances
- *
- * @return A list of PersistentEntity instances
- */
- Collection getPersistentEntities();
- E getPersistentEntity(Class> type);
+ /**
+ * Obtains a list of PersistentEntity instances
+ *
+ * @return A list of PersistentEntity instances
+ */
+ Collection getPersistentEntities();
- E getPersistentEntity(TypeInformation> type);
+ E getPersistentEntity(Class> type);
- /**
- * Obtains a validator for the given entity
- * TODO: Why do we need validators at the {@link MappingContext}?
- *
- * @param entity The entity
- * @return A validator or null if none exists for the given entity
- */
- List getEntityValidators(E entity);
+ E getPersistentEntity(TypeInformation> type);
+
+ /**
+ * Obtains a validator for the given entity
+ * TODO: Why do we need validators at the {@link MappingContext}?
+ *
+ * @param entity The entity
+ * @return A validator or null if none exists for the given entity
+ */
+ List getEntityValidators(E entity);
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingException.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingException.java
index 88af5f5da..2b62aea54 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingException.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingException.java
@@ -20,17 +20,17 @@ package org.springframework.data.mapping.model;
* @author Jon Brisbin
*/
public class MappingException extends RuntimeException {
-
+
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
public MappingException(String s) {
- super(s);
- }
+ super(s);
+ }
- public MappingException(String s, Throwable throwable) {
- super(s, throwable);
- }
+ public MappingException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingInstantiationException.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingInstantiationException.java
index 8f0bcce0e..7f8c88251 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingInstantiationException.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/MappingInstantiationException.java
@@ -20,14 +20,14 @@ package org.springframework.data.mapping.model;
* @author Jon Brisbin
*/
public class MappingInstantiationException extends RuntimeException {
-
+
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
public MappingInstantiationException(String s, Throwable throwable) {
- super(s, throwable);
- }
-
+ super(s, throwable);
+ }
+
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PersistentEntity.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PersistentEntity.java
index b3809afe4..d3351055b 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PersistentEntity.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PersistentEntity.java
@@ -1,11 +1,11 @@
package org.springframework.data.mapping.model;
+import java.util.Collection;
+
import org.springframework.data.mapping.AssociationHandler;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.util.TypeInformation;
-import java.util.Collection;
-
/**
* Represents a persistent entity
@@ -16,62 +16,62 @@ import java.util.Collection;
*/
public interface PersistentEntity> {
- /**
- * The entity name including any package prefix
- *
- * @return The entity name
- */
- String getName();
+ /**
+ * The entity name including any package prefix
+ *
+ * @return The entity name
+ */
+ String getName();
- PreferredConstructor getPreferredConstructor();
+ PreferredConstructor getPreferredConstructor();
- /**
- * Returns the id property of the {@link PersistentEntity}. Must never
- * return {@literal null} as a {@link PersistentEntity} instance must not be
- * created if there is no id property.
- *
- * @return the id property of the {@link PersistentEntity}.
- */
- P getIdProperty();
+ /**
+ * Returns the id property of the {@link PersistentEntity}. Must never
+ * return {@literal null} as a {@link PersistentEntity} instance must not be
+ * created if there is no id property.
+ *
+ * @return the id property of the {@link PersistentEntity}.
+ */
+ P getIdProperty();
- /**
- * A list of properties to be persisted
- *
- * @return A list of PersistentProperty instances
- */
- Collection getPersistentProperties();
+ /**
+ * A list of properties to be persisted
+ *
+ * @return A list of PersistentProperty instances
+ */
+ Collection
getPersistentProperties();
- /**
- * A list of the associations for this entity. This is typically a subset of the list returned by {@link #getPersistentProperties()}
- *
- * @return A list of associations
- */
- Collection> getAssociations();
+ /**
+ * A list of the associations for this entity. This is typically a subset of the list returned by {@link #getPersistentProperties()}
+ *
+ * @return A list of associations
+ */
+ Collection> getAssociations();
- /**
- * Obtains a PersistentProperty instance by name
- *
- * @param name The name of the property
- * @return The PersistentProperty or null if it doesn't exist
- */
- P getPersistentProperty(String name);
+ /**
+ * Obtains a PersistentProperty instance by name
+ *
+ * @param name The name of the property
+ * @return The PersistentProperty or null if it doesn't exist
+ */
+ P getPersistentProperty(String name);
- /**
- * @return The underlying Java class for this entity
- */
- Class getType();
-
- TypeInformation getTypeInformation();
+ /**
+ * @return The underlying Java class for this entity
+ */
+ Class getType();
- /**
- * A list of property names
- *
- * @return A List of strings
- */
- Collection getPersistentPropertyNames();
+ TypeInformation getTypeInformation();
- void doWithProperties(PropertyHandler handler);
+ /**
+ * A list of property names
+ *
+ * @return A List of strings
+ */
+ Collection getPersistentPropertyNames();
- void doWithAssociations(AssociationHandler handler);
+ void doWithProperties(PropertyHandler
handler);
+
+ void doWithAssociations(AssociationHandler
handler);
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructor.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructor.java
index b2eacb19a..be98a1b01 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructor.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PreferredConstructor.java
@@ -28,8 +28,8 @@ import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
- * Value object to encapsulate the constructor to be used when mapping persistent data to objects.
- *
+ * Value object to encapsulate the constructor to be used when mapping persistent data to objects.
+ *
* @author Jon Brisbin
* @author Oliver Gierke
*/
@@ -39,7 +39,7 @@ public class PreferredConstructor {
private final List> parameters;
public PreferredConstructor(Constructor constructor, Parameter>... parameters) {
- ReflectionUtils.makeAccessible(constructor);
+ ReflectionUtils.makeAccessible(constructor);
this.constructor = constructor;
this.parameters = Arrays.asList(parameters);
}
@@ -51,23 +51,23 @@ public class PreferredConstructor {
public List> getParameters() {
return parameters;
}
-
+
/**
* Returns whether the constructor does not have any arguments.
- *
+ *
* @return
*/
public boolean isNoArgConstructor() {
- return parameters.isEmpty();
+ return parameters.isEmpty();
}
-
+
/**
* Returns whether the constructor was explicitly selected (by {@link PersistenceConstructor}).
- *
+ *
* @return
*/
public boolean isExplicitlyAnnotated() {
- return constructor.isAnnotationPresent(PersistenceConstructor.class);
+ return constructor.isAnnotationPresent(PersistenceConstructor.class);
}
public static class Parameter {
@@ -76,22 +76,22 @@ public class PreferredConstructor {
private final String key;
public Parameter(String name, TypeInformation type, Annotation[] annotations) {
-
- Assert.notNull(type);
- Assert.notNull(annotations);
-
- this.name = name;
- this.type = type;
- this.key = getValue(annotations);
+
+ Assert.notNull(type);
+ Assert.notNull(annotations);
+
+ this.name = name;
+ this.type = type;
+ this.key = getValue(annotations);
}
-
+
private String getValue(Annotation[] annotations) {
- for (Annotation anno : annotations) {
- if (anno.annotationType() == Value.class) {
- return ((Value) anno).value();
- }
- }
- return null;
+ for (Annotation anno : annotations) {
+ if (anno.annotationType() == Value.class) {
+ return ((Value) anno).value();
+ }
+ }
+ return null;
}
public String getName() {
@@ -101,9 +101,9 @@ public class PreferredConstructor {
public TypeInformation getType() {
return type;
}
-
+
public Class getRawType() {
- return type.getType();
+ return type.getType();
}
public String getKey() {
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java
index 9fceb6812..9e6aadd62 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/persistence/AbstractConstructorEntityInstantiator.java
@@ -1,141 +1,142 @@
-package org.springframework.data.persistence;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.util.ClassUtils;
-import sun.reflect.ReflectionFactory;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Try for a constructor taking state: failing that, try a no-arg
- * constructor and then setUnderlyingNode().
- *
- * @author Rod Johnson
- */
-public abstract class AbstractConstructorEntityInstantiator implements EntityInstantiator {
-
- private final Log log = LogFactory.getLog(getClass());
- private final Map,StateBackedCreator extends BACKING_INTERFACE,STATE>> cache = new HashMap,StateBackedCreator extends BACKING_INTERFACE,STATE>>();
-
- public T createEntityFromState(STATE n, Class c) {
- try {
- StateBackedCreator creator = (StateBackedCreator) cache.get(c);
- if (creator !=null) return creator.create(n,c);
- synchronized (cache) {
- creator = (StateBackedCreator) cache.get(c);
- if (creator !=null) return creator.create(n,c);
- Class stateClass = (Class) n.getClass();
- creator =createInstantiator(c, stateClass);
- cache.put(c, creator);
- return creator.create(n,c);
- }
- } catch (IllegalArgumentException e) {
- throw e;
- } catch (InvocationTargetException e) {
- throw new IllegalArgumentException(e.getTargetException());
- } catch (Exception e) {
- throw new IllegalArgumentException(e);
- }
- }
-
-
- public void setInstantiators(Map,StateBackedCreator extends BACKING_INTERFACE,STATE>> instantiators) {
- this.cache.putAll(instantiators);
- }
-
- protected StateBackedCreator createInstantiator(Class type, final Class stateType) {
- StateBackedCreator creator = stateTakingConstructorInstantiator(type,stateType);
- if (creator !=null) return creator;
- creator = emptyConstructorStateSettingInstantiator(type,stateType);
- if (creator !=null) return creator;
- return createFailingInstantiator(stateType);
- }
-
- protected StateBackedCreator createFailingInstantiator(final Class stateType) {
- return new StateBackedCreator() {
- public T create(STATE n, Class c) throws Exception {
- throw new IllegalArgumentException(getFailingMessageForClass(c, stateType));
- }
- };
- }
-
- protected String getFailingMessageForClass(Class> entityClass, Class stateClass) {
- return getClass().getSimpleName() + ": entity " + entityClass +
- " must have either a constructor taking [" + stateClass + "] or a no-arg constructor and state setter.";
- }
-
- private StateBackedCreator emptyConstructorStateSettingInstantiator(Class type, Class stateType) {
- final Constructor constructor = getNoArgConstructor(type);
- if (constructor == null) return null;
-
- log.info("Using " + type + " no-arg constructor");
-
- return new StateBackedCreator() {
- public T create(STATE state, Class c) throws Exception {
- try {
- StateProvider.setUnderlyingState(state);
- T newInstance = constructor.newInstance();
- setState(newInstance, state);
- return newInstance;
- } finally {
- StateProvider.retrieveState();
- }
- }
- };
- }
-
- protected StateBackedCreator createWithoutConstructorInvocation(final Class type, Class stateType) {
- ReflectionFactory rf = ReflectionFactory.getReflectionFactory();
- Constructor> objectConstructor = getDeclaredConstructor(Object.class);
- final Constructor> serializationConstructor = rf.newConstructorForSerialization(type, objectConstructor);
- return new StateBackedCreator() {
- public T create(STATE state, Class c) throws Exception {
- final T result = type.cast(serializationConstructor.newInstance());
- setState(result,state);
- return result;
- }
- };
- }
-
-
- protected Constructor getNoArgConstructor(Class type) {
- Constructor constructor = ClassUtils.getConstructorIfAvailable(type);
- if (constructor != null) return constructor;
- return getDeclaredConstructor(type);
- }
-
- protected StateBackedCreator stateTakingConstructorInstantiator(Class type, Class stateType) {
- Class extends STATE> stateInterface = (Class extends STATE>) stateType.getInterfaces()[0];
- final Constructor constructor = ClassUtils.getConstructorIfAvailable(type, stateInterface);
- if (constructor == null) return null;
-
- log.info("Using " + type + " constructor taking " + stateInterface);
- return new StateBackedCreator() {
- public T create(STATE n, Class c) throws Exception {
- return constructor.newInstance(n);
- }
- };
- }
-
- protected Constructor getDeclaredConstructor(Class c) {
- try {
- final Constructor declaredConstructor = c.getDeclaredConstructor();
- declaredConstructor.setAccessible(true);
- return declaredConstructor;
- } catch (NoSuchMethodException e) {
- return null;
- }
- }
-
- /**
- * Subclasses must implement to set state
- * @param entity
- * @param s
- */
- protected abstract void setState(BACKING_INTERFACE entity, STATE s);
-
-}
+package org.springframework.data.persistence;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.util.ClassUtils;
+import sun.reflect.ReflectionFactory;
+
+/**
+ * Try for a constructor taking state: failing that, try a no-arg
+ * constructor and then setUnderlyingNode().
+ *
+ * @author Rod Johnson
+ */
+public abstract class AbstractConstructorEntityInstantiator implements EntityInstantiator {
+
+ private final Log log = LogFactory.getLog(getClass());
+ private final Map, StateBackedCreator extends BACKING_INTERFACE, STATE>> cache = new HashMap, StateBackedCreator extends BACKING_INTERFACE, STATE>>();
+
+ public T createEntityFromState(STATE n, Class c) {
+ try {
+ StateBackedCreator creator = (StateBackedCreator) cache.get(c);
+ if (creator != null) return creator.create(n, c);
+ synchronized (cache) {
+ creator = (StateBackedCreator