#include <OraDatabaseSchema.h>
Public Member Functions | |
void | addContainer (int id, const std::string &containerName, const std::string &className) |
void | create () |
void | decrementNumberOfObjects (int id) |
void | drop () |
bool | exists () |
bool | getContainerData (std::map< std::string, ContainerHeaderData > &destination) |
void | incrementNumberOfObjects (int id) |
bool | lockContainer (int id, ContainerHeaderData &destination) |
std::string | name () |
OraContainerHeaderTable (coral::ISchema &dbSchema) | |
void | removeContainer (int id) |
void | updateNumberOfObjects (const std::map< int, unsigned int > &numberOfObjectsForContainerIds) |
virtual | ~OraContainerHeaderTable () |
Static Public Member Functions | |
static std::string | classNameColumn () |
static std::string | containerIdColumn () |
static std::string | containerNameColumn () |
static std::string | numberOfObjectsColumn () |
static std::string | tableName () |
Private Member Functions | |
void | updateContainer (int id, const std::string &setClause) |
Definition at line 88 of file OraDatabaseSchema.h.
ora::OraContainerHeaderTable::OraContainerHeaderTable | ( | coral::ISchema & | dbSchema | ) | [explicit] |
Definition at line 421 of file OraDatabaseSchema.cc.
: IContainerHeaderTable(dbSchema){ }
ora::OraContainerHeaderTable::~OraContainerHeaderTable | ( | ) | [virtual] |
Definition at line 425 of file OraDatabaseSchema.cc.
{ }
void ora::OraContainerHeaderTable::addContainer | ( | int | id, |
const std::string & | containerName, | ||
const std::string & | className | ||
) | [virtual] |
Implements ora::IContainerHeaderTable.
Definition at line 452 of file OraDatabaseSchema.cc.
References python::IdGenerator::schema.
{ coral::AttributeList dataToInsert; unsigned int numberOfObjects = 0; dataToInsert.extend<int>( containerIdColumn()); dataToInsert.extend<std::string>( containerNameColumn()); dataToInsert.extend<std::string>( classNameColumn()); dataToInsert.extend<unsigned int>( numberOfObjectsColumn()); dataToInsert[ containerIdColumn() ].data<int>() = containerId; dataToInsert[ containerNameColumn() ].data<std::string>() = containerName; dataToInsert[ classNameColumn() ].data<std::string>() = className; dataToInsert[ numberOfObjectsColumn() ].data<unsigned int>() = numberOfObjects; coral::ITable& containerTable = schema().tableHandle( tableName() ); containerTable.dataEditor().insertRow( dataToInsert ); }
std::string ora::OraContainerHeaderTable::classNameColumn | ( | ) | [static] |
Definition at line 411 of file OraDatabaseSchema.cc.
{ static std::string s_column("CLASS_NAME"); return s_column; }
std::string ora::OraContainerHeaderTable::containerIdColumn | ( | ) | [static] |
Definition at line 400 of file OraDatabaseSchema.cc.
Referenced by ora::OraClassVersionTable::create().
{ static std::string s_column("CONTAINER_ID"); return s_column; }
std::string ora::OraContainerHeaderTable::containerNameColumn | ( | ) | [static] |
Definition at line 406 of file OraDatabaseSchema.cc.
{ static std::string s_column("CONTAINER_NAME"); return s_column; }
void ora::OraContainerHeaderTable::create | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 560 of file OraDatabaseSchema.cc.
References python::IdGenerator::schema, and ora::throwException().
{ if( schema().existsTable( tableName() )){ throwException( "ORA database container header table already exists in this schema.", "OraContainerHeaderTable::create"); } coral::TableDescription descr( "OraDb" ); descr.setName( tableName() ); descr.insertColumn( containerIdColumn(), coral::AttributeSpecification::typeNameForType<int>() ); descr.insertColumn( containerNameColumn(), coral::AttributeSpecification::typeNameForType<std::string>() ); descr.insertColumn( classNameColumn(), coral::AttributeSpecification::typeNameForType<std::string>() ); descr.insertColumn( numberOfObjectsColumn(), coral::AttributeSpecification::typeNameForType<unsigned int>() ); descr.setNotNullConstraint( containerIdColumn() ); descr.setNotNullConstraint( containerNameColumn() ); descr.setNotNullConstraint( classNameColumn() ); descr.setNotNullConstraint( numberOfObjectsColumn() ); descr.setPrimaryKey( std::vector<std::string>( 1, containerIdColumn() ) ); descr.setUniqueConstraint( containerNameColumn() ); schema().createTable( descr ); }
void ora::OraContainerHeaderTable::decrementNumberOfObjects | ( | int | id | ) | [virtual] |
Implements ora::IContainerHeaderTable.
Definition at line 522 of file OraDatabaseSchema.cc.
{ std::stringstream setClause; setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " - 1"; return updateContainer( containerId, setClause.str() ); }
void ora::OraContainerHeaderTable::drop | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 585 of file OraDatabaseSchema.cc.
References python::IdGenerator::schema.
bool ora::OraContainerHeaderTable::exists | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 556 of file OraDatabaseSchema.cc.
References python::IdGenerator::schema.
bool ora::OraContainerHeaderTable::getContainerData | ( | std::map< std::string, ContainerHeaderData > & | destination | ) | [virtual] |
Implements ora::IContainerHeaderTable.
void ora::OraContainerHeaderTable::incrementNumberOfObjects | ( | int | id | ) | [virtual] |
Implements ora::IContainerHeaderTable.
Definition at line 516 of file OraDatabaseSchema.cc.
{ std::stringstream setClause; setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " + 1"; return updateContainer( containerId, setClause.str() ); }
bool ora::OraContainerHeaderTable::lockContainer | ( | int | id, |
ora::ContainerHeaderData & | dest | ||
) | [virtual] |
Implements ora::IContainerHeaderTable.
Definition at line 490 of file OraDatabaseSchema.cc.
References ora::ContainerHeaderData::className, ora::ContainerHeaderData::id, ora::ContainerHeaderData::numberOfObjects, o2o::query, run_regression::ret, and python::IdGenerator::schema.
{ bool ret = false; coral::ITable& containerTable = schema().tableHandle( tableName() ); std::auto_ptr<coral::IQuery> query( containerTable.newQuery()); query->addToOutputList( classNameColumn() ); query->defineOutputType( classNameColumn() , coral::AttributeSpecification::typeNameForType<std::string>() ); query->addToOutputList( numberOfObjectsColumn() ); query->defineOutputType( numberOfObjectsColumn() , coral::AttributeSpecification::typeNameForType<unsigned int>() ); std::stringstream whereClause; whereClause << containerIdColumn() << "= :" <<containerIdColumn(); coral::AttributeList whereData; whereData.extend<int>( containerIdColumn() ); whereData.begin()->data<int>() = id; query->setCondition( whereClause.str(), whereData ); query->setForUpdate(); coral::ICursor& cursor = query->execute(); if( cursor.next() ) { ret = true; const coral::AttributeList& row = cursor.currentRow(); dest.id = id; dest.className = row[ classNameColumn()].data< std::string >(); dest.numberOfObjects = row[ numberOfObjectsColumn()].data< unsigned int >(); } return ret; }
std::string ora::OraContainerHeaderTable::name | ( | ) | [virtual] |
Implements ora::IDatabaseTable.
Definition at line 552 of file OraDatabaseSchema.cc.
{ return tableName(); }
std::string ora::OraContainerHeaderTable::numberOfObjectsColumn | ( | ) | [static] |
Definition at line 416 of file OraDatabaseSchema.cc.
{ static std::string s_column("NUMBER_OF_OBJECTS"); return s_column; }
void ora::OraContainerHeaderTable::removeContainer | ( | int | id | ) | [virtual] |
Implements ora::IContainerHeaderTable.
Definition at line 469 of file OraDatabaseSchema.cc.
References python::IdGenerator::schema.
{ std::stringstream whereClause; whereClause << containerIdColumn() << "= :" <<containerIdColumn(); coral::AttributeList whereData; whereData.extend< int >( containerIdColumn() ); whereData.begin()->data< int >() = id; coral::ITable& containerTable = schema().tableHandle( tableName() ); containerTable.dataEditor().deleteRows(whereClause.str(),whereData); }
std::string ora::OraContainerHeaderTable::tableName | ( | ) | [static] |
Definition at line 394 of file OraDatabaseSchema.cc.
Referenced by ora::OraClassVersionTable::create().
{ static std::string s_name("ORA_CONTAINER"); return s_name; }
void ora::OraContainerHeaderTable::updateContainer | ( | int | id, |
const std::string & | setClause | ||
) | [private] |
Definition at line 479 of file OraDatabaseSchema.cc.
References python::IdGenerator::schema.
{ std::stringstream whereClause; whereClause << containerIdColumn() << "= :" <<containerIdColumn(); coral::AttributeList updateData; updateData.extend<int>( containerIdColumn() ); updateData.begin()->data<int>() = containerId; coral::ITable& containerTable = schema().tableHandle( tableName() ); containerTable.dataEditor().updateRows(setClause,whereClause.str(),updateData); }
void ora::OraContainerHeaderTable::updateNumberOfObjects | ( | const std::map< int, unsigned int > & | numberOfObjectsForContainerIds | ) | [virtual] |
Implements ora::IContainerHeaderTable.
Definition at line 528 of file OraDatabaseSchema.cc.
References python::IdGenerator::schema.
{ if( numberOfObjectsForContainerIds.size() ){ std::stringstream whereClause; whereClause << containerIdColumn() << "= :" <<containerIdColumn(); std::stringstream setClause; setClause << numberOfObjectsColumn() << " = :" <<numberOfObjectsColumn(); coral::AttributeList updateData; updateData.extend<unsigned int>( numberOfObjectsColumn() ); updateData.extend<int>( containerIdColumn() ); coral::ITable& containerTable = schema().tableHandle( tableName() ); std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size())); for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin(); iCont != numberOfObjectsForContainerIds.end(); ++iCont ){ updateData[containerIdColumn()].data<int>() = iCont->first; updateData[numberOfObjectsColumn()].data<unsigned int>() = iCont->second; bulkUpdate->processNextIteration(); } bulkUpdate->flush(); } }