DATAREST-39 Introduced new property on AttributeMetadata to encapsulate the decision of whether or not a property is nullable. Removed references to JPA-specific classes from everything but the JpaAttributeMetadata class.
This commit is contained in:
@@ -40,6 +40,13 @@ public interface AttributeMetadata {
|
||||
*/
|
||||
Class<?> elementType();
|
||||
|
||||
/**
|
||||
* Whether this attribute can be nulled or not.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean isNullable();
|
||||
|
||||
/**
|
||||
* Can this attribute look like a {@link Collection}?
|
||||
*
|
||||
|
||||
@@ -7,6 +7,8 @@ import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
import javax.persistence.metamodel.EntityType;
|
||||
import javax.persistence.metamodel.MapAttribute;
|
||||
@@ -72,6 +74,18 @@ public class JpaAttributeMetadata implements AttributeMetadata {
|
||||
: null);
|
||||
}
|
||||
|
||||
@Override public boolean isNullable() {
|
||||
if(hasAnnotation(ManyToOne.class)) {
|
||||
return annotation(ManyToOne.class).optional();
|
||||
}
|
||||
|
||||
if(hasAnnotation(OneToOne.class)) {
|
||||
return annotation(OneToOne.class).optional();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean isCollectionLike() {
|
||||
if(attribute instanceof PluralAttribute) {
|
||||
PluralAttribute plattr = (PluralAttribute)attribute;
|
||||
|
||||
Reference in New Issue
Block a user