1 package com.daffodilwoods.daffodildb.server.sessionsystem; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.client.*; 6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 7 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record; 8 import com.daffodilwoods.daffodildb.server.sessionsystem.sessioncondition.*; 9 import com.daffodilwoods.daffodildb.server.sql99.common.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 12 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 13 import com.daffodilwoods.daffodildb.utils.comparator.*; 14 import com.daffodilwoods.daffodildb.utils.field.*; 15 import com.daffodilwoods.database.resource.*; 16 import com.daffodilwoods.database.sqlinitiator.*; 17 import com.daffodilwoods.database.general.SystemFields; 18 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem. 19 DatabaseConstants; 20 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs; 21 import com.daffodilwoods.daffodildb.utils.BufferRange; 22 import com.daffodilwoods.daffodildb.utils.FieldUtility; 23 import com.daffodilwoods.database.utility.P; 24 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation. 25 constraintsystem.UniqueConstraintException; 26 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation. 27 constraintsystem.ForeignConstraintException; 28 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation. 29 constraintsystem.PrimaryAndUniqueConstraintVerifier; 30 import com.daffodilwoods.daffodildb.utils.comparator.CKpjoDpnqbsbups; 31 32 public class RowIdSessionIterator 33 extends BaseExceptionSingleIterator 34 implements _Iterator, _TableOperations, _IndexIteratorInfo { 35 _Iterator iterator, fileIterator, memoryIterator; 36 _SessionCondition sessionCondition; 37 int[] columnIndexesUntillRowID; 38 SuperComparator objectComparator; 39 boolean usingOlderVersion = false; 40 41 42 public RowIdSessionIterator(_Iterator iterator0, 43 _SessionCondition sessionCondition0) { 44 iterator = iterator0; 45 sessionCondition = sessionCondition0; 46 47 Object [] allColumns = null; 48 try { 49 allColumns = iterator.getUniqueColumnReference(); 50 int[] cloumnIndexes = (int[])allColumns[0]; 51 usingOlderVersion = cloumnIndexes.length != 1; 52 String [] columnNames = (String [])allColumns[1]; 53 ArrayList list = new ArrayList(); 54 55 for (int i = 0; i < columnNames.length; i++) { 56 list.add(new Integer (cloumnIndexes[i])); 57 if((columnNames[i].equalsIgnoreCase(SystemFields.systemFields[SystemFields.rowId]))){ 58 break; 59 } 60 } 61 62 columnIndexesUntillRowID = new int[list.size()]; 63 for (int j = 0; j < list.size(); j++) { 64 columnIndexesUntillRowID[j] = ((Integer )list.get(j)).intValue(); 65 } 66 objectComparator = ((_IndexIteratorInfo)iterator).getComparator(); 67 } 68 catch (Exception ex) { 69 } 70 } 71 72 public void setKeyCount(Object [][] tableAndKeyCount) throws DException { 73 74 throw new java.lang.UnsupportedOperationException ( 75 "Method setKeyCount() not yet implemented."); 76 } 77 78 public _OrderCount getOrderCounts() throws com.daffodilwoods.database. 79 resource.DException { 80 return iterator.getOrderCounts(); 81 } 82 83 public TableDetails[] getTableDetails() throws com.daffodilwoods.database. 84 resource.DException { 85 return iterator.getTableDetails(); 86 } 87 88 public _Iterator getBaseIterator(ColumnDetails column) throws com. 89 daffodilwoods.database.resource.DException { 90 return iterator.getBaseIterator(column); 91 } 92 93 public void setConditionVariableValue(_Reference[] parm1, Object [] parm2, 94 int parm3) throws com.daffodilwoods. 95 database.resource.DException { 96 iterator.setConditionVariableValue(parm1, parm2, parm3); 97 } 98 99 public Object getColumnValues() throws com.daffodilwoods.database.resource. 100 DException { 101 return iterator.getColumnValues(); 102 } 103 104 public _KeyColumnInformation[] getKeyColumnInformations() throws com. 105 daffodilwoods.database.resource.DException { 106 _KeyColumnInformation[] keyColumnInformation = iterator. 107 getKeyColumnInformations(); 108 if (columnIndexesUntillRowID == null) 109 return keyColumnInformation; 110 _KeyColumnInformation[] keyColumnInformationToReturn = new 111 _KeyColumnInformation[columnIndexesUntillRowID.length]; 112 for (int i = 0; i < columnIndexesUntillRowID.length; i++) { 113 keyColumnInformationToReturn[i] = keyColumnInformation[i]; 114 } 115 116 return keyColumnInformationToReturn; 117 } 118 119 public Object [] getUniqueColumnReference() throws com.daffodilwoods.database. 120 resource.DException { 121 return iterator.getUniqueColumnReference(); 122 } 123 124 public boolean seek(Object parm1) throws com.daffodilwoods.database.resource. 125 DException { 126 if (columnIndexesUntillRowID == null) { 127 boolean val = iterator.seek(parm1); 128 return val; 129 } 130 if (! (parm1 instanceof Object [])) 131 parm1 = new Object [] { 132 parm1}; 133 if (!iterator.seek(parm1)) { 134 return false; 135 } 136 137 int length = ( (Object []) parm1).length; 138 int[] subSetValues = new int[length]; 139 System.arraycopy(columnIndexesUntillRowID, 0, subSetValues, 0, length); 140 boolean isNext = false; 141 do { 142 Object [] iteratorValues = (Object []) iterator.getColumnValues(subSetValues); 143 if (objectComparator.compare( getBufferKey(iteratorValues) , getBufferKey((Object [])parm1)) != 0) 144 return false; 145 if (sessionCondition.evaluate(iterator)) { 146 return true; 147 } 148 isNext = iterator.next(); 149 } 150 while (isNext); 151 return false; 152 } 153 154 155 public _Order getDefaultOrder() throws com.daffodilwoods.database.resource. 156 DException { 157 return iterator.getDefaultOrder(); 158 } 159 160 public Object getColumnValues(_Reference[] parm1) throws com.daffodilwoods. 161 database.resource.DException { 162 return iterator.getColumnValues(parm1); 163 } 164 165 public Object getColumnValues(_Reference parm1) throws com.daffodilwoods. 166 database.resource.DException { 167 return iterator.getColumnValues(parm1); 168 } 169 170 public boolean seekFromTop(_IndexPredicate[] parm1) throws com.daffodilwoods. 171 database.resource.DException { 172 return iterator.seekFromTop(parm1); 173 } 174 175 public boolean seekFromTopRelative(Object parm1) throws com.daffodilwoods. 176 database.resource.DException { 177 return iterator.seekFromTopRelative(parm1); 178 } 179 180 public boolean seekFromBottom(_IndexPredicate[] parm1) throws com. 181 daffodilwoods.database.resource.DException { 182 return iterator.seekFromBottom(parm1); 183 } 184 185 public boolean seekFromBottomRelative(Object parm1) throws com.daffodilwoods. 186 database.resource.DException { 187 return iterator.seekFromBottomRelative(parm1); 188 } 189 190 public boolean first() throws com.daffodilwoods.database.resource.DException { 191 return iterator.first(); 192 } 193 194 public boolean last() throws com.daffodilwoods.database.resource.DException { 195 return iterator.last(); 196 } 197 198 public boolean next() throws com.daffodilwoods.database.resource.DException { 199 return iterator.next(); 200 } 201 202 public boolean previous() throws com.daffodilwoods.database.resource. 203 DException { 204 return iterator.previous(); 205 } 206 207 public Object getKey() throws com.daffodilwoods.database.resource.DException { 208 209 return iterator.getColumnValues(columnIndexesUntillRowID); 210 } 211 212 public void move(Object parm1) throws com.daffodilwoods.database.resource. 213 DException { 214 if (!seek(parm1)) { 215 216 217 throw new DException("DSE5518", null); 218 } 219 } 220 221 public Object getColumnValues(int[] parm1) throws com.daffodilwoods.database. 222 resource.DException { 223 return iterator.getColumnValues(parm1); 224 } 225 226 public _Record getRecord() throws com.daffodilwoods.database.resource. 227 DException { 228 return iterator.getRecord(); 229 } 230 231 public void insert(Object parm1) throws com.daffodilwoods.database.resource. 232 DException { 233 ( (_TableOperations) iterator).insert(parm1); 234 } 235 236 public void update(Object parm1) throws com.daffodilwoods.database.resource. 237 DException { 238 ( (_TableOperations) iterator).update(parm1); 239 } 240 241 public void update(int[] parm1, Object [] parm2) throws com.daffodilwoods. 242 database.resource.DException { 243 ( (_TableOperations) iterator).update(parm1, parm2); 244 } 245 246 public void delete() throws com.daffodilwoods.database.resource.DException { 247 ( (_TableOperations) iterator).delete(); 248 } 249 250 public int getBtreeIndex() throws com.daffodilwoods.database.resource. 251 DException { 252 return ( (_IndexIteratorInfo) iterator).getBtreeIndex(); 253 } 254 255 public boolean locateKey(Object parm1, boolean parm2) throws com. 256 daffodilwoods.database.resource.DException { 257 return ( (_IndexIteratorInfo) iterator).locateKey(parm1, parm2); 258 } 259 260 261 public void ensureRecordInMemory() throws com.daffodilwoods.database.resource. 262 DException { 263 ( (_IndexIteratorInfo) iterator).ensureRecordInMemory(); 264 265 } 266 267 public void moveOnActualKey(Object parm1) throws com.daffodilwoods.database. 268 resource.DException { 269 iterator.seek(parm1); 270 } 271 272 public Object getActualKey() throws com.daffodilwoods.database.resource. 273 DException { 274 return iterator.getKey(); 275 } 276 277 public String toString() { 278 return "RowIdSessionIterator[" + iterator + "]"; 279 } 280 281 public Object getColumnValues(int column) throws DException { 282 283 throw new java.lang.UnsupportedOperationException ( 284 "Method getColumnValues() not yet implemented."); 285 } 286 287 public _ExecutionPlan getExecutionPlan() throws DException { 288 _ExecutionPlan plan = iterator.getExecutionPlan(); 289 _ExecutionPlan cplans[] = plan == null ? null : new _ExecutionPlan[] { 290 plan}; 291 return new ExecutionPlan("RowIdSessionIterator", cplans, 292 " SessionCondition " + sessionCondition, null, null); 293 } 294 295 public boolean seekKeyAddress(Object parm1) throws com.daffodilwoods.database. 296 resource.DException { 297 return ( (_IndexIteratorInfo) iterator).seekKeyAddress(parm1); 298 } 299 300 public Object getPhysicalAddress() throws com.daffodilwoods.database.resource. 301 DException { 302 303 throw new java.lang.UnsupportedOperationException ( 304 "Method getPhysicalAddress() not yet implemented."); 305 } 306 307 public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException { 308 return iterator.getExecutionPlanForBrowser(); 309 } 310 311 public SuperComparator getComparator() { 312 return ( (_IndexIteratorInfo) iterator).getComparator(); 313 } 314 315 public SuperComparator getObjectComparator() throws com.daffodilwoods. 316 database.resource.DException { 317 return objectComparator; 318 } 319 320 public _Iterator getBaseIteratorHasRecord(ColumnDetails hasRecordColumn) throws 321 DException { 322 return iterator.getBaseIteratorHasRecord(hasRecordColumn); 323 } 324 325 public FieldBase field(_Reference reference) throws com.daffodilwoods. 326 database.resource.DException { 327 return iterator.field(reference); 328 } 329 330 public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods. 331 database.resource.DException { 332 return iterator.fields(references); 333 } 334 335 public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database. 336 resource.DException { 337 return iterator.fields(columns); 338 } 339 340 public void releaseResource() throws DException { 341 iterator.releaseResource(); 342 } 343 344 public byte[] getByteKey() throws DException { 345 FieldBase[] columnValues = FieldUtility.changeIntoFildBase(getKey()); 346 int numberOfColumns = columnValues.length; 347 int totalLengthOfKey = numberOfColumns * 2 * SessionIterator.LENGTH + 348 SessionIterator.LENGTH; 349 for (int i = 0; i < numberOfColumns; i++) { 350 totalLengthOfKey += columnValues[i].getLength(); 351 } 352 byte[] byteKey = new byte[totalLengthOfKey]; 353 int pointer = 0; 354 System.arraycopy(CCzufDpowfsufs.getBytes( (short) numberOfColumns), 0, 355 byteKey, pointer, SessionIterator.LENGTH); 356 pointer += SessionIterator.LENGTH; 357 for (int i = 0; i < numberOfColumns; i++) { 358 short dataType = (short) columnValues[i].getDatatype(); 359 short length = 0; 360 byte[] columnValue = new byte[] {}; 361 if (!columnValues[i].isNull()) { 362 columnValue = columnValues[i].getBytes(); 363 length = (short) columnValue.length; 364 } 365 System.arraycopy(CCzufDpowfsufs.getBytes(dataType), 0, byteKey, pointer, 366 SessionIterator.LENGTH); 367 pointer += SessionIterator.LENGTH; 368 System.arraycopy(CCzufDpowfsufs.getBytes(length), 0, byteKey, pointer, 369 SessionIterator.LENGTH); 370 pointer += SessionIterator.LENGTH; 371 System.arraycopy(columnValue, 0, byteKey, pointer, length); 372 pointer += length; 373 } 374 return byteKey; 375 } 376 377 public void moveByteKey(byte[] key) throws DException { 378 int pointer = 0; 379 int numberOfColumns = CCzufDpowfsufs.getShortValue(key, pointer); 380 pointer += SessionIterator.LENGTH; 381 Object [] columnValues = new Object [numberOfColumns]; 382 for (int i = 0; i < numberOfColumns; i++) { 383 int dataType = CCzufDpowfsufs.getShortValue(key, pointer); 384 pointer += SessionIterator.LENGTH; 385 int columnLength = CCzufDpowfsufs.getShortValue(key, pointer); 386 pointer += SessionIterator.LENGTH; 387 byte[] b = new byte[columnLength]; 388 System.arraycopy(key, pointer, b, 0, columnLength); 389 BufferRange buffer = null; 390 if (columnLength == 0) 391 buffer = FieldUtility.NULLBUFFERRANGE; 392 else 393 buffer = new BufferRange(b, 0, columnLength); 394 columnValues[i] = FieldUtility.getField(dataType, buffer); 395 pointer += columnLength; 396 } 397 move(columnValues); 398 } 399 400 public void setOptimalIteartors(_Iterator memory, _Iterator file) { 401 memoryIterator = memory; 402 fileIterator = file; 403 } 404 405 public void seekForPrimary(Object [] parm1, int[] columns) throws DException { 406 if (fileIterator.seek(parm1)) { 407 Object rowid = fileIterator.getColumnValues(SessionConditionReferences. 408 rowIdReference_0); 409 if (memoryIterator.seek(parm1)) 410 do { 411 Object [] primaryColumns = (Object []) memoryIterator.getColumnValues( 412 columns); 413 if (!Arrays.equals(parm1, primaryColumns)) { 414 return; 415 } 416 if (sessionCondition.evaluate(memoryIterator)) { 417 Object memoryRowId = memoryIterator.getColumnValues( 418 SessionConditionReferences.rowIdReference_0); 419 if (!rowid.equals(memoryRowId)) 420 throw new UniqueConstraintException("DSE1032", null); 421 } 422 } 423 while (memoryIterator.next()); 424 } 425 else { 426 if (memoryIterator.seek(parm1)) { 427 Object rowid = null; do { 429 Object [] primaryColumns = (Object []) memoryIterator.getColumnValues( 430 columns); 431 if (!Arrays.equals(parm1, primaryColumns)) { 432 return; 433 } 434 if (sessionCondition.evaluate(memoryIterator)) { 435 Object memoryRowId = memoryIterator.getColumnValues( 436 SessionConditionReferences.rowIdReference_0); 437 if (rowid == null) 438 rowid = memoryRowId; 439 else if (!rowid.equals(memoryRowId)) 440 throw new UniqueConstraintException("DSE1032", null); 441 } 442 } 443 while (memoryIterator.next()); 444 } 445 } 446 } 447 448 public void seekForReferencing(Object [] parm1, int[] columns, 449 String constraintName, String tableName, CKpjoDpnqbsbups comp) throws 450 DException { 451 if (fileIterator.seek(parm1)) { 452 if (memoryIterator.seek(parm1)) { 453 do { 454 Object [] primaryColumns = (Object []) memoryIterator.getColumnValues(columns); 455 if (!Arrays.equals(parm1, primaryColumns)) { 456 throw new ForeignConstraintException("DSE382", 457 new Object [] {constraintName, 458 tableName}); 459 } 460 if (sessionCondition.evaluate(memoryIterator)) { 461 return; 462 } 463 } 464 while (memoryIterator.next()); 465 throw new ForeignConstraintException("DSE382", 466 new Object [] {constraintName, 467 tableName}); 468 469 } 470 else { 471 return; 472 } 473 } 474 else { 475 if (memoryIterator.seek(parm1)) { 476 do { 477 Object [] primaryColumns = (Object []) memoryIterator.getColumnValues( 478 columns); 479 if(comp.compare(parm1,primaryColumns) != 0){ 480 throw new DException("DSE1026",new Object []{constraintName , tableName } ); 481 } 482 483 if (sessionCondition.evaluate(memoryIterator)) { 484 return; 485 } 486 } 487 while (memoryIterator.next()); 488 } 489 else { 490 throw new ForeignConstraintException("DSE382", 491 new Object [] {constraintName, 492 tableName}); 493 } 494 } 495 496 } 497 private Object getBufferKey(Object [] key) throws DException{ 498 if (columnIndexesUntillRowID.length == 1) { 499 if (usingOlderVersion) 500 return new BufferRange[] { 501 ( (FieldBase) key[0]).getBufferRange()}; 502 else 503 return ( (FieldBase) key[0]).getBufferRange(); 504 } 505 return key; 506 } 507 508 public void deleteBlobClobRecord(_DatabaseUser user) throws com.daffodilwoods.database.resource.DException { 509 ( (_TableOperations) iterator).deleteBlobClobRecord(user) ; 510 } 511 512 513 } 514 | Popular Tags |