CMS 3D CMS Logo

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

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

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.

                                                           :
  m_schema( schema){
}
ora::OraSequenceTable::~OraSequenceTable ( ) [virtual]

Definition at line 117 of file OraDatabaseSchema.cc.

                                      {
}

Member Function Documentation

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

Implements ora::ISequenceTable.

Definition at line 121 of file OraDatabaseSchema.cc.

                                                       {
  // Create the entry in the table 
  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::OraSequenceTable::create ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 182 of file OraDatabaseSchema.cc.

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

                                {
  if( m_schema.existsTable( tableName() )){
    throwException( "ORA database sequence table already exists in this schema.",
                    "OraSequenceTable::create");
  }
  
  coral::TableDescription description( "OraDb" );
  description.setName( tableName() );

  description.insertColumn( sequenceNameColumn(), coral::AttributeSpecification::typeNameForType<std::string>() );
  description.setNotNullConstraint( sequenceNameColumn() );

  description.insertColumn( sequenceValueColumn(),coral::AttributeSpecification::typeNameForType<int>() );
  description.setNotNullConstraint( sequenceValueColumn() );

  description.setPrimaryKey( std::vector< std::string >( 1, sequenceNameColumn() ) );
  m_schema.createTable( description ).privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
}
void ora::OraSequenceTable::drop ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 201 of file OraDatabaseSchema.cc.

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

Implements ora::ISequenceTable.

Definition at line 170 of file OraDatabaseSchema.cc.

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

Implements ora::IDatabaseTable.

Definition at line 178 of file OraDatabaseSchema.cc.

                                {
  return m_schema.existsTable( 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.

                                                {
  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;
}
std::string ora::OraSequenceTable::sequenceNameColumn ( ) [static]

Definition at line 103 of file OraDatabaseSchema.cc.

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

Definition at line 108 of file OraDatabaseSchema.cc.

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

Implements ora::ISequenceTable.

Definition at line 155 of file OraDatabaseSchema.cc.

                                                        {
  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::OraSequenceTable::tableName ( ) [static]

Definition at line 98 of file OraDatabaseSchema.cc.

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

Member Data Documentation

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

Definition at line 47 of file OraDatabaseSchema.h.