test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SessionImpl.cc
Go to the documentation of this file.
2 #include "SessionImpl.h"
3 #include "DbConnectionString.h"
4 //
5 //
6 #include "RelationalAccess/ISessionProxy.h"
7 #include "RelationalAccess/ITransaction.h"
8 
9 namespace cond {
10 
11  namespace persistency {
12 
14  public:
15  CondDBTransaction( const boost::shared_ptr<coral::ISessionProxy>& coralSession ):
16  m_session( coralSession ){
17  }
18  virtual ~CondDBTransaction(){}
19 
20  void commit(){
21  m_session->transaction().commit();
22  }
23 
24  void rollback(){
25  m_session->transaction().rollback();
26  }
27 
28  bool isActive(){
29  return m_session->transaction().isActive();
30  }
31  private:
32  boost::shared_ptr<coral::ISessionProxy> m_session;
33  };
34 
36  coralSession(){
37  }
38 
39  SessionImpl::SessionImpl( boost::shared_ptr<coral::ISessionProxy>& session,
40  const std::string& connectionStr ):
41  coralSession( session ),
42  connectionString( connectionStr ){
43  }
44 
46  close();
47  }
48 
50  if( coralSession.get() ){
51  if( coralSession->transaction().isActive() ){
52  coralSession->transaction().rollback();
53  }
54  coralSession.reset();
55  }
56  transaction.reset();
57  }
58 
59  bool SessionImpl::isActive() const {
60  return coralSession.get();
61  }
62 
63  void SessionImpl::startTransaction( bool readOnly ){
64  if( !transaction.get() ){
65  coralSession->transaction().start( readOnly );
66  iovSchemaHandle.reset( new IOVSchema( coralSession->nominalSchema() ) );
67  gtSchemaHandle.reset( new GTSchema( coralSession->nominalSchema() ) );
69  } else {
70  if(!readOnly ) throwException( "An update transaction is already active.",
71  "SessionImpl::startTransaction" );
72  }
73  transaction->clients++;
74  }
75 
77  if( transaction ) {
78  transaction->clients--;
79  if( !transaction->clients ){
80  transaction->commit();
81  transaction.reset();
82  iovSchemaHandle.reset();
83  gtSchemaHandle.reset();
84  }
85  }
86  }
87 
89  if( transaction ) {
90  transaction->rollback();
91  transaction.reset();
92  iovSchemaHandle.reset();
93  gtSchemaHandle.reset();
94  }
95  }
96 
97  bool SessionImpl::isTransactionActive( bool deep ) const {
98  if( !transaction ) return false;
99  if( !deep ) return true;
100  return transaction->isActive();
101  }
102 
104  if(!transaction.get()) throwException( "The transaction is not active.","SessionImpl::openIovDb" );
105  if( !transaction->iovDbOpen ){
106  transaction->iovDbExists = iovSchemaHandle->exists();
107  transaction->iovDbOpen = true;
108  }
109  if( !transaction->iovDbExists ){
110  if( policy==CREATE ){
111  iovSchemaHandle->create();
112  transaction->iovDbExists = true;
113  } else {
114  if( policy==THROW) throwException( "IOV Database does not exist.","SessionImpl::openIovDb");
115  }
116  }
117  }
118 
120  if(!transaction.get()) throwException( "The transaction is not active.","SessionImpl::open" );
121  if( !transaction->gtDbOpen ){
122  transaction->gtDbExists = gtSchemaHandle->exists();
123  transaction->gtDbOpen = true;
124  }
125  if( !transaction->gtDbExists ){
126  if( policy==CREATE ){
127  gtSchemaHandle->create();
128  transaction->gtDbExists = true;
129  } else {
130  if( policy==THROW) throwException( "GT Database does not exist.","SessionImpl::openGTDb");
131  }
132  }
133  }
134 
136  if(!transaction.get()) throwException( "The transaction is not active.","SessionImpl::openIovDb" );
137  if( !transaction->iovDbOpen ){
138  transaction->iovDbExists = iovSchemaHandle->exists();
139  transaction->iovDbOpen = true;
140  }
141  if( !transaction->gtDbOpen ){
142  transaction->gtDbExists = gtSchemaHandle->exists();
143  transaction->gtDbOpen = true;
144  }
145  if( !transaction->iovDbExists ){
146  iovSchemaHandle->create();
147  transaction->iovDbExists = true;
148  if( !transaction->gtDbExists ){
149  gtSchemaHandle->create();
150  transaction->gtDbExists = true;
151  }
152  }
153  }
154 
156  return *iovSchemaHandle;
157  }
158 
160  return *gtSchemaHandle;
161  }
162 
164  if(!transaction.get()) throwException( "The transaction is not active.","SessionImpl::open" );
165  return transaction->isOra;
166  }
167 
168  }
169 }
void openGTDb(FailureOnOpeningPolicy policy=THROW)
Definition: SessionImpl.cc:119
void openIovDb(FailureOnOpeningPolicy policy=THROW)
Definition: SessionImpl.cc:103
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:69
CondDBTransaction(const boost::shared_ptr< coral::ISessionProxy > &coralSession)
Definition: SessionImpl.cc:15
boost::shared_ptr< coral::ISessionProxy > m_session
Definition: SessionImpl.cc:32
boost::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:65
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:70
void startTransaction(bool readOnly=true)
Definition: SessionImpl.cc:63
string connectionString
Definition: autoCondHLT.py:4
bool isTransactionActive(bool deep=true) const
Definition: SessionImpl.cc:97
session
Definition: models.py:201
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:68
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14