ionflux.org | Impressum

Ionflux::Tools::BufferedTable Class Reference
[Database interface]

Buffered database table. More...

#include <BufferedTable.hpp>

Inheritance diagram for Ionflux::Tools::BufferedTable:

Inheritance graph
[legend]
Collaboration diagram for Ionflux::Tools::BufferedTable:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 BufferedTable ()
 Constructor.
 BufferedTable (unsigned int initBlockSize)
 Constructor.
 BufferedTable (Ionflux::Tools::Database *initDatabase)
 Constructor.
 BufferedTable (Ionflux::Tools::Database *initDatabase, unsigned int initBlockSize)
 Constructor.
 BufferedTable (Ionflux::Tools::Database *initDatabase, unsigned int initBlockSize, const std::string &initTable, const std::string &initKeyField, const std::vector< std::string > &initFields)
 Constructor.
 BufferedTable (Ionflux::Tools::Database *initDatabase, unsigned int initBlockSize, const std::string &initTable, const std::string &initKeyField, const std::vector< std::string > &initFields, const std::string &initOrigin)
 Constructor.
virtual ~BufferedTable ()
 Destructor.
virtual void setConfig (Ionflux::Tools::Node &newConfig)
 Set configuration.
virtual void setDatabase (Ionflux::Tools::Database *newDatabase)
 Set source database.
virtual Ionflux::Tools::DatabasegetDatabase ()
 Get source database.
virtual bool validateTable ()
 Validate database table.
virtual Ionflux::Tools::NodegetRecord (int recIndex)
 Get record.
virtual Ionflux::Tools::Nodeoperator[] (int recIndex)
 Get record.
virtual Ionflux::Tools::NodegetCurrentRecord ()
 Get current record.
virtual Ionflux::Tools::NodegetNextRecord ()
 Get next record.
virtual Ionflux::Tools::NodegetPrevRecord ()
 Get previous record.
virtual int getTableOffset (const std::string &key)
 Get key table offset.
virtual std::string getKey (const std::string &key, int recOffset)
 Get key.
virtual std::string getKey (int recIndex)
 Get key by index.
virtual std::string fetchKey (unsigned int offset)
 Get key from database table.
virtual unsigned int getNumRecs ()
 Get number of records.
virtual unsigned int getFieldIndex (const std::string &fieldName)
 Get field index.
virtual void refresh ()
 Refresh buffer.
virtual void clearBlocks ()
 Clear buffer blocks.
virtual void clear ()
 Clear buffer.
virtual Ionflux::Tools::ReportergetLog ()
 Get Console output/logging facility.
virtual void setOrigin (unsigned int offset)
 Set key of the record with index pointer zero.
virtual void setCurrentRecord (const std::string &newKey)
 Set current record.
virtual void setBlockSize (unsigned int newBlockSize)
 Set buffer block size.
virtual void setOrigin (const std::string &newOrigin)
 Set key of the record with index pointer zero.
virtual void setTable (const std::string &newTable)
 Set source database table name.
virtual void setKeyField (const std::string &newKeyField)
 Set name of the key field of the source database table.
virtual void setFields (const std::vector< std::string > &newFields)
 Set names of fields to be included in each record.
virtual void setCurrentIndex (int newCurrentIndex)
 Set index of current record.
virtual void setCreateTemplate (const std::string &newCreateTemplate)
 Set create template.
virtual void setCreateTemplateFile (const std::string &newCreateTemplateFile)
 Set create template file name.
virtual unsigned int getBlockSize () const
 Get buffer block size.
virtual std::string getOrigin () const
 Get key of the record with index pointer zero.
virtual std::string getTable () const
 Get source database table name.
virtual std::string getKeyField () const
 Get name of the key field of the source database table.
virtual std::vector< std::string > getFields () const
 Get names of fields to be included in each record.
virtual int getCurrentIndex () const
 Get index of current record.
virtual std::string getCreateTemplate () const
 Get create template.
virtual std::string getCreateTemplateFile () const
 Get create template file name.

Static Public Attributes

static const unsigned int DEFAULT_BLOCK_SIZE = 50
 Default buffering block size.

