1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.compile.RowOrdering; 25 import org.apache.derby.iapi.sql.compile.Optimizable; 26 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 29 import java.util.Vector ; 30 31 class ColumnOrdering { 32 33 34 int myDirection; 35 36 37 Vector columns = new Vector (); 38 39 43 Vector tables = new Vector (); 44 45 48 ColumnOrdering(int direction) { 49 myDirection = direction; 50 } 51 52 62 boolean ordered(int direction, int tableNumber, int columnNumber) { 63 66 if (direction != RowOrdering.DONTCARE) { 67 if (direction != myDirection) 68 return false; 69 } 70 71 72 return contains(tableNumber, columnNumber); 73 } 74 75 83 boolean contains(int tableNumber, int columnNumber) 84 { 85 for (int i = 0; i < columns.size(); i++) { 86 Integer col = (Integer ) columns.elementAt(i); 87 Integer tab = (Integer ) tables.elementAt(i); 88 89 if (tab.intValue() == tableNumber && 90 col.intValue() == columnNumber) { 91 92 return true; 93 } 94 } 95 96 return false; 97 } 98 99 102 int direction() 103 { 104 return myDirection; 105 } 106 107 113 void addColumn(int tableNumber, int columnNumber) 114 { 115 tables.addElement(new Integer (tableNumber)); 116 columns.addElement(new Integer (columnNumber)); 117 } 118 119 122 void removeColumns(int tableNumber) 123 { 124 128 for (int i = tables.size() - 1; i >= 0; i--) 129 { 130 Integer tab = (Integer ) tables.elementAt(i); 131 if (tab.intValue() == tableNumber) 132 { 133 tables.removeElementAt(i); 134 columns.removeElementAt(i); 135 } 136 } 137 } 138 139 142 boolean empty() 143 { 144 return (tables.size() == 0); 145 } 146 147 148 ColumnOrdering cloneMe() { 149 ColumnOrdering retval = new ColumnOrdering(myDirection); 150 151 for (int i = 0; i < columns.size(); i++) { 152 153 retval.columns.addElement(columns.elementAt(i)); 154 retval.tables.addElement(tables.elementAt(i)); 155 } 156 157 return retval; 158 } 159 160 161 boolean hasTable(int tableNumber) { 162 if (tables.size() == 0) 163 return false; 164 165 for (int i = 0; i < tables.size(); i++) { 166 Integer tab = (Integer ) tables.elementAt(i); 167 168 if (tab.intValue() == tableNumber) 169 return true; 170 } 171 172 return false; 173 } 174 175 176 boolean hasAnyOtherTable(int tableNumber) { 177 if (tables.size() == 0) 178 return false; 179 180 for (int i = 0; i < tables.size(); i++) { 181 Integer tab = (Integer ) tables.elementAt(i); 182 183 if (tab.intValue() != tableNumber) 184 return true; 185 } 186 187 return false; 188 } 189 190 public String toString() { 191 String retval = ""; 192 193 if (SanityManager.DEBUG) { 194 retval += "Direction: " + myDirection; 195 196 for (int i = 0; i < columns.size(); i++) { 197 retval += " Table " + tables.elementAt(i) + 198 ", Column " + columns.elementAt(i); 199 } 200 } 201 202 return retval; 203 } 204 } 205 | Popular Tags |