simpledb.buffer
Class Buffer

java.lang.Object
  extended by simpledb.buffer.Buffer

public class Buffer
extends Object

An individual buffer. A buffer wraps a page and stores information about its status, such as the disk block associated with the page, the number of times the block has been pinned, whether the contents of the page have been modified, and if so, the id of the modifying transaction and the LSN of the corresponding log record.

Author:
Edward Sciore

Constructor Summary
Buffer()
          Creates a new buffer, wrapping a new page.
 
Method Summary
 Block block()
          Returns a reference to the disk block that the buffer is pinned to.
 int getInt(int offset)
          Returns the integer value at the specified offset of the buffer's page.
 String getString(int offset)
          Returns the string value at the specified offset of the buffer's page.
 void setInt(int offset, int val, int txnum, int lsn)
          Writes an integer to the specified offset of the buffer's page.
 void setString(int offset, String val, int txnum, int lsn)
          Writes a string to the specified offset of the buffer's page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Buffer

public Buffer()
Creates a new buffer, wrapping a new page. This constructor is called exclusively by the class BasicBufferMgr. It depends on the LogMgr object that it gets from the class SimpleDB. That object is created during system initialization. Thus this constructor cannot be called until SimpleDB.initFileAndLogMgr(String) or is called first.

Method Detail

getInt

public int getInt(int offset)
Returns the integer value at the specified offset of the buffer's page. If an integer was not stored at that location, the behavior of the method is unpredictable.

Parameters:
offset - the byte offset of the page
Returns:
the integer value at that offset

getString

public String getString(int offset)
Returns the string value at the specified offset of the buffer's page. If a string was not stored at that location, the behavior of the method is unpredictable.

Parameters:
offset - the byte offset of the page
Returns:
the string value at that offset

setInt

public void setInt(int offset,
                   int val,
                   int txnum,
                   int lsn)
Writes an integer to the specified offset of the buffer's page. This method assumes that the transaction has already written an appropriate log record. The buffer saves the id of the transaction and the LSN of the log record. A negative lsn value indicates that a log record was not necessary.

Parameters:
offset - the byte offset within the page
val - the new integer value to be written
txnum - the id of the transaction performing the modification
lsn - the LSN of the corresponding log record

setString

public void setString(int offset,
                      String val,
                      int txnum,
                      int lsn)
Writes a string to the specified offset of the buffer's page. This method assumes that the transaction has already written an appropriate log record. A negative lsn value indicates that a log record was not necessary. The buffer saves the id of the transaction and the LSN of the log record.

Parameters:
offset - the byte offset within the page
val - the new string value to be written
txnum - the id of the transaction performing the modification
lsn - the LSN of the corresponding log record

block

public Block block()
Returns a reference to the disk block that the buffer is pinned to.

Returns:
a reference to a disk block


Copyright © 2011. All Rights Reserved.