Protected Member Functions

virtual void cycleForward ()
 Cycle buffers (forward).
virtual void cycleBackward ()
 Cycle buffers (backward).
virtual void updateIndices ()
 Update indices.
virtual void initBlock (Ionflux::Tools::Node *target, const std::string &fromKey, bool invert=false)
 Initialize buffer block.
virtual int getBlockStartOffset (const std::string &key)
 Get block start offset.

Protected Attributes

Ionflux::Tools::Reporter log
 Console output/logging.
Ionflux::Tools::ObjectPool pool
 Object allocation pool.
Ionflux::Tools::Databasedatabase
 Source database.
Ionflux::Tools::NodeprevBlock
 Previous block.
Ionflux::Tools::NodecurrentBlock
 Current block.
Ionflux::Tools::NodenextBlock
 Next block.
int currentOffset
 Index of the first record of the current block.
std::map< std::string, unsigned
int > 
offsetIndex
 Key/offset index.
std::vector< std::string > keyIndex
 Offset/key index.
unsigned int blockSize
 Buffer block size.
std::string origin
 Key of the record with index pointer zero.
std::string table
 Source database table name.
std::string keyField
 Name of the key field of the source database table.
std::vector< std::string > fields
 Names of fields to be included in each record.
int currentIndex
 Index of current record.
std::string createTemplate
 Create template.
std::string createTemplateFile
 Create template file name.
Ionflux::Tools::Node config
 Buffered table configuration node.

Detailed Description

Buffered database table.

A buffered table providing access to records which are stored in a database table. The table buffer allows for the efficient sequential retrieval of records from the database, where the order of records is defined by a specified key field. This is achieved by fetching a block (or page) of records on each database query. Records from the blocks loaded into memory may then be accessed sequentially. A new block is fetched from the database automatically whenever the current index pointer goes out of the scope of a block.

Note:
The buffered table also allows random access, however, this does not have any advantages in efficiency unless the random accesses occur within order of the block size.


Constructor & Destructor Documentation

Ionflux::Tools::BufferedTable::BufferedTable  ) 
 

Constructor.

Construct new BufferedTable object.

Ionflux::Tools::BufferedTable::BufferedTable unsigned int  initBlockSize  ) 
 

Constructor.

Construct new BufferedTable object.

Parameters:
initBlockSize Buffering block size.

Ionflux::Tools::BufferedTable::BufferedTable Ionflux::Tools::Database initDatabase  ) 
 

Constructor.

Construct new BufferedTable object.

Parameters:
initDatabase Source database.

Ionflux::Tools::BufferedTable::BufferedTable Ionflux::Tools::Database initDatabase,
unsigned int  initBlockSize
 

Constructor.

Construct new BufferedTable object.

Parameters:
initDatabase Source database.
initBlockSize Buffering block size.

Ionflux::Tools::BufferedTable::BufferedTable Ionflux::Tools::Database initDatabase,
unsigned int  initBlockSize,
const std::string &  initTable,
const std::string &  initKeyField,
const std::vector< std::string > &  initFields
 

Constructor.

Construct new BufferedTable object.

Parameters:
initDatabase Source database.
initBlockSize Buffering block size.
initTable Source database table name.
initKeyField Name of the key field of the source database table.
initFields Names of fields to be included in each record.

Ionflux::Tools::BufferedTable::BufferedTable Ionflux::Tools::Database initDatabase,
unsigned int  initBlockSize,
const std::string &  initTable,
const std::string &  initKeyField,
const std::vector< std::string > &  initFields,
const std::string &  initOrigin
 

Constructor.

Construct new BufferedTable object.

Parameters:
initDatabase Source database.
initBlockSize Buffering block size.
initTable Source database table name.
initKeyField Name of the key field of the source database table.
initFields Names of fields to be included in each record.
initOrigin Key of the record with index pointer zero.

Ionflux::Tools::BufferedTable::~BufferedTable  )  [virtual]
 

Destructor.

Destruct BufferedTable object.


Member Function Documentation

void Ionflux::Tools::BufferedTable::clear  )  [virtual]
 

