simpledb
Interface DbFile

All Known Implementing Classes:
HeapFile

public interface DbFile

The interface for database files on disk. Each table is represented by a single DbFile. DbFiles can fetch pages and iterate through tuples. Each file has a unique id used to store metadata about the table in the Catalog. DbFiles are generally accessed through the buffer pool, rather than directly by operators.


Method Summary
 Page deleteTuple(TransactionId tid, Tuple t)
          Removes the specifed tuple from the file on behalf of the specified transaction.
 int getId()
          Returns a unique ID used to identify this DbFile in the Catalog.
 TupleDesc getTupleDesc()
          Returns the TupleDesc of the table stored in this DbFile.
 java.util.ArrayList<Page> insertTuple(TransactionId tid, Tuple t)
          Inserts the specified tuple to the file on behalf of transaction.
 DbFileIterator iterator(TransactionId tid)
          Returns an iterator over all the tuples stored in this DbFile.
 Page readPage(PageId id)
          Read the specified page from disk.
 void writePage(Page p)
          Push the specified page to disk.
 

Method Detail

readPage

Page readPage(PageId id)
Read the specified page from disk.

Throws:
java.lang.IllegalArgumentException - if the page does not exist in this file.

writePage

void writePage(Page p)
               throws java.io.IOException
Push the specified page to disk.

Parameters:
p - The page to write. page.getId().pageno() specifies the offset into the file where the page should be written.
Throws:
java.io.IOException - if the write fails

insertTuple

java.util.ArrayList<Page> insertTuple(TransactionId tid,
                                      Tuple t)
                                      throws DbException,
                                             java.io.IOException,
                                             TransactionAbortedException
Inserts the specified tuple to the file on behalf of transaction. This method will acquire a lock on the affected pages of the file, and may block until the lock can be acquired.

Parameters:
tid - The transaction performing the update
t - The tuple to add. This tuple should be updated to reflect that it is now stored in this file.
Returns:
An ArrayList contain the pages that were modified
Throws:
DbException - if the tuple cannot be added
java.io.IOException - if the needed file can't be read/written
TransactionAbortedException

deleteTuple

Page deleteTuple(TransactionId tid,
                 Tuple t)
                 throws DbException,
                        TransactionAbortedException
Removes the specifed tuple from the file on behalf of the specified transaction. This method will acquire a lock on the affected pages of the file, and may block until the lock can be acquired.

Throws:
DbException - if the tuple cannot be deleted or is not a member of the file
TransactionAbortedException

iterator

DbFileIterator iterator(TransactionId tid)
Returns an iterator over all the tuples stored in this DbFile. The iterator must use BufferPool.getPage(simpledb.TransactionId, simpledb.PageId, simpledb.Permissions), rather than readPage(simpledb.PageId) to iterate through the pages.

Returns:
an iterator over all the tuples stored in this DbFile.

getId

int getId()
Returns a unique ID used to identify this DbFile in the Catalog. This id can be used to look up the table via Catalog.getDbFile(int) and Catalog.getTupleDesc(int).

Implementation note: you will need to generate this tableid somewhere, ensure that each HeapFile has a "unique id," and that you always return the same value for a particular HeapFile. A simple implementation is to use the hash code of the absolute path of the file underlying the HeapFile, i.e. f.getAbsoluteFile().hashCode().

Returns:
an ID uniquely identifying this HeapFile.

getTupleDesc

TupleDesc getTupleDesc()
Returns the TupleDesc of the table stored in this DbFile.

Returns:
TupleDesc of this DbFile.