#include <PoolDatabaseSchema.h>
Public Member Functions | |
bool | add (const std::string &sequenceName) |
void | create () |
void | drop () |
void | erase (const std::string &sequenceName) |
bool | exists () |
bool | getLastId (const std::string &sequenceName, int &lastId) |
void | init (PoolDbCache &dbCache) |
std::string | name () |
PoolSequenceTable (coral::ISchema &dbSchema) | |
void | sinchronize (const std::string &sequenceName, int lastValue) |
virtual | ~PoolSequenceTable () |
Static Public Member Functions | |
static std::string | sequenceNameColumn () |
static std::string | sequenceValueColumn () |
static std::string | tableName () |
Private Attributes | |
PoolDbCache * | m_dbCache |
Definition at line 66 of file PoolDatabaseSchema.h.
ora::PoolSequenceTable::PoolSequenceTable | ( | coral::ISchema & | dbSchema | ) | [explicit] |
Definition at line 87 of file PoolDatabaseSchema.cc.
: ISequenceTable( schema), m_dbCache( 0 ){ }
ora::PoolSequenceTable::~PoolSequenceTable | ( | ) | [virtual] |
Definition at line 92 of file PoolDatabaseSchema.cc.
{ }
bool ora::PoolSequenceTable::add | ( | const std::string & | sequenceName | ) | [virtual] |
Implements ora::ISequenceTable.
Definition at line 100 of file PoolDatabaseSchema.cc.
References python::IdGenerator::schema.
{ // Create the entry in the table if it does not exist. coral::AttributeList insertData; insertData.extend<std::string>(sequenceNameColumn()); insertData.extend<int>(sequenceValueColumn()); coral::AttributeList::iterator iAttribute = insertData.begin(); iAttribute->data< std::string >() = sequenceName; ++iAttribute; iAttribute->data< int >() = 0; schema().tableHandle( tableName() ).dataEditor().insertRow( insertData ); return true; }
void ora::PoolSequenceTable::create | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 194 of file PoolDatabaseSchema.cc.
References python::IdGenerator::schema, and ora::throwException().
{ if( schema().existsTable( tableName() )){ throwException( "POOL database sequence table already exists in this schema.", "PoolSequenceTable::create"); } throwException( "POOL database cannot be created.","PoolSequenceTable::create"); }
void ora::PoolSequenceTable::drop | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 202 of file PoolDatabaseSchema.cc.
References python::IdGenerator::schema.
void ora::PoolSequenceTable::erase | ( | const std::string & | sequenceName | ) | [virtual] |
Implements ora::ISequenceTable.
Definition at line 174 of file PoolDatabaseSchema.cc.
References python::IdGenerator::schema.
{ coral::AttributeList whereData; whereData.extend<std::string>(sequenceNameColumn()); whereData[ sequenceNameColumn() ].data<std::string>() = sequenceName; std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() ); schema().tableHandle( tableName() ).dataEditor().deleteRows( whereClause, whereData ); }
bool ora::PoolSequenceTable::exists | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 186 of file PoolDatabaseSchema.cc.
References python::IdGenerator::schema, and ora::throwException().
{ if(!m_dbCache){ throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::exists"); } // ???? return schema().existsTable( tableName() ); }
bool ora::PoolSequenceTable::getLastId | ( | const std::string & | sequenceName, |
int & | lastId | ||
) | [virtual] |
Implements ora::ISequenceTable.
Definition at line 114 of file PoolDatabaseSchema.cc.
References o2o::query, python::IdGenerator::schema, and ora::throwException().
{ if(!m_dbCache){ throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::getLastId"); } // first lookup in the cache for the built in sequences... std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences(); std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName ); if( iS != seq.end()){ if( iS->second->m_nobjWr == 0 ) return false; lastId = iS->second->m_nobjWr-1; return true; } // otherwise, look up into the regular sequence table. std::auto_ptr< coral::IQuery > query( schema().tableHandle( tableName() ).newQuery() ); query->limitReturnedRows( 1, 0 ); query->addToOutputList( sequenceValueColumn() ); query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() ); query->setForUpdate(); std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() ); coral::AttributeList rowData; rowData.extend<std::string>(sequenceNameColumn()); rowData.begin()->data< std::string >() = sequenceName; query->setCondition( whereClause, rowData ); coral::ICursor& cursor = query->execute(); if ( cursor.next() ) { lastId = cursor.currentRow().begin()->data<int >(); return true; } return false; }
void ora::PoolSequenceTable::init | ( | PoolDbCache & | dbCache | ) |
Definition at line 95 of file PoolDatabaseSchema.cc.
Referenced by ora::PoolDatabaseSchema::PoolDatabaseSchema().
{ m_dbCache = &dbCache; }
std::string ora::PoolSequenceTable::name | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 182 of file PoolDatabaseSchema.cc.
{ return tableName(); }
std::string ora::PoolSequenceTable::sequenceNameColumn | ( | ) | [static] |
Definition at line 77 of file PoolDatabaseSchema.cc.
{ static std::string s_column("NAME"); return s_column; }
std::string ora::PoolSequenceTable::sequenceValueColumn | ( | ) | [static] |
Definition at line 82 of file PoolDatabaseSchema.cc.
{ static std::string s_column("VALUE"); return s_column; }
void ora::PoolSequenceTable::sinchronize | ( | const std::string & | sequenceName, |
int | lastValue | ||
) | [virtual] |
Implements ora::ISequenceTable.
Definition at line 148 of file PoolDatabaseSchema.cc.
References python::IdGenerator::schema, and ora::throwException().
{ if(!m_dbCache){ throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::sinchronize"); } // nothing to do in the db if the sequence is in the cache... std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences(); std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName ); if( iS != seq.end()){ iS->second->m_nobjWr = lastValue+1; return; } coral::AttributeList updateData; updateData.extend<std::string>(sequenceNameColumn()); updateData.extend<int>(sequenceValueColumn()); std::string setClause( sequenceValueColumn() + " = :" + sequenceValueColumn() ); std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() ); // Increment the oid in the database as well coral::AttributeList::iterator iAttribute = updateData.begin(); iAttribute->data< std::string >() = sequenceName; ++iAttribute; iAttribute->data< int >() = lastValue; schema().tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData ); }
std::string ora::PoolSequenceTable::tableName | ( | ) | [static] |
Definition at line 72 of file PoolDatabaseSchema.cc.
{ static std::string s_name("POOL_RSS_SEQ"); return s_name; }
PoolDbCache* ora::PoolSequenceTable::m_dbCache [private] |
Definition at line 85 of file PoolDatabaseSchema.h.