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

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.

73  :
74  m_schema( schema),
75  m_dbCache( 0 ){
76 }
coral::ISchema & m_schema
ora::PoolSequenceTable::~PoolSequenceTable ( )
virtual

Definition at line 78 of file PoolDatabaseSchema.cc.

78  {
79 }

Member Function Documentation

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

Implements ora::ISequenceTable.

Definition at line 86 of file PoolDatabaseSchema.cc.

86  {
87  // Create the entry in the table if it does not exist.
88  coral::AttributeList insertData;
89  insertData.extend<std::string>(sequenceNameColumn());
90  insertData.extend<int>(sequenceValueColumn());
91  coral::AttributeList::iterator iAttribute = insertData.begin();
92  iAttribute->data< std::string >() = sequenceName;
93  ++iAttribute;
94  iAttribute->data< int >() = 0;
95  m_schema.tableHandle( tableName() ).dataEditor().insertRow( insertData );
96  return true;
97 }
static std::string tableName()
static std::string sequenceNameColumn()
static std::string sequenceValueColumn()
coral::ISchema & m_schema
void ora::PoolSequenceTable::create ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 176 of file PoolDatabaseSchema.cc.

References ora::throwException().

176  {
177  if( m_schema.existsTable( tableName() )){
178  throwException( "POOL database sequence table already exists in this schema.",
179  "PoolSequenceTable::create");
180  }
181  throwException( "POOL database cannot be created.","PoolSequenceTable::create");
182 }
static std::string tableName()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
coral::ISchema & m_schema
void ora::PoolSequenceTable::drop ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 184 of file PoolDatabaseSchema.cc.

184  {
185  m_schema.dropIfExistsTable( tableName() );
186 }
static std::string tableName()
coral::ISchema & m_schema
void ora::PoolSequenceTable::erase ( const std::string &  sequenceName)
virtual

Implements ora::ISequenceTable.

Definition at line 160 of file PoolDatabaseSchema.cc.

160  {
161  coral::AttributeList whereData;
162  whereData.extend<std::string>(sequenceNameColumn());
163  whereData[ sequenceNameColumn() ].data<std::string>() = sequenceName;
164  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
165  m_schema.tableHandle( tableName() ).dataEditor().deleteRows( whereClause, whereData );
166 }
static std::string tableName()
static std::string sequenceNameColumn()
coral::ISchema & m_schema
bool ora::PoolSequenceTable::exists ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 168 of file PoolDatabaseSchema.cc.

References ora::throwException().

168  {
169  if(!m_dbCache){
170  throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::exists");
171  }
172  // ????
173  return m_schema.existsTable( tableName() );
174 }
static std::string tableName()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
coral::ISchema & m_schema
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().

101  {
102  if(!m_dbCache){
103  throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::getLastId");
104  }
105 
106  // first lookup in the cache for the built in sequences...
107  std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
108  std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
109  if( iS != seq.end()){
110  if( iS->second->m_nobjWr == 0 ) return false;
111  lastId = iS->second->m_nobjWr-1;
112  return true;
113  }
114 
115  // otherwise, look up into the regular sequence table.
116  std::auto_ptr< coral::IQuery > query( m_schema.tableHandle( tableName() ).newQuery() );
117  query->limitReturnedRows( 1, 0 );
118  query->addToOutputList( sequenceValueColumn() );
119  query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() );
120  query->setForUpdate();
121  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
122  coral::AttributeList rowData;
123  rowData.extend<std::string>(sequenceNameColumn());
124  rowData.begin()->data< std::string >() = sequenceName;
125  query->setCondition( whereClause, rowData );
126  coral::ICursor& cursor = query->execute();
127  if ( cursor.next() ) {
128  lastId = cursor.currentRow().begin()->data<int >();
129  return true;
130  }
131  return false;
132 }
static std::string tableName()
std::map< std::string, PoolDbCacheData * > & sequences()
static std::string sequenceNameColumn()
static std::string sequenceValueColumn()
tuple query
Definition: o2o.py:269
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
coral::ISchema & m_schema
void ora::PoolSequenceTable::init ( PoolDbCache dbCache)

Definition at line 81 of file PoolDatabaseSchema.cc.

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

81  {
82  m_dbCache = &dbCache;
83 }
std::string ora::PoolSequenceTable::sequenceNameColumn ( )
static

Definition at line 63 of file PoolDatabaseSchema.cc.

63  {
64  static std::string s_column("NAME");
65  return s_column;
66 }
std::string ora::PoolSequenceTable::sequenceValueColumn ( )
static

Definition at line 68 of file PoolDatabaseSchema.cc.

68  {
69  static std::string s_column("VALUE");
70  return s_column;
71 }
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().

135  {
136  if(!m_dbCache){
137  throwException("Sequence Table handle has not been initialized.","PoolSequenceTable::sinchronize");
138  }
139  // nothing to do in the db if the sequence is in the cache...
140  std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
141  std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
142  if( iS != seq.end()){
143  iS->second->m_nobjWr = lastValue+1;
144  return;
145  }
146 
147  coral::AttributeList updateData;
148  updateData.extend<std::string>(sequenceNameColumn());
149  updateData.extend<int>(sequenceValueColumn());
150  std::string setClause( sequenceValueColumn() + " = :" + sequenceValueColumn() );
151  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
152  // Increment the oid in the database as well
153  coral::AttributeList::iterator iAttribute = updateData.begin();
154  iAttribute->data< std::string >() = sequenceName;
155  ++iAttribute;
156  iAttribute->data< int >() = lastValue;
157  m_schema.tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData );
158 }
static std::string tableName()
std::map< std::string, PoolDbCacheData * > & sequences()
static std::string sequenceNameColumn()
static std::string sequenceValueColumn()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
coral::ISchema & m_schema
std::string ora::PoolSequenceTable::tableName ( )
static

Definition at line 58 of file PoolDatabaseSchema.cc.

58  {
59  static std::string s_name("POOL_RSS_SEQ");
60  return s_name;
61 }

Member Data Documentation

PoolDbCache* ora::PoolSequenceTable::m_dbCache
private

Definition at line 84 of file PoolDatabaseSchema.h.

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

Definition at line 83 of file PoolDatabaseSchema.h.