Quadcap Embeddable Database

com.quadcap.sql.file.Block Class Reference

Inheritance diagram for com.quadcap.sql.file.Block:

com.quadcap.sql.file.Cacheable com.quadcap.sql.file.Page Object List of all members.

Detailed Description

This class represents a block/page of data in a random access file, which may be cached.

The key is an Integer specifying the block number, while the data is a byte array containing the actual data.

Author:
Stan Bailes

Definition at line 55 of file Block.java.

Public Member Functions

long getPageNum ()
 Return this page's block number.

void init (Object store, long key) throws IOException
 Initialize this block.

final void flush () throws IOException
 Write the contents of the buffer back to the underlying store.

final Object getData ()
 From the Cacheable class, return the underlying data object.

byte[] getDataAndReset ()
 Return a reference to the array containing the data for this block, and create a new buffer, so that the reference returned can be used in a subsequent setData call to another buffer.

void setData (Object obj)
 From the Cacheable class, set the underlying data object.

String toString ()
 Only a debugging version implemented so far...

final int read (int pos, byte[] pbuf, int offset, int len)
 Read a range of bytes from the page.

final int write (int pos, byte[] pbuf, int offset, int len)
 Write a range of bytes to the page.

final byte readByte (int pos)
final void writeByte (int pos, byte val)
final short readShort (int pos)
 Read a short (2-byte) value from the page.

final void writeShort (int pos, short val)
 Write a short (2-byte) value to the page.

final int readInt (int pos)
 Read an integer (4-byte) value from the page.

final void writeInt (int pos, int val)
 Write an integer (4-byte) value to the page.

final long readLong (int pos)
 Read a long (8-byte) value from the page.

final void writeLong (int pos, long val)
 Write a long (8-byte) value to the page.

final void takeData (Page p)
 Move the contents of the other page to this page, and zero out the other page.

void clear ()
 Zero this page.

String signature ()

Static Public Member Functions

String signature (byte[] buf)
String signature (byte[] buf, int off, int cnt)
void main (String args[])

Package Functions

void init ()

Private Attributes

byte[] buf


Member Function Documentation

void com.quadcap.sql.file.Block.clear  ) 
 

Zero this page.

Implements com.quadcap.sql.file.Page.

Definition at line 327 of file Block.java.

References com.quadcap.sql.file.Block.buf.

Referenced by com.quadcap.sql.file.BlockFile.newPage().

final void com.quadcap.sql.file.Block.flush  )  throws IOException
 

Write the contents of the buffer back to the underlying store.

Reimplemented from com.quadcap.sql.file.Cacheable.

Definition at line 86 of file Block.java.

References com.quadcap.sql.file.Block.buf, com.quadcap.sql.file.Block.getPageNum(), and com.quadcap.sql.file.BlockStore.write().

final Object com.quadcap.sql.file.Block.getData  )  [virtual]
 

From the Cacheable class, return the underlying data object.

When used as a Block, we typically use the read() and write methods to access the underlying data...

Implements com.quadcap.sql.file.Cacheable.

Definition at line 109 of file Block.java.

References com.quadcap.sql.file.Block.buf.

Referenced by com.quadcap.sql.index.Bnode.moveKeys().

byte [] com.quadcap.sql.file.Block.getDataAndReset  ) 
 

Return a reference to the array containing the data for this block, and create a new buffer, so that the reference returned can be used in a subsequent setData call to another buffer.

This allows the contents of one block to be moved to another block with a minimum of array copying.

Definition at line 118 of file Block.java.

References com.quadcap.sql.file.Block.buf.

Referenced by com.quadcap.sql.file.BlockFile.freePage(), and com.quadcap.sql.file.Block.takeData().

long com.quadcap.sql.file.Block.getPageNum  ) 
 

Return this page's block number.

Implements com.quadcap.sql.file.Page.

Definition at line 58 of file Block.java.

Referenced by com.quadcap.sql.index.Bnode.checkMagic(), com.quadcap.sql.index.Bnode.display(), com.quadcap.sql.file.Block.flush(), com.quadcap.sql.index.Bnode.free(), com.quadcap.sql.file.Block.init(), and com.quadcap.sql.index.Bnode.propogateSplit().

void com.quadcap.sql.file.Block.init  )  [package]
 

Definition at line 334 of file Block.java.

References com.quadcap.sql.file.Block.buf.

void com.quadcap.sql.file.Block.init Object  store,
long  key
throws IOException
 

Initialize this block.

Create the buffer if necessary, and initialize the buffer contents from the underlying store. We assume that the BlockStore.read() method will fill the buffer with zeros if we're attempting to "read" a block that doesn't exist yet.

Parameters:
store the underlying BlockStore which manages the blocks.
key an Integer specifying the block number.

Reimplemented from com.quadcap.sql.file.Cacheable.

Definition at line 70 of file Block.java.

References com.quadcap.sql.file.BlockStore.blockSize, com.quadcap.sql.file.Block.buf, com.quadcap.sql.file.Block.getPageNum(), and com.quadcap.sql.file.BlockStore.read().

