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 TableExprAsSubquery extends TableExpression 28 { 29 protected final ArrayList columns = new ArrayList (); 30 protected boolean multipleTablesReferenced = false; 31 32 public TableExprAsSubquery(QueryStatement qs, Table mainTable, SQLIdentifier mainRangeVar) 33 { 34 super(qs, mainTable, mainRangeVar); 35 } 36 37 public String referenceColumn(Column col) 38 { 39 assertNotFrozen(); 40 41 Table table = col.getTable(); 42 43 if (!table.equals(mainTable)) 44 { 45 if (!(mainTable instanceof ClassBaseTable) || !(table instanceof ClassBaseTable)) 46 throw new TableMismatchException(col, mainTable); 47 48 54 55 multipleTablesReferenced = true; 56 } 57 58 if (!columns.contains(col)) 59 columns.add(col); 60 61 return mainRangeVar + "." + col.getName(); 62 } 63 64 public String toString() 65 { 66 if (sqlText == null) 67 { 68 StringBuffer sb = new StringBuffer (); 69 SQLIdentifier mainTableName = mainTable.getName(); 70 71 if (!multipleTablesReferenced) 72 { 73 sb.append(mainTableName); 74 75 if (!mainRangeVar.equals(mainTableName)) 76 sb.append(' ').append(mainRangeVar); 77 } 78 else 79 { 80 FetchStatement subQuery = new FetchStatement((ClassBaseTable)mainTable); 81 82 Iterator i = columns.iterator(); 83 84 while (i.hasNext()) 85 subQuery.select((Column)i.next()); 86 87 sb.append('(').append(subQuery).append(") ").append(mainRangeVar); 88 } 89 90 sqlText = sb.toString(); 91 } 92 93 return sqlText; 94 } 95 } 96 | Popular Tags |