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::PoolSequenceTable Class Reference

#include <PoolDatabaseSchema.h>

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

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)
 
std::string name ()
 
 PoolSequenceTable (coral::ISchema &dbSchema)
 
void sinchronize (const std::string &sequenceName, int lastValue)
 
virtual ~PoolSequenceTable ()
 
- Public Member Functions inherited from ora::ISequenceTable
 ISequenceTable (coral::ISchema &schema)
 
virtual ~ISequenceTable ()
 
- 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 sequenceNameColumn ()
 
static std::string sequenceValueColumn ()
 
static std::string tableName ()
 

Private Attributes

PoolDbCachem_dbCache
 

Detailed Description

Definition at line 66 of file PoolDatabaseSchema.h.

Constructor & Destructor Documentation

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

Definition at line 87 of file PoolDatabaseSchema.cc.

87  :
89  m_dbCache( 0 ){
90 }
coral::ISchema & schema()
ISequenceTable(coral::ISchema &schema)
ora::PoolSequenceTable::~PoolSequenceTable ( )
virtual

Definition at line 92 of file PoolDatabaseSchema.cc.

92  {
93 }

Member Function Documentation

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

Implements ora::ISequenceTable.

Definition at line 100 of file PoolDatabaseSchema.cc.

References python.IdGenerator::schema, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by counter.Counter::register().

100  {
101  // Create the entry in the table if it does not exist.
102  coral::AttributeList insertData;
103  insertData.extend<std::string>(sequenceNameColumn());
104  insertData.extend<int>(sequenceValueColumn());
105  coral::AttributeList::iterator iAttribute = insertData.begin();
106  iAttribute->data< std::string >() = sequenceName;
107  ++iAttribute;
108  iAttribute->data< int >() = 0;
109  schema().tableHandle( tableName() ).dataEditor().insertRow( insertData );
110  return true;
111 }
static std::string tableName()
static std::string sequenceNameColumn()
static std::string sequenceValueColumn()
coral::ISchema & schema()
void ora::PoolSequenceTable::create ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 194 of file PoolDatabaseSchema.cc.

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

194  {
195  if( schema().existsTable( tableName() )){
196  throwException( "POOL database sequence table already exists in this schema.",
197  "PoolSequenceTable::create");
198  }
199  throwException( "POOL database cannot be created.","PoolSequenceTable::create");
200 }
static std::string tableName()
coral::ISchema & schema()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void ora::PoolSequenceTable::drop ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 202 of file PoolDatabaseSchema.cc.

References python.IdGenerator::schema.

202  {
203  schema().dropIfExistsTable( tableName() );
204 }
static std::string tableName()
coral::ISchema & schema()
void ora::PoolSequenceTable::erase ( const std::string &  sequenceName)
virtual

Implements ora::ISequenceTable.

Definition at line 174 of file PoolDatabaseSchema.cc.

References python.IdGenerator::schema, and AlCaHLTBitMon_QueryRunRegistry::string.

174  {
175  coral::AttributeList whereData;
176  whereData.extend<std::string>(sequenceNameColumn());
177  whereData[ sequenceNameColumn() ].data<std::string>() = sequenceName;
178  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
179  schema().tableHandle( tableName() ).dataEditor().deleteRows( whereClause, whereData );
180 }
static std::string tableName()
static std::string sequenceNameColumn()
coral::ISchema & schema()
bool ora::PoolSequenceTable::exists ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 186 of file PoolDatabaseSchema.cc.

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

186  {
187  if(!m_dbCache){
188  throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::exists");
189  }
190  // ????
191  return schema().existsTable( tableName() );
192 }
static std::string tableName()
coral::ISchema & schema()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
bool ora::PoolSequenceTable::getLastId ( const std::string &  sequenceName,
int &  lastId 
)
virtual

Implements ora::ISequenceTable.

Definition at line 114 of file PoolDatabaseSchema.cc.

References o2o::query, python.IdGenerator::schema, AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().

115  {
116  if(!m_dbCache){
117  throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::getLastId");
118  }
119 
120  // first lookup in the cache for the built in sequences...
121  std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
122  std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
123  if( iS != seq.end()){
124  if( iS->second->m_nobjWr == 0 ) return false;
125  lastId = iS->second->m_nobjWr-1;
126  return true;
127  }
128 
129  // otherwise, look up into the regular sequence table.
130  std::auto_ptr< coral::IQuery > query( schema().tableHandle( tableName() ).newQuery() );
131  query->limitReturnedRows( 1, 0 );
132  query->addToOutputList( sequenceValueColumn() );
133  query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() );
134  query->setForUpdate();
135  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
136  coral::AttributeList rowData;
137  rowData.extend<std::string>(sequenceNameColumn());
138  rowData.begin()->data< std::string >() = sequenceName;
139  query->setCondition( whereClause, rowData );
140  coral::ICursor& cursor = query->execute();
141  if ( cursor.next() ) {
142  lastId = cursor.currentRow().begin()->data<int >();
143  return true;
144  }
145  return false;
146 }
static std::string tableName()
std::map< std::string, PoolDbCacheData * > & sequences()
static std::string sequenceNameColumn()
static std::string sequenceValueColumn()
coral::ISchema & schema()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
tuple query
Definition: o2o.py:269
void ora::PoolSequenceTable::init ( PoolDbCache dbCache)

Definition at line 95 of file PoolDatabaseSchema.cc.

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

95  {
96  m_dbCache = &dbCache;
97 }
std::string ora::PoolSequenceTable::name ( )
virtual
std::string ora::PoolSequenceTable::sequenceNameColumn ( )
static

Definition at line 77 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

77  {
78  static const std::string s_column("NAME");
79  return s_column;
80 }
std::string ora::PoolSequenceTable::sequenceValueColumn ( )
static

Definition at line 82 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

Implements ora::ISequenceTable.

Definition at line 148 of file PoolDatabaseSchema.cc.

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

149  {
150  if(!m_dbCache){
151  throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::sinchronize");
152  }
153  // nothing to do in the db if the sequence is in the cache...
154  std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
155  std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
156  if( iS != seq.end()){
157  iS->second->m_nobjWr = lastValue+1;
158  return;
159  }
160 
161  coral::AttributeList updateData;
162  updateData.extend<std::string>(sequenceNameColumn());
163  updateData.extend<int>(sequenceValueColumn());
164  std::string setClause( sequenceValueColumn() + " = :" + sequenceValueColumn() );
165  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
166  // Increment the oid in the database as well
167  coral::AttributeList::iterator iAttribute = updateData.begin();
168  iAttribute->data< std::string >() = sequenceName;
169  ++iAttribute;
170  iAttribute->data< int >() = lastValue;
171  schema().tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData );
172 }
static std::string tableName()
std::map< std::string, PoolDbCacheData * > & sequences()
static std::string sequenceNameColumn()
static std::string sequenceValueColumn()
coral::ISchema & schema()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
std::string ora::PoolSequenceTable::tableName ( )
static

Definition at line 72 of file PoolDatabaseSchema.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

72  {
73  static const std::string s_name("POOL_RSS_SEQ");
74  return s_name;
75 }

Member Data Documentation

PoolDbCache* ora::PoolSequenceTable::m_dbCache
private

Definition at line 85 of file PoolDatabaseSchema.h.