|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectneustore.base.DBIndex
public abstract class DBIndex
Abstract base class for a disk-based, paginated and buffered index.
The index reads and writes DBPage
using a DBBuffer
.
Usage:
HeapFile
, by
implementing the three abstract functions that manage the head information (to
be explained).
+------+-------+-------+-------+-------+-------+-------+ | head | page1 | page2 | page3 | page4 | page5 | page6 | +------+-------+-------+-------+-------+-------+-------+
initIndexHead
: called when the index is built;
readIndexHead
: called when the index is opened;
writeIndexHead
: called right before the index is closed.
close()
function, typical usages
of the DBIndex
are:
allocate
: to get a new pageID;
freePage
: to declare a pageID to be empty;
buffer.readPage
,
buffer.writePage
.
DBPage
,
DBBuffer
Field Summary | |
---|---|
DBBuffer |
buffer
The buffer manager. |
static boolean |
CREATE
|
protected java.io.RandomAccessFile |
file
The random access file. |
protected int |
firstEmpty
The first empty page ID. |
protected int |
numPages
The number of non-empty pages (excluding the head page). |
static boolean |
OPEN
|
protected static int |
OVERHEAD
The length of the system information in bytes. |
protected int |
pageSize
The size of a page. |
Constructor Summary | |
---|---|
DBIndex(DBBuffer buffer,
java.lang.String filename,
boolean isCreate)
Creates or Opens an index file. |
Method Summary | |
---|---|
int |
allocate()
Assigns a new pageID. |
void |
close()
Saves the header page to disk and flushes the buffer. |
void |
freePage(int pageID)
Frees an empty page. |
protected abstract void |
initIndexHead()
Initializes index head information. |
protected abstract void |
readIndexHead(byte[] indexHead)
Reads index head information from a byte array. |
protected abstract void |
writeIndexHead(byte[] indexHead)
Writes index head information to a byte array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean CREATE
public static final boolean OPEN
protected int pageSize
protected int numPages
protected int firstEmpty
public DBBuffer buffer
protected static final int OVERHEAD
protected java.io.RandomAccessFile file
Constructor Detail |
---|
public DBIndex(DBBuffer buffer, java.lang.String filename, boolean isCreate) throws java.io.IOException
buffer
- the buffer managerfilename
- the filenameisCreate
- whether create (or open)
java.io.IOException
Method Detail |
---|
public int allocate()
public void freePage(int pageID) throws java.io.IOException
pageID
- the to-be-freed page ID
java.io.IOException
public void close() throws java.io.IOException
close()
before exiting.
Otherwise the file may be corrupted.
java.io.IOException
protected abstract void readIndexHead(byte[] indexHead)
indexHead
- the byte array of length pageSize-OVERHEADprotected abstract void writeIndexHead(byte[] indexHead)
indexHead
- the byte array of length pageSize-OVERHEADprotected abstract void initIndexHead()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |