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

#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
 

Detailed Description

Definition at line 21 of file SchemaUtils.h.

Constructor & Destructor Documentation

ora::Serializer::Serializer ( )

Definition at line 58 of file SchemaUtils.cc.

58  :
59  m_connServ( new coral::ConnectionService ),
60  m_session(),
61  m_lock( false ){
62 }
std::auto_ptr< coral::ISessionProxy > m_session
Definition: SchemaUtils.h:37
std::auto_ptr< coral::ConnectionService > m_connServ
Definition: SchemaUtils.h:36
ora::Serializer::~Serializer ( )
virtual

Definition at line 64 of file SchemaUtils.cc.

References fetchall_from_DQM_v2::release.

64  {
65  release();
66 }

Member Function Documentation

void ora::Serializer::lock ( const std::string &  connectionString)

Definition at line 68 of file SchemaUtils.cc.

References data, o2o::query, python.IdGenerator::schema, AlCaHLTBitMon_QueryRunRegistry::string, table, and HLT_25ns14e33_v1_cff::tableName.

68  {
69  if( !m_lock ){
70  m_connServ->configuration().setConnectionTimeOut(0);
71  m_session.reset( m_connServ->connect( connectionString, coral::Update ) );
72  m_session->transaction().start( false );
73  coral::ISchema& schema = m_session->nominalSchema();
74  if(!schema.existsTable( tableName() )){
75  coral::TableDescription descr( "OraDb" );
76  descr.setName( tableName() );
77  descr.insertColumn( "P_LOCK",
78  coral::AttributeSpecification::typeNameForType<int>() );
79  descr.setNotNullConstraint( "P_LOCK" );
80  descr.setPrimaryKey( std::vector<std::string>( 1, "P_LOCK" ) );
81  coral::ITable& table = schema.createTable( descr );
82  table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
83  }
84  coral::ITable& table = schema.tableHandle( tableName() );
85  std::string condition("P_LOCK = 1");
86  std::auto_ptr<coral::IQuery> query( table.newQuery() );
87  query->addToOutputList( "P_LOCK" );
88  query->defineOutputType( "P_LOCK", coral::AttributeSpecification::typeNameForType<int>());
89  query->setCondition( condition, coral::AttributeList() );
90  query->setForUpdate();
91  coral::ICursor& cursor = query->execute();
92  coral::AttributeList data;
93  data.extend<int>( "P_LOCK" );
94  data["P_LOCK"].data<int>() = 1;
95  if( cursor.next() ){
96  // row found. will be locked by the DB if some other session owns the transaction...
97  std::string setCLause = "P_LOCK = :P_LOCK";
98  table.dataEditor().updateRows( setCLause, condition , data );
99  } else {
100  // no row found... no lock!
101  table.dataEditor().insertRow( data );
102  }
103  m_lock = true;
104  }
105 }
std::auto_ptr< coral::ISessionProxy > m_session
Definition: SchemaUtils.h:37
std::auto_ptr< coral::ConnectionService > m_connServ
Definition: SchemaUtils.h:36
static const std::string & tableName()
Definition: SchemaUtils.cc:53
#define table(NAME)
Definition: DbCore.h:49
string connectionString
Definition: autoCondHLT.py:4
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple query
Definition: o2o.py:269
void ora::Serializer::release ( )

Definition at line 108 of file SchemaUtils.cc.

Referenced by cuy.ValElement::__init__().

108  {
109  if( m_lock ){
110  m_lock = false;
111  m_session->transaction().commit();
112  }
113 }
std::auto_ptr< coral::ISessionProxy > m_session
Definition: SchemaUtils.h:37
const std::string & ora::Serializer::tableName ( )
static

Definition at line 53 of file SchemaUtils.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

53  {
54  static const std::string s_tableName("ORA_LOCK");
55  return s_tableName;
56 }

Member Data Documentation

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.