Referenced by com.quadcap.sql.file.Block.main().

void com.quadcap.sql.file.Block.main String  args[]  )  [static]
 

Definition at line 359 of file Block.java.

References com.quadcap.sql.file.Block.init(), com.quadcap.sql.file.Block.main(), com.quadcap.sql.file.Block.read(), com.quadcap.sql.file.Block.readInt(), and com.quadcap.sql.file.Block.writeInt().

Referenced by com.quadcap.sql.file.Block.main().

final int com.quadcap.sql.file.Block.read int  pos,
byte[]  pbuf,
int  offset,
int  len
 

Read a range of bytes from the page.

Parameters:
pos the offset in the page of the first byte to read
pbuf the buffer into which the bytes are placed.
offset the offset in pbuf where the first byte is placed.
len the number of bytes to read

Implements com.quadcap.sql.file.Page.

Definition at line 168 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.read().

Referenced by com.quadcap.sql.index.Bnode.dataAtPos(), com.quadcap.sql.file.BlockFile.dump(), com.quadcap.sql.index.Bnode.getBytes(), com.quadcap.sql.file.BlockFile.getBytes(), com.quadcap.sql.index.Bnode.keyAtPos(), com.quadcap.sql.file.Block.main(), com.quadcap.sql.file.SubPage.read(), and com.quadcap.sql.file.Block.read().

final byte com.quadcap.sql.file.Block.readByte int  pos  ) 
 

Definition at line 208 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.readByte().

Referenced by com.quadcap.sql.file.BlockFile.dump(), com.quadcap.sql.index.Bnode.getBytes(), com.quadcap.sql.index.Bnode.getKeyEnd(), com.quadcap.sql.index.Bnode.getKeyLen(), com.quadcap.sql.index.Bnode.longDataAtPos(), and com.quadcap.sql.file.Block.readByte().

final int com.quadcap.sql.file.Block.readInt int  pos  ) 
 

Read an integer (4-byte) value from the page.

Parameters:
pos the offset in the page of the integer.

Implements com.quadcap.sql.file.Page.

Definition at line 264 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.readInt().

Referenced by com.quadcap.sql.file.BlockFile.dump(), com.quadcap.sql.index.Bnode.getBos(), com.quadcap.sql.index.Bnode.getCount(), com.quadcap.sql.index.Bnode.getFlags(), com.quadcap.sql.index.Bnode.getGarbage(), com.quadcap.sql.file.Block.main(), com.quadcap.sql.file.SubPage.readInt(), and com.quadcap.sql.file.Block.readInt().

final long com.quadcap.sql.file.Block.readLong int  pos  ) 
 

Read a long (8-byte) value from the page.

Parameters:
pos the offset in the page of the long.

Implements com.quadcap.sql.file.Page.

Definition at line 296 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.readLong().

Referenced by com.quadcap.sql.file.BlockFile.BlockFile(), com.quadcap.sql.file.BlockFile.dump(), com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.BlockFile.freePage(), com.quadcap.sql.file.BlockFile.getBytes(), com.quadcap.sql.index.Bnode.getParent(), com.quadcap.sql.file.BlockFile.getUserBlock(), com.quadcap.sql.index.Bnode.longDataAtPos(), com.quadcap.sql.file.SubPageManager.newPage(), com.quadcap.sql.file.BlockFile.newPage(), com.quadcap.sql.file.SubPage.readLong(), com.quadcap.sql.file.Block.readLong(), com.quadcap.sql.file.Log1.reallyCheckpoint(), com.quadcap.sql.file.Log1.restoreBlocks(), com.quadcap.sql.file.BlockFile.revert(), and com.quadcap.sql.file.BlockFile.updateBytes().

final short com.quadcap.sql.file.Block.readShort int  pos  ) 
 

Read a short (2-byte) value from the page.

Parameters:
pos the offset in the page of the short.

Definition at line 232 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.readShort().

Referenced by com.quadcap.sql.file.BlockFile.dump(), com.quadcap.sql.index.Bnode.getKeyIndex(), and com.quadcap.sql.file.Block.readShort().

void com.quadcap.sql.file.Block.setData Object  obj  )  [virtual]
 

From the Cacheable class, set the underlying data object.

When used as a Block, we typically use the read() and write methods to access the underlying data...

Implements com.quadcap.sql.file.Cacheable.

Definition at line 135 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.setData().

Referenced by com.quadcap.sql.file.Block.setData().

String com.quadcap.sql.file.Block.signature byte[]  buf,
int  off,
int  cnt
[static]
 

Definition at line 346 of file Block.java.

String com.quadcap.sql.file.Block.signature byte[]  buf  )  [static]
 

Definition at line 343 of file Block.java.

References com.quadcap.sql.file.Block.signature().

String com.quadcap.sql.file.Block.signature  ) 
 

Definition at line 339 of file Block.java.

