Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

GeneralData Class Reference

This class is the base class for all data items that are to be stored in the Berkeley Db databases. It has methods for serializing its data to and from a bytestream and has methods for writing the same data to and from a xml dom tree. It also let you specify how this data should be indexed in the Berkeley Db databases for very fast retrieval. More...

#include <generaldata.h>

Inheritance diagram for GeneralData:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 GeneralData ()
virtual ~GeneralData ()
virtual void print_debug_info ()
db_recno_t getRecno ()
void setRecno (db_recno_t recno)
virtual void readAttributes (const QXmlAttributes &attr)=0
virtual void writeXml (std::ostream &stream)=0
virtual void readDom (QDomElement &elem)
virtual void writeDom (QDomElement &elem)
virtual void readStream (QDataStream &stream)=0
virtual void writeStream (QDataStream &stream)=0
virtual TrDb::IndexMap getIndexMap ()=0
virtual std::string uniqueName ()=0
void copy (GeneralData *other)

Protected Attributes

db_recno_t m_recno

Detailed Description

This class is the base class for all data items that are to be stored in the Berkeley Db databases. It has methods for serializing its data to and from a bytestream and has methods for writing the same data to and from a xml dom tree. It also let you specify how this data should be indexed in the Berkeley Db databases for very fast retrieval.

The function of this class is to transport data in and out of the Berkeley db backend. It is important to realize that changing values of data members of GeneralData and its subclasses will have no effect to other parts of your application before your GeneralData object has been used in the Database interface.

When you are implementing subclasses of GeneralData you will see the benifits of object orientation. You just have to serialize/unserialize the extra data members of the subclass. The parent class will have to serialize/unserialize its data members so you have to remember letting readStream() and writeStream() of your subclass call the readStream() resp. writeStream() of its parent class. Just be careful of the order of things when doing serializing and unserializing.

Right now there is a limit of 2^32 ( ca 4 billions ) of records that can be stored in the berkeley db backend for each GeneralData subclass. This limit is easy to recognize from the fact that the index type, db_recno_t, is a u_int32_t. For more information about berkeley db limits see: http://www.sleepycat.com/docs/ref/am_misc/dbsizes.html

Idea for the future to maybe implement: add hooks to GeneralData, like virtual void hookBeforeCreate(Txnid *) and virtual void hookBeforeRemove(Txnid *). Database::Creator would then call these hooks everytime a create or remove is to be done. We would now have the possibility to add substring search functionality for the dna sequence in the DnaStrData feature. We implement a new Class, SubStrData : public GeneralData that stores e.g. sequences of length 12. The DnaStrData::hookBeforeCreate(Txnid *) creates each possible 12-length-substring as records in the SubStrData. The SubStrData::getIndexMap() should return two secondary indices: one with sorting of the DnaStrData recno, and one with sorting in lexicographical order of the 12-length-substring

Definition at line 80 of file generaldata.h.


Constructor & Destructor Documentation

GeneralData::GeneralData  ) 
 

Definition at line 21 of file generaldata.cpp.

00022 {}

virtual GeneralData::~GeneralData  )  [inline, virtual]
 

Definition at line 84 of file generaldata.h.

00084 {}


Member Function Documentation

void GeneralData::copy GeneralData other  ) 
 

Definition at line 43 of file generaldata.cpp.

References getRecno(), readStream(), setRecno(), uniqueName(), and writeStream().

Referenced by TrapperDoc::importChromat(), TrapperDoc::importMates(), and TrapperDoc::importPhd().

00044 {
00045   if (this == other || this->uniqueName() != other->uniqueName()) {
00046     return;
00047   }
00048   QByteArray ar;
00049   QDataStream streamout( ar, IO_WriteOnly );
00050   other->writeStream(streamout);
00051   QDataStream streamin( ar, IO_ReadOnly );
00052   this->readStream(streamin);
00053   
00054   this->setRecno( other->getRecno() );
00055 }

virtual TrDb::IndexMap GeneralData::getIndexMap  )  [pure virtual]
 

Returns a TrDb::IndexMap that specifies which secondary indexes should be generated for stored data objects of this class in the Berkeley Db backend. Each record in the TrDb::IndexMap generates a secondary index built as a btree ( a DB_BTREE in Berkeley Db wording ). The secondary index is sorted which makes it possible to do queries like "Give me the object that has the smallest value, bigger or equal than x".

And about speed performance, a quote from Berkeley Db documentation says: "Searches take O(log base_b N) time, where base_b is the average number of keys per page, and N is the total number of keys stored"

Implemented in FeatureData, DnpData, and ReadData.

Referenced by hookBeforeCreate(), and TrapperDoc::openDbs().

db_recno_t GeneralData::getRecno  ) 
 

