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 Attributes
ora::PoolContainerHeaderTable Class Reference

#include <PoolDatabaseSchema.h>

Inheritance diagram for ora::PoolContainerHeaderTable:
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)
 
void init (PoolDbCache &dbCache)
 
 PoolContainerHeaderTable (coral::ISchema &dbSchema)
 
void removeContainer (int id)
 
void updateNumberOfObjects (const std::map< int, unsigned int > &numberOfObjectsForContainerIds)
 
virtual ~PoolContainerHeaderTable ()
 
- 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 baseMappingVersionColumn ()
 
static std::string classNameColumn ()
 
static std::string containerIdColumn ()
 
static std::string containerNameColumn ()
 
static std::string containerTypeColumn ()
 
static std::string homogeneousContainerType ()
 
static std::string numberOfDeletedObjectsColumn ()
 
static std::string numberOfWrittenObjectsColumn ()
 
static std::string tableName ()
 
static std::string tableNameColumn ()
 

Private Attributes

PoolDbCachem_dbCache
 
coral::ISchema & m_schema
 

Detailed Description

Definition at line 126 of file PoolDatabaseSchema.h.

Constructor & Destructor Documentation

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

Definition at line 458 of file PoolDatabaseSchema.cc.

458  :
459  m_schema(dbSchema),
460  m_dbCache( 0 ){
461 }
ora::PoolContainerHeaderTable::~PoolContainerHeaderTable ( )
virtual

Definition at line 463 of file PoolDatabaseSchema.cc.

463  {
464 }

Member Function Documentation

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

if(!m_dbCache){ throwException("Container Table handle has not been initialized.","PoolContainerHeaderTable::addContainer"); } PoolDbCacheData& contData = m_dbCache->find( containerId );

unsigned int nobj = 0; coral::AttributeList dataToInsert; dataToInsert.extend<int>( containerIdColumn()); dataToInsert.extend<std::string>( containerNameColumn()); dataToInsert.extend<std::string>( classNameColumn()); dataToInsert.extend<std::string>( tableNameColumn()); dataToInsert.extend<std::string>( baseMappingVersionColumn()); dataToInsert.extend<unsigned int>( numberOfWrittenObjectsColumn()); dataToInsert.extend<unsigned int>( numberOfDeletedObjectsColumn()); dataToInsert[ containerIdColumn() ].data<int>() = containerId; dataToInsert[ containerNameColumn() ].data<std::string>() = containerName; dataToInsert[ classNameColumn() ].data<std::string>() = className; dataToInsert[ tableNameColumn() ].data<std::string>() = "-"; dataToInsert[ baseMappingVersionColumn() ].data<std::string>() = contData.m_mappingVersion; dataToInsert[ numberOfWrittenObjectsColumn() ].data<unsigned int>() = nobj; dataToInsert[ numberOfDeletedObjectsColumn() ].data<unsigned int>() = nobj; coral::ITable& containerTable = m_schema.tableHandle( tableName() ); containerTable.dataEditor().insertRow( dataToInsert );

Implements ora::IContainerHeaderTable.

Definition at line 517 of file PoolDatabaseSchema.cc.

References ora::throwException().

519  {
545  throwException( "Cannot create new Containers into POOL database.","PoolContainerHeaderTable::addContainer");
546 }
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
std::string ora::PoolContainerHeaderTable::baseMappingVersionColumn ( )
static

Definition at line 438 of file PoolDatabaseSchema.cc.

438  {
439  static std::string s_column("MAPPING_VERSION");
440  return s_column;
441 }
std::string ora::PoolContainerHeaderTable::classNameColumn ( )
static

Definition at line 433 of file PoolDatabaseSchema.cc.

433  {
434  static std::string s_column("CLASS_NAME");
435  return s_column;
436 }
std::string ora::PoolContainerHeaderTable::containerIdColumn ( )
static

Definition at line 412 of file PoolDatabaseSchema.cc.

Referenced by ora::PoolMappingSchema::getClassVersionListForContainer(), ora::PoolMappingSchema::getMappingVersionListForContainer(), and ora::PoolMappingSchema::selectMappingVersion().

412  {
413  static std::string s_column("CONTAINER_ID");
414  return s_column;
415 }
std::string ora::PoolContainerHeaderTable::containerNameColumn ( )
static

Definition at line 418 of file PoolDatabaseSchema.cc.

Referenced by ora::PoolMappingSchema::getClassVersionListForContainer(), ora::PoolMappingSchema::getMappingVersionListForContainer(), and ora::PoolMappingSchema::selectMappingVersion().

418  {
419  static std::string s_column("CONTAINER_NAME");
420  return s_column;
421 }
std::string ora::PoolContainerHeaderTable::containerTypeColumn ( )
static

Definition at line 423 of file PoolDatabaseSchema.cc.

423  {
424  static std::string s_column("CONTAINER_TYPE");
425  return s_column;
426 }
void ora::PoolContainerHeaderTable::create ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 611 of file PoolDatabaseSchema.cc.

References ora::throwException().

611  {
612  if( m_schema.existsTable( tableName() )){
613  throwException( "POOL database container header table already exists in this schema.",
614  "PoolContainerHeaderTable::create");
615  }
616  throwException( "POOL database cannot be created.","PoolContainerHeaderTable::create");
617 }
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::PoolContainerHeaderTable::decrementNumberOfObjects ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 566 of file PoolDatabaseSchema.cc.

References ora::throwException().

566  {
567  throwException( "Operation not supported into POOL database.","PoolContainerHeaderTable::decrementNumberOfObjects");
568 }
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::PoolContainerHeaderTable::drop ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 619 of file PoolDatabaseSchema.cc.

619  {
620  m_schema.dropIfExistsTable( tableName() );
621 }
bool ora::PoolContainerHeaderTable::exists ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 607 of file PoolDatabaseSchema.cc.

607  {
608  return m_schema.existsTable( tableName() );
609 }
bool ora::PoolContainerHeaderTable::getContainerData ( std::map< std::string, ContainerHeaderData > &  destination)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 470 of file PoolDatabaseSchema.cc.

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

471  {
472  if(!m_dbCache){
473  throwException("Container Table handle has not been initialized.","PoolContainerHeaderTable::getContainerData");
474  }
475  bool ret = false;
476  m_dbCache->clear();
477  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
478  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
479  coral::AttributeList outputBuffer;
480  outputBuffer.extend<int>( containerIdColumn() );
481  outputBuffer.extend<std::string>( containerNameColumn() );
482  outputBuffer.extend<std::string>( classNameColumn() );
483  outputBuffer.extend<std::string>( baseMappingVersionColumn() );
484  outputBuffer.extend<unsigned int>( numberOfWrittenObjectsColumn() );
485  outputBuffer.extend<unsigned int>( numberOfDeletedObjectsColumn() );
486  query->defineOutput( outputBuffer );
487  query->addToOutputList( containerIdColumn() );
488  query->addToOutputList( containerNameColumn() );
489  query->addToOutputList( classNameColumn() );
490  query->addToOutputList( baseMappingVersionColumn() );
491  query->addToOutputList( numberOfWrittenObjectsColumn() );
492  query->addToOutputList( numberOfDeletedObjectsColumn() );
493  std::stringstream condition;
494  condition << containerTypeColumn()<<" = :"<<containerTypeColumn();
495  coral::AttributeList condData;
496  condData.extend<std::string>( containerTypeColumn() );
497  condData[ containerTypeColumn() ].data<std::string>()=homogeneousContainerType();
498  query->setCondition( condition.str(), condData );
499  coral::ICursor& cursor = query->execute();
500  while ( cursor.next() ) {
501  ret = true;
502  const coral::AttributeList& row = cursor.currentRow();
503  int containerId = row[ containerIdColumn() ].data< int >() - 1; //POOL starts counting from 1!
504  std::string containerName = row[ containerNameColumn()].data< std::string >();
505  std::string className = row[ classNameColumn()].data< std::string >();
506  std::string baseMappingVersion = row[ baseMappingVersionColumn()].data< std::string >();
507  unsigned int numberOfWrittenObjects = row[ numberOfWrittenObjectsColumn()].data< unsigned int >();
508  unsigned int numberOfDeletedObjects = row[ numberOfDeletedObjectsColumn()].data< unsigned int >();
509  // containers non-homogeneous are ignored.
510  dest.insert( std::make_pair( containerName, ContainerHeaderData( containerId, className,
511  numberOfWrittenObjects-numberOfDeletedObjects ) )) ;
512  m_dbCache->add( containerId, PoolDbCacheData(containerId, containerName, className, baseMappingVersion, numberOfWrittenObjects) );
513  }
514  return ret;
515 }
static std::string numberOfWrittenObjectsColumn()
static std::string containerNameColumn()
static std::string containerTypeColumn()
static std::string baseMappingVersionColumn()
static std::string containerIdColumn()
void add(int id, const PoolDbCacheData &data)
static std::string numberOfDeletedObjectsColumn()
static std::string homogeneousContainerType()
static std::string classNameColumn()
tuple query
Definition: o2o.py:269
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
std::string className(const T &t)
Definition: ClassName.h:30
std::string ora::PoolContainerHeaderTable::homogeneousContainerType ( )
static

Definition at line 453 of file PoolDatabaseSchema.cc.

453  {
454  static std::string s_type("Homogeneous");
455  return s_type;
456 }
void ora::PoolContainerHeaderTable::incrementNumberOfObjects ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 562 of file PoolDatabaseSchema.cc.

