Skip to content

Commit

Permalink
add support for >9 joins for FrontBase and DB2
Browse files Browse the repository at this point in the history
  • Loading branch information
darkv committed Aug 21, 2012
1 parent 23cc1bb commit 956af74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public String assembleJoinClause(String leftName,
}
JoinClause jc = new JoinClause();

jc.table1 = leftTable + " " + leftAlias;
jc.setTable1(leftTable, leftAlias);

switch (semantic) {
case EORelationship.LeftOuterJoin:
Expand Down Expand Up @@ -759,34 +759,47 @@ public String tableListWithRootEntity(EOEntity entity) {
//NSLog.out.appendln("PostgresqlExpression.tableListWithRootEntity " + entity.externalName() + ", useAliases() = " + useAliases() + ", sql = " + sql);
return sql;
}

/**
* Helper class that stores a join definition and
* helps <code>DB2Expression</code> to assemble
* the correct join clause.
*/
public class JoinClause {
public static class JoinClause {
String table1;
String op;
String table2;
String joinCondition;
String sortKey;

@Override
public String toString() {
return table1 + op + table2 + joinCondition;
}

public boolean equals( Object obj ) {
@Override
public boolean equals(Object obj) {
if( obj == null || !(obj instanceof JoinClause) ) {
return false;
}
return toString().equals( obj.toString() );
}

public void setTable1(String leftTable, String leftAlias) {
table1 = leftTable + " " + leftAlias;
sortKey = leftAlias.substring(1);
if (sortKey.length() < 2) {
// add padding for cases with >9 joins
sortKey = " " + sortKey;
}
}

/**
* Property that makes this class "sortable".
* Needed to correctly assemble a join clause.
*/
public String sortKey() {
return table1.substring( table1.indexOf( " " ) + 1 );
return sortKey;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ public String assembleJoinClause(String leftName, String rightName, int semantic
String leftTable = leftEntity.valueForSQLExpression(this);
JoinClause jc = new JoinClause();

jc.table1 = leftTable + " " + leftAlias;
jc.setTable1(leftTable, leftAlias);
jc.table2 = rightTable + " " + rightAlias;

switch (semantic) {
Expand Down Expand Up @@ -1940,6 +1940,7 @@ public static class JoinClause {
String op;
String table2;
String joinCondition;
String sortKey;

@Override
public String toString() {
Expand All @@ -1953,6 +1954,15 @@ public boolean equals(Object obj) {
}
return toString().equals(obj.toString());
}

public void setTable1(String leftTable, String leftAlias) {
table1 = leftTable + " " + leftAlias;
sortKey = leftAlias.substring(1);
if (sortKey.length() < 2) {
// add padding for cases with >9 joins
sortKey = " " + sortKey;
}
}

/**
* Returns the table alias for the first table (e.g. returns T2 if table 1 is "Students" T2). This makes this class "sortable"
Expand All @@ -1961,7 +1971,7 @@ public boolean equals(Object obj) {
* @return the table alias (e.g. returns T2 if table1 is "Students" T2)
*/
public String sortKey() {
return table1.substring(table1.indexOf(" ") + 1);
return sortKey;
}
}

Expand Down

0 comments on commit 956af74

Please sign in to comment.