No effective change - format only

This commit is contained in:
Robin Bygrave
2015-08-26 10:47:22 +12:00
parent 5a0b65b4f2
commit d592e7d35f
2 changed files with 343 additions and 344 deletions
@@ -1,161 +1,160 @@
package com.avaje.ebeaninternal.server.deploy.parse;
import com.avaje.ebeaninternal.server.core.BootupClasses;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Inheritance;
import java.lang.annotation.Annotation;
import java.sql.Types;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Inheritance;
import com.avaje.ebeaninternal.server.core.BootupClasses;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
/**
* Builds the InheritInfo deployment information.
*/
public class DeployInherit {
private final Map<Class<?>, DeployInheritInfo> deployMap = new LinkedHashMap<Class<?>, DeployInheritInfo>();
private final Map<Class<?>, DeployInheritInfo> deployMap = new LinkedHashMap<Class<?>, DeployInheritInfo>();
private final Map<Class<?>, InheritInfo> finalMap = new LinkedHashMap<Class<?>, InheritInfo>();
private final Map<Class<?>, InheritInfo> finalMap = new LinkedHashMap<Class<?>, InheritInfo>();
private final BootupClasses bootupClasses;
/**
* Create the InheritInfoDeploy.
*/
public DeployInherit(BootupClasses bootupClasses) {
this.bootupClasses = bootupClasses;
initialise();
}
private final BootupClasses bootupClasses;
public void process(DeployBeanDescriptor<?> desc) {
InheritInfo inheritInfo = finalMap.get(desc.getBeanType());
desc.setInheritInfo(inheritInfo);
}
/**
* Create the InheritInfoDeploy.
*/
public DeployInherit(BootupClasses bootupClasses) {
this.bootupClasses = bootupClasses;
initialise();
}
private void initialise() {
List<Class<?>> entityList = bootupClasses.getEntities();
public void process(DeployBeanDescriptor<?> desc) {
InheritInfo inheritInfo = finalMap.get(desc.getBeanType());
desc.setInheritInfo(inheritInfo);
}
findInheritClasses(entityList);
buildDeployTree();
buildFinalTree();
}
private void initialise() {
List<Class<?>> entityList = bootupClasses.getEntities();
private void findInheritClasses(List<Class<?>> entityList) {
findInheritClasses(entityList);
buildDeployTree();
buildFinalTree();
}
// go through each class and initialise the info object...
for (Class<?> cls : entityList) {
if (isInheritanceClass(cls)) {
DeployInheritInfo info = createInfo(cls);
deployMap.put(cls, info);
}
}
}
private void findInheritClasses(List<Class<?>> entityList) {
private void buildDeployTree() {
// go through each class and initialise the info object...
for (Class<?> cls : entityList) {
if (isInheritanceClass(cls)) {
DeployInheritInfo info = createInfo(cls);
deployMap.put(cls, info);
}
}
}
for (DeployInheritInfo info : deployMap.values()) {
if (!info.isRoot()) {
DeployInheritInfo parent = getInfo(info.getParent());
parent.addChild(info);
}
}
}
private void buildDeployTree() {
private void buildFinalTree() {
for (DeployInheritInfo info : deployMap.values()) {
if (!info.isRoot()) {
DeployInheritInfo parent = getInfo(info.getParent());
parent.addChild(info);
}
}
}
for (DeployInheritInfo deploy : deployMap.values()) {
if (deploy.isRoot()) {
// build tree top down...
createFinalInfo(null, null, deploy);
}
}
}
private void buildFinalTree() {
private void createFinalInfo(InheritInfo root, InheritInfo parent, DeployInheritInfo deploy) {
for (DeployInheritInfo deploy : deployMap.values()) {
if (deploy.isRoot()) {
// build tree top down...
createFinalInfo(null, null, deploy);
}
}
}
InheritInfo node = new InheritInfo(root, parent, deploy);
if (parent != null) {
parent.addChild(node);
}
finalMap.put(node.getType(), node);
private void createFinalInfo(InheritInfo root, InheritInfo parent, DeployInheritInfo deploy) {
if (root == null) {
root = node;
}
InheritInfo node = new InheritInfo(root, parent, deploy);
if (parent != null) {
parent.addChild(node);
}
finalMap.put(node.getType(), node);
// buildFinalChildren(root, child, deploy);
for (DeployInheritInfo childDeploy : deploy.children()) {
createFinalInfo(root, node, childDeploy);
}
}
if (root == null) {
root = node;
}
/**
* Build the InheritInfo for a given class.
*/
private DeployInheritInfo getInfo(Class<?> cls) {
return deployMap.get(cls);
}
// buildFinalChildren(root, child, deploy);
for (DeployInheritInfo childDeploy : deploy.children()) {
createFinalInfo(root, node, childDeploy);
}
}
private DeployInheritInfo createInfo(Class<?> cls) {
/**
* Build the InheritInfo for a given class.
*/
private DeployInheritInfo getInfo(Class<?> cls) {
return deployMap.get(cls);
}
DeployInheritInfo info = new DeployInheritInfo(cls);
private DeployInheritInfo createInfo(Class<?> cls) {
Class<?> parent = findParent(cls);
if (parent != null) {
info.setParent(parent);
}
DeployInheritInfo info = new DeployInheritInfo(cls);
Inheritance ia = cls.getAnnotation(Inheritance.class);
if (ia != null) {
ia.strategy();
}
DiscriminatorColumn da = cls.getAnnotation(DiscriminatorColumn.class);
if (da != null) {
// lowercase the discriminator column for RawSql and JSON
info.setDiscriminatorColumn(da.name().toLowerCase());
DiscriminatorType discriminatorType = da.discriminatorType();
if (discriminatorType.equals(DiscriminatorType.INTEGER)){
info.setDiscriminatorType(Types.INTEGER);
} else {
info.setDiscriminatorType(Types.VARCHAR);
}
info.setDiscriminatorLength(da.length());
}
Class<?> parent = findParent(cls);
if (parent != null) {
info.setParent(parent);
}
DiscriminatorValue dv = cls.getAnnotation(DiscriminatorValue.class);
if (dv != null) {
info.setDiscriminatorValue(dv.value());
}
return info;
}
Inheritance ia = cls.getAnnotation(Inheritance.class);
if (ia != null) {
ia.strategy();
}
DiscriminatorColumn da = cls.getAnnotation(DiscriminatorColumn.class);
if (da != null) {
// lowercase the discriminator column for RawSql and JSON
info.setDiscriminatorColumn(da.name().toLowerCase());
DiscriminatorType discriminatorType = da.discriminatorType();
if (discriminatorType.equals(DiscriminatorType.INTEGER)) {
info.setDiscriminatorType(Types.INTEGER);
} else {
info.setDiscriminatorType(Types.VARCHAR);
}
info.setDiscriminatorLength(da.length());
}
private Class<?> findParent(Class<?> cls) {
Class<?> superCls = cls.getSuperclass();
if (isInheritanceClass(superCls)) {
return superCls;
} else {
return null;
}
}
DiscriminatorValue dv = cls.getAnnotation(DiscriminatorValue.class);
if (dv != null) {
info.setDiscriminatorValue(dv.value());
}
private boolean isInheritanceClass(Class<?> cls) {
if (cls.equals(Object.class)) {
return false;
}
Annotation a = cls.getAnnotation(Inheritance.class);
if (a != null) {
return true;
}
// search up the inheritance heirarchy
return isInheritanceClass(cls.getSuperclass());
}
return info;
}
private Class<?> findParent(Class<?> cls) {
Class<?> superCls = cls.getSuperclass();
if (isInheritanceClass(superCls)) {
return superCls;
} else {
return null;
}
}
private boolean isInheritanceClass(Class<?> cls) {
if (cls.equals(Object.class)) {
return false;
}
Annotation a = cls.getAnnotation(Inheritance.class);
if (a != null) {
return true;
}
// search up the inheritance heirarchy
return isInheritanceClass(cls.getSuperclass());
}
}
@@ -1,257 +1,257 @@
package com.avaje.ebeaninternal.server.deploy.parse;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
/**
* Represents a node in the Inheritance tree.
* Holds information regarding Super Subclass support.
* Holds information regarding Super Subclass support.
*/
public class DeployInheritInfo {
/**
* the default discriminator column according to the JPA 1.0 spec.
*/
private static final String JPA_DEFAULT_DISCRIM_COLUMN = "dtype";
private int discriminatorLength;
private int discriminatorType;
private String discriminatorStringValue;
private Object discriminatorObjectValue;
private String discriminatorColumn;
/**
* the default discriminator column according to the JPA 1.0 spec.
*/
private static final String JPA_DEFAULT_DISCRIM_COLUMN = "dtype";
private String discriminatorWhere;
private int discriminatorLength;
private final Class<?> type;
private int discriminatorType;
private Class<?> parent;
private final ArrayList<DeployInheritInfo> children = new ArrayList<DeployInheritInfo>();
/**
* Create for a given type.
*/
public DeployInheritInfo(Class<?> type){
this.type = type;
}
/**
* return the type.
*/
public Class<?> getType() {
return type;
}
private String discriminatorStringValue;
private Object discriminatorObjectValue;
/**
* Return the type of the root object.
*/
public Class<?> getParent() {
return parent;
}
private String discriminatorColumn;
/**
* Set the type of the root object.
*/
public void setParent(Class<?> parent) {
this.parent = parent;
}
/**
* Return true if this is abstract node.
*/
public boolean isAbstract() {
return (discriminatorObjectValue == null);
}
/**
* Return true if this is the root node.
*/
public boolean isRoot(){
return parent == null;
}
private String discriminatorWhere;
/**
* Return the child nodes.
*/
public List<DeployInheritInfo> children() {
return children;
}
/**
* Add a child node.
*/
public void addChild(DeployInheritInfo childInfo){
children.add(childInfo);
}
private final Class<?> type;
/**
* Return the derived where for the discriminator.
*/
public String getDiscriminatorWhere() {
return discriminatorWhere;
}
private Class<?> parent;
/**
* Set the derived where for the discriminator.
*/
public void setDiscriminatorWhere(String discriminatorWhere) {
this.discriminatorWhere = discriminatorWhere;
}
private final ArrayList<DeployInheritInfo> children = new ArrayList<DeployInheritInfo>();
/**
* Return the column name of the discriminator.
*/
public String getDiscriminatorColumn(InheritInfo parent) {
if (discriminatorColumn == null){
if (parent == null){
discriminatorColumn = JPA_DEFAULT_DISCRIM_COLUMN;
} else {
discriminatorColumn = parent.getDiscriminatorColumn();
}
}
return discriminatorColumn;
}
/**
* Create for a given type.
*/
public DeployInheritInfo(Class<?> type) {
this.type = type;
}
/**
* Set the column name of the discriminator.
*/
public void setDiscriminatorColumn(String discriminatorColumn) {
this.discriminatorColumn = discriminatorColumn;
}
/**
* return the type.
*/
public Class<?> getType() {
return type;
}
public int getDiscriminatorLength(InheritInfo parent) {
if (discriminatorLength == 0){
if (parent == null){
discriminatorLength = 10;
} else {
discriminatorLength = parent.getDiscriminatorLength();
}
}
return discriminatorLength;
}
/**
* Return the sql type of the discriminator value.
*/
public int getDiscriminatorType(InheritInfo parent) {
if (discriminatorType == 0){
if (parent == null){
discriminatorType = Types.VARCHAR;
} else {
discriminatorType = parent.getDiscriminatorType();
}
}
return discriminatorType;
}
/**
* Return the type of the root object.
*/
public Class<?> getParent() {
return parent;
}
/**
* Set the sql type of the discriminator.
*/
public void setDiscriminatorType(int discriminatorType) {
this.discriminatorType = discriminatorType;
}
/**
* Return the length of the discriminator column.
*/
public int getDiscriminatorLength() {
return discriminatorLength;
}
/**
* Set the type of the root object.
*/
public void setParent(Class<?> parent) {
this.parent = parent;
}
/**
* Set the length of the discriminator column.
*/
public void setDiscriminatorLength(int discriminatorLength) {
this.discriminatorLength = discriminatorLength;
}
/**
* Return true if this is abstract node.
*/
public boolean isAbstract() {
return (discriminatorObjectValue == null);
}
/**
* Return the discriminator value for this node.
*/
public Object getDiscriminatorObjectValue() {
return discriminatorObjectValue;
}
/**
* Return true if this is the root node.
*/
public boolean isRoot() {
return parent == null;
}
public String getDiscriminatorStringValue() {
return discriminatorStringValue;
}
/**
* Return the child nodes.
*/
public List<DeployInheritInfo> children() {
return children;
}
/**
* Set the discriminator value for this node.
*/
public void setDiscriminatorValue(String value) {
if (value != null){
value = value.trim();
if (value.length() != 0) {
discriminatorStringValue = value;
// convert the value if desired
if (discriminatorType == Types.INTEGER){
this.discriminatorObjectValue = Integer.valueOf(value);
} else {
this.discriminatorObjectValue = value;
}
}
}
}
public String getWhere() {
List<Object> discList = new ArrayList<Object>();
appendDiscriminator(discList);
/**
* Add a child node.
*/
public void addChild(DeployInheritInfo childInfo) {
children.add(childInfo);
}
return buildWhereLiteral(discList);
}
/**
* Return the derived where for the discriminator.
*/
public String getDiscriminatorWhere() {
return discriminatorWhere;
}
private void appendDiscriminator(List<Object> list) {
if (discriminatorObjectValue != null){
list.add(discriminatorObjectValue);
}
for (DeployInheritInfo child : children) {
child.appendDiscriminator(list);
}
/**
* Set the derived where for the discriminator.
*/
public void setDiscriminatorWhere(String discriminatorWhere) {
this.discriminatorWhere = discriminatorWhere;
}
/**
* Return the column name of the discriminator.
*/
public String getDiscriminatorColumn(InheritInfo parent) {
if (discriminatorColumn == null) {
if (parent == null) {
discriminatorColumn = JPA_DEFAULT_DISCRIM_COLUMN;
} else {
discriminatorColumn = parent.getDiscriminatorColumn();
}
}
private String buildWhereLiteral(List<Object> discList) {
int size = discList.size();
if (size == 0){
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(discriminatorColumn);
if (size == 1){
sb.append(" = ");
} else {
sb.append(" in (");
}
for (int i = 0; i < discList.size(); i++) {
appendSqlLiteralValue(i, discList.get(i), sb);
}
if (size > 1){
sb.append(")");
}
return sb.toString();
return discriminatorColumn;
}
/**
* Set the column name of the discriminator.
*/
public void setDiscriminatorColumn(String discriminatorColumn) {
this.discriminatorColumn = discriminatorColumn;
}
public int getDiscriminatorLength(InheritInfo parent) {
if (discriminatorLength == 0) {
if (parent == null) {
discriminatorLength = 10;
} else {
discriminatorLength = parent.getDiscriminatorLength();
}
}
private void appendSqlLiteralValue(int count, Object value, StringBuilder sb) {
if (count > 0){
sb.append(",");
}
if (value instanceof String){
sb.append("'").append(value).append("'");
return discriminatorLength;
}
/**
* Return the sql type of the discriminator value.
*/
public int getDiscriminatorType(InheritInfo parent) {
if (discriminatorType == 0) {
if (parent == null) {
discriminatorType = Types.VARCHAR;
} else {
discriminatorType = parent.getDiscriminatorType();
}
}
return discriminatorType;
}
/**
* Set the sql type of the discriminator.
*/
public void setDiscriminatorType(int discriminatorType) {
this.discriminatorType = discriminatorType;
}
/**
* Return the length of the discriminator column.
*/
public int getDiscriminatorLength() {
return discriminatorLength;
}
/**
* Set the length of the discriminator column.
*/
public void setDiscriminatorLength(int discriminatorLength) {
this.discriminatorLength = discriminatorLength;
}
/**
* Return the discriminator value for this node.
*/
public Object getDiscriminatorObjectValue() {
return discriminatorObjectValue;
}
public String getDiscriminatorStringValue() {
return discriminatorStringValue;
}
/**
* Set the discriminator value for this node.
*/
public void setDiscriminatorValue(String value) {
if (value != null) {
value = value.trim();
if (value.length() != 0) {
discriminatorStringValue = value;
// convert the value if desired
if (discriminatorType == Types.INTEGER) {
this.discriminatorObjectValue = Integer.valueOf(value);
} else {
sb.append(value);
this.discriminatorObjectValue = value;
}
}
}
public String toString() {
return "InheritInfo[" + type.getName() + "]" + " root[" + parent.getName() + "]" + " disValue[" + discriminatorStringValue + "]";
}
public String getWhere() {
List<Object> discList = new ArrayList<Object>();
appendDiscriminator(discList);
return buildWhereLiteral(discList);
}
private void appendDiscriminator(List<Object> list) {
if (discriminatorObjectValue != null) {
list.add(discriminatorObjectValue);
}
for (DeployInheritInfo child : children) {
child.appendDiscriminator(list);
}
}
private String buildWhereLiteral(List<Object> discList) {
int size = discList.size();
if (size == 0) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(discriminatorColumn);
if (size == 1) {
sb.append(" = ");
} else {
sb.append(" in (");
}
for (int i = 0; i < discList.size(); i++) {
appendSqlLiteralValue(i, discList.get(i), sb);
}
if (size > 1) {
sb.append(")");
}
return sb.toString();
}
private void appendSqlLiteralValue(int count, Object value, StringBuilder sb) {
if (count > 0) {
sb.append(",");
}
if (value instanceof String) {
sb.append("'").append(value).append("'");
} else {
sb.append(value);
}
}
public String toString() {
return "InheritInfo[" + type.getName() + "]" + " root[" + parent.getName() + "]" + " disValue[" + discriminatorStringValue + "]";
}
}