Quadcap Embeddable Database

com.quadcap.sql.file.BlockAccess Class Reference

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

com.quadcap.sql.file.RandomAccess List of all members.

Detailed Description

This class implements a randomly accessible, growable region within a BlockFile object.

The region is defined by a root block, which either contains the entire data for the region (if it will fit), or contains a set of references to secondary blocks which contain the actual data. If the region is large enough, those secondary blocks themselves may be references, and so on.

Author:
Stan Bailes

Definition at line 58 of file BlockAccess.java.

Public Member Functions

 BlockAccess ()
 Default public constructor.

 BlockAccess (PageManager file, long rootBlock) throws IOException
 Construct a new BlockAccess attached to the specified block.

void init (PageManager file, long rootBlock) throws IOException
long size ()
 Return the size of this region.

void resize (long newSize) throws IOException
 Resize the region.

void write (long pos, byte[] buf, int offset, int len) throws IOException
 Write into the data region.

void read (long pos, byte[] buf, int offset, int len) throws IOException
 Read from the data region.

void close ()
 Finalization: We're done with this region.

void flush ()
String toString ()

Package Functions

final int[] radicesForDepth (int depth)
 Build the radices array for a region of the specified depth.

final long getBlockRef (Page b, int pos, boolean isRoot) throws IOException
 Return the specified block reference.

final long makeBlockRef (Page b, int pos, boolean isRoot) throws IOException
 Return the specified block reference.

final void setBlockRef (Page b, int pos, long val, boolean isRoot)
 Set the specified block reference.

final int refsForLevel (int level)
 Return the number of blockrefs that will fit in a block.

final int bufLen ()
 Return the size of the data portion of the block.

final String toString (long page)

Package Attributes

PageManager file
 The underlying store.

long rootBlock
 The 'root' block of this data area.

long size
int[] radices = null
 A vector of depth elements, indicating the size of the recursive sub-block at each level.

byte[] b1 = new byte[1]
int depth = 0
 Depth of this data area.

BlockPath path = null
 Path from root to leaf blocks.

Object fileLock = null
 The file lock.


Static Package Attributes

final int HEADER_SIZE = 8
final int REF_SIZE = 8

Private Member Functions

final BlockPath getPath (long pos) throws IOException
final long maxSizeForDepth (int level)
 Return the maximum size for a region of the specified depth.

final int depthForSize (long size)
 Return the depth necessary to represent a region of the specified size.


Constructor & Destructor Documentation

com.quadcap.sql.file.BlockAccess.BlockAccess  ) 
 

Default public constructor.

Definition at line 106 of file BlockAccess.java.

com.quadcap.sql.file.BlockAccess.BlockAccess PageManager  file,
long  rootBlock
throws IOException
 

Construct a new BlockAccess attached to the specified block.

Definition at line 112 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.file, com.quadcap.sql.file.BlockAccess.init(), and com.quadcap.sql.file.BlockAccess.rootBlock.


Member Function Documentation

final int com.quadcap.sql.file.BlockAccess.bufLen  )  [package]
 

Return the size of the data portion of the block.

Definition at line 403 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.file, and com.quadcap.sql.file.PageManager.getPageSize().

Referenced by com.quadcap.sql.file.BlockAccess.depthForSize(), com.quadcap.sql.file.BlockAccess.maxSizeForDepth(), com.quadcap.sql.file.BlockAccess.radicesForDepth(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.refsForLevel(), com.quadcap.sql.file.BlockAccess.resize(), and com.quadcap.sql.file.BlockAccess.write().

void com.quadcap.sql.file.BlockAccess.close  )  [virtual]
 

Finalization: We're done with this region.

Implements com.quadcap.sql.file.RandomAccess.

Definition at line 314 of file BlockAccess.java.

final int com.quadcap.sql.file.BlockAccess.depthForSize long  size  )  [private]
 

Return the depth necessary to represent a region of the specified size.

Parameters:
size the size of the region

Definition at line 426 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.BlockAccess.depthForSize(), and com.quadcap.sql.file.BlockAccess.HEADER_SIZE.

Referenced by com.quadcap.sql.file.BlockAccess.depthForSize(), com.quadcap.sql.file.BlockAccess.init(), and com.quadcap.sql.file.BlockAccess.resize().

void com.quadcap.sql.file.BlockAccess.flush  )  [virtual]
 

Implements com.quadcap.sql.file.RandomAccess.

Definition at line 317 of file BlockAccess.java.

final long com.quadcap.sql.file.BlockAccess.getBlockRef Page  b,
int  pos,
boolean  isRoot
throws IOException [package]
 

Return the specified block reference.

This method treats the data portion of the block as an array of integer blockrefs.

