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
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)
 
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 ()
 
- 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 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)
 

Detailed Description

Definition at line 88 of file OraDatabaseSchema.h.

Constructor & Destructor Documentation

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

Definition at line 421 of file OraDatabaseSchema.cc.

421  :
422  IContainerHeaderTable(dbSchema){
423 }
IContainerHeaderTable(coral::ISchema &schema)
ora::OraContainerHeaderTable::~OraContainerHeaderTable ( )
virtual

Definition at line 425 of file OraDatabaseSchema.cc.

425  {
426 }

Member Function Documentation

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, and AlCaHLTBitMon_QueryRunRegistry::string.

454  {
455  coral::AttributeList dataToInsert;
456  unsigned int numberOfObjects = 0;
457  dataToInsert.extend<int>( containerIdColumn());
458  dataToInsert.extend<std::string>( containerNameColumn());
459  dataToInsert.extend<std::string>( classNameColumn());
460  dataToInsert.extend<unsigned int>( numberOfObjectsColumn());
461  dataToInsert[ containerIdColumn() ].data<int>() = containerId;
462  dataToInsert[ containerNameColumn() ].data<std::string>() = containerName;
463  dataToInsert[ classNameColumn() ].data<std::string>() = className;
464  dataToInsert[ numberOfObjectsColumn() ].data<unsigned int>() = numberOfObjects;
465  coral::ITable& containerTable = schema().tableHandle( tableName() );
466  containerTable.dataEditor().insertRow( dataToInsert );
467 }
static std::string containerNameColumn()
static std::string classNameColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
coral::ISchema & schema()
static std::string containerIdColumn()
std::string className(const T &t)
Definition: ClassName.h:30
std::string ora::OraContainerHeaderTable::classNameColumn ( )
static

Definition at line 411 of file OraDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

411  {
412  static const std::string s_column("CLASS_NAME");
413  return s_column;
414 }
std::string ora::OraContainerHeaderTable::containerIdColumn ( )
static

Definition at line 400 of file OraDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

400  {
401  static const std::string s_column("CONTAINER_ID");
402  return s_column;
403 }
std::string ora::OraContainerHeaderTable::containerNameColumn ( )
static

Definition at line 406 of file OraDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

406  {
407  static const std::string s_column("CONTAINER_NAME");
408  return s_column;
409 }
void ora::OraContainerHeaderTable::create ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 560 of file OraDatabaseSchema.cc.

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

560  {
561  if( schema().existsTable( tableName() )){
562  throwException( "ORA database container header table already exists in this schema.",
563  "OraContainerHeaderTable::create");
564  }
565 
566  coral::TableDescription descr( "OraDb" );
567  descr.setName( tableName() );
568  descr.insertColumn( containerIdColumn(),
569  coral::AttributeSpecification::typeNameForType<int>() );
570  descr.insertColumn( containerNameColumn(),
571  coral::AttributeSpecification::typeNameForType<std::string>() );
572  descr.insertColumn( classNameColumn(),
573  coral::AttributeSpecification::typeNameForType<std::string>() );
574  descr.insertColumn( numberOfObjectsColumn(),
575  coral::AttributeSpecification::typeNameForType<unsigned int>() );
576  descr.setNotNullConstraint( containerIdColumn() );
577  descr.setNotNullConstraint( containerNameColumn() );
578  descr.setNotNullConstraint( classNameColumn() );
579  descr.setNotNullConstraint( numberOfObjectsColumn() );
580  descr.setPrimaryKey( std::vector<std::string>( 1, containerIdColumn() ) );
581  descr.setUniqueConstraint( containerNameColumn() );
582  schema().createTable( descr );
583 }
static std::string containerNameColumn()
static std::string classNameColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
coral::ISchema & schema()
static std::string containerIdColumn()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void ora::OraContainerHeaderTable::decrementNumberOfObjects ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 522 of file OraDatabaseSchema.cc.

522  {
523  std::stringstream setClause;
524  setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " - 1";
525  return updateContainer( containerId, setClause.str() );
526 }
void updateContainer(int id, const std::string &setClause)
static std::string numberOfObjectsColumn()
void ora::OraContainerHeaderTable::drop ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 585 of file OraDatabaseSchema.cc.

References python.IdGenerator::schema.

585  {
586  schema().dropIfExistsTable( tableName() );
587 }
static std::string tableName()
coral::ISchema & schema()
bool ora::OraContainerHeaderTable::exists ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 556 of file OraDatabaseSchema.cc.

References python.IdGenerator::schema.

556  {
557  return schema().existsTable( tableName() );
558 }
static std::string tableName()
coral::ISchema & schema()
bool ora::OraContainerHeaderTable::getContainerData ( std::map< std::string, ContainerHeaderData > &  destination)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 428 of file OraDatabaseSchema.cc.

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

