|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimpledb.HeapPage
public class HeapPage
HeapPage stores pages of HeapFiles and implements the Page interface that is used by BufferPool.
HeapFile
,
BufferPool
Field Summary | |
---|---|
(package private) int[] |
header
|
(package private) int |
numSlots
|
(package private) HeapPageId |
pid
|
(package private) TupleDesc |
td
|
(package private) Tuple[] |
tuples
|
Constructor Summary | |
---|---|
HeapPage(HeapPageId id,
byte[] data)
Create a HeapPage from a set of bytes of data read from disk. |
Method Summary | |
---|---|
void |
addTuple(Tuple t)
Adds the specified tuple to the page. |
static byte[] |
createEmptyPageData(int tableid)
Static method to generate a byte array corresponding to an empty HeapPage. |
boolean |
deleteTuple(Tuple t)
Delete the specified tuple from the page. |
HeapPage |
getBeforeImage()
Return a view of this page before it was modified -- used by recovery |
int |
getNumEmptySlots()
Returns the number of empty slots on this page. |
byte[] |
getPageData()
Generates a byte array representing the contents of this page. |
boolean |
getSlot(int i)
Returns true if associated slot on this page is filled. |
HeapPageId |
id()
Return the id of this page. |
TransactionId |
isDirty()
Returns the tid of the transaction that last dirtied this page, or null if the page is not dirty |
java.util.Iterator<Tuple> |
iterator()
|
void |
markDirty(boolean dirty,
TransactionId tid)
Marks this page as dirty/not dirty and record that transaction that did the dirtying |
private Tuple |
readNextTuple(java.io.DataInputStream dis,
int slotId)
Suck up tuples from the source file. |
private void |
setSlot(int i,
boolean value)
Abstraction to fill a slot on this page. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
HeapPageId pid
TupleDesc td
int[] header
Tuple[] tuples
int numSlots
Constructor Detail |
---|
public HeapPage(HeapPageId id, byte[] data) throws java.io.IOException
Catalog.getTupleDesc(int)
.
The number of 32-bit header words is equal to:
(no. tuple slots / 32) + 1
java.io.IOException
Database.getCatalog()
,
Catalog.getTupleDesc(int)
,
BufferPool.PAGE_SIZE
Method Detail |
---|
public HeapPage getBeforeImage()
getBeforeImage
in interface Page
public HeapPageId id()
Page
id
in interface Page
private Tuple readNextTuple(java.io.DataInputStream dis, int slotId) throws java.util.NoSuchElementException
java.util.NoSuchElementException
public byte[] getPageData()
The invariant here is that it should be possible to pass the byte array generated by getPageData to the HeapPage constructor and have it produce an identical HeapPage object.
getPageData
in interface Page
HeapPage(simpledb.HeapPageId, byte[])
public static byte[] createEmptyPageData(int tableid)
tableid
- The id of the table that this empty page will belong to.
public boolean deleteTuple(Tuple t) throws DbException
t
- The tuple to delete
DbException
- if this tuple is not on this page, or tuple slot is
already empty.public void addTuple(Tuple t) throws DbException
t
- The tuple to add.
DbException
- if the page is full (no empty slots) or tupledesc
is mismatch.public void markDirty(boolean dirty, TransactionId tid)
markDirty
in interface Page
public TransactionId isDirty()
isDirty
in interface Page
public int getNumEmptySlots()
public boolean getSlot(int i)
private void setSlot(int i, boolean value)
public java.util.Iterator<Tuple> iterator()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |