CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
ora::OraContainerHeaderTable Class Reference

#include <OraDatabaseSchema.h>

Inheritance diagram for ora::OraContainerHeaderTable:
ora::IContainerHeaderTable ora::IDatabaseTable

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)
 
 OraContainerHeaderTable (coral::ISchema &dbSchema)
 
void removeContainer (int id)
 
void updateNumberOfObjects (const std::map< int, unsigned int > &numberOfObjectsForContainerIds)
 
virtual ~OraContainerHeaderTable ()
 
- Public Member Functions inherited from ora::IContainerHeaderTable
virtual ~IContainerHeaderTable ()
 
- Public Member Functions inherited from ora::IDatabaseTable
virtual ~IDatabaseTable ()
 

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)
 

Private Attributes

coral::ISchema & m_schema
 

Detailed Description

Definition at line 88 of file OraDatabaseSchema.h.

Constructor & Destructor Documentation

ora::OraContainerHeaderTable::OraContainerHeaderTable ( coral::ISchema &  dbSchema)
explicit

Definition at line 385 of file OraDatabaseSchema.cc.

385  :
386  m_schema(dbSchema){
387 }
ora::OraContainerHeaderTable::~OraContainerHeaderTable ( )
virtual

Definition at line 389 of file OraDatabaseSchema.cc.

389  {
390 }

Member Function Documentation

void ora::OraContainerHeaderTable::addContainer ( int  id,
const std::string &  containerName,
const std::string &  className 
)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 416 of file OraDatabaseSchema.cc.

418  {
419  coral::AttributeList dataToInsert;
420  unsigned int numberOfObjects = 0;
421  dataToInsert.extend<int>( containerIdColumn());
422  dataToInsert.extend<std::string>( containerNameColumn());
423  dataToInsert.extend<std::string>( classNameColumn());
424  dataToInsert.extend<unsigned int>( numberOfObjectsColumn());
425  dataToInsert[ containerIdColumn() ].data<int>() = containerId;
426  dataToInsert[ containerNameColumn() ].data<std::string>() = containerName;
427  dataToInsert[ classNameColumn() ].data<std::string>() = className;
428  dataToInsert[ numberOfObjectsColumn() ].data<unsigned int>() = numberOfObjects;
429  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
430  containerTable.dataEditor().insertRow( dataToInsert );
431 }
static std::string containerNameColumn()
static std::string classNameColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
static std::string containerIdColumn()
std::string className(const T &t)
Definition: ClassName.h:30
std::string ora::OraContainerHeaderTable::classNameColumn ( )
static

Definition at line 375 of file OraDatabaseSchema.cc.

375  {
376  static std::string s_column("CLASS_NAME");
377  return s_column;
378 }
std::string ora::OraContainerHeaderTable::containerIdColumn ( )
static

Definition at line 364 of file OraDatabaseSchema.cc.

Referenced by ora::OraClassVersionTable::create().

364  {
365  static std::string s_column("CONTAINER_ID");
366  return s_column;
367 }
std::string ora::OraContainerHeaderTable::containerNameColumn ( )
static

Definition at line 370 of file OraDatabaseSchema.cc.

370  {
371  static std::string s_column("CONTAINER_NAME");
372  return s_column;
373 }
void ora::OraContainerHeaderTable::create ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 494 of file OraDatabaseSchema.cc.

References asciidump::table, and ora::throwException().

494  {
495  if( m_schema.existsTable( tableName() )){
496  throwException( "ORA database container header table already exists in this schema.",
497  "OraContainerHeaderTable::create");
498  }
499 
500  coral::TableDescription descr( "OraDb" );
501  descr.setName( tableName() );
502  descr.insertColumn( containerIdColumn(),
503  coral::AttributeSpecification::typeNameForType<int>() );
504  descr.insertColumn( containerNameColumn(),
505  coral::AttributeSpecification::typeNameForType<std::string>() );
506  descr.insertColumn( classNameColumn(),
507  coral::AttributeSpecification::typeNameForType<std::string>() );
508  descr.insertColumn( numberOfObjectsColumn(),
509  coral::AttributeSpecification::typeNameForType<unsigned int>() );
510  descr.setNotNullConstraint( containerIdColumn() );
511  descr.setNotNullConstraint( containerNameColumn() );
512  descr.setNotNullConstraint( classNameColumn() );
513  descr.setNotNullConstraint( numberOfObjectsColumn() );
514  descr.setPrimaryKey( std::vector<std::string>( 1, containerIdColumn() ) );
515  descr.setUniqueConstraint( containerNameColumn() );
516  coral::ITable& table = m_schema.createTable( descr );
517  table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
518 }
list table
Definition: asciidump.py:386
static std::string containerNameColumn()
static std::string classNameColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
static std::string containerIdColumn()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::OraContainerHeaderTable::decrementNumberOfObjects ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 460 of file OraDatabaseSchema.cc.

460  {
461  std::stringstream setClause;
462  setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " - 1";
463  return updateContainer( containerId, setClause.str() );
464 }
void updateContainer(int id, const std::string &setClause)
static std::string numberOfObjectsColumn()
void ora::OraContainerHeaderTable::drop ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 520 of file OraDatabaseSchema.cc.