Clear buffer.

Clear all records from the buffer.

void Ionflux::Tools::BufferedTable::clearBlocks  )  [virtual]
 

Clear buffer blocks.

Clear all records from the buffer blocks.

Note:
While this function will clear all data from the buffer, it will not touch any of the other internal state (unlike clear()).
See also:
clear

void Ionflux::Tools::BufferedTable::cycleBackward  )  [protected, virtual]
 

Cycle buffers (backward).

Cycle the buffer blocks backward.

Note:
This effectively discards the next block, sets the next block to the current block, the current block to the previous block end empties the previous block.

void Ionflux::Tools::BufferedTable::cycleForward  )  [protected, virtual]
 

Cycle buffers (forward).

Cycle the buffer blocks forward.

Note:
This effectively discards the previous block, sets the previous block to the current block, the current block to the next block end empties the next block.

std::string Ionflux::Tools::BufferedTable::fetchKey unsigned int  offset  )  [virtual]
 

Get key from database table.

Get the key of the record with the specified offset from the start of the database table.

See also:
getKey
Parameters:
offset Record offset.
Returns:
Key of record with specified offset, or an empty string if record does not exist..

unsigned int Ionflux::Tools::BufferedTable::getBlockSize  )  const [virtual]
 

Get buffer block size.

Returns:
Current value of buffer block size.

int Ionflux::Tools::BufferedTable::getBlockStartOffset const std::string &  key  )  [protected, virtual]
 

Get block start offset.

Get the offset of the start of the data block which contains the specified key, relative to the specified key.

Note:
A data block is a block of data in the source database table of buffer block size, with the first block aligned to the start of the table. The data block that contains a certain key may be different from the buffer block that contains that same key. Data and buffer blocks can contain the same data only if the buffer block boundaries are aligned to the data block boundaries.
Parameters:
key Key.
Returns:
Block start offset.

std::string Ionflux::Tools::BufferedTable::getCreateTemplate  )  const [virtual]
 

Get create template.

Returns:
Current value of create template.

std::string Ionflux::Tools::BufferedTable::getCreateTemplateFile  )  const [virtual]
 

Get create template file name.

Returns:
Current value of create template file name.

int Ionflux::Tools::BufferedTable::getCurrentIndex  )  const [virtual]
 

Get index of current record.

Returns:
Current value of index of current record.

Ionflux::Tools::Node * Ionflux::Tools::BufferedTable::getCurrentRecord  )  [virtual]
 

Get current record.

Get the current record.

Returns:
Current record, or null if the record does not exist.

Ionflux::Tools::Database * Ionflux::Tools::BufferedTable::getDatabase  )  [virtual]
 

Get source database.

Get the source database that will be used for fetching record blocks.

Returns:
Source database. (The returned object will be referenced).

unsigned int Ionflux::Tools::BufferedTable::getFieldIndex const std::string &  fieldName  )  [virtual]
 

Get field index.

Get the index of the specified field.

Parameters:
fieldName Field name.
Returns:
Field index.

std::vector< std::string > Ionflux::Tools::BufferedTable::getFields  )  const [virtual]
 

Get names of fields to be included in each record.

Returns:
Current value of names of fields to be included in each record.

std::string Ionflux::Tools::BufferedTable::getKey int  recIndex  )  [virtual]
 

Get key by index.

Get the key of the record with the specified index relative to the origin.

See also:
fetchKey
Parameters:
recIndex Record index.
Returns:
Key of record with specified index, or an empty string if the record does not exist.

std::string Ionflux::Tools::BufferedTable::getKey const std::string &  key,
int  recOffset
[virtual]
 

Get key.

Get the key of the record with the specified offset relative to the record with the specified key.

See also:
fetchKey
Parameters:
key Key.
recOffset Offset of target record.
Returns:
Key of record with specified offset relative to specified key, or an empty string if the record does not exist.

std::string Ionflux::Tools::BufferedTable::getKeyField  )  const [virtual]
 

Get name of the key field of the source database table.

Returns:
Current value of name of the key field of the source database table.

Ionflux::Tools::Reporter & Ionflux::Tools::BufferedTable::getLog  )  [virtual]
 

