From 956af748b8659638526f93db7bda971d5e692156 Mon Sep 17 00:00:00 2001 From: Johann Werner Date: Tue, 21 Aug 2012 14:11:39 +0200 Subject: [PATCH] add support for >9 joins for FrontBase and DB2 --- .../webobjects/jdbcadaptor/DB2Expression.java | 21 +++++++++++++++---- .../jdbcadaptor/_FrontBasePlugIn.java | 14 +++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Frameworks/PlugIns/DB2PlugIn/Sources/com/webobjects/jdbcadaptor/DB2Expression.java b/Frameworks/PlugIns/DB2PlugIn/Sources/com/webobjects/jdbcadaptor/DB2Expression.java index b95f496ff15..405fe400b2f 100644 --- a/Frameworks/PlugIns/DB2PlugIn/Sources/com/webobjects/jdbcadaptor/DB2Expression.java +++ b/Frameworks/PlugIns/DB2PlugIn/Sources/com/webobjects/jdbcadaptor/DB2Expression.java @@ -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: @@ -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 DB2Expression 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; } } diff --git a/Frameworks/PlugIns/FrontBasePlugIn/Sources/com/webobjects/jdbcadaptor/_FrontBasePlugIn.java b/Frameworks/PlugIns/FrontBasePlugIn/Sources/com/webobjects/jdbcadaptor/_FrontBasePlugIn.java index a60d6df405d..88553c0d161 100644 --- a/Frameworks/PlugIns/FrontBasePlugIn/Sources/com/webobjects/jdbcadaptor/_FrontBasePlugIn.java +++ b/Frameworks/PlugIns/FrontBasePlugIn/Sources/com/webobjects/jdbcadaptor/_FrontBasePlugIn.java @@ -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) { @@ -1940,6 +1940,7 @@ public static class JoinClause { String op; String table2; String joinCondition; + String sortKey; @Override public String toString() { @@ -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" @@ -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; } }