Browse Source

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.
pull/93/head
Oliver Gierke 12 years ago
parent
commit
c9dd679cd1
  1. 34
      src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java
  2. 16
      src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java

34
src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java

@ -18,8 +18,7 @@ package org.springframework.data.mapping.model; @@ -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> @@ -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> @@ -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;
}
/*

16
src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java

@ -26,6 +26,7 @@ import java.lang.annotation.Annotation; @@ -26,6 +26,7 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import org.junit.Before;
@ -260,6 +261,17 @@ public class AbstractPersistentPropertyUnitTests { @@ -260,6 +261,17 @@ public class AbstractPersistentPropertyUnitTests {
assertThat(property.isEntity(), is(false));
}
/**
* @see DATACMNS-562
*/
@Test
public void doesNotConsiderPropertyWithTreeMapMapValueAnEntity() {
SamplePersistentProperty property = getProperty(TreeMapWrapper.class, "map");
assertThat(property.getPersistentEntityType(), is(emptyIterable()));
assertThat(property.isEntity(), is(false));
}
private <T> SamplePersistentProperty getProperty(Class<T> type, String name) {
BasicPersistentEntity<T, SamplePersistentProperty> entity = new BasicPersistentEntity<T, SamplePersistentProperty>(
@ -401,4 +413,8 @@ public class AbstractPersistentPropertyUnitTests { @@ -401,4 +413,8 @@ public class AbstractPersistentPropertyUnitTests {
Map<String, Person> personMap;
Collection<String> strings;
}
class TreeMapWrapper {
TreeMap<String, TreeMap<String, String>> map;
}
}

Loading…
Cancel
Save