/** * Remove the specified tuple from the buffer pool. Will acquire a write lock on the page the * tuple is removed from. May block if the lock cannot be acquired. * * <p>Marks any pages that were dirtied by the operation as dirty by calling their markDirty bit. * Does not need to update cached versions of any pages that have been dirtied, as it is not * possible that a new page was created during the deletion (note difference from addTuple). * * @param tid the transaction deleting the tuple. * @param t the tuple to delete */ public void deleteTuple(TransactionId tid, Tuple t) throws DbException, TransactionAbortedException { HeapFile heapFile = (HeapFile) Database.getCatalog().getDatabaseFile(t.getRecordId().getPageId().getTableId()); Page dirtiedPage = heapFile.deleteTuple(tid, t); dirtiedPage.markDirty(true, tid); }
/** * Delete the specified tuple from the page; the tuple should be updated to reflect that it is no * longer stored on any page. * * @throws DbException if this tuple is not on this page, or tuple slot is already empty. * @param t The tuple to delete */ public void deleteTuple(Tuple t) throws DbException { // some code goes here // not necessary for lab1 RecordId targetrid = t.getRecordId(); int tslotnum = targetrid.tupleno(); if (!targetrid.getPageId().equals(pid) || !isSlotUsed(tslotnum)) { throw new DbException("Either wrong page number or requested tuple didn't exist"); } markSlotUsed(tslotnum, false); tuples[tslotnum] = null; }
// see DbFile.java for javadocs public Page deleteTuple(TransactionId tid, Tuple t) throws DbException, TransactionAbortedException { // some code goes here BufferPool bp = Database.getBufferPool(); RecordId rid = t.getRecordId(); if (rid == null) { throw new DbException("Tuple is not a member of this file"); } HeapPage p = (HeapPage) bp.getPage(tid, rid.getPageId(), Permissions.READ_WRITE); p.deleteTuple(t); return p; }
/** Unit test for Tuple.getRecordId() and Tuple.setRecordId() */ @Test public void modifyRecordId() { Tuple tup1 = new Tuple(Utility.getTupleDesc(1)); HeapPageId pid1 = new HeapPageId(0, 0); RecordId rid1 = new RecordId(pid1, 0); tup1.setRecordId(rid1); try { assertEquals(rid1, tup1.getRecordId()); } catch (java.lang.UnsupportedOperationException e) { // rethrow the exception with an explanation throw new UnsupportedOperationException( "modifyRecordId() test failed due to " + "RecordId.equals() not being implemented. This is not required for Lab 1, " + "but should pass when you do implement the RecordId class."); } }
/** * Adds the specified tuple to the page; the tuple should be updated to reflect that it is now * stored on this page. * * @throws DbException if the page is full (no empty slots) or tupledesc is mismatch. * @param t The tuple to add. */ public void insertTuple(Tuple t) throws DbException { // some code goes here // not necessary for lab1 RecordId targetrid = t.getRecordId(); if (getNumEmptySlots() == 0 || !td.equals(t.getTupleDesc())) { throw new DbException("Either page is full or tuple desc doesn't match"); } for (int i = 0; i < getNumTuples(); i++) { if (!isSlotUsed(i)) { markSlotUsed(i, true); RecordId rid = new RecordId(pid, i); t.setRecordId(rid); tuples[i] = t; return; } } }