CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes | Private Attributes
cond::persistency::SessionImpl Class Reference

#include <SessionImpl.h>

Public Types

enum  FailureOnOpeningPolicy { THROW, DO_NOT_THROW, CREATE }
 

Public Member Functions

void close ()
 
void commitTransaction ()
 
IGTSchemagtSchema ()
 
IIOVSchemaiovSchema ()
 
bool isActive () const
 
bool isTransactionActive (bool deep=true) const
 
void openDb ()
 
void openGTDb (FailureOnOpeningPolicy policy=THROW)
 
void openIovDb (FailureOnOpeningPolicy policy=THROW)
 
void openRunInfoDb ()
 
void rollbackTransaction ()
 
IRunInfoSchemarunInfoSchema ()
 
 SessionImpl ()
 
 SessionImpl (std::shared_ptr< coral::ISessionProxy > &session, const std::string &connectionString)
 
void startTransaction (bool readOnly=true)
 
 ~SessionImpl ()
 

Public Attributes

std::string connectionString
 
std::shared_ptr< coral::ISessionProxy > coralSession
 
std::unique_ptr< IGTSchemagtSchemaHandle
 
std::unique_ptr< IIOVSchemaiovSchemaHandle
 
std::unique_ptr< IRunInfoSchemarunInfoSchemaHandle
 
std::unique_ptr< ITransactiontransaction
 

Private Attributes

std::unique_lock< std::recursive_mutex > transactionLock
 
std::recursive_mutex transactionMutex
 

Detailed Description

Definition at line 40 of file SessionImpl.h.

Member Enumeration Documentation

◆ FailureOnOpeningPolicy

Enumerator
THROW 
DO_NOT_THROW 
CREATE 

Definition at line 42 of file SessionImpl.h.

Constructor & Destructor Documentation

◆ SessionImpl() [1/2]

cond::persistency::SessionImpl::SessionImpl ( )

Definition at line 31 of file SessionImpl.cc.

31 : coralSession() {}

◆ SessionImpl() [2/2]

cond::persistency::SessionImpl::SessionImpl ( std::shared_ptr< coral::ISessionProxy > &  session,
const std::string &  connectionString 
)

Definition at line 33 of file SessionImpl.cc.

34  : coralSession(session), connectionString(connectionStr) {}

◆ ~SessionImpl()

cond::persistency::SessionImpl::~SessionImpl ( )

Definition at line 36 of file SessionImpl.cc.

36 { close(); }

References close().

Member Function Documentation

◆ close()

void cond::persistency::SessionImpl::close ( void  )

Definition at line 38 of file SessionImpl.cc.

38  {
39  if (coralSession.get()) {
40  if (coralSession->transaction().isActive()) {
41  coralSession->transaction().rollback();
42  }
43  coralSession.reset();
44  }
45  transaction.reset();
46  }

References coralSession, and transaction.

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), and ~SessionImpl().

◆ commitTransaction()

void cond::persistency::SessionImpl::commitTransaction ( )

Definition at line 66 of file SessionImpl.cc.

66  {
67  std::unique_lock<std::recursive_mutex> lock;
68  lock.swap(transactionLock);
69  if (transaction) {
70  transaction->clients--;
71  if (!transaction->clients) {
72  transaction->commit();
73  transaction.reset();
74  iovSchemaHandle.reset();
75  gtSchemaHandle.reset();
76  runInfoSchemaHandle.reset();
77  }
78  }
79  }

References gtSchemaHandle, iovSchemaHandle, CommonMethods::lock(), runInfoSchemaHandle, transaction, and transactionLock.

Referenced by cond::persistency::Transaction::commit().

◆ gtSchema()

IGTSchema & cond::persistency::SessionImpl::gtSchema ( )

Definition at line 172 of file SessionImpl.cc.

172 { return *gtSchemaHandle; }

References gtSchemaHandle.

◆ iovSchema()

IIOVSchema & cond::persistency::SessionImpl::iovSchema ( )

Definition at line 170 of file SessionImpl.cc.

170 { return *iovSchemaHandle; }

References iovSchemaHandle.

◆ isActive()

bool cond::persistency::SessionImpl::isActive ( ) const

Definition at line 48 of file SessionImpl.cc.

48 { return coralSession.get(); }

References coralSession.

◆ isTransactionActive()