Get Console output/logging facility.

The console output/logging facility used by this object.

Returns:
Console output/logging facility.

Ionflux::Tools::Node * Ionflux::Tools::BufferedTable::getNextRecord  )  [virtual]
 

Get next record.

Get the next record.

Note:
This also makes the next record the current record.
Returns:
Next record, or null if the record does not exist.

unsigned int Ionflux::Tools::BufferedTable::getNumRecs  )  [virtual]
 

Get number of records.

Get the number of records in the source database table.

Returns:
Number of records.

std::string Ionflux::Tools::BufferedTable::getOrigin  )  const [virtual]
 

Get key of the record with index pointer zero.

Returns:
Current value of key of the record with index pointer zero.

Ionflux::Tools::Node * Ionflux::Tools::BufferedTable::getPrevRecord  )  [virtual]
 

Get previous record.

Get the previous record.

Note:
This also makes the previous record the current record.
Returns:
Previous record, or null if the record does not exist.

Ionflux::Tools::Node * Ionflux::Tools::BufferedTable::getRecord int  recIndex  )  [virtual]
 

Get record.

Get the record with the specified index.

Parameters:
recIndex Record index.
Returns:
Record with specified index, or null if the record does not exist.

std::string Ionflux::Tools::BufferedTable::getTable  )  const [virtual]
 

Get source database table name.

Returns:
Current value of source database table name.

int Ionflux::Tools::BufferedTable::getTableOffset const std::string &  key  )  [virtual]
 

Get key table offset.

Get the database table offset (position relative to the start of the table) of a key.

Parameters:
key Key.
Returns:
Table offset.

void Ionflux::Tools::BufferedTable::initBlock Ionflux::Tools::Node target,
const std::string &  fromKey,
bool  invert = false
[protected, virtual]
 

Initialize buffer block.

Initialize a block of the buffer with records starting from the specified key value.

Note:
Pass true to invert to initialize a block with records starting from the last record (instead of the first) counting records backwards and result records being aligned to the end of the block (instead of the start of the block).
Parameters:
target Where to store the resulting records.
fromKey Key of the first (or last, if invert is true) record of the block.
invert Whether initialization order should be inverted.

Ionflux::Tools::Node * Ionflux::Tools::BufferedTable::operator[] int  recIndex  )  [virtual]
 

Get record.

Get the record with the specified index.

Parameters:
recIndex Record index.
Returns:
Record with specified index, or null if the record does not exist.

void Ionflux::Tools::BufferedTable::refresh  )  [virtual]
 

Refresh buffer.

Refresh the buffer to reflect changes in the database table.

Note:
This function should always be called after records have been inserted, changed or deleted in the database table. Failing to do this may result in inaccurate buffers or even errors.

void Ionflux::Tools::BufferedTable::setBlockSize unsigned int  newBlockSize  )  [virtual]
 

Set buffer block size.

Set new value of buffer block size.

Parameters:
newBlockSize New value of buffer block size.

void Ionflux::Tools::BufferedTable::setConfig Ionflux::Tools::Node newConfig  )  [virtual]
 

Set configuration.

Initialize the configuration of the buffered table from a configuration data node.

Parameters:
newConfig Configuration node.

void Ionflux::Tools::BufferedTable::setCreateTemplate const std::string &  newCreateTemplate  )  [virtual]
 

Set create template.

Set new value of create template.

Parameters:
newCreateTemplate New value of create template.

void Ionflux::Tools::BufferedTable::setCreateTemplateFile const std::string &  newCreateTemplateFile  )  [virtual]
 

Set create template file name.

Set new value of create template file name.

Parameters:
newCreateTemplateFile New value of create template file name.

void Ionflux::Tools::BufferedTable::setCurrentIndex int  newCurrentIndex  )  [virtual]
 

Set index of current record.

Set new value of index of current record.

Parameters:
newCurrentIndex New value of index of current record.

void Ionflux::Tools::BufferedTable::setCurrentRecord const std::string &  newKey  )  [virtual]
 

Set current record.

Set the current record by key.

