CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Attributes

ora::PoolSequenceTable Class Reference

#include <PoolDatabaseSchema.h>

Inheritance diagram for ora::PoolSequenceTable:
ora::ISequenceTable ora::IDatabaseTable

List of all members.

Public Member Functions

bool add (const std::string &sequenceName)
void create ()
void drop ()
void erase (const std::string &sequenceName)
bool exists ()
bool getLastId (const std::string &sequenceName, int &lastId)
void init (PoolDbCache &dbCache)
 PoolSequenceTable (coral::ISchema &dbSchema)
void sinchronize (const std::string &sequenceName, int lastValue)
virtual ~PoolSequenceTable ()

Static Public Member Functions

static std::string sequenceNameColumn ()
static std::string sequenceValueColumn ()
static std::string tableName ()

Private Attributes

PoolDbCachem_dbCache
coral::ISchema & m_schema

Detailed Description

Definition at line 65 of file PoolDatabaseSchema.h.


Constructor & Destructor Documentation

ora::PoolSequenceTable::PoolSequenceTable ( coral::ISchema &  dbSchema) [explicit]

Definition at line 73 of file PoolDatabaseSchema.cc.

                                                             :
  m_schema( schema),
  m_dbCache( 0 ){
}
ora::PoolSequenceTable::~PoolSequenceTable ( ) [virtual]

Definition at line 78 of file PoolDatabaseSchema.cc.

                                        {
}

Member Function Documentation

bool ora::PoolSequenceTable::add ( const std::string &  sequenceName) [virtual]

Implements ora::ISequenceTable.

Definition at line 86 of file PoolDatabaseSchema.cc.

                                                        {
  // Create the entry in the table if it does not exist.
  coral::AttributeList insertData;
  insertData.extend<std::string>(sequenceNameColumn());
  insertData.extend<int>(sequenceValueColumn());
  coral::AttributeList::iterator iAttribute = insertData.begin();
  iAttribute->data< std::string >() = sequenceName;
  ++iAttribute;
  iAttribute->data< int >() = 0;
  m_schema.tableHandle( tableName() ).dataEditor().insertRow( insertData );
  return true;
}
void ora::PoolSequenceTable::create ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 176 of file PoolDatabaseSchema.cc.

References ora::throwException().

                                 {
  if( m_schema.existsTable( tableName() )){
    throwException( "POOL database sequence table already exists in this schema.",
                    "PoolSequenceTable::create");
  }
  throwException( "POOL database cannot be created.","PoolSequenceTable::create");  
}
void ora::PoolSequenceTable::drop ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 184 of file PoolDatabaseSchema.cc.

                               {
  m_schema.dropIfExistsTable( tableName() );
}
void ora::PoolSequenceTable::erase ( const std::string &  sequenceName) [virtual]

Implements ora::ISequenceTable.

Definition at line 160 of file PoolDatabaseSchema.cc.

                                                               {
  coral::AttributeList whereData;
  whereData.extend<std::string>(sequenceNameColumn());
  whereData[ sequenceNameColumn() ].data<std::string>() = sequenceName;
  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
  m_schema.tableHandle( tableName() ).dataEditor().deleteRows( whereClause, whereData );
}
bool ora::PoolSequenceTable::exists ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 168 of file PoolDatabaseSchema.cc.

References ora::throwException().

                                 {
  if(!m_dbCache){
    throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::exists");
  }
  // ????
  return m_schema.existsTable( tableName() );
}
bool ora::PoolSequenceTable::getLastId ( const std::string &  sequenceName,
int &  lastId 
) [virtual]

Implements ora::ISequenceTable.

Definition at line 100 of file PoolDatabaseSchema.cc.

References o2o::query, and ora::throwException().

                                                 {
  if(!m_dbCache){
    throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::getLastId");
  }
  
  // first lookup in the cache for the built in sequences...
  std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
  std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
  if( iS != seq.end()){
    if( iS->second->m_nobjWr == 0 ) return false;
    lastId = iS->second->m_nobjWr-1;
    return true;
  }
  
  // otherwise, look up into the regular sequence table.
  std::auto_ptr< coral::IQuery > query( m_schema.tableHandle( tableName() ).newQuery() );
  query->limitReturnedRows( 1, 0 );
  query->addToOutputList( sequenceValueColumn() );
  query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() );
  query->setForUpdate();
  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
  coral::AttributeList rowData;
  rowData.extend<std::string>(sequenceNameColumn());
  rowData.begin()->data< std::string >() = sequenceName;
  query->setCondition( whereClause, rowData );
  coral::ICursor& cursor = query->execute();
  if ( cursor.next() ) {
    lastId = cursor.currentRow().begin()->data<int >();
    return true;
  }
  return false;
}
void ora::PoolSequenceTable::init ( PoolDbCache dbCache)

Definition at line 81 of file PoolDatabaseSchema.cc.

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

                                                     {
  m_dbCache = &dbCache;
}
std::string ora::PoolSequenceTable::sequenceNameColumn ( ) [static]

Definition at line 63 of file PoolDatabaseSchema.cc.

                                                  {
  static std::string s_column("NAME");
  return s_column;
}
std::string ora::PoolSequenceTable::sequenceValueColumn ( ) [static]

Definition at line 68 of file PoolDatabaseSchema.cc.

                                                   {
  static std::string s_column("VALUE");
  return s_column;
}
void ora::PoolSequenceTable::sinchronize ( const std::string &  sequenceName,
int  lastValue 
) [virtual]

Implements ora::ISequenceTable.

Definition at line 134 of file PoolDatabaseSchema.cc.

References ora::throwException().

                                                         {
  if(!m_dbCache){
    throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::sinchronize");
  }
  // nothing to do in the db if the sequence is in the cache...
  std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
  std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
  if( iS != seq.end()){
    iS->second->m_nobjWr = lastValue+1;
    return;
  }

  coral::AttributeList updateData;
  updateData.extend<std::string>(sequenceNameColumn());
  updateData.extend<int>(sequenceValueColumn());
  std::string setClause( sequenceValueColumn() + " = :" +  sequenceValueColumn() );
  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
  // Increment the oid in the database as well
  coral::AttributeList::iterator iAttribute = updateData.begin();
  iAttribute->data< std::string >() = sequenceName;
  ++iAttribute;
  iAttribute->data< int >() = lastValue;
  m_schema.tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData );
}
std::string ora::PoolSequenceTable::tableName ( ) [static]

Definition at line 58 of file PoolDatabaseSchema.cc.

                                         {
  static std::string s_name("POOL_RSS_SEQ");
  return s_name;
}

Member Data Documentation

Definition at line 84 of file PoolDatabaseSchema.h.

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

Definition at line 83 of file PoolDatabaseSchema.h.