CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions

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)
std::string name ()
 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 ()

Detailed Description

Definition at line 30 of file OraDatabaseSchema.h.


Constructor & Destructor Documentation

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

Definition at line 130 of file OraDatabaseSchema.cc.

ora::OraSequenceTable::~OraSequenceTable ( ) [virtual]

Definition at line 134 of file OraDatabaseSchema.cc.

                                      {
}

Member Function Documentation

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

Implements ora::ISequenceTable.

Definition at line 138 of file OraDatabaseSchema.cc.

References python::IdGenerator::schema.

                                                       {
  // 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 >() = -1;
  schema().tableHandle( tableName() ).dataEditor().insertRow( insertData );
  return true;
}
void ora::OraSequenceTable::create ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 203 of file OraDatabaseSchema.cc.

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

                                {
  if( 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() ) );
  schema().createTable( description );
  //.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
}
void ora::OraSequenceTable::drop ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 223 of file OraDatabaseSchema.cc.

References python::IdGenerator::schema.

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

Implements ora::ISequenceTable.

Definition at line 187 of file OraDatabaseSchema.cc.

References python::IdGenerator::schema.

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

Implements ora::IDatabaseTable.

Definition at line 199 of file OraDatabaseSchema.cc.

References python::IdGenerator::schema.

                                {
  return schema().existsTable( tableName() );
}
bool ora::OraSequenceTable::getLastId ( const std::string &  sequenceName,
int &  lastId 
) [virtual]

Implements ora::ISequenceTable.

Definition at line 152 of file OraDatabaseSchema.cc.

References o2o::query, and python::IdGenerator::schema.

                                                {
  std::auto_ptr< coral::IQuery > query( 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::name ( ) [virtual]

Implements ora::IDatabaseTable.

Definition at line 195 of file OraDatabaseSchema.cc.

                                   {
  return tableName();
}
std::string ora::OraSequenceTable::sequenceNameColumn ( ) [static]

Definition at line 120 of file OraDatabaseSchema.cc.

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

Definition at line 125 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 172 of file OraDatabaseSchema.cc.

References python::IdGenerator::schema.

                                                        {
  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;
  schema().tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData );
}
std::string ora::OraSequenceTable::tableName ( ) [static]

Definition at line 115 of file OraDatabaseSchema.cc.

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