bool cond::persistency::SessionImpl::isTransactionActive ( bool  deep = true) const

Definition at line 93 of file SessionImpl.cc.

93  {
94  if (!transaction)
95  return false;
96  if (!deep)
97  return true;
98  return transaction->isActive();
99  }

References transaction.

Referenced by cond::persistency::Transaction::isActive().

◆ openDb()

void cond::persistency::SessionImpl::openDb ( )

Definition at line 149 of file SessionImpl.cc.

149  {
150  if (!transaction.get())
151  throwException("The transaction is not active.", "SessionImpl::openIovDb");
152  if (!transaction->iovDbOpen) {
153  transaction->iovDbExists = iovSchemaHandle->exists();
154  transaction->iovDbOpen = true;
155  }
156  if (!transaction->gtDbOpen) {
157  transaction->gtDbExists = gtSchemaHandle->exists();
158  transaction->gtDbOpen = true;
159  }
160  if (!transaction->iovDbExists) {
161  iovSchemaHandle->create();
162  transaction->iovDbExists = true;
163  if (!transaction->gtDbExists) {
164  gtSchemaHandle->create();
165  transaction->gtDbExists = true;
166  }
167  }
168  }

References gtSchemaHandle, iovSchemaHandle, cond::persistency::throwException(), and transaction.

◆ openGTDb()

void cond::persistency::SessionImpl::openGTDb ( SessionImpl::FailureOnOpeningPolicy  policy = THROW)

Definition at line 119 of file SessionImpl.cc.

119  {
120  if (!transaction.get())
121  throwException("The transaction is not active.", "SessionImpl::openGTDb");
122  if (!transaction->gtDbOpen) {
123  transaction->gtDbExists = gtSchemaHandle->exists();
124  transaction->gtDbOpen = true;
125  }
126  if (!transaction->gtDbExists) {
127  if (policy == CREATE) {
128  gtSchemaHandle->create();
129  transaction->gtDbExists = true;
130  } else {
131  if (policy == THROW)
132  throwException("GT Database does not exist.", "SessionImpl::openGTDb");
133  }
134  }
135  }

References CREATE, gtSchemaHandle, THROW, cond::persistency::throwException(), and transaction.

◆ openIovDb()

void cond::persistency::SessionImpl::openIovDb ( SessionImpl::FailureOnOpeningPolicy  policy = THROW)

Definition at line 101 of file SessionImpl.cc.

101  {
102  if (!transaction.get())
103  throwException("The transaction is not active.", "SessionImpl::openIovDb");
104  if (!transaction->iovDbOpen) {
105  transaction->iovDbExists = iovSchemaHandle->exists();
106  transaction->iovDbOpen = true;
107  }
108  if (!transaction->iovDbExists) {
109  if (policy == CREATE) {
110  iovSchemaHandle->create();
111  transaction->iovDbExists = true;
112  } else {
113  if (policy == THROW)
114  throwException("IOV Database does not exist.", "SessionImpl::openIovDb");
115  }
116  }
117  }

References CREATE, iovSchemaHandle, THROW, cond::persistency::throwException(), and transaction.

◆ openRunInfoDb()

void cond::persistency::SessionImpl::openRunInfoDb ( )

Definition at line 137 of file SessionImpl.cc.

137  {
138  if (!transaction.get())
139  throwException("The transaction is not active.", "SessionImpl::openRunInfoDb");
140  if (!transaction->runInfoDbOpen) {
141  transaction->runInfoDbExists = runInfoSchemaHandle->exists();
142  transaction->runInfoDbOpen = true;
143  }
144  if (!transaction->runInfoDbExists) {
145  throwException("RunInfo Database does not exist.", "SessionImpl::openRunInfoDb");
146  }
147  }

References runInfoSchemaHandle, cond::persistency::throwException(), and transaction.

◆ rollbackTransaction()

void cond::persistency::SessionImpl::rollbackTransaction ( )

Definition at line 81 of file SessionImpl.cc.

81  {
82  std::unique_lock<std::recursive_mutex> lock;
83  lock.swap(transactionLock);
84  if (transaction) {
85  transaction->rollback();
86  transaction.reset();
87  iovSchemaHandle.reset();
88  gtSchemaHandle.reset();
89  runInfoSchemaHandle.reset();
90  }
91  }