429  {
430  bool ret = false;
431  coral::ITable& containerTable = schema().tableHandle( tableName() );
432  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
433  coral::AttributeList outputBuffer;
434  outputBuffer.extend<int>( containerIdColumn() );
435  outputBuffer.extend<std::string>( containerNameColumn() );
436  outputBuffer.extend<std::string>( classNameColumn() );
437  outputBuffer.extend<unsigned int>( numberOfObjectsColumn() );
438  query->defineOutput( outputBuffer );
439  coral::ICursor& cursor = query->execute();
440  while ( cursor.next() ) {
441  ret = true;
442  const coral::AttributeList& row = cursor.currentRow();
443  int containerId = row[ containerIdColumn() ].data< int >();
444  std::string containerName = row[ containerNameColumn()].data< std::string >();
445  std::string className = row[ classNameColumn()].data< std::string >();
446  unsigned int numberOfObjects = row[ numberOfObjectsColumn()].data< unsigned int >();
447  dest.insert( std::make_pair( containerName, ContainerHeaderData( containerId, className, numberOfObjects ) )) ;
448  }
449  return ret;
450 }
static std::string containerNameColumn()
static std::string classNameColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
coral::ISchema & schema()
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 516 of file OraDatabaseSchema.cc.

516  {
517  std::stringstream setClause;
518  setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " + 1";
519  return updateContainer( containerId, setClause.str() );
520 }
void updateContainer(int id, const std::string &setClause)
static std::string numberOfObjectsColumn()
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, python.IdGenerator::schema, and AlCaHLTBitMon_QueryRunRegistry::string.

490  {
491  bool ret = false;
492  coral::ITable& containerTable = schema().tableHandle( tableName() );
493  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
494  query->addToOutputList( classNameColumn() );
495  query->defineOutputType( classNameColumn() , coral::AttributeSpecification::typeNameForType<std::string>() );
496  query->addToOutputList( numberOfObjectsColumn() );
497  query->defineOutputType( numberOfObjectsColumn() , coral::AttributeSpecification::typeNameForType<unsigned int>() );
498  std::stringstream whereClause;
499  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
500  coral::AttributeList whereData;
501  whereData.extend<int>( containerIdColumn() );
502  whereData.begin()->data<int>() = id;
503  query->setCondition( whereClause.str(), whereData );
504  query->setForUpdate();
505  coral::ICursor& cursor = query->execute();
506  if( cursor.next() ) {
507  ret = true;
508  const coral::AttributeList& row = cursor.currentRow();
509  dest.id = id;
510  dest.className = row[ classNameColumn()].data< std::string >();
511  dest.numberOfObjects = row[ numberOfObjectsColumn()].data< unsigned int >();
512  }
513  return ret;
514 }
static std::string classNameColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
coral::ISchema & schema()
static std::string containerIdColumn()
tuple query
Definition: o2o.py:269
std::string ora::OraContainerHeaderTable::name ( )
virtual
std::string ora::OraContainerHeaderTable::numberOfObjectsColumn ( )
static

Definition at line 416 of file OraDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

416  {
417  static const std::string s_column("NUMBER_OF_OBJECTS");
418  return s_column;
419 }
void ora::OraContainerHeaderTable::removeContainer ( int  id)
virtual

Implements ora::IContainerHeaderTable.

Definition at line 469 of file OraDatabaseSchema.cc.

References python.IdGenerator::schema.

469  {
470  std::stringstream whereClause;
471  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
472  coral::AttributeList whereData;
473  whereData.extend< int >( containerIdColumn() );
474  whereData.begin()->data< int >() = id;
475  coral::ITable& containerTable = schema().tableHandle( tableName() );
476  containerTable.dataEditor().deleteRows(whereClause.str(),whereData);
477 }
static std::string tableName()
coral::ISchema & schema()
static std::string containerIdColumn()
std::string ora::OraContainerHeaderTable::tableName ( )
static

Definition at line 394 of file OraDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

394  {
395  static const std::string s_name("ORA_CONTAINER");
396  return s_name;
397 }
void ora::OraContainerHeaderTable::updateContainer ( int  id,
const std::string &  setClause 
)
private

Definition at line 479 of file OraDatabaseSchema.cc.

References python.IdGenerator::schema.

480  {
481  std::stringstream whereClause;
482  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
483  coral::AttributeList updateData;
484  updateData.extend<int>( containerIdColumn() );
485  updateData.begin()->data<int>() = containerId;
486  coral::ITable& containerTable = schema().tableHandle( tableName() );
487  containerTable.dataEditor().updateRows(setClause,whereClause.str(),updateData);
488 }
static std::string tableName()
coral::ISchema & schema()
static std::string containerIdColumn()
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.

528  {
529  if( numberOfObjectsForContainerIds.size() ){
530 
531  std::stringstream whereClause;
532  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
533  std::stringstream setClause;
534  setClause << numberOfObjectsColumn() << " = :" <<numberOfObjectsColumn();
535  coral::AttributeList updateData;
536  updateData.extend<unsigned int>( numberOfObjectsColumn() );
537  updateData.extend<int>( containerIdColumn() );
538 
539  coral::ITable& containerTable = schema().tableHandle( tableName() );
540  std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size()));
541 
542  for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin();
543  iCont != numberOfObjectsForContainerIds.end(); ++iCont ){
544  updateData[containerIdColumn()].data<int>() = iCont->first;
545  updateData[numberOfObjectsColumn()].data<unsigned int>() = iCont->second;
546  bulkUpdate->processNextIteration();
547  }
548  bulkUpdate->flush();
549  }
550 }
static std::string tableName()
static std::string numberOfObjectsColumn()
coral::ISchema & schema()
static std::string containerIdColumn()