Parameters:
b the block containing the array of blockrefs
pos the location in the blockref array of the block number to fetch.

Definition at line 350 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.getBlockRef(), com.quadcap.sql.file.BlockAccess.HEADER_SIZE, and com.quadcap.sql.file.BlockAccess.REF_SIZE.

Referenced by com.quadcap.sql.file.BlockAccess.getBlockRef(), and com.quadcap.sql.file.BlockAccess.resize().

final BlockPath com.quadcap.sql.file.BlockAccess.getPath long  pos  )  throws IOException [private]
 

Definition at line 320 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.depth, com.quadcap.sql.file.BlockPath.getDepth(), com.quadcap.sql.file.BlockAccess.getPath(), com.quadcap.sql.file.BlockAccess.path, and com.quadcap.sql.file.BlockPath.setPos().

Referenced by com.quadcap.sql.file.BlockAccess.getPath(), com.quadcap.sql.file.BlockAccess.read(), and com.quadcap.sql.file.BlockAccess.write().

void com.quadcap.sql.file.BlockAccess.init PageManager  file,
long  rootBlock
throws IOException
 

Definition at line 116 of file BlockAccess.java.

References com.quadcap.sql.file.Page.decrRefCount(), com.quadcap.sql.file.BlockAccess.depth, com.quadcap.sql.file.BlockAccess.depthForSize(), com.quadcap.sql.file.BlockAccess.file, com.quadcap.sql.file.BlockAccess.fileLock, com.quadcap.sql.file.PageManager.getLock(), com.quadcap.sql.file.PageManager.getPage(), com.quadcap.sql.file.BlockAccess.init(), com.quadcap.sql.file.BlockAccess.radicesForDepth(), com.quadcap.sql.file.Page.readLong(), com.quadcap.sql.file.BlockAccess.rootBlock, and com.quadcap.sql.file.BlockAccess.size.

Referenced by com.quadcap.sql.file.BlockAccess.BlockAccess(), com.quadcap.sql.file.BlockFile.getBytes(), com.quadcap.sql.file.BlockAccess.init(), com.quadcap.sql.file.BlockFile.putBytes(), and com.quadcap.sql.file.BlockFile.updateBytes().

final long com.quadcap.sql.file.BlockAccess.makeBlockRef Page  b,
int  pos,
boolean  isRoot
throws IOException [package]
 

Return the specified block reference.

This method treats the data portion of the block as an array of long blockrefs. If the selected blockref is zero, this routine will allocate a new block and return the blockref of the newly created block, as well as update b's blockref array with the new blockref.

Parameters:
b the block containing the array of blockrefs
pos the location in the blockref array of the block number to fetch.

Definition at line 369 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.file, com.quadcap.sql.file.BlockAccess.HEADER_SIZE, com.quadcap.sql.file.BlockAccess.makeBlockRef(), com.quadcap.sql.file.PageManager.newPage(), and com.quadcap.sql.file.BlockAccess.REF_SIZE.

Referenced by com.quadcap.sql.file.BlockPath.getRefs(), com.quadcap.sql.file.BlockAccess.makeBlockRef(), and com.quadcap.sql.file.BlockPath.updatePath().

final long com.quadcap.sql.file.BlockAccess.maxSizeForDepth int  level  )  [private]
 

Return the maximum size for a region of the specified depth.

Definition at line 410 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.BlockAccess.HEADER_SIZE, and com.quadcap.sql.file.BlockAccess.maxSizeForDepth().

Referenced by com.quadcap.sql.file.BlockAccess.maxSizeForDepth().

final int [] com.quadcap.sql.file.BlockAccess.radicesForDepth int  depth  )  [package]
 

Build the radices array for a region of the specified depth.

Definition at line 332 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.BlockAccess.radicesForDepth(), and com.quadcap.sql.file.BlockAccess.refsForLevel().

Referenced by com.quadcap.sql.file.BlockAccess.init(), com.quadcap.sql.file.BlockAccess.radicesForDepth(), and com.quadcap.sql.file.BlockAccess.resize().

void com.quadcap.sql.file.BlockAccess.read long  pos,
byte[]  buf,
int  offset,
int  len
throws IOException [virtual]
 

Read from the data region.

Implements com.quadcap.sql.file.RandomAccess.

