1 10 11 package com.triactive.jdo.store; 12 13 import java.util.HashMap ; 14 15 16 25 26 class TableExprAsJoins extends TableExpression 27 { 28 protected final HashMap rangeVarsByTable = new HashMap (); 29 30 public TableExprAsJoins(QueryStatement qs, Table mainTable, SQLIdentifier mainRangeVar) 31 { 32 super(qs, mainTable, mainRangeVar); 33 34 rangeVarsByTable.put(mainTable, mainRangeVar); 35 } 36 37 public String referenceColumn(Column col) 38 { 39 assertNotFrozen(); 40 41 Table table = col.getTable(); 42 SQLIdentifier rangeVar = (SQLIdentifier)rangeVarsByTable.get(table); 43 44 if (rangeVar == null) 45 { 46 if (!(mainTable instanceof ClassBaseTable) || !(table instanceof ClassBaseTable)) 47 throw new TableMismatchException(col, mainTable); 48 49 60 61 rangeVar = new SQLIdentifier(storeMgr.getDatabaseAdapter(), mainRangeVar.toString() + '_' + rangeVarsByTable.size()); 62 rangeVarsByTable.put(table, rangeVar); 63 64 65 66 ClassBaseTable mt = (ClassBaseTable)mainTable; 67 ClassBaseTable st = (ClassBaseTable)table; 68 TableExpression stExpr = qs.newTableExpression(st, rangeVar); 69 70 QueryStatement.QueryColumn mtCol = qs.getColumn(this, mt.getIDMapping().getColumn()); 71 QueryStatement.QueryColumn stCol = qs.getColumn(stExpr, st.getIDMapping().getColumn()); 72 73 qs.innerJoin(mtCol, stCol); 74 } 75 76 return rangeVar + "." + col.getName(); 77 } 78 79 public String toString() 80 { 81 if (sqlText == null) 82 { 83 SQLIdentifier mainTableName = mainTable.getName(); 84 85 StringBuffer sb = new StringBuffer (mainTableName.toString()); 86 87 if (!mainRangeVar.equals(mainTableName)) 88 sb.append(' ').append(mainRangeVar); 89 90 sqlText = sb.toString(); 91 } 92 93 return sqlText; 94 } 95 } 96 | Popular Tags |