1 10 11 package com.triactive.jdo.store; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 16 17 26 27 class TableExprAsSubjoins extends TableExpression 28 { 29 protected final ArrayList supertables = new ArrayList (); 30 31 public TableExprAsSubjoins(QueryStatement qs, Table mainTable, SQLIdentifier mainRangeVar) 32 { 33 super(qs, mainTable, mainRangeVar); 34 } 35 36 public String referenceColumn(Column col) 37 { 38 assertNotFrozen(); 39 40 Table table = col.getTable(); 41 42 if (!table.equals(mainTable)) 43 { 44 if (!(mainTable instanceof ClassBaseTable) || !(table instanceof ClassBaseTable)) 45 throw new TableMismatchException(col, mainTable); 46 47 53 if (!(supertables.contains(table))) 54 supertables.add(table); 55 } 56 57 return mainRangeVar + "." + col.getName(); 58 } 59 60 public String toString() 61 { 62 if (sqlText == null) 63 { 64 StringBuffer sb = new StringBuffer (); 65 SQLIdentifier mainTableName = mainTable.getName(); 66 67 Iterator i = supertables.iterator(); 68 69 if (i.hasNext()) 70 { 71 SQLIdentifier mainTableIDColumnName = ((ClassBaseTable)mainTable).getIDMapping().getColumn().getName(); 72 sb.append('(').append(mainTableName); 73 74 while (i.hasNext()) 75 { 76 ClassBaseTable supertable = (ClassBaseTable)i.next(); 77 SQLIdentifier supertableName = supertable.getName(); 78 79 sb.append(" INNER JOIN ").append(supertableName) 80 .append(" ON ") 81 .append(mainTableName).append('.').append(mainTableIDColumnName) 82 .append(" = ") 83 .append(supertableName).append('.').append(supertable.getIDMapping().getColumn().getName()); 84 } 85 86 sb.append(") ").append(mainRangeVar); 87 } 88 else 89 { 90 sb.append(mainTableName); 91 92 if (!mainRangeVar.equals(mainTableName)) 93 sb.append(' ').append(mainRangeVar); 94 } 95 96 sqlText = sb.toString(); 97 } 98 99 return sqlText; 100 } 101 } 102 | Popular Tags |