1 package com.daffodilwoods.daffodildb.server.datasystem.indexsystem; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.btree.*; 4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 5 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.*; 6 import com.daffodilwoods.daffodildb.server.datasystem.utility.*; 7 import com.daffodilwoods.daffodildb.server.datasystem.utility._Record; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 9 import com.daffodilwoods.daffodildb.utils.*; 10 import com.daffodilwoods.daffodildb.utils.field.*; 11 import com.daffodilwoods.database.general.*; 12 import com.daffodilwoods.database.resource.*; 13 import com.daffodilwoods.database.utility.*; 14 import com.daffodilwoods.fulltext.common._FullTextDML; 15 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dml. 16 _FullTextIndexInformation; 17 18 21 22 public class ColumnObjectsTable implements _IndexTableList, _IndexTable { 23 24 27 protected _IndexTableList table; 28 29 32 protected TableCharacteristics tableCharacteristics; 33 34 37 38 private QualifiedIdentifier tableName; 39 40 43 44 private _DataTable dataTable; 45 int defaultIndex = -1; 46 47 public ColumnObjectsTable(_DataTable tab, QualifiedIdentifier tableName0, 48 LobManager lobManager0) throws DException { 49 dataTable = tab; 50 tableName = tableName0; 51 tableCharacteristics = (TableCharacteristics) dataTable. 52 getTableCharacteristics(); 53 54 } 55 56 69 70 public Object insert(_TableIterator iterator, _DatabaseUser user, 71 Object [] values, int index) throws DException { 72 insertIntoFullTextDML(user, values); 73 return table.insert(iterator, user, 74 tableCharacteristics.getBufferRange(values), index); 75 } 76 77 88 89 public Object update(_TableIterator iterator, _DatabaseUser user, 90 Object [] values, int index) throws DException { 91 updateIntoFullTextDML(user, values, iterator); 92 BufferRange[] bytes = tableCharacteristics.getBufferRange(values); 93 return table.update(iterator, user, bytes, index); 94 } 95 96 public Object delete(_TableIterator iterator, _DatabaseUser user, int index) throws 97 DException { 98 deleteFromFullTextDML(user, iterator); 99 return table.delete(iterator, user, index); 100 } 101 102 public _IndexTableList getTable() { 103 return table; 104 } 105 106 public void setTable(_IndexTableList table1) throws DException { 107 table = table1; 108 _IndexInformation[] iinf = getIndexInformations(); 109 for (int i = 0; i < iinf.length; i++) { 110 if (iinf[i].isDefault()) { 111 defaultIndex = i; 112 break; 113 } 114 } 115 116 if (defaultIndex == -1) { 117 for (int i = 0; i < iinf.length; i++) { 118 ; 120 121 } 122 } 123 } 124 125 public Object getColumnObjects(_TableIterator iterator, int[] columns) throws 126 DException { 127 Object [] values = (Object []) iterator.getColumnValues(columns); 128 FieldBase[] temp = new FieldBase[columns.length]; 129 for (int i = 0; i < columns.length; i++) 130 temp[i] = (FieldBase) tableCharacteristics.getObject(columns[i], 131 (BufferRange) values[i]); 132 return temp; 133 } 134 135 public _TableCharacteristics getTableCharacteristics() throws DException { 136 return tableCharacteristics; 137 } 138 139 public Object insert(_TableIterator iterator, Object [] values, int index) throws 140 DException { 141 return table.insert(iterator, convertValuesIntoBytes(values), index); 142 } 143 144 public Object update(_TableIterator iterator, Object [] values, int index) throws 145 DException { 146 return table.update(iterator, convertValuesIntoBytes(values), index); 147 } 148 149 public Object delete(_TableIterator iterator, int index) throws DException { 150 return table.delete(iterator, index); 151 } 152 153 public Object getColumnObjects(_TableIterator iterator, int column) throws 154 DException { 155 return (FieldBase) tableCharacteristics.getObject(column, 156 (BufferRange) iterator.getColumnValues(column)); 157 158 } 159 160 161 public Object getColumnObjects(_TableIterator iterator) throws DException { 162 Object [] bytes = (Object []) iterator.getColumnValues(); 163 FieldBase[] values = new FieldBase[bytes.length]; 164 for (int i = 0, count = tableCharacteristics.getColumnCount(); i < count; i++) 165 values[i] = (FieldBase) tableCharacteristics.getObject(i, 166 (BufferRange) bytes[i]); 167 return values; 168 } 169 170 public _IndexInformation[] getIndexInformations() throws com.daffodilwoods. 171 database.resource.DException { 172 return table.getIndexInformations(); 173 } 174 175 public _Iterator getIterator(int index) throws com.daffodilwoods.database. 176 resource.DException { 177 _IndexIterator it = new IndexTableIterator(this, index, 178 dataTable.getIterator()); 179 IteratorWrapper iw = new IteratorWrapper(it); 180 iw.setTableName(tableName); 181 return iw; 182 } 183 184 public _Index getIndex(int position) { 185 return table.getIndex(position); 186 } 187 188 public _Index[] getIndexes() throws DException { 189 return table.getIndexes(); 190 } 191 192 public void setFullTextDML(_FullTextDML fullTextDML[]) throws DException { 193 table.setFullTextDML(fullTextDML); 194 } 195 196 public _FullTextDML[] getFullTextDML() throws DException { 197 return table.getFullTextDML(); 198 } 199 200 public _Record getBlankRecord() throws com.daffodilwoods.database.resource. 201 DException { 202 return new Record(tableCharacteristics, 203 new Object [tableCharacteristics.getColumnCount()]); 204 } 205 206 public void rollback() throws DException { 207 if (table instanceof Table) { 208 table.rollback(); 209 ( (Table) dataTable).rollBack(); 210 } 211 } 212 213 public Object seek(_Index btree, Object indexKey) throws DException { 214 return btree.seek(getSeekKey(indexKey, btree.getIndexInformation().getColumnIndexes())); 215 } 216 217 public Object seekFromTopRelative(_Index btree, Object currentKey, 218 Object indexKey) throws DException { 219 return btree.seekFromTopRelative(currentKey, 220 getSeekKey(indexKey, btree.getIndexInformation().getColumnIndexes())); 221 222 } 223 224 public Object seekFromBottomRelative(_Index btree, Object currentKey, 225 Object indexKey) throws DException { 226 return btree.seekFromBottomRelative(currentKey, 227 getSeekKey(indexKey, btree.getIndexInformation().getColumnIndexes())); 228 } 229 230 public Object locateKey(_Index btree, Object indexKey, boolean flag) throws 231 DException { 232 _IndexKey locateKey = (_IndexKey) btree.locateKey(getSeekKey(indexKey, btree.getIndexInformation().getColumnIndexes()), 233 flag); 234 return locateKey; 235 } 236 237 public void setIndexes(_Index btrees[]) throws DException { 238 table.setIndexes(btrees); 239 } 240 241 public _Iterator getDefaultIterator() throws com.daffodilwoods.database. 242 resource.DException { 243 if (defaultIndex == -1) 244 throw new DException("DSE2015", new Object [] {tableName.toString()}); 245 IteratorWrapper iw = new IteratorWrapper(new IndexTableIterator(this, 246 defaultIndex, 247 dataTable.getIterator())); 248 iw.setTableName(tableName); 249 return iw; 250 } 251 252 public int getEstimatedRowCount() throws com.daffodilwoods.database.resource. 253 DException { 254 return ( (_IndexTable) table).getEstimatedRowCount(); 255 } 256 257 public String toString() { 258 return "" + tableName; 259 } 260 261 262 270 271 public Object update(_TableIterator iterator, _DatabaseUser user, 272 int[] columns, Object [] columnValues, int index) throws 273 DException { 274 BufferRange[] bytes = (BufferRange[]) iterator.getColumnValues(); 275 updateIntoFullTextDML(user, columnValues, bytes, columns); 276 277 BufferRange[] bytesOfColumns = tableCharacteristics.getBufferRange(columns, 278 columnValues); 279 for (int i = 0; i < columns.length; i++) 280 bytes[columns[i]] = bytesOfColumns[i]; 281 return table.update(iterator, user, columns, bytes, index); 282 } 283 284 public Object update(_TableIterator iterator, int[] columns, Object [] values, 285 int index) throws DException { 286 Object [] rowBytes = (Object []) iterator.getColumnValues(); 287 Object [] tempValues = new Object [rowBytes.length]; 288 System.arraycopy(rowBytes, 0, tempValues, 0, rowBytes.length); 289 for (int i = 0; i < values.length; i++) { 290 tempValues[columns[i]] = !tableCharacteristics.isBlobClob(columns[i]) ? 291 ( (FieldBase) values[i]).getBufferRange() 292 : values[i]; 293 } 294 return table.update(iterator, columns, tempValues, index); 295 } 296 297 private Object getSeekKey(Object indexKey, int[] columnIndexes) throws 298 DException { 299 if (columnIndexes.length == 1) { 300 if (! (indexKey instanceof BufferRange) && 301 ! (indexKey instanceof BufferRange[])) { 302 try { 303 indexKey = tableCharacteristics.getBufferRange(columnIndexes[0], 304 indexKey); 305 } catch (ClassCastException ex) { 306 indexKey = tableCharacteristics.getBufferRange(columnIndexes[0], 307 ( (Object []) indexKey)[0]); 308 } 309 } 310 } else { 311 Object [] key = (Object []) indexKey; 312 int[] seekColumns = new int[key.length]; 313 for (int i = 0; i < key.length; i++) 314 seekColumns[i] = columnIndexes[i]; 315 if (! (key[0] instanceof BufferRange)) 316 indexKey = tableCharacteristics.getBufferRange(seekColumns, 317 (Object []) indexKey); 318 319 } 320 321 return indexKey; 322 } 323 324 private Object [] convertValuesIntoBytes(Object [] values) throws DException { 325 int length = values.length; 326 Object [] bytes = new Object [length]; 327 for (int i = 0; i < length; i++) 328 bytes[i] = ( (FieldBase) values[i]).getBufferRange(); 329 return bytes; 330 } 331 332 338 public ReadWriteLock getLock() { 339 return table.getLock(); 340 } 341 342 public boolean isAnyIndexUpdated(int[] columns) throws DException { 343 return table.isAnyIndexUpdated(columns); 344 } 345 346 public _FullTextIndexInformation[] getFullTextIndexInformation() throws 347 DException { 348 return table.getFullTextIndexInformation(); 349 } 350 351 public _Database getDatabase() throws DException { 352 return table.getDatabase(); 353 } 354 355 363 private void insertIntoFullTextDML(_DatabaseUser user, Object [] values) throws 364 DException { 365 _FullTextDML[] fullTextDML = table.getFullTextDML(); 366 if (fullTextDML != null) { 367 Object rowid = values[SystemFields.rowId]; 368 int[] columnIndex; 369 Object valuesToInsert[]; 370 for (int i = 0; i < fullTextDML.length; i++) { 371 columnIndex = fullTextDML[i].getColumnIndex(); 372 valuesToInsert = new FieldBase[columnIndex.length]; 373 for (int k = 0; k < columnIndex.length; k++) 374 valuesToInsert[k] = values[columnIndex[k]]; 375 fullTextDML[i].insert(user, valuesToInsert, rowid); 376 } 377 } 378 379 } 380 381 389 390 private void updateIntoFullTextDML(_DatabaseUser user, Object [] newValues, 391 _TableIterator iterator) throws DException { 392 _FullTextDML[] fullTextDML = table.getFullTextDML(); 393 if (fullTextDML != null) { 394 BufferRange[] oldValues = (BufferRange[]) iterator.getColumnValues(); 395 Object rowid = newValues[SystemFields.rowId]; 396 int[] columnIndex; 397 Object valuesToUpdate[], oldValuesInDML[]; 398 for (int i = 0; i < fullTextDML.length; i++) { 399 columnIndex = fullTextDML[i].getColumnIndex(); 400 valuesToUpdate = new FieldBase[columnIndex.length]; 401 oldValuesInDML = new FieldBase[columnIndex.length]; 402 for (int k = 0; k < columnIndex.length; k++) { 403 oldValuesInDML[k] = tableCharacteristics.getObject(columnIndex[k], 404 ( (BufferRange[]) oldValues)[columnIndex[k]]); 405 valuesToUpdate[k] = newValues[columnIndex[k]]; 406 } 407 fullTextDML[i].update(user, oldValuesInDML, valuesToUpdate, rowid); 408 } 409 } 410 411 } 412 413 421 private void updateIntoFullTextDML(_DatabaseUser user, Object [] newValues, 422 Object oldValues, int[] columnIndexes) throws 423 DException { 424 _FullTextDML[] fullTextDML = table.getFullTextDML(); 425 if (fullTextDML != null) { 426 Object rowid = newValues[SystemFields.rowId]; 427 int[] columnIndex; 428 Object valuesToUpdate[], oldValuesInDML[]; 429 for (int i = 0; i < fullTextDML.length; i++) { 430 columnIndex = fullTextDML[i].getColumnIndex(); 431 valuesToUpdate = new FieldBase[columnIndex.length]; 432 oldValuesInDML = new FieldBase[columnIndex.length]; 433 boolean isAnyColumnUpdated = false; 434 int colIndex; 435 for (int k = 0; k < columnIndex.length; k++) { 436 colIndex = checkUpdateColumnsInFullText(columnIndexes, 437 columnIndex[k]); 438 oldValuesInDML[k] = tableCharacteristics.getObject(columnIndex[k], 439 ( (BufferRange[]) oldValues)[columnIndex[k]]); 440 if (colIndex != -1) { 441 isAnyColumnUpdated = true; 442 443 valuesToUpdate[k] = newValues[colIndex]; 444 } else { 445 valuesToUpdate[k] = oldValuesInDML[k]; 446 } 447 448 } 449 if (isAnyColumnUpdated) fullTextDML[i].update(user, oldValuesInDML, valuesToUpdate, rowid); 451 } 452 } 453 454 } 455 456 private int checkUpdateColumnsInFullText(int[] updateColumns, 457 int fullTextColumn) { 458 for (int i = 0; i < updateColumns.length; i++) { 459 if (updateColumns[i] == fullTextColumn) 460 return i; 461 } 462 return -1; 463 } 464 465 472 private void deleteFromFullTextDML(_DatabaseUser user, 473 _TableIterator iterator) throws DException { 474 _FullTextDML[] fullTextDML = table.getFullTextDML(); 475 if (fullTextDML != null) { 476 BufferRange[] values = (BufferRange[]) iterator.getColumnValues(); 477 Object rowid = tableCharacteristics.getObject(SystemFields.rowId, 478 ( (BufferRange[]) values)[SystemFields.rowId]); 479 for (int i = 0; i < fullTextDML.length; i++) 480 fullTextDML[i].delete(user, rowid); 481 } 482 } 483 484 public void setDuplicateKeysAllowedInBtrees() throws DException { 485 ( (_IndexTable) table).setDuplicateKeysAllowedInBtrees(); 486 } 487 488 public Object deleteBlobClobRecord(_TableIterator iterator, _DatabaseUser user, int index) throws 489 DException { 490 deleteFromFullTextDML(user, iterator); 491 return table.deleteBlobClobRecord(iterator, user, index); 492 } 493 494 495 525 } 526 | Popular Tags |