520  {
521  m_schema.dropIfExistsTable( tableName() );
522 }
static std::string tableName()
bool ora::OraContainerHeaderTable::exists ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 490 of file OraDatabaseSchema.cc.

490  {
491  return m_schema.existsTable( tableName() );
492 }
static std::string tableName()
bool ora::OraContainerHeaderTable::getContainerData ( std::map< std::string, ContainerHeaderData > &  destination)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 392 of file OraDatabaseSchema.cc.

References className(), alignmentValidation::dest, o2o::query, and runTheMatrix::ret.

393  {
394  bool ret = false;
395  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
396  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
397  coral::AttributeList outputBuffer;
398  outputBuffer.extend<int>( containerIdColumn() );
399  outputBuffer.extend<std::string>( containerNameColumn() );
400  outputBuffer.extend<std::string>( classNameColumn() );
401  outputBuffer.extend<unsigned int>( numberOfObjectsColumn() );
402  query->defineOutput( outputBuffer );
403  coral::ICursor& cursor = query->execute();
404  while ( cursor.next() ) {
405  ret = true;
406  const coral::AttributeList& row = cursor.currentRow();
407  int containerId = row[ containerIdColumn() ].data< int >();
408  std::string containerName = row[ containerNameColumn()].data< std::string >();
409  std::string className = row[ classNameColumn()].data< std::string >();
410  unsigned int numberOfObjects = row[ numberOfObjectsColumn()].data< unsigned int >();
411  dest.insert( std::make_pair( containerName, ContainerHeaderData( containerId, className, numberOfObjects ) )) ;
412  }
413  return ret;
414 }
static std::string containerNameColumn()
static std::string classNameColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
static std::string containerIdColumn()
tuple query
Definition: o2o.py:269
std::string className(const T &t)
Definition: ClassName.h:30
void ora::OraContainerHeaderTable::incrementNumberOfObjects ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 454 of file OraDatabaseSchema.cc.

454  {
455  std::stringstream setClause;
456  setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " + 1";
457  return updateContainer( containerId, setClause.str() );
458 }
void updateContainer(int id, const std::string &setClause)
static std::string numberOfObjectsColumn()
std::string ora::OraContainerHeaderTable::numberOfObjectsColumn ( )
static

Definition at line 380 of file OraDatabaseSchema.cc.

380  {
381  static std::string s_column("NUMBER_OF_OBJECTS");
382  return s_column;
383 }
void ora::OraContainerHeaderTable::removeContainer ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 433 of file OraDatabaseSchema.cc.

433  {
434  std::stringstream whereClause;
435  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
436  coral::AttributeList whereData;
437  whereData.extend< int >( containerIdColumn() );
438  whereData.begin()->data< int >() = id;
439  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
440  containerTable.dataEditor().deleteRows(whereClause.str(),whereData);
441 }
static std::string tableName()
static std::string containerIdColumn()
std::string ora::OraContainerHeaderTable::tableName ( )
static

Definition at line 358 of file OraDatabaseSchema.cc.

Referenced by ora::OraClassVersionTable::create().

358  {
359  static std::string s_name("ORA_CONTAINER");
360  return s_name;
361 }
void ora::OraContainerHeaderTable::updateContainer ( int  id,
const std::string &  setClause 
)
private

Definition at line 443 of file OraDatabaseSchema.cc.

444  {
445  std::stringstream whereClause;
446  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
447  coral::AttributeList updateData;
448  updateData.extend<int>( containerIdColumn() );
449  updateData.begin()->data<int>() = containerId;
450  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
451  containerTable.dataEditor().updateRows(setClause,whereClause.str(),updateData);
452 }
static std::string tableName()
static std::string containerIdColumn()
void ora::OraContainerHeaderTable::updateNumberOfObjects ( const std::map< int, unsigned int > &  numberOfObjectsForContainerIds)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 466 of file OraDatabaseSchema.cc.

466  {
467  if( numberOfObjectsForContainerIds.size() ){
468 
469  std::stringstream whereClause;
470  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
471  std::stringstream setClause;
472  setClause << numberOfObjectsColumn() << " = :" <<numberOfObjectsColumn();
473  coral::AttributeList updateData;
474  updateData.extend<unsigned int>( numberOfObjectsColumn() );
475  updateData.extend<int>( containerIdColumn() );
476 
477  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
478  std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size()));
479 
480  for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin();
481  iCont != numberOfObjectsForContainerIds.end(); ++iCont ){
482  updateData[containerIdColumn()].data<int>() = iCont->first;
483  updateData[numberOfObjectsColumn()].data<unsigned int>() = iCont->second;
484  bulkUpdate->processNextIteration();
485  }
486  bulkUpdate->flush();
487  }
488 }
static std::string tableName()
static std::string numberOfObjectsColumn()
static std::string containerIdColumn()

Member Data Documentation

coral::ISchema& ora::OraContainerHeaderTable::m_schema
private

Definition at line 112 of file OraDatabaseSchema.h.