diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployTableJoin.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployTableJoin.java index 02bb17492..8034f975e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployTableJoin.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployTableJoin.java @@ -19,199 +19,198 @@ import com.avaje.ebeaninternal.server.query.SqlJoinType; */ public class DeployTableJoin { - /** - * Flag set when the imported key maps to the primary key. - * This occurs for intersection tables (ManyToMany). - */ - private boolean importedPrimaryKey; - - /** - * The joined table. - */ - private String table; - - /** - * The type of join. LEFT OUTER etc. - */ - private SqlJoinType type = SqlJoinType.INNER; + /** + * Flag set when the imported key maps to the primary key. This occurs for intersection tables + * (ManyToMany). + */ + private boolean importedPrimaryKey; - /** - * The list of properties mapped to this joined table. - */ - private ArrayList properties = new ArrayList(); + /** + * The joined table. + */ + private String table; - /** - * The list of join column pairs. Used to generate the on clause. - */ - private ArrayList columns = new ArrayList(); + /** + * The type of join. LEFT OUTER etc. + */ + private SqlJoinType type = SqlJoinType.INNER; - /** - * The persist cascade info. - */ - private BeanCascadeInfo cascadeInfo = new BeanCascadeInfo(); - - private InheritInfo inheritInfo; + /** + * The list of properties mapped to this joined table. + */ + private ArrayList properties = new ArrayList(); - /** - * Create a DeployTableJoin. - */ - public DeployTableJoin() { - } - - public String toString() { - return type + " " + table + " " + columns; - } + /** + * The list of join column pairs. Used to generate the on clause. + */ + private ArrayList columns = new ArrayList(4); - /** - * Return true if the imported foreign key maps to the primary key. - */ - public boolean isImportedPrimaryKey() { - return importedPrimaryKey; - } + /** + * The persist cascade info. + */ + private BeanCascadeInfo cascadeInfo = new BeanCascadeInfo(); - /** - * Flag set when the imported key maps to the primary key. - * This occurs for intersection tables (ManyToMany). - */ - public void setImportedPrimaryKey(boolean importedPrimaryKey) { - this.importedPrimaryKey = importedPrimaryKey; - } + private InheritInfo inheritInfo; - /** - * Return true if the JoinOnPair have been set. - */ - public boolean hasJoinColumns() { - return columns.size() > 0; - } + /** + * Create a DeployTableJoin. + */ + public DeployTableJoin() { + } - /** - * Return the persist info. - */ - public BeanCascadeInfo getCascadeInfo() { - return cascadeInfo; - } - + public String toString() { + return type + " " + table + " " + columns; + } - /** - * Copy all the columns to this join potentially reversing the columns. - */ - public void setColumns(DeployTableJoinColumn[] cols, boolean reverse) { - columns = new ArrayList(); - for (int i = 0; i < cols.length; i++) { - addJoinColumn(cols[i].copy(reverse)); - } - } - - /** - * Add a join pair - */ - public void addJoinColumn(DeployTableJoinColumn pair) { - columns.add(pair); - } + /** + * Return true if the imported foreign key maps to the primary key. + */ + public boolean isImportedPrimaryKey() { + return importedPrimaryKey; + } - /** - * Add a JoinColumn - *

- * The order is generally true for OneToMany and false for ManyToOne relationships. - *

- */ - public void addJoinColumn(boolean order, JoinColumn jc, BeanTable beanTable) { - if (!"".equals(jc.table())) { - setTable(jc.table()); - } - addJoinColumn(new DeployTableJoinColumn(order, jc, beanTable)); - } - - /** - * Add a JoinColumn array. - */ - public void addJoinColumn(boolean order, JoinColumn[] jcArray, BeanTable beanTable) { - for (int i = 0; i < jcArray.length; i++) { - addJoinColumn(order, jcArray[i], beanTable); - } - } - - /** - * Return the join columns. - */ - public DeployTableJoinColumn[] columns() { - return (DeployTableJoinColumn[])columns.toArray(new DeployTableJoinColumn[columns.size()]); - } + /** + * Flag set when the imported key maps to the primary key. This occurs for intersection tables + * (ManyToMany). + */ + public void setImportedPrimaryKey(boolean importedPrimaryKey) { + this.importedPrimaryKey = importedPrimaryKey; + } - - /** - * For secondary table joins returns the properties mapped to that table. - */ - public DeployBeanProperty[] properties() { - return (DeployBeanProperty[])properties.toArray(new DeployBeanProperty[properties.size()]); - } + /** + * Return true if the JoinOnPair have been set. + */ + public boolean hasJoinColumns() { + return columns.size() > 0; + } - /** - * Return the joined table name. - */ - public String getTable() { - return table; - } + /** + * Return the persist info. + */ + public BeanCascadeInfo getCascadeInfo() { + return cascadeInfo; + } - /** - * set the joined table name. - */ - public void setTable(String table) { - this.table = table; + /** + * Copy all the columns to this join potentially reversing the columns. + */ + public void setColumns(DeployTableJoinColumn[] cols, boolean reverse) { + columns = new ArrayList(); + for (int i = 0; i < cols.length; i++) { + addJoinColumn(cols[i].copy(reverse)); } + } - /** - * Return the type of join. LEFT OUTER JOIN etc. - */ - public SqlJoinType getType() { - return type; - } + /** + * Add a join pair + */ + public void addJoinColumn(DeployTableJoinColumn pair) { + columns.add(pair); + } - /** - * Return true if this join is a left outer join. - */ - public boolean isOuterJoin() { - return type == SqlJoinType.OUTER; + /** + * Add a JoinColumn + *

+ * The order is generally true for OneToMany and false for ManyToOne relationships. + *

+ */ + public void addJoinColumn(boolean order, JoinColumn jc, BeanTable beanTable) { + if (!"".equals(jc.table())) { + setTable(jc.table()); } - - private void setType(SqlJoinType type) { - this.type = type; + if (!"".equals(jc.name()) || !"".equals(jc.referencedColumnName())) { + // only add the join column details when name or referencedColumnName is specified + addJoinColumn(new DeployTableJoinColumn(order, jc, beanTable)); } - - /** - * Set the type of join. - */ - public void setType(String joinType) { - joinType = joinType.toUpperCase(); - if (joinType.equalsIgnoreCase(TableJoin.JOIN)) { - type = SqlJoinType.INNER; - } else if (joinType.indexOf("LEFT") > -1) { - type = SqlJoinType.OUTER; - } else if (joinType.indexOf("OUTER") > -1) { - type = SqlJoinType.OUTER; - } else if (joinType.indexOf("INNER") > -1) { - type = SqlJoinType.INNER; - } else { - throw new RuntimeException(Message.msg("join.type.unknown", joinType)); - } - } - - public DeployTableJoin createInverse(String tableName) { - - DeployTableJoin inverse = new DeployTableJoin(); + } - return copyTo(inverse, true, tableName); + /** + * Add a JoinColumn array. + */ + public void addJoinColumn(boolean order, JoinColumn[] jcArray, BeanTable beanTable) { + for (int i = 0; i < jcArray.length; i++) { + addJoinColumn(order, jcArray[i], beanTable); + } + } + /** + * Return the join columns. + */ + public DeployTableJoinColumn[] columns() { + return (DeployTableJoinColumn[]) columns.toArray(new DeployTableJoinColumn[columns.size()]); + } + + /** + * For secondary table joins returns the properties mapped to that table. + */ + public DeployBeanProperty[] properties() { + return (DeployBeanProperty[]) properties.toArray(new DeployBeanProperty[properties.size()]); + } + + /** + * Return the joined table name. + */ + public String getTable() { + return table; + } + + /** + * set the joined table name. + */ + public void setTable(String table) { + this.table = table; + } + + /** + * Return the type of join. LEFT OUTER JOIN etc. + */ + public SqlJoinType getType() { + return type; + } + + /** + * Return true if this join is a left outer join. + */ + public boolean isOuterJoin() { + return type == SqlJoinType.OUTER; + } + + private void setType(SqlJoinType type) { + this.type = type; + } + + /** + * Set the type of join. + */ + public void setType(String joinType) { + joinType = joinType.toUpperCase(); + if (joinType.equalsIgnoreCase(TableJoin.JOIN)) { + type = SqlJoinType.INNER; + } else if (joinType.indexOf("LEFT") > -1) { + type = SqlJoinType.OUTER; + } else if (joinType.indexOf("OUTER") > -1) { + type = SqlJoinType.OUTER; + } else if (joinType.indexOf("INNER") > -1) { + type = SqlJoinType.INNER; + } else { + throw new RuntimeException(Message.msg("join.type.unknown", joinType)); } - - public DeployTableJoin copyTo(DeployTableJoin destJoin, boolean reverse, String tableName) { - - destJoin.setTable(tableName); - destJoin.setType(type); - destJoin.setColumns(columns(), reverse); - - return destJoin; - } + } + + public DeployTableJoin createInverse(String tableName) { + + DeployTableJoin inverse = new DeployTableJoin(); + return copyTo(inverse, true, tableName); + } + + public DeployTableJoin copyTo(DeployTableJoin destJoin, boolean reverse, String tableName) { + + destJoin.setTable(tableName); + destJoin.setType(type); + destJoin.setColumns(columns(), reverse); + + return destJoin; + } public InheritInfo getInheritInfo() { return inheritInfo;