1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 import org.apache.derby.iapi.error.StandardException; 26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 27 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator; 28 import org.apache.derby.iapi.sql.execute.ExecRow; 29 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 30 31 import org.apache.derby.iapi.sql.Activation; 32 33 import org.apache.derby.iapi.store.access.ConglomerateController; 34 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo; 35 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo; 36 import org.apache.derby.iapi.store.access.TransactionController; 37 38 import org.apache.derby.iapi.types.RowLocation; 39 40 import org.apache.derby.iapi.services.io.FormatableBitSet; 41 42 46 public class IndexSetChanger 47 { 48 IndexRowGenerator[] irgs; 51 long[] indexCIDS; 55 private DynamicCompiledOpenConglomInfo[] indexDCOCIs; 56 private StaticCompiledOpenConglomInfo[] indexSCOCIs; 57 String [] indexNames; 58 ConglomerateController baseCC; 59 FormatableBitSet baseRowReadMap; 60 61 TransactionController tc; 63 64 TemporaryRowHolderImpl rowHolder; 65 66 IndexChanger[] indexChangers; 67 68 private int lockMode; 70 71 boolean[] fixOnUpdate; 73 74 boolean isOpen = false; 75 76 private static final int NO_INDEXES = 0; 79 private static final int UPDATE_INDEXES = 1; 82 private static final int ALL_INDEXES = 2; 85 86 private int whatIsOpen = NO_INDEXES; 89 90 private int isolationLevel; 91 private Activation activation; 92 93 112 public IndexSetChanger(IndexRowGenerator[] irgs, 113 long[] indexCIDS, 114 StaticCompiledOpenConglomInfo[] indexSCOCIs, 115 DynamicCompiledOpenConglomInfo[] indexDCOCIs, 116 String [] indexNames, 117 ConglomerateController baseCC, 118 TransactionController tc, 119 int lockMode, 120 FormatableBitSet baseRowReadMap, 121 int isolationLevel, 122 Activation activation) 123 throws StandardException 124 { 125 this.irgs = irgs; 126 this.indexCIDS = indexCIDS; 127 this.indexSCOCIs = indexSCOCIs; 128 this.indexDCOCIs = indexDCOCIs; 129 this.indexNames = indexNames; 130 this.baseCC = baseCC; 131 this.tc = tc; 132 this.lockMode = lockMode; 133 this.baseRowReadMap = baseRowReadMap; 134 this.isolationLevel = isolationLevel; 135 this.activation = activation; 136 137 if (SanityManager.DEBUG) 138 { 139 SanityManager.ASSERT(indexCIDS != null, "indexCIDS is null"); 140 } 141 142 indexChangers = new IndexChanger[irgs.length]; 143 } 144 145 155 public void open(boolean[] fixOnUpdate) 156 throws StandardException 157 { 158 if (SanityManager.DEBUG) 159 SanityManager.ASSERT( ! isOpen, "IndexSetChanger already open"); 160 161 this.fixOnUpdate = fixOnUpdate; 162 isOpen = true; 163 } 164 165 174 public void setRowHolder(TemporaryRowHolderImpl rowHolder) 175 { 176 this.rowHolder = rowHolder; 177 } 178 179 186 private void openIndexes(int whatToOpen) 187 throws StandardException 188 { 189 if (SanityManager.DEBUG) 190 SanityManager.ASSERT( isOpen, "IndexSetChanger closed"); 191 192 if (whatIsOpen >= whatToOpen) return; 193 194 for (int ix = 0; ix < indexChangers.length; ix++) 195 { 196 if (whatToOpen == UPDATE_INDEXES && 197 !fixOnUpdate[ix]) 198 continue; 199 200 204 if (indexChangers[ix] == null) 205 { 206 207 indexChangers[ix] = 208 new IndexChanger(irgs[ix], 209 indexCIDS[ix], 210 (indexSCOCIs == null) ? 211 (StaticCompiledOpenConglomInfo) null : 212 indexSCOCIs[ix], 213 (indexDCOCIs == null) ? 214 (DynamicCompiledOpenConglomInfo) null : 215 indexDCOCIs[ix], 216 (indexNames == null) ? null : 217 indexNames[ix], 218 baseCC, 219 tc, 220 lockMode, 221 baseRowReadMap, 222 isolationLevel, 223 activation); 224 indexChangers[ix].setRowHolder(rowHolder); 225 } 226 else 227 { 228 indexChangers[ix].setBaseCC(baseCC); 229 } 230 indexChangers[ix].open(); 231 } 232 whatIsOpen = whatToOpen; 233 } 234 235 244 public void delete(ExecRow baseRow, 245 RowLocation baseRowLocation) 246 throws StandardException 247 { 248 openIndexes(ALL_INDEXES); 249 for (int ix = 0; ix < indexChangers.length; ix++) 250 indexChangers[ix].delete(baseRow,baseRowLocation); 251 } 252 253 262 public void insert(ExecRow baseRow, 263 RowLocation baseRowLocation) 264 throws StandardException 265 { 266 openIndexes(ALL_INDEXES); 267 for (int ix = 0; ix < indexChangers.length; ix++) 268 indexChangers[ix].insert(baseRow,baseRowLocation); 269 } 270 271 281 public void update(ExecRow oldBaseRow, 282 ExecRow newBaseRow, 283 RowLocation baseRowLocation) 284 throws StandardException 285 { 286 openIndexes(UPDATE_INDEXES); 287 for (int ix = 0; ix < indexChangers.length; ix++) 288 if (fixOnUpdate[ix]) 289 indexChangers[ix].update(oldBaseRow, 290 newBaseRow, 291 baseRowLocation); 292 } 293 294 300 public void setBaseCC(ConglomerateController baseCC) 301 { 302 for (int ix = 0; ix < indexChangers.length; ix++) 303 { 304 if (indexChangers[ix] != null) 305 { 306 indexChangers[ix].setBaseCC(baseCC); 307 } 308 } 309 this.baseCC = baseCC; 310 } 311 312 318 public void finish() 319 throws StandardException 320 { 321 for (int ix = 0; ix < indexChangers.length; ix++) 322 { 323 if (indexChangers[ix] != null) 324 { 325 indexChangers[ix].finish(); 326 } 327 } 328 } 329 330 335 public void close() 336 throws StandardException 337 { 338 whatIsOpen = NO_INDEXES; 339 for (int ix = 0; ix < indexChangers.length; ix++) 340 { 341 if (indexChangers[ix] != null) 342 { 343 indexChangers[ix].close(); 344 } 345 } 346 fixOnUpdate = null; 347 isOpen = false; 348 rowHolder = null; 349 } 350 351 354 public String toString() 355 { 356 if (SanityManager.DEBUG) 357 { 358 String whatIsOpen_s = null; 359 switch (whatIsOpen) 360 { 361 case NO_INDEXES: 362 whatIsOpen_s = "No open indexes "; 363 break; 364 case UPDATE_INDEXES: 365 whatIsOpen_s = "Update indexes open "; 366 break; 367 case ALL_INDEXES: 368 whatIsOpen_s = "All indexes open "; 369 break; 370 default: 371 SanityManager.THROWASSERT("bad whatIsOpen value "+whatIsOpen); 372 break; 373 } 374 375 String fixOnUpdate_s = "fixOnUpdate=("; 376 for (int ix = 0; ix < fixOnUpdate.length; ix++) 377 { 378 if (ix > 0) 379 fixOnUpdate_s+=","; 380 381 fixOnUpdate_s += fixOnUpdate[ix]; 382 } 383 fixOnUpdate_s +=")"; 384 385 String indexDesc_s = "\n"; 386 for (int ix = 0; ix < indexCIDS.length; ix++) 387 { 388 if (indexChangers[ix] == null) 389 indexDesc_s += " Index["+ix+"] cid="+ 390 indexCIDS[ix]+" closed. \n"; 391 else 392 indexDesc_s += 393 " "+ 394 indexChangers[ix].toString() + "\n"; 395 } 396 397 return "IndexSetChanger: "+ 398 whatIsOpen_s+ 399 fixOnUpdate_s+ 400 indexDesc_s; 401 } 402 403 return null; 404 } 405 } 406 | Popular Tags |