Definition at line 254 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.Page.decrRefCount(), com.quadcap.sql.file.BlockAccess.depth, com.quadcap.sql.file.BlockAccess.file, com.quadcap.sql.file.BlockAccess.fileLock, com.quadcap.sql.file.BlockPath.getBufPos(), com.quadcap.sql.file.BlockPath.getLeafBlock(), com.quadcap.sql.file.PageManager.getPage(), com.quadcap.sql.file.BlockAccess.getPath(), com.quadcap.sql.file.BlockAccess.HEADER_SIZE, com.quadcap.sql.file.BlockPath.incr(), com.quadcap.sql.file.BlockAccess.radices, com.quadcap.sql.file.Page.read(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.rootBlock, and com.quadcap.sql.file.BlockAccess.size().

Referenced by com.quadcap.sql.file.BlockFile.getBytes(), and com.quadcap.sql.file.BlockAccess.read().

final int com.quadcap.sql.file.BlockAccess.refsForLevel int  level  )  [package]
 

Return the number of blockrefs that will fit in a block.

Definition at line 396 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.BlockAccess.HEADER_SIZE, com.quadcap.sql.file.BlockAccess.REF_SIZE, and com.quadcap.sql.file.BlockAccess.refsForLevel().

Referenced by com.quadcap.sql.file.BlockAccess.radicesForDepth(), com.quadcap.sql.file.BlockAccess.refsForLevel(), and com.quadcap.sql.file.BlockAccess.resize().

void com.quadcap.sql.file.BlockAccess.resize long  newSize  )  throws IOException [virtual]
 

Resize the region.

Implements com.quadcap.sql.file.RandomAccess.

Definition at line 149 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.Page.clear(), com.quadcap.sql.file.Page.decrRefCount(), com.quadcap.sql.file.BlockAccess.depth, com.quadcap.sql.file.BlockAccess.depthForSize(), com.quadcap.sql.file.BlockAccess.file, com.quadcap.sql.file.BlockAccess.fileLock, com.quadcap.sql.file.PageManager.freePage(), com.quadcap.sql.file.BlockAccess.getBlockRef(), com.quadcap.sql.file.PageManager.getPage(), com.quadcap.sql.file.BlockAccess.HEADER_SIZE, com.quadcap.sql.file.PageManager.newPage(), com.quadcap.sql.file.BlockAccess.radices, com.quadcap.sql.file.BlockAccess.radicesForDepth(), com.quadcap.sql.file.Page.read(), com.quadcap.sql.file.Page.readLong(), com.quadcap.sql.file.BlockAccess.refsForLevel(), com.quadcap.sql.file.BlockAccess.resize(), com.quadcap.sql.file.BlockAccess.rootBlock, com.quadcap.sql.file.BlockAccess.setBlockRef(), com.quadcap.sql.file.BlockAccess.toString(), com.quadcap.sql.file.Page.write(), and com.quadcap.sql.file.Page.writeLong().

Referenced by com.quadcap.sql.file.BlockFile.putBytes(), com.quadcap.sql.file.BlockAccess.resize(), and com.quadcap.sql.file.BlockFile.updateBytes().

final void com.quadcap.sql.file.BlockAccess.setBlockRef Page  b,
int  pos,
long  val,
boolean  isRoot
[package]
 

Set the specified block reference.

Parameters:
b the block containing the array of blockrefs
pos the (zero-offset) index of the blockref within the array
val the value to store in the array

Definition at line 388 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.HEADER_SIZE, com.quadcap.sql.file.BlockAccess.REF_SIZE, com.quadcap.sql.file.BlockAccess.setBlockRef(), and com.quadcap.sql.file.Page.writeLong().

Referenced by com.quadcap.sql.file.BlockAccess.resize(), and com.quadcap.sql.file.BlockAccess.setBlockRef().

long com.quadcap.sql.file.BlockAccess.size  )  [virtual]
 

Return the size of this region.

Implements com.quadcap.sql.file.RandomAccess.

Definition at line 142 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockAccess.read().

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

Definition at line 443 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.depth, com.quadcap.sql.file.BlockAccess.path, com.quadcap.sql.file.BlockAccess.radices, and com.quadcap.sql.file.BlockAccess.rootBlock.

Referenced by com.quadcap.sql.file.BlockAccess.resize(), and com.quadcap.sql.file.BlockAccess.write().

final String com.quadcap.sql.file.BlockAccess.toString long  page  )  [package]
 

Definition at line 439 of file BlockAccess.java.

void com.quadcap.sql.file.BlockAccess.write long  pos,
byte[]  buf,
int  offset,
int  len
throws IOException [virtual]
 

Write into the data region.

Parameters:
pos the starting position to write
buf the buffer containing the data to write
offset the position of the first byte in the buffer
len the number of bytes to write

Implements com.quadcap.sql.file.RandomAccess.

Definition at line 215 of file BlockAccess.java.