References com.quadcap.sql.file.Block.buf.

Referenced by com.quadcap.sql.file.BlockFile.signature(), and com.quadcap.sql.file.Block.signature().

final void com.quadcap.sql.file.Block.takeData Page  p  ) 
 

Move the contents of the other page to this page, and zero out the other page.

Implements com.quadcap.sql.file.Page.

Definition at line 323 of file Block.java.

References com.quadcap.sql.file.Block.getDataAndReset(), and com.quadcap.sql.file.Block.takeData().

Referenced by com.quadcap.sql.index.Bnode.propogateSplit(), and com.quadcap.sql.file.Block.takeData().

String com.quadcap.sql.file.Block.toString  ) 
 

Only a debugging version implemented so far...

Definition at line 152 of file Block.java.

References com.quadcap.sql.file.Cacheable.getKey().

final int com.quadcap.sql.file.Block.write int  pos,
byte[]  pbuf,
int  offset,
int  len
 

Write a range of bytes to the page.

Parameters:
pos the offset in the page of the first byte to write
pbuf the buffer from which the bytes are obtained
offset the offset in pbuf of the first byte to write
len the number of bytes to write

Implements com.quadcap.sql.file.Page.

Definition at line 196 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.write().

Referenced by com.quadcap.sql.index.Bnode.insertKeyData(), com.quadcap.sql.file.BlockFile.putBytes(), com.quadcap.sql.file.BlockFile.updateBytes(), com.quadcap.sql.file.SubPage.write(), and com.quadcap.sql.file.Block.write().

final void com.quadcap.sql.file.Block.writeByte int  pos,
byte  val
 

Definition at line 217 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.writeByte().

Referenced by com.quadcap.sql.file.Block.writeByte(), and com.quadcap.sql.index.Bnode.writeLenLen().

final void com.quadcap.sql.file.Block.writeInt int  pos,
int  val
 

Write an integer (4-byte) value to the page.

Parameters:
pos the offset in the page of the integer.
val the integer value to write.

Implements com.quadcap.sql.file.Page.

Definition at line 280 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.writeInt().

Referenced by com.quadcap.sql.file.Block.main(), com.quadcap.sql.index.Bnode.setBos(), com.quadcap.sql.index.Bnode.setCount(), com.quadcap.sql.index.Bnode.setFlags(), com.quadcap.sql.index.Bnode.setGarbage(), com.quadcap.sql.file.SubPage.writeInt(), and com.quadcap.sql.file.Block.writeInt().

final void com.quadcap.sql.file.Block.writeLong int  pos,
long  val
 

Write a long (8-byte) value to the page.

Parameters:
pos the offset in the page of the long.
val the long value to write.

Implements com.quadcap.sql.file.Page.

Definition at line 312 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.writeLong().

Referenced by com.quadcap.sql.file.SubPageManager.allocateNewBlock(), com.quadcap.sql.file.BlockFile.ensureLastBlock(), com.quadcap.sql.file.SubPageManager.freePage(), com.quadcap.sql.file.BlockFile.freePage(), com.quadcap.sql.file.BlockFile.getUserBlock(), com.quadcap.sql.file.SubPageManager.newPage(), com.quadcap.sql.file.BlockFile.newPage(), com.quadcap.sql.file.BlockFile.putBytes(), com.quadcap.sql.index.Bnode.setParent(), com.quadcap.sql.file.BlockFile.updateBytes(), com.quadcap.sql.file.SubPage.writeLong(), and com.quadcap.sql.file.Block.writeLong().

final void com.quadcap.sql.file.Block.writeShort int  pos,
short  val
 

Write a short (2-byte) value to the page.

Parameters:
pos the offset in the page of the short.
val the short value to write.

Definition at line 248 of file Block.java.

References com.quadcap.sql.file.Block.buf, and com.quadcap.sql.file.Block.writeShort().

Referenced by com.quadcap.sql.index.Bnode.setKeyIndex(), and com.quadcap.sql.file.Block.writeShort().


Member Data Documentation

byte [] com.quadcap.sql.file.Block.buf [private]
 

Definition at line 56 of file Block.java.

Referenced by com.quadcap.sql.file.Block.clear(), com.quadcap.sql.file.Block.flush(), com.quadcap.sql.file.Block.getData(), com.quadcap.sql.file.Block.getDataAndReset(), com.quadcap.sql.file.Block.init(), com.quadcap.sql.file.Block.read(), com.quadcap.sql.file.Block.readByte(), com.quadcap.sql.file.Block.readInt(), com.quadcap.sql.file.Block.readLong(), com.quadcap.sql.file.Block.readShort(), com.quadcap.sql.file.Block.setData(), com.quadcap.sql.file.Block.signature(), com.quadcap.sql.file.Block.write(), com.quadcap.sql.file.Block.writeByte(), com.quadcap.sql.file.Block.writeInt(), com.quadcap.sql.file.Block.writeLong(), and com.quadcap.sql.file.Block.writeShort().