Inheritance - Add support for @DiscriminatorValue to be optional (#1361)

This commit is contained in:
André Camilo
2018-04-12 20:38:09 +12:00
committed by Rob Bygrave
parent b0d3921264
commit a8434f22ff
3 changed files with 7 additions and 3 deletions
@@ -6,6 +6,7 @@ import io.ebeaninternal.server.deploy.id.IdBinder;
import io.ebeaninternal.server.deploy.parse.DeployInheritInfo;
import io.ebeaninternal.server.query.SqlTreeProperties;
import java.lang.reflect.Modifier;
import javax.persistence.PersistenceException;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -291,7 +292,7 @@ public class InheritInfo {
* Return true if this is considered a concrete type in the inheritance hierarchy.
*/
public boolean isConcrete() {
return discriminatorValue != null;
return !Modifier.isAbstract(type.getModifiers());
}
/**
@@ -126,6 +126,8 @@ public class DeployInherit {
DiscriminatorValue dv = AnnotationUtil.findAnnotation(cls, DiscriminatorValue.class); // do not search recursive
if (dv != null) {
info.setDiscriminatorValue(dv.value());
} else {
info.setDiscriminatorValue(cls.getSimpleName());
}
return info;
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.deploy.parse;
import io.ebeaninternal.server.deploy.InheritInfo;
import java.lang.reflect.Modifier;
import javax.persistence.DiscriminatorType;
import java.sql.Types;
import java.util.ArrayList;
@@ -64,7 +65,7 @@ public class DeployInheritInfo {
* Return true if this is abstract node.
*/
public boolean isAbstract() {
return (discriminatorObjectValue == null);
return Modifier.isAbstract(type.getModifiers());
}
/**
@@ -205,7 +206,7 @@ public class DeployInheritInfo {
}
private void appendDiscriminator(List<Object> list) {
if (discriminatorObjectValue != null) {
if (!isAbstract()) {
list.add(discriminatorObjectValue);
}
for (DeployInheritInfo child : children) {