public void insert ( RecordId rid ) { // Block read-only transaction if ( tx . isReadOnly ( ) && ! isTempTable ( ) ) throw new UnsupportedOperationException ( ) ; // Insertion may change the properties of this file, // so that we need to lock the file. if ( ! isTempTable ( ) ) tx . concurrencyMgr ( ) . modifyFile ( fileName ) ; // Open the header if ( fhp == null ) fhp = openHeaderForModification ( ) ; // Log that this logical operation starts tx . recoveryMgr ( ) . logLogicalStart ( ) ; // Mark the specified slot as in used moveToRecordId ( rid ) ; if ( ! rp . insertIntoTheCurrentSlot ( ) ) throw new RuntimeException ( "the specified slot: " + rid + " is in used" ) ; // Traverse the free chain to find the specified slot RecordId lastSlot = null ; RecordId currentSlot = fhp . getLastDeletedSlot ( ) ; while ( ! currentSlot . equals ( rid ) && currentSlot . block ( ) . number ( ) != FileHeaderPage . NO_SLOT_BLOCKID ) { moveToRecordId ( currentSlot ) ; lastSlot = currentSlot ; currentSlot = rp . getNextDeletedSlotId ( ) ; } // Remove the specified slot from the chain // If it is the first slot if ( lastSlot == null ) { moveToRecordId ( currentSlot ) ; fhp . setLastDeletedSlot ( rp . getNextDeletedSlotId ( ) ) ; // If it is in the middle } else if ( currentSlot . block ( ) . number ( ) != FileHeaderPage . NO_SLOT_BLOCKID ) { moveToRecordId ( currentSlot ) ; RecordId nextSlot = rp . getNextDeletedSlotId ( ) ; moveToRecordId ( lastSlot ) ; rp . setNextDeletedSlotId ( nextSlot ) ; } // Log that this logical operation ends tx . recoveryMgr ( ) . logRecordFileInsertionEnd ( ti . tableName ( ) , rid . block ( ) . number ( ) , rid . id ( ) ) ; // Close the header (release the header lock) closeHeader ( ) ; }
Inserts a record to a specified physical address .