#include <SchemaUtils.h>
Public Member Functions | |
void | lock (const std::string &connectionString) |
void | release () |
Serializer () | |
virtual | ~Serializer () |
Static Public Member Functions | |
static const std::string & | tableName () |
Private Attributes | |
std::auto_ptr < coral::ConnectionService > | m_connServ |
bool | m_lock |
std::auto_ptr < coral::ISessionProxy > | m_session |
Definition at line 21 of file SchemaUtils.h.
ora::Serializer::Serializer | ( | ) |
Definition at line 58 of file SchemaUtils.cc.
: m_connServ( new coral::ConnectionService ), m_session(), m_lock( false ){ }
ora::Serializer::~Serializer | ( | ) | [virtual] |
Definition at line 64 of file SchemaUtils.cc.
References fetchall_from_DQM_v2::release.
{ release(); }
void ora::Serializer::lock | ( | const std::string & | connectionString | ) |
Definition at line 68 of file SchemaUtils.cc.
References AlCaHLTBitMon_QueryRunRegistry::data, o2o::query, python::IdGenerator::schema, and asciidump::table.
{ if( !m_lock ){ m_connServ->configuration().setConnectionTimeOut(0); m_session.reset( m_connServ->connect( connectionString, coral::Update ) ); m_session->transaction().start( false ); coral::ISchema& schema = m_session->nominalSchema(); if(!schema.existsTable( tableName() )){ coral::TableDescription descr( "OraDb" ); descr.setName( tableName() ); descr.insertColumn( "P_LOCK", coral::AttributeSpecification::typeNameForType<int>() ); descr.setNotNullConstraint( "P_LOCK" ); descr.setPrimaryKey( std::vector<std::string>( 1, "P_LOCK" ) ); coral::ITable& table = schema.createTable( descr ); table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select ); } coral::ITable& table = schema.tableHandle( tableName() ); std::string condition("P_LOCK = 1"); std::auto_ptr<coral::IQuery> query( table.newQuery() ); query->addToOutputList( "P_LOCK" ); query->defineOutputType( "P_LOCK", coral::AttributeSpecification::typeNameForType<int>()); query->setCondition( condition, coral::AttributeList() ); query->setForUpdate(); coral::ICursor& cursor = query->execute(); coral::AttributeList data; data.extend<int>( "P_LOCK" ); data["P_LOCK"].data<int>() = 1; if( cursor.next() ){ // row found. will be locked by the DB if some other session owns the transaction... std::string setCLause = "P_LOCK = :P_LOCK"; table.dataEditor().updateRows( setCLause, condition , data ); } else { // no row found... no lock! table.dataEditor().insertRow( data ); } m_lock = true; } }
void ora::Serializer::release | ( | ) |
Definition at line 108 of file SchemaUtils.cc.
const std::string & ora::Serializer::tableName | ( | ) | [static] |
Definition at line 53 of file SchemaUtils.cc.
{ static const std::string s_tableName("ORA_LOCK"); return s_tableName; }
std::auto_ptr<coral::ConnectionService> ora::Serializer::m_connServ [private] |
Definition at line 36 of file SchemaUtils.h.
bool ora::Serializer::m_lock [private] |
Definition at line 38 of file SchemaUtils.h.
std::auto_ptr<coral::ISessionProxy> ora::Serializer::m_session [private] |
Definition at line 37 of file SchemaUtils.h.