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

#include <OraDatabaseSchema.h>

Inheritance diagram for ora::OraSequenceTable:
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)
 
 OraSequenceTable (coral::ISchema &dbSchema)
 
void sinchronize (const std::string &sequenceName, int lastValue)
 
virtual ~OraSequenceTable ()
 
- 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

coral::ISchema & m_schema
 

Detailed Description

Definition at line 30 of file OraDatabaseSchema.h.

Constructor & Destructor Documentation

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

Definition at line 113 of file OraDatabaseSchema.cc.

113  :
114  m_schema( schema){
115 }
coral::ISchema & m_schema
ora::OraSequenceTable::~OraSequenceTable ( )
virtual

Definition at line 117 of file OraDatabaseSchema.cc.

117  {
118 }

Member Function Documentation

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

Implements ora::ISequenceTable.

Definition at line 121 of file OraDatabaseSchema.cc.

121  {
122  // Create the entry in the table
123  coral::AttributeList insertData;
124  insertData.extend<std::string>(sequenceNameColumn());
125  insertData.extend<int>(sequenceValueColumn());
126  coral::AttributeList::iterator iAttribute = insertData.begin();
127  iAttribute->data< std::string >() = sequenceName;
128  ++iAttribute;
129  iAttribute->data< int >() = 0;
130  m_schema.tableHandle( tableName() ).dataEditor().insertRow( insertData );
131  return true;
132 }
coral::ISchema & m_schema
static std::string sequenceNameColumn()
static std::string tableName()
static std::string sequenceValueColumn()
void ora::OraSequenceTable::create ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 182 of file OraDatabaseSchema.cc.

References idDealer::description, and ora::throwException().

182  {
183  if( m_schema.existsTable( tableName() )){
184  throwException( "ORA database sequence table already exists in this schema.",
185  "OraSequenceTable::create");
186  }
187 
188  coral::TableDescription description( "OraDb" );
189  description.setName( tableName() );
190 
191  description.insertColumn( sequenceNameColumn(), coral::AttributeSpecification::typeNameForType<std::string>() );
192  description.setNotNullConstraint( sequenceNameColumn() );
193 
194  description.insertColumn( sequenceValueColumn(),coral::AttributeSpecification::typeNameForType<int>() );
195  description.setNotNullConstraint( sequenceValueColumn() );
196 
197  description.setPrimaryKey( std::vector< std::string >( 1, sequenceNameColumn() ) );
198  m_schema.createTable( description ).privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
199 }
coral::ISchema & m_schema
static std::string sequenceNameColumn()
static std::string tableName()
static std::string sequenceValueColumn()
tuple description
Definition: idDealer.py:66
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::OraSequenceTable::drop ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 201 of file OraDatabaseSchema.cc.

201  {
202  m_schema.dropIfExistsTable( tableName() );
203 }
coral::ISchema & m_schema
static std::string tableName()
void ora::OraSequenceTable::erase ( const std::string &  sequenceName)
virtual

Implements ora::ISequenceTable.

Definition at line 170 of file OraDatabaseSchema.cc.

170  {
171  coral::AttributeList whereData;
172  whereData.extend<std::string>(sequenceNameColumn());
173  whereData[ sequenceNameColumn() ].data<std::string>() = name;
174  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
175  m_schema.tableHandle( tableName() ).dataEditor().deleteRows( whereClause, whereData );
176 }
coral::ISchema & m_schema
static std::string sequenceNameColumn()
static std::string tableName()
bool ora::OraSequenceTable::exists ( )
virtual

Implements ora::IDatabaseTable.

Definition at line 178 of file OraDatabaseSchema.cc.

178  {
179  return m_schema.existsTable( tableName() );
180 }
coral::ISchema & m_schema
static std::string tableName()
bool ora::OraSequenceTable::getLastId ( const std::string &  sequenceName,
int &  lastId 
)
virtual

Implements ora::ISequenceTable.

Definition at line 135 of file OraDatabaseSchema.cc.

References o2o::query.

136  {
137  std::auto_ptr< coral::IQuery > query( m_schema.tableHandle( tableName() ).newQuery() );
138  query->limitReturnedRows( 1, 0 );
139  query->addToOutputList( sequenceValueColumn() );
140  query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() );
141  query->setForUpdate();
142  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
143  coral::AttributeList rowData;
144  rowData.extend<std::string>(sequenceNameColumn());
145  rowData.begin()->data< std::string >() = sequenceName;
146  query->setCondition( whereClause, rowData );
147  coral::ICursor& cursor = query->execute();
148  if ( cursor.next() ) {
149  lastId = cursor.currentRow().begin()->data<int >();
150  return true;
151  }
152  return false;
153 }
coral::ISchema & m_schema
static std::string sequenceNameColumn()
static std::string tableName()
static std::string sequenceValueColumn()
tuple query
Definition: o2o.py:269
std::string ora::OraSequenceTable::sequenceNameColumn ( )
static

Definition at line 103 of file OraDatabaseSchema.cc.

103  {
104  static std::string s_column("NAME");
105  return s_column;
106 }
std::string ora::OraSequenceTable::sequenceValueColumn ( )
static

Definition at line 108 of file OraDatabaseSchema.cc.

108  {
109  static std::string s_column("VALUE");
110  return s_column;
111 }
void ora::OraSequenceTable::sinchronize ( const std::string &  sequenceName,
int  lastValue 
)
virtual

Implements ora::ISequenceTable.

Definition at line 155 of file OraDatabaseSchema.cc.

156  {
157  coral::AttributeList updateData;
158  updateData.extend<std::string>(sequenceNameColumn());
159  updateData.extend<int>(sequenceValueColumn());
160  std::string setClause( sequenceValueColumn() + " = :" + sequenceValueColumn() );
161  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
162  // Increment the oid in the database as well
163  coral::AttributeList::iterator iAttribute = updateData.begin();
164  iAttribute->data< std::string >() = sequenceName;
165  ++iAttribute;
166  iAttribute->data< int >() = lastValue;
167  m_schema.tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData );
168 }
coral::ISchema & m_schema
static std::string sequenceNameColumn()
static std::string tableName()
static std::string sequenceValueColumn()
std::string ora::OraSequenceTable::tableName ( )
static

Definition at line 98 of file OraDatabaseSchema.cc.

98  {
99  static std::string s_name("ORA_SEQUENCE");
100  return s_name;
101 }

Member Data Documentation

coral::ISchema& ora::OraSequenceTable::m_schema
private

Definition at line 47 of file OraDatabaseSchema.h.