References ora::throwException().

562  {
563  throwException( "Operation not supported into POOL database.","PoolContainerHeaderTable::incrementNumberOfObjects");
564 }
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::PoolContainerHeaderTable::init ( PoolDbCache dbCache)

Definition at line 466 of file PoolDatabaseSchema.cc.

Referenced by ora::PoolDatabaseSchema::PoolDatabaseSchema().

466  {
467  m_dbCache = &dbCache;
468 }
std::string ora::PoolContainerHeaderTable::numberOfDeletedObjectsColumn ( )
static

Definition at line 448 of file PoolDatabaseSchema.cc.

448  {
449  static std::string s_column("NUMBER_OF_DELETED_OBJECTS");
450  return s_column;
451 }
std::string ora::PoolContainerHeaderTable::numberOfWrittenObjectsColumn ( )
static

Definition at line 443 of file PoolDatabaseSchema.cc.

443  {
444  static std::string s_column("NUMBER_OF_WRITTEN_OBJECTS");
445  return s_column;
446 }
void ora::PoolContainerHeaderTable::removeContainer ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 548 of file PoolDatabaseSchema.cc.

References ora::throwException().

548  {
549  if(!m_dbCache){
550  throwException("Container Table handle has not been initialized.","PoolContainerHeaderTable::removeContainer");
551  }
552  m_dbCache->remove( id );
553  std::stringstream whereClause;
554  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
555  coral::AttributeList whereData;
556  whereData.extend< int >( containerIdColumn() );
557  whereData.begin()->data< int >() = id + 1; //POOL starts counting from 1!;
558  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
559  containerTable.dataEditor().deleteRows(whereClause.str(),whereData);
560 }
static std::string containerIdColumn()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
std::string ora::PoolContainerHeaderTable::tableName ( )
static

Definition at line 406 of file PoolDatabaseSchema.cc.

Referenced by ora::PoolMappingSchema::getClassVersionListForContainer(), ora::PoolMappingSchema::getMappingVersionListForContainer(), and ora::PoolMappingSchema::selectMappingVersion().

406  {
407  static std::string s_name("POOL_RSS_CONTAINERS");
408  return s_name;
409 }
std::string ora::PoolContainerHeaderTable::tableNameColumn ( )
static

Definition at line 428 of file PoolDatabaseSchema.cc.

428  {
429  static std::string s_column("TABLE_NAME");
430  return s_column;
431 }
void ora::PoolContainerHeaderTable::updateNumberOfObjects ( const std::map< int, unsigned int > &  numberOfObjectsForContainerIds)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 570 of file PoolDatabaseSchema.cc.

References ora::PoolDbCacheData::m_nobjWr, and ora::throwException().

570  {
571  if( numberOfObjectsForContainerIds.size() ){
572 
573  if(!m_dbCache){
574  throwException("Container Table handle has not been initialized.","PoolContainerHeaderTable::updateNumberOfObjects");
575  }
576 
577  std::stringstream whereClause;
578  whereClause << containerIdColumn() << " = :" <<containerIdColumn();
579  std::stringstream setClause;
581  setClause << " , "<< numberOfDeletedObjectsColumn()<< " = :"<<numberOfDeletedObjectsColumn();
582  coral::AttributeList updateData;
583  updateData.extend<unsigned int>( numberOfWrittenObjectsColumn() );
584  updateData.extend<unsigned int>( numberOfDeletedObjectsColumn() );
585  updateData.extend<int>( containerIdColumn() );
586 
587  coral::ITable& containerTable = m_schema.tableHandle( tableName() );
588  std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size()+1));
589 
590  for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin();
591  iCont != numberOfObjectsForContainerIds.end(); ++iCont ){
592 
593  PoolDbCacheData& contData = m_dbCache->find( iCont->first );
594  unsigned int nwrt = contData.m_nobjWr;
595  unsigned int ndel = nwrt-iCont->second;
596 
597  updateData[containerIdColumn()].data<int>() = iCont->first + 1; //POOL starts counting from 1!;
598  updateData[numberOfWrittenObjectsColumn()].data<unsigned int>() = nwrt;
599  updateData[numberOfDeletedObjectsColumn()].data<unsigned int>() = ndel;
600  bulkUpdate->processNextIteration();
601 
602  }
603  bulkUpdate->flush();
604  }
605 }
static std::string numberOfWrittenObjectsColumn()
static std::string containerIdColumn()
static std::string numberOfDeletedObjectsColumn()
PoolDbCacheData & find(int id)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10

Member Data Documentation

PoolDbCache* ora::PoolContainerHeaderTable::m_dbCache
private

Definition at line 154 of file PoolDatabaseSchema.h.

coral::ISchema& ora::PoolContainerHeaderTable::m_schema
private

Definition at line 153 of file PoolDatabaseSchema.h.