DATACMNS-462 - AbstractPersistentProperty considers collections and maps entities now.
Removed the rejecting check for collections and maps and solely rely on the evaluation of the actual type for the ….isEntity() decision in AbstractPersistentProperty. This will cause collection and map properties also being inspected for persistent types as soon as the owner type gets added to the mapping context.
This commit is contained in:
@@ -224,6 +224,16 @@ public class AbstractMappingContextUnitTests {
|
||||
assertThat(context.getPersistentEntity(Integer.class), is(nullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-462
|
||||
*/
|
||||
@Test
|
||||
public void hasPersistentEntityForCollectionPropertiesAfterInitialization() {
|
||||
|
||||
context.getPersistentEntity(Sample.class);
|
||||
assertThat(context.hasPersistentEntityFor(Person.class), is(true));
|
||||
}
|
||||
|
||||
class Person {
|
||||
String name;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,6 +51,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
typeInfo = ClassTypeInformation.from(TestClassComplex.class);
|
||||
entity = new BasicPersistentEntity<TestClassComplex, SamplePersistentProperty>(typeInfo);
|
||||
typeHolder = new SimpleTypeHolder();
|
||||
@@ -68,6 +69,9 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
property.getComponentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-101
|
||||
*/
|
||||
@Test
|
||||
public void returnsNestedEntityTypeCorrectly() {
|
||||
|
||||
@@ -197,25 +201,6 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.getSetter(), is(nullValue()));
|
||||
}
|
||||
|
||||
private static PropertyDescriptor getPropertyDescriptor(Class<?> type, String propertyName) {
|
||||
|
||||
try {
|
||||
|
||||
BeanInfo info = Introspector.getBeanInfo(type);
|
||||
|
||||
for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
|
||||
if (descriptor.getName().equals(propertyName)) {
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
} catch (IntrospectionException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-337
|
||||
*/
|
||||
@@ -235,6 +220,46 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.getActualType(), is((Object) Person.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-462
|
||||
*/
|
||||
@Test
|
||||
public void considersCollectionPropertyEntitiesIfComponentTypeIsEntity() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "persons");
|
||||
assertThat(property.isEntity(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-462
|
||||
*/
|
||||
@Test
|
||||
public void considersMapPropertyEntitiesIfValueTypeIsEntity() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "personMap");
|
||||
assertThat(property.isEntity(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-462
|
||||
*/
|
||||
@Test
|
||||
public void considersArrayPropertyEntitiesIfComponentTypeIsEntity() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "personArray");
|
||||
assertThat(property.isEntity(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-462
|
||||
*/
|
||||
@Test
|
||||
public void considersCollectionPropertySimpleIfComponentTypeIsSimple() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "strings");
|
||||
assertThat(property.isEntity(), is(false));
|
||||
}
|
||||
|
||||
private <T> SamplePersistentProperty getProperty(Class<T> type, String name) {
|
||||
|
||||
BasicPersistentEntity<T, SamplePersistentProperty> entity = new BasicPersistentEntity<T, SamplePersistentProperty>(
|
||||
@@ -244,6 +269,25 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
return new SamplePersistentProperty(field, null, entity, typeHolder);
|
||||
}
|
||||
|
||||
private static PropertyDescriptor getPropertyDescriptor(Class<?> type, String propertyName) {
|
||||
|
||||
try {
|
||||
|
||||
BeanInfo info = Introspector.getBeanInfo(type);
|
||||
|
||||
for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
|
||||
if (descriptor.getName().equals(propertyName)) {
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
} catch (IntrospectionException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class Generic<T> {
|
||||
T genericField;
|
||||
|
||||
@@ -345,5 +389,6 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
Collection<Person> persons;
|
||||
Person[] personArray;
|
||||
Map<String, Person> personMap;
|
||||
Collection<String> strings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user