1 30 31 32 package org.hsqldb; 33 34 import org.hsqldb.lib.ObjectComparator; 35 36 46 class SubQuery implements ObjectComparator { 47 48 int level; 49 boolean hasParams; 50 boolean isResolved; 51 boolean isExistsPredicate; 52 boolean uniqueRows; 53 Select select; 54 Table table; 55 View view; 56 boolean isMaterialised; 57 58 void populateTable(Session session) throws HsqlException { 59 60 Result r = select.getResult(session, isExistsPredicate ? 1 61 : 0); 62 63 if (uniqueRows) { 64 r.removeDuplicates(session, select.iResultLen); 65 } 66 67 table.insertResult(session, r); 68 } 69 70 82 public int compare(Object a, Object b) { 83 84 SubQuery sqa = (SubQuery) a; 85 SubQuery sqb = (SubQuery) b; 86 87 if (sqa.view == null && sqb.view == null) { 88 return sqb.level - sqa.level; 89 } else if (sqa.view != null && sqb.view != null) { 90 Database db = sqa.view.database; 91 int ia = db.schemaManager.getTableIndex(sqa.view); 92 int ib = db.schemaManager.getTableIndex(sqb.view); 93 94 if (ia == -1) { 95 ia = db.schemaManager.getTables( 96 sqa.view.getSchemaName()).size(); 97 } 98 99 if (ib == -1) { 100 ib = db.schemaManager.getTables( 101 sqb.view.getSchemaName()).size(); 102 } 103 104 int diff = ia - ib; 105 106 return diff == 0 ? sqb.level - sqa.level 107 : diff; 108 } else { 109 return sqa.view == null ? 1 110 : -1; 111 } 112 } 113 } 114 | Popular Tags |