1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.sql.execute.ExecutionContext; 25 26 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 27 28 import org.apache.derby.iapi.services.io.ArrayUtil; 29 import org.apache.derby.iapi.services.io.Formatable; 30 31 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 32 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 33 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 34 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 35 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 36 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator; 37 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 38 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 39 40 import org.apache.derby.iapi.sql.execute.ConstantAction; 41 import org.apache.derby.iapi.sql.execute.ExecRow; 42 43 import org.apache.derby.iapi.sql.Activation; 44 45 import org.apache.derby.iapi.error.StandardException; 46 47 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo; 48 49 import org.apache.derby.iapi.services.sanity.SanityManager; 50 51 import org.apache.derby.iapi.services.io.FormatableBitSet; 52 53 import org.apache.derby.catalog.UUID; 54 55 import java.io.ObjectOutput ; 56 import java.io.ObjectInput ; 57 import java.io.IOException ; 58 59 import java.util.Properties ; 60 61 62 68 69 abstract class WriteCursorConstantAction implements ConstantAction, Formatable 70 { 71 72 81 82 long conglomId; 83 StaticCompiledOpenConglomInfo heapSCOCI; 84 IndexRowGenerator[] irgs; 85 long[] indexCIDS; 86 StaticCompiledOpenConglomInfo[] indexSCOCIs; 87 String [] indexNames; 88 boolean deferred; 89 private Properties targetProperties; 90 UUID targetUUID; 91 int lockMode; 92 private FKInfo[] fkInfo; 93 private TriggerInfo triggerInfo; 94 95 private ExecRow emptyHeapRow; 96 private FormatableBitSet baseRowReadList; 97 private int[] baseRowReadMap; 98 private int[] streamStorableHeapColIds; 99 boolean singleRowSource; 100 101 102 104 108 public WriteCursorConstantAction() {} 109 110 130 public WriteCursorConstantAction( 131 long conglomId, 132 StaticCompiledOpenConglomInfo heapSCOCI, 133 IndexRowGenerator[] irgs, 134 long[] indexCIDS, 135 StaticCompiledOpenConglomInfo[] indexSCOCIs, 136 String [] indexNames, 137 boolean deferred, 138 Properties targetProperties, 139 UUID targetUUID, 140 int lockMode, 141 FKInfo[] fkInfo, 142 TriggerInfo triggerInfo, 143 ExecRow emptyHeapRow, 144 FormatableBitSet baseRowReadList, 145 int[] baseRowReadMap, 146 int[] streamStorableHeapColIds, 147 boolean singleRowSource 148 ) 149 { 150 this.conglomId = conglomId; 151 this.heapSCOCI = heapSCOCI; 152 this.irgs = irgs; 153 this.indexSCOCIs = indexSCOCIs; 154 this.indexCIDS = indexCIDS; 155 this.indexSCOCIs = indexSCOCIs; 156 this.deferred = deferred; 157 this.targetProperties = targetProperties; 158 this.targetUUID = targetUUID; 159 this.lockMode = lockMode; 160 this.emptyHeapRow = emptyHeapRow; 161 this.fkInfo = fkInfo; 162 this.triggerInfo = triggerInfo; 163 this.baseRowReadList = baseRowReadList; 164 this.baseRowReadMap = baseRowReadMap; 165 this.streamStorableHeapColIds = streamStorableHeapColIds; 166 this.singleRowSource = singleRowSource; 167 this.indexNames = indexNames; 168 if (SanityManager.DEBUG) 169 { 170 if (fkInfo != null) 171 { 172 SanityManager.ASSERT(fkInfo.length != 0, "fkinfo array has no elements, if there are no foreign keys, then pass in null"); 173 } 174 } 175 } 176 177 183 200 public FKInfo[] getFKInfo 201 ( 202 ExecutionContext ec 203 ) 204 throws StandardException 205 { 206 FKInfo[] siftedArray = (FKInfo[]) ec.siftForeignKeys( fkInfo ); 207 208 return siftedArray; 209 } 210 211 218 public TriggerInfo getTriggerInfo(ExecutionContext ec) 219 throws StandardException 220 { 221 return (TriggerInfo)ec.siftTriggers(triggerInfo); 222 } 223 224 225 231 238 public final void executeConstantAction( Activation activation ) 239 throws StandardException { } 240 241 250 public void readExternal( ObjectInput in ) 251 throws IOException , ClassNotFoundException 252 { 253 conglomId = in.readLong(); 254 heapSCOCI = (StaticCompiledOpenConglomInfo) in.readObject(); 255 irgs = new IndexRowGenerator[ArrayUtil.readArrayLength(in)]; 256 ArrayUtil.readArrayItems(in, irgs); 257 258 indexCIDS = ArrayUtil.readLongArray(in); 259 indexSCOCIs = new StaticCompiledOpenConglomInfo[ArrayUtil.readArrayLength(in)]; 260 ArrayUtil.readArrayItems(in, indexSCOCIs); 261 262 deferred = in.readBoolean(); 263 targetProperties = (Properties ) in.readObject(); 264 targetUUID = (UUID) in.readObject(); 265 lockMode = in.readInt(); 266 267 fkInfo = new FKInfo[ArrayUtil.readArrayLength(in)]; 268 ArrayUtil.readArrayItems(in, fkInfo); 269 270 triggerInfo = (TriggerInfo)in.readObject(); 271 272 baseRowReadList = (FormatableBitSet)in.readObject(); 273 baseRowReadMap = ArrayUtil.readIntArray(in); 274 streamStorableHeapColIds = ArrayUtil.readIntArray(in); 275 singleRowSource = in.readBoolean(); 276 indexNames = ArrayUtil.readStringArray(in); 277 } 278 279 286 public void writeExternal( ObjectOutput out ) 287 throws IOException 288 { 289 out.writeLong(conglomId); 290 out.writeObject(heapSCOCI); 291 ArrayUtil.writeArray(out, irgs); 292 ArrayUtil.writeLongArray(out, indexCIDS); 293 ArrayUtil.writeArray(out, indexSCOCIs); 294 out.writeBoolean(deferred); 295 out.writeObject(targetProperties); 296 out.writeObject(targetUUID); 297 out.writeInt(lockMode); 298 ArrayUtil.writeArray(out, fkInfo); 299 300 out.writeObject(triggerInfo); 303 304 out.writeObject(baseRowReadList); 307 308 ArrayUtil.writeIntArray(out,baseRowReadMap); 311 ArrayUtil.writeIntArray(out,streamStorableHeapColIds); 312 313 out.writeBoolean(singleRowSource); 315 316 ArrayUtil.writeArray(out, indexNames); 318 319 } 320 321 323 327 public long getConglomerateId() { return conglomId; } 328 329 338 public ExecRow getEmptyHeapRow(LanguageConnectionContext lcc) throws StandardException 339 { 340 DataDictionary dd; 341 TableDescriptor td; 342 343 if (emptyHeapRow == null) 344 { 345 346 dd = lcc.getDataDictionary(); 347 348 td = dd.getTableDescriptor(targetUUID); 349 350 emptyHeapRow = td.getEmptyExecRow(lcc.getContextManager()); 351 } 352 353 return emptyHeapRow.getClone(); 354 } 355 356 361 public Properties getTargetProperties() 362 { 363 return targetProperties; 364 } 365 366 375 public String getProperty(String key) 376 { 377 return (targetProperties == null) ? null : targetProperties.getProperty(key); 378 } 379 380 public FormatableBitSet getBaseRowReadList() { return baseRowReadList; } 381 public int[] getBaseRowReadMap() { return baseRowReadMap; } 382 public int[] getStreamStorableHeapColIds() { return streamStorableHeapColIds; } 383 384 391 public String getIndexNameFromCID(long indexCID) 392 { 393 int size = indexCIDS.length; 394 395 if (indexNames == null) 396 { 397 return null; 398 } 399 400 for (int i = 0; i < size; i++) 401 { 402 if (indexCIDS[i] == indexCID) 403 return indexNames[i]; 404 } 405 return null; 406 } 407 408 public String [] getIndexNames() 409 { 410 return indexNames; 411 } 412 } 413 414 | Popular Tags |