CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Attributes

ora::CondMetadataTable Class Reference

#include <PoolDatabaseSchema.h>

Inheritance diagram for ora::CondMetadataTable:
ora::INamingServiceTable ora::IDatabaseTable

List of all members.

Public Member Functions

 CondMetadataTable (coral::ISchema &dbSchema, PoolDbCache &dbCache)
void create ()
void drop ()
bool eraseAllNames ()
bool eraseObjectName (const std::string &name)
bool exists ()
bool getAllNames (std::vector< std::string > &destination)
bool getNamesForContainer (int contId, std::vector< std::string > &destination)
bool getNamesForObject (int contId, int itemId, std::vector< std::string > &destination)
bool getObjectByName (const std::string &name, std::pair< int, int > &destination)
std::string name ()
void setObjectName (const std::string &name, int contId, int itemId)
virtual ~CondMetadataTable ()

Static Public Member Functions

static std::string & objectNameColumn ()
static std::string & tableName ()
static std::string & timetypeColumn ()
static std::string & tokenColumn ()

Private Attributes

PoolDbCachem_dbCache

Detailed Description

Definition at line 201 of file PoolDatabaseSchema.h.


Constructor & Destructor Documentation

ora::CondMetadataTable::CondMetadataTable ( coral::ISchema &  dbSchema,
PoolDbCache dbCache 
)

Definition at line 1168 of file PoolDatabaseSchema.cc.

                                                                 :
  INamingServiceTable( dbSchema ),
  m_dbCache( dbCache ){
}
ora::CondMetadataTable::~CondMetadataTable ( ) [virtual]

Definition at line 1174 of file PoolDatabaseSchema.cc.

                                        {
}

Member Function Documentation

void ora::CondMetadataTable::create ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 1319 of file PoolDatabaseSchema.cc.

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

                                 {
  if( schema().existsTable( tableName() )){
    throwException( "Metadata table already exists in this schema.",
                    "CondMetadataTable::create");
  }
  throwException( "Cond Metadata table cannot be created.","CondMetadataTable::create");  
}
void ora::CondMetadataTable::drop ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 1327 of file PoolDatabaseSchema.cc.

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

                               {
  if( !schema().existsTable( tableName() )){
    throwException( "Metadata table does not exists in this schema.",
                    "CondMetadataTable::drop");
  }
  throwException( "Cond Metadata table cannot be dropped.","CondMetadataTable::drop");  
}
bool ora::CondMetadataTable::eraseAllNames ( ) [virtual]

Implements ora::INamingServiceTable.

Definition at line 1200 of file PoolDatabaseSchema.cc.

References python::IdGenerator::schema.

                                        {
  std::string condition("");
  coral::AttributeList whereData;
  return schema().tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
}
bool ora::CondMetadataTable::eraseObjectName ( const std::string &  name) [virtual]

Implements ora::INamingServiceTable.

Definition at line 1192 of file PoolDatabaseSchema.cc.

References python::IdGenerator::schema.

                                                                 {
  coral::AttributeList whereData;
  whereData.extend<std::string>( objectNameColumn() );
  whereData.begin()->data<std::string>() = name;
  std::string condition = objectNameColumn() + " = :" + objectNameColumn();
  return schema().tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
}
bool ora::CondMetadataTable::exists ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 1315 of file PoolDatabaseSchema.cc.

References python::IdGenerator::schema.

                                 {
  return schema().existsTable( tableName() );
}
bool ora::CondMetadataTable::getAllNames ( std::vector< std::string > &  destination) [virtual]

Implements ora::INamingServiceTable.

Definition at line 1292 of file PoolDatabaseSchema.cc.

References mergeVDriftHistosByStation::name, o2o::query, runTheMatrix::ret, and python::IdGenerator::schema.

                                                                         {
  
  bool ret = false;
  coral::ITable& containerTable = schema().tableHandle( tableName() );
  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
  coral::AttributeList outputBuffer;
  outputBuffer.extend<std::string>( objectNameColumn() );
  query->defineOutput( outputBuffer );
  query->addToOutputList( objectNameColumn() );
  coral::ICursor& cursor = query->execute();
  while ( cursor.next() ) {
    ret = true;
    const coral::AttributeList& row = cursor.currentRow();
    std::string name = row[ objectNameColumn() ].data< std::string >();
    destination.push_back( name );
  }
  return ret;
}
bool ora::CondMetadataTable::getNamesForContainer ( int  contId,
std::vector< std::string > &  destination 
) [virtual]

Implements ora::INamingServiceTable.

Definition at line 1263 of file PoolDatabaseSchema.cc.

References ora::PoolDbCacheData::m_className, ora::PoolDbCacheData::m_name, mergeVDriftHistosByStation::name, o2o::query, runTheMatrix::ret, python::IdGenerator::schema, and cond::writeTokenContainerFragment().

                                                                                      {
  
  bool ret = false;
  coral::ITable& containerTable = schema().tableHandle( tableName() );
  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
  coral::AttributeList outputBuffer;
  outputBuffer.extend<std::string>( objectNameColumn() );
  query->defineOutput( outputBuffer );
  query->addToOutputList( objectNameColumn() );
  std::ostringstream condition;
  condition << tokenColumn()<<" LIKE :"<< tokenColumn();
  ora::PoolDbCacheData& contData = m_dbCache.find( contId );
  std::string tokenFragment = cond::writeTokenContainerFragment( contData.m_name, contData.m_className )+"%";
  coral::AttributeList condData;
  condData.extend<std::string>( tokenColumn() );
  coral::AttributeList::iterator iAttribute = condData.begin();
  iAttribute->data< std::string >() = tokenFragment;
  query->setCondition( condition.str(), condData );
  coral::ICursor& cursor = query->execute();
  while ( cursor.next() ) {
    ret = true;
    const coral::AttributeList& row = cursor.currentRow();
    std::string name = row[ objectNameColumn() ].data< std::string >();
    destination.push_back( name );
  }
  return ret;
}
bool ora::CondMetadataTable::getNamesForObject ( int  contId,
int  itemId,
std::vector< std::string > &  destination 
) [virtual]