References gtSchemaHandle, iovSchemaHandle, CommonMethods::lock(), runInfoSchemaHandle, transaction, and transactionLock.

Referenced by cond::persistency::Transaction::rollback().

◆ runInfoSchema()

IRunInfoSchema & cond::persistency::SessionImpl::runInfoSchema ( )

Definition at line 174 of file SessionImpl.cc.

174 { return *runInfoSchemaHandle; }

References runInfoSchemaHandle.

◆ startTransaction()

void cond::persistency::SessionImpl::startTransaction ( bool  readOnly = true)

Definition at line 50 of file SessionImpl.cc.

50  {
51  std::unique_lock<std::recursive_mutex> lock(transactionMutex);
52  if (!transaction.get()) {
53  coralSession->transaction().start(readOnly);
54  iovSchemaHandle = std::make_unique<IOVSchema>(coralSession->nominalSchema());
55  gtSchemaHandle = std::make_unique<GTSchema>(coralSession->nominalSchema());
56  runInfoSchemaHandle = std::make_unique<RunInfoSchema>(coralSession->nominalSchema());
57  transaction = std::make_unique<CondDBTransaction>(coralSession);
58  } else {
59  if (!readOnly)
60  throwException("An update transaction is already active.", "SessionImpl::startTransaction");
61  }
62  transaction->clients++;
63  transactionLock.swap(lock);
64  }

References coralSession, gtSchemaHandle, iovSchemaHandle, CommonMethods::lock(), runInfoSchemaHandle, cond::persistency::throwException(), transaction, transactionLock, and transactionMutex.

Referenced by cond::persistency::Transaction::start().

Member Data Documentation

◆ connectionString

std::string cond::persistency::SessionImpl::connectionString

Definition at line 69 of file SessionImpl.h.

◆ coralSession

std::shared_ptr<coral::ISessionProxy> cond::persistency::SessionImpl::coralSession

Definition at line 67 of file SessionImpl.h.

Referenced by close(), isActive(), and startTransaction().

◆ gtSchemaHandle

std::unique_ptr<IGTSchema> cond::persistency::SessionImpl::gtSchemaHandle

◆ iovSchemaHandle

std::unique_ptr<IIOVSchema> cond::persistency::SessionImpl::iovSchemaHandle

◆ runInfoSchemaHandle

std::unique_ptr<IRunInfoSchema> cond::persistency::SessionImpl::runInfoSchemaHandle

◆ transaction

std::unique_ptr<ITransaction> cond::persistency::SessionImpl::transaction

◆ transactionLock

std::unique_lock<std::recursive_mutex> cond::persistency::SessionImpl::transactionLock
private

Definition at line 77 of file SessionImpl.h.

Referenced by commitTransaction(), rollbackTransaction(), and startTransaction().

◆ transactionMutex

std::recursive_mutex cond::persistency::SessionImpl::transactionMutex
private

Definition at line 76 of file SessionImpl.h.

Referenced by startTransaction().

cond::persistency::SessionImpl::connectionString
std::string connectionString
Definition: SessionImpl.h:69
cond::persistency::SessionImpl::transactionLock
std::unique_lock< std::recursive_mutex > transactionLock
Definition: SessionImpl.h:77
cond::persistency::SessionImpl::close
void close()
Definition: SessionImpl.cc:38
cond::persistency::SessionImpl::DO_NOT_THROW
Definition: SessionImpl.h:42
CommonMethods.lock
def lock()
Definition: CommonMethods.py:82
cond::persistency::SessionImpl::iovSchemaHandle
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:71
cond::persistency::SessionImpl::runInfoSchemaHandle
std::unique_ptr< IRunInfoSchema > runInfoSchemaHandle
Definition: SessionImpl.h:73
cond::persistency::SessionImpl::transactionMutex
std::recursive_mutex transactionMutex
Definition: SessionImpl.h:76
cond::persistency::SessionImpl::coralSession
std::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:67
cond::persistency::SessionImpl::gtSchemaHandle
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:72
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::persistency::SessionImpl::CREATE
Definition: SessionImpl.h:42
cond::persistency::SessionImpl::THROW
Definition: SessionImpl.h:42
cond::persistency::SessionImpl::FailureOnOpeningPolicy
FailureOnOpeningPolicy
Definition: SessionImpl.h:42
cond::persistency::SessionImpl::transaction
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:70