See also:
setCurrentIndex
Parameters:
newKey Key of record to be set as current record.

void Ionflux::Tools::BufferedTable::setDatabase Ionflux::Tools::Database newDatabase  )  [virtual]
 

Set source database.

Set the source database that will be used for fetching record blocks.

Parameters:
newDatabase Source database.

void Ionflux::Tools::BufferedTable::setFields const std::vector< std::string > &  newFields  )  [virtual]
 

Set names of fields to be included in each record.

Set new value of names of fields to be included in each record.

Parameters:
newFields New value of names of fields to be included in each record.

void Ionflux::Tools::BufferedTable::setKeyField const std::string &  newKeyField  )  [virtual]
 

Set name of the key field of the source database table.

Set new value of name of the key field of the source database table.

Parameters:
newKeyField New value of name of the key field of the source database table.

void Ionflux::Tools::BufferedTable::setOrigin const std::string &  newOrigin  )  [virtual]
 

Set key of the record with index pointer zero.

Set new value of key of the record with index pointer zero.

Parameters:
newOrigin New value of key of the record with index pointer zero.

void Ionflux::Tools::BufferedTable::setOrigin unsigned int  offset  )  [virtual]
 

Set key of the record with index pointer zero.

Set the key of the record with index pointer zero by its offset in the database table.

Parameters:
offset Database table offset.

void Ionflux::Tools::BufferedTable::setTable const std::string &  newTable  )  [virtual]
 

Set source database table name.

Set new value of source database table name.

Parameters:
newTable New value of source database table name.

void Ionflux::Tools::BufferedTable::updateIndices  )  [protected, virtual]
 

Update indices.

Update the key/offset and offset/key indices.

bool Ionflux::Tools::BufferedTable::validateTable  )  [virtual]
 

Validate database table.

Validate the existence of the database table. If the table does not exist and a template is set, the table will be created automatically.

Returns:
true on success, false otherwise.


Member Data Documentation

unsigned int Ionflux::Tools::BufferedTable::blockSize [protected]
 

Buffer block size.

Ionflux::Tools::Node Ionflux::Tools::BufferedTable::config [protected]
 

Buffered table configuration node.

std::string Ionflux::Tools::BufferedTable::createTemplate [protected]
 

Create template.

std::string Ionflux::Tools::BufferedTable::createTemplateFile [protected]
 

Create template file name.

Ionflux::Tools::Node* Ionflux::Tools::BufferedTable::currentBlock [protected]
 

Current block.

int Ionflux::Tools::BufferedTable::currentIndex [protected]
 

Index of current record.

int Ionflux::Tools::BufferedTable::currentOffset [protected]
 

Index of the first record of the current block.

Ionflux::Tools::Database* Ionflux::Tools::BufferedTable::database [protected]
 

Source database.

const unsigned int Ionflux::Tools::BufferedTable::DEFAULT_BLOCK_SIZE = 50 [static]
 

Default buffering block size.

std::vector<std::string> Ionflux::Tools::BufferedTable::fields [protected]
 

Names of fields to be included in each record.

std::string Ionflux::Tools::BufferedTable::keyField [protected]
 

Name of the key field of the source database table.

std::vector<std::string> Ionflux::Tools::BufferedTable::keyIndex [protected]
 

Offset/key index.

Ionflux::Tools::Reporter Ionflux::Tools::BufferedTable::log [protected]
 

Console output/logging.

Ionflux::Tools::Node* Ionflux::Tools::BufferedTable::nextBlock [protected]
 

Next block.

std::map<std::string, unsigned int> Ionflux::Tools::BufferedTable::offsetIndex [protected]
 

Key/offset index.

std::string Ionflux::Tools::BufferedTable::origin [protected]
 

Key of the record with index pointer zero.

Ionflux::Tools::ObjectPool Ionflux::Tools::BufferedTable::pool [protected]
 

Object allocation pool.

Ionflux::Tools::Node* Ionflux::Tools::BufferedTable::prevBlock [protected]
 

Previous block.

std::string Ionflux::Tools::BufferedTable::table [protected]
 

Source database table name.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:07:26 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6