|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsimpledb.file.Page
public class Page
The contents of a disk block in memory.
A page is treated as an array of BLOCK_SIZE bytes.
There are methods to get/set values into this array,
and to read/write the contents of this array to a disk block.
For an example of how to use Page and
Block objects,
consider the following code fragment.
The first portion increments the integer at offset 792 of block 6 of file junk.
The second portion stores the string "hello" at offset 20 of a page,
and then appends it to a new block of the file.
It then reads that block into another page
and extracts the value "hello" into variable s.
Page p1 = new Page();
Block blk = new Block("junk", 6);
p1.read(blk);
int n = p1.getInt(792);
p1.setInt(792, n+1);
p1.write(blk);
Page p2 = new Page();
p2.setString(20, "hello");
blk = p2.append("junk");
Page p3 = new Page();
p3.read(blk);
String s = p3.getString(20);
| Field Summary | |
|---|---|
static int |
BLOCK_SIZE
The number of bytes in a block. |
static int |
INT_SIZE
The size of an integer in bytes. |
| Constructor Summary | |
|---|---|
Page()
Creates a new page. |
|
| Method Summary | |
|---|---|
Block |
append(java.lang.String filename)
Appends the contents of the page to the specified file. |
int |
getInt(int offset)
Returns the integer value at a specified offset of the page. |
java.lang.String |
getString(int offset)
Returns the string value at the specified offset of the page. |
void |
read(Block blk)
Populates the page with the contents of the specified disk block. |
void |
setInt(int offset,
int val)
Writes an integer to the specified offset on the page. |
void |
setString(int offset,
java.lang.String val)
Writes a string to the specified offset on the page. |
static int |
STR_SIZE(int n)
The maximum size, in bytes, of a string of length n. |
void |
write(Block blk)
Writes the contents of the page to the specified disk block. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int BLOCK_SIZE
public static final int INT_SIZE
| Constructor Detail |
|---|
public Page()
FileMgr object that it gets from the
method SimpleDB.fileMgr().
That object is created during system initialization.
Thus this constructor cannot be called until either
SimpleDB.init(String) or
SimpleDB.initFileMgr(String) or
SimpleDB.initFileAndLogMgr(String) or
SimpleDB.initFileLogAndBufferMgr(String)
is called first.
| Method Detail |
|---|
public static final int STR_SIZE(int n)
n - the size of the string
public void read(Block blk)
blk - a reference to a disk blockpublic void write(Block blk)
blk - a reference to a disk blockpublic Block append(java.lang.String filename)
filename - the name of the file
public int getInt(int offset)
offset - the byte offset within the page
public void setInt(int offset,
int val)
offset - the byte offset within the pageval - the integer to be written to the pagepublic java.lang.String getString(int offset)
offset - the byte offset within the page
public void setString(int offset,
java.lang.String val)
offset - the byte offset within the pageval - the string to be written to the page
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||