예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 // 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;
 }
예제 #3
0
 /**
  * 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;
     }
   }
 }
  /** 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.");
    }
  }