1 package com.daffodilwoods.daffodildb.server.serversystem.chainedcolumn; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.client.*; 6 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record; 7 import com.daffodilwoods.daffodildb.server.serversystem.*; 8 import com.daffodilwoods.daffodildb.server.sql99.common.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 11 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 12 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 13 import com.daffodilwoods.daffodildb.utils.field.*; 14 import com.daffodilwoods.database.general.*; 15 import com.daffodilwoods.database.resource.*; 16 import com.daffodilwoods.database.sqlinitiator.*; 17 18 public class ForeignKeyIterator implements _Iterator { 19 20 ChainedTableInfo startingChainedTableInfo; 21 HashMap tablesMapping; HashMap iteratorMapping; HashMap columnsMapping; 24 _Iterator startingTableIterator; 25 _ServerSession serverSession; 26 ArrayList tableDetails; 27 28 public ForeignKeyIterator(_ServerSession serverSession0, 29 _Iterator startingTableIterator0, 30 HashMap tablesMapping0, 31 ChainedTableInfo cti0, 32 HashMap columnsMapping0, 33 ArrayList tableDetailsList0) throws DException { 34 this.serverSession = serverSession0; 35 this.startingTableIterator = startingTableIterator0; 36 this.tablesMapping = tablesMapping0; 37 this.startingChainedTableInfo = cti0; 38 this.columnsMapping = columnsMapping0; 39 this.tableDetails = tableDetailsList0; 40 iteratorMapping = new HashMap(); 41 iteratorMapping.put(startingChainedTableInfo.getChainedColumnInfo(), 42 startingTableIterator); 43 makeIterator(startingChainedTableInfo); 44 } 45 public _OrderCount getOrderCounts() throws DException { 46 47 throw new java.lang.UnsupportedOperationException ( 48 "Method getOrderCounts() not yet implemented."); 49 } 50 51 public void setKeyCount(Object [][] tt) throws DException{ 52 53 throw new java.lang.UnsupportedOperationException ( 54 "Method setKeyCount() not yet implemented."); 55 } 56 57 public TableDetails[] getTableDetails() throws DException { 58 return (TableDetails[]) tableDetails.toArray(new TableDetails[tableDetails. 59 size()]); 60 } 61 62 63 public _Iterator getBaseIterator(ColumnDetails column) throws DException { 64 65 throw new java.lang.UnsupportedOperationException ( 66 "Method getBaseIterator() not yet implemented."); 67 } 68 69 public void setConditionVariableValue(_Reference[] parm1, Object [] parm2, 70 int parm3) throws DException { 71 startingTableIterator.setConditionVariableValue(parm1, parm2, parm3); 72 } 73 74 public Object getColumnValues() throws DException { 75 Object [] tds = tableDetails.toArray(); 76 int valuesCount = 0; 77 for (int i = 0; i < tds.length; i++) { 78 valuesCount += ( (TableDetails) tds[i]).cc.getColumnCount(); 79 } 80 Object [] ccis = tablesMapping.keySet().toArray(); 81 Object [] values = new Object [valuesCount]; 82 int pos = 0; 83 for (int i = 0; i < tds.length; i++) { 84 Object [] val = (Object []) ( (_Iterator) iteratorMapping.get(ccis[i])). 85 getColumnValues(); 86 System.arraycopy(val, 0, values, pos, val.length); 87 pos = pos + val.length; 88 } 89 return values; 90 } 91 92 public _KeyColumnInformation[] getKeyColumnInformations() throws DException { 93 Object [] ccis = tablesMapping.keySet().toArray(); 94 ArrayList kcis = new ArrayList(); 95 for (int i = 0; i < ccis.length; i++) { 96 _KeyColumnInformation[] kci = ( (_Iterator) iteratorMapping.get(ccis[i])). 97 getKeyColumnInformations(); 98 for (int j = 0; j < kci.length; j++) { 99 kcis.add(kci[j]); 100 } 101 } 102 return (_KeyColumnInformation[]) (kcis.toArray(new _KeyColumnInformation[ 103 kcis.size()])); 104 } 105 106 public Object [] getUniqueColumnReference() throws DException { 107 108 throw new java.lang.UnsupportedOperationException ( 109 "Method getUniqueColumnReference() not yet implemented."); 110 } 111 112 public boolean seek(Object parm1) throws DException { 113 boolean found = startingTableIterator.seek(parm1); 114 if (found) { 115 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 116 } 117 return found; 118 } 119 120 public _Order getDefaultOrder() throws DException { 121 Object [] ccis = tablesMapping.keySet().toArray(); 122 ArrayList listOfCDs = new ArrayList(); 123 boolean[] array = null; 124 for (int i = 0; i < ccis.length; i++) { 125 _Order order = ( (_Iterator) iteratorMapping.get(ccis[i])). 126 getDefaultOrder(); 127 listOfCDs.addAll(Arrays.asList(order.getKeyColumnDetails())); 128 array = array == null ? order.getOrderOfColumns() : 129 concatenateBooleans(array, order.getOrderOfColumns()); 130 } 131 SelectOrder selectOrder = new SelectOrder( (ColumnDetails[]) listOfCDs. 132 toArray(new ColumnDetails[ 133 listOfCDs.size()]), array); 134 return selectOrder; 135 } 136 137 private boolean[] concatenateBooleans(boolean[] array, 138 boolean[] orderBooleans) throws 139 DException { 140 boolean[] newb = new boolean[array.length + orderBooleans.length]; 141 System.arraycopy(array, 0, newb, 0, array.length); 142 System.arraycopy(orderBooleans, 0, newb, array.length, orderBooleans.length); 143 return newb; 144 } 145 146 public Object getColumnValues(_Reference[] parm1) throws DException { 147 Object [] values = new Object [parm1.length]; 148 for (int i = 0; i < parm1.length; i++) { 149 String [] aliasName = ( (ColumnDetails) parm1[i]).getTableAliasArray(); 150 if (aliasName == null) 151 values[i] = startingTableIterator.getColumnValues(parm1); 152 _Iterator iterator = (_Iterator) iteratorMapping.get(columnsMapping.get( 153 aliasName)); 154 if (iterator != null) 155 values[i] = iterator.getColumnValues(parm1); 156 } 157 return values; 158 } 159 160 public Object getColumnValues(_Reference parm1) throws DException { 161 String [] aliasName = ( (ColumnDetails) parm1).getTableAliasArray(); 162 if (aliasName == null) 163 return startingTableIterator.getColumnValues(parm1); 164 _Iterator iterator = (_Iterator) iteratorMapping.get(columnsMapping.get( 165 aliasName)); 166 if (iterator != null) 167 return iterator.getColumnValues(parm1); 168 return null; } 170 171 public void setIterator(_Iterator parm1) throws DException { 172 173 throw new java.lang.UnsupportedOperationException ( 174 "Method setIterator() not yet implemented."); 175 } 176 177 public void addReferences(_Reference[] parm1) throws DException { 178 179 throw new java.lang.UnsupportedOperationException ( 180 "Method addReferences() not yet implemented."); 181 } 182 183 public Object [][] getReferenceAndValuePair() throws DException { 184 185 throw new java.lang.UnsupportedOperationException ( 186 "Method getReferenceAndValuePair() not yet implemented."); 187 } 188 189 public boolean seekFromTop(_IndexPredicate[] parm1) throws DException { 190 boolean found = startingTableIterator.seekFromTop(parm1); 191 if (found) { 192 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 193 } 194 return found; 195 } 196 197 public boolean seekFromTopRelative(Object parm1) throws DException { 198 boolean found = startingTableIterator.seekFromTopRelative(parm1); 199 if (found) { 200 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 201 } 202 return found; 203 } 204 205 public boolean seekFromBottom(_IndexPredicate[] parm1) throws DException { 206 boolean found = startingTableIterator.seekFromBottom(parm1); 207 if (found) { 208 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 209 } 210 return found; 211 } 212 213 public boolean seekFromBottomRelative(Object parm1) throws DException { 214 boolean found = startingTableIterator.seekFromBottomRelative(parm1); 215 if (found) { 216 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 217 } 218 return found; 219 } 220 221 public boolean first() throws DException { 222 boolean firstFound = startingTableIterator.first(); 223 if (firstFound) { 224 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 225 } 226 return firstFound; 227 } 228 229 public boolean last() throws DException { 230 boolean lastFound = startingTableIterator.last(); 231 if (lastFound) { 232 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 233 } 234 return lastFound; 235 } 236 237 public boolean next() throws DException { 238 boolean nextFound = startingTableIterator.next(); 239 if (nextFound) { 240 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 241 } 242 return nextFound; 243 } 244 245 public boolean previous() throws DException { 246 boolean preFound = startingTableIterator.previous(); 247 if (preFound) { 248 alignChilds(startingChainedTableInfo, startingTableIterator.getRecord()); 249 } 250 return preFound; 251 } 252 253 public Object getKey() throws DException { 254 return startingTableIterator.getKey(); 255 } 256 257 public void move(Object parm1) throws DException { 258 startingTableIterator.move(parm1); 259 } 260 261 public Object getColumnValues(int[] parm1) throws DException { 262 return startingTableIterator.getColumnValues(parm1); 263 } 264 265 public _Record getRecord() throws DException { 266 return startingTableIterator.getRecord(); 267 } 268 269 private void makeIterator(ChainedTableInfo startTableInfo) throws DException { 270 ArrayList childsTableInfos = startTableInfo.getChildsChainedTableInfo(); 271 if (childsTableInfos == null) 272 return; 273 for (int i = 0, size = childsTableInfos.size(); i < size; i++) { 274 ChainedTableInfo childTableInfo = (ChainedTableInfo) childsTableInfos.get( 275 i); 276 ChainedColumnInfo cci = childTableInfo.getChainedColumnInfo(); 277 IteratorInfo it = childTableInfo. 278 getReferencingToReferencedTableIteratorInfo(); 279 280 _SingleTableExecuter singleTableExecuter = new 281 ConditionSingleTableExecuter(null, it.tableDetails, serverSession, 282 it.bve, null); 283 284 _Iterator childIterator = serverSession.getIterator(childTableInfo. 285 getTableName(), singleTableExecuter); 286 iteratorMapping.put(cci, childIterator); 287 makeIterator(childTableInfo); 288 } 289 } 290 291 void alignChilds(ChainedTableInfo parent, _Record record) throws DException { 292 ArrayList childInfos = parent.getChildsChainedTableInfo(); 293 if (childInfos == null) { 294 ; return; 296 } 297 for (int i = 0, size = childInfos.size(); i < size; i++) { 298 ChainedTableInfo cti = (ChainedTableInfo) childInfos.get(i); 299 _Iterator it = (_Iterator) iteratorMapping.get(cti.getChainedColumnInfo()); 300 IteratorInfo itInfo = cti.getReferencingToReferencedTableIteratorInfo(); 301 it.setConditionVariableValue(itInfo.ref, 302 new Object [] {record.getObject(itInfo. 303 columnIndex)} 304 , 0); 305 boolean first = it.first(); 306 if (first == false) 307 continue; 308 else 309 alignChilds(cti, it.getRecord()); 310 } 311 } 312 313 public TemporaryForeignKeyIterator getTemporaryIterator(QualifiedIdentifier 314 tableName, 315 _Iterator singleRowIterator) throws DException { 316 return new TemporaryForeignKeyIterator(serverSession, tablesMapping, 317 singleRowIterator, tableName, 318 columnsMapping); 319 } 320 321 public Object getColumnValues(int column) throws DException { 322 323 throw new java.lang.UnsupportedOperationException ( 324 "Method getColumnValues() not yet implemented."); 325 } 326 327 public _ExecutionPlan getExecutionPlan() throws DException { 328 _ExecutionPlan cplan = startingTableIterator.getExecutionPlan(); 329 _ExecutionPlan cplans[] = cplan == null ? null : new _ExecutionPlan[] { 330 cplan}; 331 ExecutionPlan plan = new ExecutionPlan("ForeignKeyIterator", cplans, null, null, null); 332 return plan; 333 } 334 335 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 336 return startingTableIterator.getExecutionPlanForBrowser(); 337 } 338 339 public _Iterator getBaseIteratorHasRecord(ColumnDetails hasRecordColumn) throws 340 DException { 341 throw new DException("DSE565", new Object [] {"getBaseIterator"}); 342 343 } 344 345 public Object [][] getFunctionalColumnMapping() throws DException { 346 throw new UnsupportedOperationException ("Method not Supported"); 347 } 348 349 public FieldBase field(_Reference reference) throws com.daffodilwoods. 350 database.resource.DException { 351 throw new java.lang.UnsupportedOperationException ( 352 "Method not yet implemented."); 353 } 354 355 public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods. 356 database.resource.DException { 357 throw new java.lang.UnsupportedOperationException ( 358 "Method fields() not yet implemented."); 359 } 360 361 public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database. 362 resource.DException { 363 throw new java.lang.UnsupportedOperationException ( 364 "Method fields() not yet implemented."); 365 } 366 367 public void releaseResource() throws DException { 368 369 } 370 public byte[] getByteKey() throws DException{ 371 throw new java.lang.UnsupportedOperationException ( 372 "Method getByteKey() not yet implemented."); 373 } 374 public void moveByteKey(byte[] key) throws DException{ 375 throw new java.lang.UnsupportedOperationException ( 376 "Method mByteKey() not yet implemented."); 377 } 378 379 public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{ 380 throw new java.lang.UnsupportedOperationException ( 381 "Method setSpecificUnderlyingReferences() not yet implemented."); 382 } 383 384 } 385 | Popular Tags |