References com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.Page.decrRefCount(), com.quadcap.sql.file.BlockAccess.depth, com.quadcap.sql.file.BlockAccess.file, com.quadcap.sql.file.BlockAccess.fileLock, com.quadcap.sql.file.BlockPath.getBufPos(), com.quadcap.sql.file.BlockPath.getLeafBlock(), com.quadcap.sql.file.PageManager.getPage(), com.quadcap.sql.file.BlockAccess.getPath(), com.quadcap.sql.file.BlockAccess.HEADER_SIZE, com.quadcap.sql.file.BlockPath.incr(), com.quadcap.sql.file.BlockAccess.rootBlock, com.quadcap.sql.file.BlockAccess.toString(), com.quadcap.sql.file.Page.write(), and com.quadcap.sql.file.BlockAccess.write().

Referenced by com.quadcap.sql.file.BlockFile.putBytes(), com.quadcap.sql.file.BlockFile.updateBytes(), and com.quadcap.sql.file.BlockAccess.write().


Member Data Documentation

byte [] com.quadcap.sql.file.BlockAccess.b1 = new byte[1] [package]
 

Definition at line 81 of file BlockAccess.java.

int com.quadcap.sql.file.BlockAccess.depth = 0 [package]
 

Depth of this data area.

A depth of zero indicates that the actual data area is entirely contained within the root block. A depth of one indicates that the data is contained in sub-blocks, and the root block contains the block numbers of the sub-blocks. Larger depths indicate that the sub-blocks contain pointers to other sub-blocks, etc.

Definition at line 91 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockPath.BlockPath(), com.quadcap.sql.file.BlockAccess.getPath(), com.quadcap.sql.file.BlockAccess.init(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.resize(), com.quadcap.sql.file.BlockAccess.toString(), and com.quadcap.sql.file.BlockAccess.write().

PageManager com.quadcap.sql.file.BlockAccess.file [package]
 

The underlying store.

Definition at line 65 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockAccess.BlockAccess(), com.quadcap.sql.file.BlockAccess.bufLen(), com.quadcap.sql.file.BlockPath.getLeafBlock(), com.quadcap.sql.file.BlockPath.getRefs(), com.quadcap.sql.file.BlockAccess.init(), com.quadcap.sql.file.BlockAccess.makeBlockRef(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.resize(), com.quadcap.sql.file.BlockPath.updatePath(), and com.quadcap.sql.file.BlockAccess.write().

Object com.quadcap.sql.file.BlockAccess.fileLock = null [package]
 

The file lock.

Definition at line 101 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockAccess.init(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.resize(), and com.quadcap.sql.file.BlockAccess.write().

final int com.quadcap.sql.file.BlockAccess.HEADER_SIZE = 8 [static, package]
 

Definition at line 59 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockAccess.depthForSize(), com.quadcap.sql.file.BlockAccess.getBlockRef(), com.quadcap.sql.file.BlockAccess.makeBlockRef(), com.quadcap.sql.file.BlockAccess.maxSizeForDepth(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.refsForLevel(), com.quadcap.sql.file.BlockAccess.resize(), com.quadcap.sql.file.BlockAccess.setBlockRef(), and com.quadcap.sql.file.BlockAccess.write().

BlockPath com.quadcap.sql.file.BlockAccess.path = null [package]
 

Path from root to leaf blocks.

Definition at line 96 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockAccess.getPath(), and com.quadcap.sql.file.BlockAccess.toString().

int [] com.quadcap.sql.file.BlockAccess.radices = null [package]
 

A vector of depth elements, indicating the size of the recursive sub-block at each level.

Definition at line 79 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockPath.getPath(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.resize(), and com.quadcap.sql.file.BlockAccess.toString().

final int com.quadcap.sql.file.BlockAccess.REF_SIZE = 8 [static, package]
 

Definition at line 60 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockAccess.getBlockRef(), com.quadcap.sql.file.BlockAccess.makeBlockRef(), com.quadcap.sql.file.BlockAccess.refsForLevel(), and com.quadcap.sql.file.BlockAccess.setBlockRef().

long com.quadcap.sql.file.BlockAccess.rootBlock [package]
 

The 'root' block of this data area.

The format of this block is as follows:

Bytes 0-3: The size of this data area, in bytes.

Definition at line 72 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockAccess.BlockAccess(), com.quadcap.sql.file.BlockPath.getRefs(), com.quadcap.sql.file.BlockAccess.init(), com.quadcap.sql.file.BlockAccess.read(), com.quadcap.sql.file.BlockAccess.resize(), com.quadcap.sql.file.BlockAccess.toString(), and com.quadcap.sql.file.BlockAccess.write().

long com.quadcap.sql.file.BlockAccess.size [package]
 

Definition at line 73 of file BlockAccess.java.

Referenced by com.quadcap.sql.file.BlockFile.getBytes(), com.quadcap.sql.file.BlockAccess.init(), and com.quadcap.sql.file.BlockFile.updateBytes().