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)
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
coral::ISchema & m_schema

Detailed Description

Definition at line 202 of file PoolDatabaseSchema.h.


Constructor & Destructor Documentation

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

Definition at line 1105 of file PoolDatabaseSchema.cc.

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

Definition at line 1111 of file PoolDatabaseSchema.cc.

                                        {
}

Member Function Documentation

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

Implements ora::IDatabaseTable.

Definition at line 1252 of file PoolDatabaseSchema.cc.

References ora::throwException().

                                 {
  if( m_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 1260 of file PoolDatabaseSchema.cc.

References ora::throwException().

                               {
  if( !m_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 1137 of file PoolDatabaseSchema.cc.

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

Implements ora::INamingServiceTable.

Definition at line 1129 of file PoolDatabaseSchema.cc.

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

Implements ora::IDatabaseTable.

Definition at line 1248 of file PoolDatabaseSchema.cc.

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

Implements ora::INamingServiceTable.

Definition at line 1229 of file PoolDatabaseSchema.cc.

References mergeVDriftHistosByStation::name, o2o::query, and runTheMatrix::ret.

                                                                         {
  
  bool ret = false;
  coral::ITable& containerTable = m_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 1200 of file PoolDatabaseSchema.cc.

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

                                                                                      {
  
  bool ret = false;
  coral::ITable& containerTable = m_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 1171 of file PoolDatabaseSchema.cc.

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

                                                                                   {
  bool ret = false;
  coral::ITable& containerTable = m_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 1143 of file PoolDatabaseSchema.cc.

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

                                                                             {
  bool ret = false;
  coral::ITable& containerTable = m_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::objectNameColumn ( ) [static]

Definition at line 1090 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 1114 of file PoolDatabaseSchema.cc.

References 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 = m_schema.tableHandle( tableName() );
  containerTable.dataEditor().insertRow( dataToInsert );  
}
std::string & ora::CondMetadataTable::tableName ( ) [static]

Definition at line 1085 of file PoolDatabaseSchema.cc.

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

Definition at line 1100 of file PoolDatabaseSchema.cc.

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

Definition at line 1095 of file PoolDatabaseSchema.cc.

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

Member Data Documentation

Definition at line 224 of file PoolDatabaseSchema.h.

coral::ISchema& ora::CondMetadataTable::m_schema [private]

Definition at line 223 of file PoolDatabaseSchema.h.