Implements ora::INamingServiceTable.

Definition at line 1234 of file PoolDatabaseSchema.cc.

References ora::PoolDbCacheData::m_className, ora::PoolDbCacheData::m_name, mergeVDriftHistosByStation::name, o2o::query, runTheMatrix::ret, python::IdGenerator::schema, and cond::writeToken().

                                                                                   {
  bool ret = false;
  coral::ITable& containerTable = schema().tableHandle( tableName() );
  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
  coral::AttributeList outputBuffer;
  outputBuffer.extend<std::string>( objectNameColumn() );
  query->defineOutput( outputBuffer );
  query->addToOutputList( objectNameColumn() );
  std::ostringstream condition;
  condition << tokenColumn()<<"= :"<< tokenColumn();
  ora::PoolDbCacheData& contData = m_dbCache.find( contId );
  std::string token = cond::writeToken( contData.m_name, contId, itemId, contData.m_className );
  coral::AttributeList condData;
  condData.extend<std::string>( tokenColumn() );
  coral::AttributeList::iterator iAttribute = condData.begin();
  iAttribute->data< std::string >() = token;
  query->setCondition( condition.str(), condData );
  coral::ICursor& cursor = query->execute();
  while ( cursor.next() ) {
    ret = true;
    const coral::AttributeList& row = cursor.currentRow();
    std::string name = row[ objectNameColumn() ].data< std::string >();
    destination.push_back( name );
  }
  return ret;
}
bool ora::CondMetadataTable::getObjectByName ( const std::string &  name,
std::pair< int, int > &  destination 
) [virtual]

Implements ora::INamingServiceTable.

Definition at line 1206 of file PoolDatabaseSchema.cc.

References cond::parseToken(), o2o::query, runTheMatrix::ret, and python::IdGenerator::schema.

                                                                             {
  bool ret = false;
  coral::ITable& containerTable = schema().tableHandle( tableName() );
  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
  coral::AttributeList outputBuffer;
  outputBuffer.extend<std::string>( tokenColumn() );
  query->defineOutput( outputBuffer );
  query->addToOutputList( tokenColumn() );
  std::ostringstream condition;
  condition << objectNameColumn()<<"= :"<< objectNameColumn();
  coral::AttributeList condData;
  condData.extend<std::string>( objectNameColumn() );
  coral::AttributeList::iterator iAttribute = condData.begin();
  iAttribute->data< std::string >() = name;
  query->setCondition( condition.str(), condData );
  coral::ICursor& cursor = query->execute();
  while ( cursor.next() ) {
    ret = true;
    const coral::AttributeList& row = cursor.currentRow();
    std::string token = row[ tokenColumn() ].data< std::string >();
    std::pair<std::string,int> tokData = cond::parseToken( token ); 
    destination.first = m_dbCache.idByName( tokData.first );
    destination.second = tokData.second;
  }
  return ret;
}
std::string ora::CondMetadataTable::name ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 1311 of file PoolDatabaseSchema.cc.

                                    {
  return tableName();
}
std::string & ora::CondMetadataTable::objectNameColumn ( ) [static]

Definition at line 1153 of file PoolDatabaseSchema.cc.

                                                 {
  static std::string s_column("NAME");
  return s_column;
}
void ora::CondMetadataTable::setObjectName ( const std::string &  name,
int  contId,
int  itemId 
) [virtual]

Implements ora::INamingServiceTable.

Definition at line 1177 of file PoolDatabaseSchema.cc.

References python::IdGenerator::schema, and cond::writeToken().

                                                                    {
  coral::AttributeList dataToInsert;
  dataToInsert.extend<std::string>( objectNameColumn() );
  dataToInsert.extend<std::string>( tokenColumn());
  dataToInsert.extend<int>( timetypeColumn());
  ora::PoolDbCacheData& contData = m_dbCache.find( contId );
  std::string token = cond::writeToken( contData.m_name, contId, itemId, contData.m_className );
  dataToInsert[ objectNameColumn() ].data<std::string>() = name;
  dataToInsert[ tokenColumn() ].data<std::string>()  = token;
  dataToInsert[ timetypeColumn() ].data<int>()  = -1; // is it fine ???
  coral::ITable& containerTable = schema().tableHandle( tableName() );
  containerTable.dataEditor().insertRow( dataToInsert );  
}
std::string & ora::CondMetadataTable::tableName ( ) [static]

Definition at line 1148 of file PoolDatabaseSchema.cc.

                                          {
  static std::string s_name("METADATA");
  return s_name;
}
std::string & ora::CondMetadataTable::timetypeColumn ( ) [static]

Definition at line 1163 of file PoolDatabaseSchema.cc.

                                               {
  static std::string s_column("TIMETYPE");
  return s_column;
}
std::string & ora::CondMetadataTable::tokenColumn ( ) [static]

Definition at line 1158 of file PoolDatabaseSchema.cc.

                                            {
  static std::string s_column("TOKEN");
  return s_column;
}

Member Data Documentation

Definition at line 223 of file PoolDatabaseSchema.h.