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)
 
bool lockContainer (int id, ContainerHeaderData &destination)
 
std::string name ()
 
 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
 IContainerHeaderTable (coral::ISchema &schema)
 
virtual ~IContainerHeaderTable ()
 
- Public Member Functions inherited from ora::IDatabaseTable
 IDatabaseTable (coral::ISchema &schema)
 
coral::ISchema & schema ()
 
virtual void setAccessPermission (const std::string &principal, bool forWrite)
 
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
 

Detailed Description

Definition at line 125 of file PoolDatabaseSchema.h.

Constructor & Destructor Documentation

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

Definition at line 483 of file PoolDatabaseSchema.cc.

483  :
484  IContainerHeaderTable(dbSchema),
485  m_dbCache( 0 ){
486 }
IContainerHeaderTable(coral::ISchema &schema)
ora::PoolContainerHeaderTable::~PoolContainerHeaderTable ( )
virtual

Definition at line 488 of file PoolDatabaseSchema.cc.

488  {
489 }

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 = schema().tableHandle( tableName() ); containerTable.dataEditor().insertRow( dataToInsert );

Implements ora::IContainerHeaderTable.

Definition at line 542 of file PoolDatabaseSchema.cc.

References ora::throwException().

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

Definition at line 463 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

463  {
464  static std::string s_column("MAPPING_VERSION");
465  return s_column;
466 }
std::string ora::PoolContainerHeaderTable::classNameColumn ( )
static

Definition at line 458 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

458  {
459  static std::string s_column("CLASS_NAME");
460  return s_column;
461 }
std::string ora::PoolContainerHeaderTable::containerIdColumn ( )
static
std::string ora::PoolContainerHeaderTable::containerNameColumn ( )
static
std::string ora::PoolContainerHeaderTable::containerTypeColumn ( )
static

Definition at line 448 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

448  {
449  static std::string s_column("CONTAINER_TYPE");
450  return s_column;
451 }
void ora::PoolContainerHeaderTable::create ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 670 of file PoolDatabaseSchema.cc.

References python.IdGenerator::schema, and ora::throwException().

670  {
671  if( schema().existsTable( tableName() )){
672  throwException( "POOL database container header table already exists in this schema.",
673  "PoolContainerHeaderTable::create");
674  }
675  throwException( "POOL database cannot be created.","PoolContainerHeaderTable::create");
676 }
coral::ISchema & schema()
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 621 of file PoolDatabaseSchema.cc.

References ora::throwException().

621  {
622  throwException( "Operation not supported into POOL database.","PoolContainerHeaderTable::decrementNumberOfObjects");
623 }
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 678 of file PoolDatabaseSchema.cc.

References python.IdGenerator::schema.

678  {
679  schema().dropIfExistsTable( tableName() );
680 }
coral::ISchema & schema()
bool ora::PoolContainerHeaderTable::exists ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 666 of file PoolDatabaseSchema.cc.

References python.IdGenerator::schema.

666  {
667  return schema().existsTable( tableName() );
668 }
coral::ISchema & schema()
bool ora::PoolContainerHeaderTable::getContainerData ( std::map< std::string, ContainerHeaderData > &  destination)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 495 of file PoolDatabaseSchema.cc.

References className(), alignCSCRings::dest, o2o::query, run_regression::ret, python.IdGenerator::schema, AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().

496  {
497  if(!m_dbCache){
498  throwException("Container Table handle has not been initialized.","PoolContainerHeaderTable::getContainerData");
499  }
500  bool ret = false;
501  m_dbCache->clear();
502  coral::ITable& containerTable = schema().tableHandle( tableName() );
503  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
504  coral::AttributeList outputBuffer;
505  outputBuffer.extend<int>( containerIdColumn() );
506  outputBuffer.extend<std::string>( containerNameColumn() );
507  outputBuffer.extend<std::string>( classNameColumn() );
508  outputBuffer.extend<std::string>( baseMappingVersionColumn() );
509  outputBuffer.extend<unsigned int>( numberOfWrittenObjectsColumn() );
510  outputBuffer.extend<unsigned int>( numberOfDeletedObjectsColumn() );
511  query->defineOutput( outputBuffer );
512  query->addToOutputList( containerIdColumn() );
513  query->addToOutputList( containerNameColumn() );
514  query->addToOutputList( classNameColumn() );
515  query->addToOutputList( baseMappingVersionColumn() );
516  query->addToOutputList( numberOfWrittenObjectsColumn() );
517  query->addToOutputList( numberOfDeletedObjectsColumn() );
518  std::stringstream condition;
519  condition << containerTypeColumn()<<" = :"<<containerTypeColumn();
520  coral::AttributeList condData;
521  condData.extend<std::string>( containerTypeColumn() );
523  query->setCondition( condition.str(), condData );
524  coral::ICursor& cursor = query->execute();
525  while ( cursor.next() ) {
526  ret = true;
527  const coral::AttributeList& row = cursor.currentRow();
528  int containerId = row[ containerIdColumn() ].data< int >() - 1; //POOL starts counting from 1!
529  std::string containerName = row[ containerNameColumn()].data< std::string >();
530  std::string className = row[ classNameColumn()].data< std::string >();
531  std::string baseMappingVersion = row[ baseMappingVersionColumn()].data< std::string >();
532  unsigned int numberOfWrittenObjects = row[ numberOfWrittenObjectsColumn()].data< unsigned int >();
533  unsigned int numberOfDeletedObjects = row[ numberOfDeletedObjectsColumn()].data< unsigned int >();
534  // containers non-homogeneous are ignored.
535  dest.insert( std::make_pair( containerName, ContainerHeaderData( containerId, className,
536  numberOfWrittenObjects-numberOfDeletedObjects ) )) ;
537  m_dbCache->add( containerId, PoolDbCacheData(containerId, containerName, className, baseMappingVersion, numberOfWrittenObjects) );
538  }
539  return ret;
540 }
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()
coral::ISchema & schema()
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 478 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

478  {
479  static std::string s_type("Homogeneous");
480  return s_type;
481 }
void ora::PoolContainerHeaderTable::incrementNumberOfObjects ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 617 of file PoolDatabaseSchema.cc.

References ora::throwException().

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

Definition at line 491 of file PoolDatabaseSchema.cc.

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

491  {
492  m_dbCache = &dbCache;
493 }
bool ora::PoolContainerHeaderTable::lockContainer ( int  id,
ContainerHeaderData destination 
)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 587 of file PoolDatabaseSchema.cc.

References ora::ContainerHeaderData::className, ora::ContainerHeaderData::id, ora::ContainerHeaderData::numberOfObjects, o2o::query, run_regression::ret, python.IdGenerator::schema, and AlCaHLTBitMon_QueryRunRegistry::string.

587  {
588  bool ret = false;
589  coral::ITable& containerTable = schema().tableHandle( tableName() );
590  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
591  query->addToOutputList( classNameColumn() );
592  query->defineOutputType( classNameColumn() , coral::AttributeSpecification::typeNameForType<std::string>() );
593  query->addToOutputList( numberOfWrittenObjectsColumn() );
594  query->defineOutputType( numberOfWrittenObjectsColumn(), coral::AttributeSpecification::typeNameForType<unsigned int>() );
595  query->addToOutputList( numberOfDeletedObjectsColumn() );
596  query->defineOutputType( numberOfDeletedObjectsColumn(), coral::AttributeSpecification::typeNameForType<unsigned int>() );
597  std::stringstream whereClause;
598  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
599  coral::AttributeList whereData;
600  whereData.extend<int>( containerIdColumn() );
601  whereData.begin()->data<int>() = id +1 ; //POOL starts counting from 1!;
602  query->setCondition( whereClause.str(), whereData );
603  query->setForUpdate();
604  coral::ICursor& cursor = query->execute();
605  if( cursor.next() ) {
606  ret = true;
607  const coral::AttributeList& row = cursor.currentRow();
608  dest.id = id;
609  dest.className = row[ classNameColumn()].data< std::string >();
610  unsigned int numberOfWrittenObjects = row[ numberOfWrittenObjectsColumn()].data< unsigned int >();
611  unsigned int numberOfDeletedObjects = row[ numberOfDeletedObjectsColumn()].data< unsigned int >();
612  dest.numberOfObjects = numberOfWrittenObjects-numberOfDeletedObjects;
613  }
614  return ret;
615 }
static std::string numberOfWrittenObjectsColumn()
static std::string containerIdColumn()
static std::string numberOfDeletedObjectsColumn()
static std::string classNameColumn()
coral::ISchema & schema()
tuple query
Definition: o2o.py:269
std::string ora::PoolContainerHeaderTable::name ( )
virtual
std::string ora::PoolContainerHeaderTable::numberOfDeletedObjectsColumn ( )
static

Definition at line 473 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

473  {
474  static std::string s_column("NUMBER_OF_DELETED_OBJECTS");
475  return s_column;
476 }
std::string ora::PoolContainerHeaderTable::numberOfWrittenObjectsColumn ( )
static

Definition at line 468 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

468  {
469  static std::string s_column("NUMBER_OF_WRITTEN_OBJECTS");
470  return s_column;
471 }
void ora::PoolContainerHeaderTable::removeContainer ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 573 of file PoolDatabaseSchema.cc.

References python.IdGenerator::schema, and ora::throwException().

573  {
574  if(!m_dbCache){
575  throwException("Container Table handle has not been initialized.","PoolContainerHeaderTable::removeContainer");
576  }
577  m_dbCache->remove( id );
578  std::stringstream whereClause;
579  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
580  coral::AttributeList whereData;
581  whereData.extend< int >( containerIdColumn() );
582  whereData.begin()->data< int >() = id + 1; //POOL starts counting from 1!;
583  coral::ITable& containerTable = schema().tableHandle( tableName() );
584  containerTable.dataEditor().deleteRows(whereClause.str(),whereData);
585 }
static std::string containerIdColumn()
coral::ISchema & schema()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
std::string ora::PoolContainerHeaderTable::tableName ( )
static
std::string ora::PoolContainerHeaderTable::tableNameColumn ( )
static

Definition at line 453 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

453  {
454  static std::string s_column("TABLE_NAME");
455  return s_column;
456 }
void ora::PoolContainerHeaderTable::updateNumberOfObjects ( const std::map< int, unsigned int > &  numberOfObjectsForContainerIds)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 625 of file PoolDatabaseSchema.cc.

References ora::PoolDbCacheData::m_nobjWr, python.IdGenerator::schema, and ora::throwException().

625  {
626  if( numberOfObjectsForContainerIds.size() ){
627 
628  if(!m_dbCache){
629  throwException("Container Table handle has not been initialized.","PoolContainerHeaderTable::updateNumberOfObjects");
630  }
631 
632  std::stringstream whereClause;
633  whereClause << containerIdColumn() << " = :" <<containerIdColumn();
634  std::stringstream setClause;
636  setClause << " , "<< numberOfDeletedObjectsColumn()<< " = :"<<numberOfDeletedObjectsColumn();
637  coral::AttributeList updateData;
638  updateData.extend<unsigned int>( numberOfWrittenObjectsColumn() );
639  updateData.extend<unsigned int>( numberOfDeletedObjectsColumn() );
640  updateData.extend<int>( containerIdColumn() );
641 
642  coral::ITable& containerTable = schema().tableHandle( tableName() );
643  std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size()+1));
644 
645  for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin();
646  iCont != numberOfObjectsForContainerIds.end(); ++iCont ){
647 
648  PoolDbCacheData& contData = m_dbCache->find( iCont->first );
649  unsigned int nwrt = contData.m_nobjWr;
650  unsigned int ndel = nwrt-iCont->second;
651 
652  updateData[containerIdColumn()].data<int>() = iCont->first + 1; //POOL starts counting from 1!;
653  updateData[numberOfWrittenObjectsColumn()].data<unsigned int>() = nwrt;
654  updateData[numberOfDeletedObjectsColumn()].data<unsigned int>() = ndel;
655  bulkUpdate->processNextIteration();
656 
657  }
658  bulkUpdate->flush();
659  }
660 }
static std::string numberOfWrittenObjectsColumn()
static std::string containerIdColumn()
static std::string numberOfDeletedObjectsColumn()
PoolDbCacheData & find(int id)
coral::ISchema & schema()
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.