DATACMNS-562 - AbstractPersistentProperty doesn't consider maps and collections entities anymore.

The type detection for entity candidates of PersistentProperty instances now consistently handles collection types even if they're used als collection or map values.
This commit is contained in:
Oliver Gierke
2014-08-19 16:38:15 +02:00
parent 77a67021e5
commit c9dd679cd1
2 changed files with 31 additions and 19 deletions

View File

@@ -18,8 +18,7 @@ package org.springframework.data.mapping.model;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Map;
import org.springframework.core.annotation.AnnotationUtils;
@@ -125,23 +124,23 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
@Override
public Iterable<? extends TypeInformation<?>> getPersistentEntityType() {
List<TypeInformation<?>> result = new ArrayList<TypeInformation<?>>();
TypeInformation<?> type = getTypeInformation();
if (type.isCollectionLike() || isMap()) {
TypeInformation<?> nestedType = getTypeInformationIfNotSimpleType(getTypeInformation().getActualType());
if (nestedType != null) {
result.add(nestedType);
}
} else if (isEntity()) {
result.add(type);
if (!isEntity()) {
return Collections.emptySet();
}
return result;
TypeInformation<?> candidate = getTypeInformationIfEntityCandidate();
return candidate != null ? Collections.singleton(candidate) : Collections.<TypeInformation<?>> emptySet();
}
private TypeInformation<?> getTypeInformationIfNotSimpleType(TypeInformation<?> information) {
return information == null || simpleTypeHolder.isSimpleType(information.getType()) ? null : information;
private TypeInformation<?> getTypeInformationIfEntityCandidate() {
TypeInformation<?> candidate = information.getActualType();
if (candidate == null || simpleTypeHolder.isSimpleType(candidate.getType())) {
return null;
}
return candidate.isCollectionLike() || candidate.isMap() ? null : candidate;
}
/*
@@ -271,10 +270,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
*/
@Override
public boolean isEntity() {
TypeInformation<?> actualType = information.getActualType();
boolean isComplexType = actualType == null ? false : !simpleTypeHolder.isSimpleType(actualType.getType());
return isComplexType && !isTransient();
return !isTransient() && getTypeInformationIfEntityCandidate() != null;
}
/*