public class HeapFile extends java.lang.Object implements DbFile
HeapPage.HeapPage(simpledb.HeapPageId, byte[])
Constructor and Description |
---|
HeapFile(java.io.File f,
TupleDesc td)
Constructs a heap file backed by the specified file.
|
Modifier and Type | Method and Description |
---|---|
java.util.ArrayList<Page> |
deleteTuple(TransactionId tid,
Tuple t)
Removes the specified tuple from the file on behalf of the specified
transaction.
|
java.io.File |
getFile()
Returns the File backing this HeapFile on disk.
|
int |
getId()
Returns an ID uniquely identifying this HeapFile.
|
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.
|
int |
numPages()
Returns the number of pages in this HeapFile.
|
Page |
readPage(PageId pid)
Read the specified page from disk.
|
void |
writePage(Page page)
Push the specified page to disk.
|
public HeapFile(java.io.File f, TupleDesc td)
f
- the file that stores the on-disk backing store for this heap
file.public java.io.File getFile()
public int getId()
public TupleDesc getTupleDesc()
getTupleDesc
in interface DbFile
public Page readPage(PageId pid)
DbFile
public void writePage(Page page) throws java.io.IOException
DbFile
public int numPages()
public java.util.ArrayList<Page> insertTuple(TransactionId tid, Tuple t) throws DbException, java.io.IOException, TransactionAbortedException
DbFile
insertTuple
in interface DbFile
tid
- The transaction performing the updatet
- The tuple to add. This tuple should be updated to reflect that
it is now stored in this file.DbException
- if the tuple cannot be addedjava.io.IOException
- if the needed file can't be read/writtenTransactionAbortedException
public java.util.ArrayList<Page> deleteTuple(TransactionId tid, Tuple t) throws DbException, TransactionAbortedException
DbFile
deleteTuple
in interface DbFile
tid
- The transaction performing the updatet
- The tuple to delete. This tuple should be updated to reflect that
it is no longer stored on any page.DbException
- if the tuple cannot be deleted or is not a member
of the fileTransactionAbortedException
public DbFileIterator iterator(TransactionId tid)
DbFile
BufferPool.getPage(simpledb.TransactionId, simpledb.PageId, simpledb.Permissions)
, rather than
DbFile.readPage(simpledb.PageId)
to iterate through the pages.