Returns the primary key index value of this GeneralData object. The primary key index value is unique among all stored objects of this class. But the primary key index values are not unique between different subclasses of GeneralData. The primary key indices for GeneralData and its subclasses are all implemented as primary databases of type Recno.

See also:
http://www.sleepycat.com/docs/ref/am_conf/intro.html

Definition at line 38 of file generaldata.cpp.

References m_recno.

Referenced by TrapperView::contentsMousePressEvent(), copy(), TrapperView::findRead(), TrapperView::getInfo(), TrapperDoc::importChromat(), TrapperDoc::importPhd(), ReadData::print_debug_info(), TrapperDoc::saveExport(), TrapperView::selectAll(), TrapperView::selectBetween(), and FindMatesAlgo::start().

00039 {
00040     return m_recno;
00041 }

virtual void GeneralData::print_debug_info  )  [inline, virtual]
 

Prints some info for debugging, this should be removed in release version!

Reimplemented in FeatureData, and ReadData.

Definition at line 86 of file generaldata.h.

References uniqueName().

00086 { std::cerr<<"No debug info for class "<<uniqueName()<<endl;}

virtual void GeneralData::readAttributes const QXmlAttributes &  attr  )  [pure virtual]
 

Loads the state of this object from QXmlAttributes.This method is used for importing.

Implemented in FeatureData, DnpData, DnaStrData, ChromatData, QualityData, and ReadData.

Referenced by TrapperParser::startElement().

void GeneralData::readDom QDomElement &  elem  )  [virtual]
 

Loads the state of this object from a dom tree. Or in other words reads in the values of the data members of this class from a dom tree underneath the QDomElement elem. This method is used for importing.

Reimplemented in FeatureData, DnpData, DnaStrData, ChromatData, QualityData, and ReadData.

Definition at line 29 of file generaldata.cpp.

References m_recno.

Referenced by TrapperDoc::import(), ReadData::readDom(), and FeatureData::readDom().

00030 {
00031     Q_ASSERT( elem.hasAttribute( "recno" ));
00032     QString recnoStr = elem.attribute("recno");
00033     ulong recnoULong = recnoStr.toULong();
00034     m_recno = static_cast< db_recno_t > ( recnoULong );
00035     return;
00036 }

virtual void GeneralData::readStream QDataStream &  stream  )  [pure virtual]
 

Loads the state of this object from a byte stream. Or in other words reads and unserializes a byte stream to set the values of this class object. This method is used for loading a GeneralData object from Berkeley Db.

Implemented in FeatureData, DnpData, DnaStrData, ChromatData, QualityData, and ReadData.

Referenced by copy(), TrapperView::readSelected(), and Database::setFromDbt().

void GeneralData::setRecno db_recno_t  recno  )  [inline]
 

Set the primary key index value of this GeneralData object.

Definition at line 97 of file generaldata.h.

References m_recno.

Referenced by MAl::commit_seq_to_db(), copy(), Destroyer::destroy(), and MoveAlgo::start().

00097 { m_recno = recno; }

virtual std::string GeneralData::uniqueName  )  [pure virtual]
 

Specifies a name that uniquely should identify this class. It will be used for lookups in the GeneralMaker class.

Implemented in DnpData, DnaStrData, ChromatData, QualityData, and ReadData.

Referenced by copy(), print_debug_info(), and FeatureData::writeXml().

void GeneralData::writeDom QDomElement &  elem  )  [virtual]
 

Saves the state of this object to a dom tree. Or in other words writes out the internal data held in this class to a dom tree underneath the QDomElement elem. This method is used for exporting.

Reimplemented in FeatureData, DnpData, DnaStrData, ChromatData, QualityData, and ReadData.

Definition at line 24 of file generaldata.cpp.

References m_recno.

Referenced by ReadData::writeDom(), and FeatureData::writeDom().

00025 {
00026     elem.setAttribute("recno",m_recno);
00027 }

virtual void GeneralData::writeStream QDataStream &  stream  )  [pure virtual]
 

Saves the state of this object to a byte stream. Or in other words serializes and writes the internal data held in this class object to a byte stream. This method is used for storing a GeneralData object into Berkeley Db.

Implemented in FeatureData, DnpData, DnaStrData, ChromatData, QualityData, and ReadData.

Referenced by copy().

virtual void GeneralData::writeXml std::ostream &  stream  )  [pure virtual]
 

Writes the state of this object to a stream as an XML entry. This method is used for exporting

Implemented in ReadData.


Member Data Documentation

db_recno_t GeneralData::m_recno [protected]
 

Definition at line 151 of file generaldata.h.

Referenced by getRecno(), readDom(), setRecno(), and writeDom().


The documentation for this class was generated from the following files:
Generated on Fri Mar 17 17:44:59 2006 for trapper by  doxygen 1.4.4