CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes | Private Member Functions | 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, const std::string &principalName)
 
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::set< std::string > lockedTags
 
std::string principalName
 
std::unique_ptr< IRunInfoSchemarunInfoSchemaHandle
 
std::string sessionHash
 
std::unique_ptr< ITransactiontransaction
 

Private Member Functions

void releaseTagLocks ()
 

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 33 of file SessionImpl.cc.

33 : coralSession() {}

◆ SessionImpl() [2/2]

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

◆ ~SessionImpl()

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

Definition at line 43 of file SessionImpl.cc.

43 { close(); }

References close().

Member Function Documentation

◆ close()

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

Definition at line 45 of file SessionImpl.cc.

45  {
46  if (isActive()) {
47  if (coralSession->transaction().isActive()) {
49  }
50  if (!lockedTags.empty()) {
51  startTransaction(false);
54  }
55  coralSession.reset();
56  }
57  transaction.reset();
58  }

References commitTransaction(), coralSession, isActive(), lockedTags, releaseTagLocks(), rollbackTransaction(), startTransaction(), and transaction.

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

◆ commitTransaction()

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

Definition at line 78 of file SessionImpl.cc.

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

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

Referenced by close(), and cond::persistency::Transaction::commit().

◆ gtSchema()

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

Definition at line 202 of file SessionImpl.cc.

202 { return *gtSchemaHandle; }

References gtSchemaHandle.

◆ iovSchema()

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

Definition at line 200 of file SessionImpl.cc.

200 { return *iovSchemaHandle; }

References iovSchemaHandle.

Referenced by releaseTagLocks().

◆ isActive()

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

Definition at line 60 of file SessionImpl.cc.

60 { return coralSession.get(); }

References coralSession.

Referenced by close().

◆ isTransactionActive()

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

Definition at line 105 of file SessionImpl.cc.

105  {
106  if (!transaction)
107  return false;
108  if (!deep)
109  return true;
110  return transaction->isActive();
111  }

References transaction.

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

◆ openDb()

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

Definition at line 179 of file SessionImpl.cc.

179  {
180  if (!transaction.get())
181  throwException("The transaction is not active.", "SessionImpl::openIovDb");
182  if (!transaction->iovDbOpen) {
183  transaction->iovDbExists = iovSchemaHandle->exists();
184  transaction->iovDbOpen = true;
185  }
186  if (!transaction->gtDbOpen) {
187  transaction->gtDbExists = gtSchemaHandle->exists();
188  transaction->gtDbOpen = true;
189  }
190  if (!transaction->iovDbExists) {
191  iovSchemaHandle->create();
192  transaction->iovDbExists = true;
193  if (!transaction->gtDbExists) {
194  gtSchemaHandle->create();
195  transaction->gtDbExists = true;
196  }
197  }
198  }

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

◆ openGTDb()

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

Definition at line 149 of file SessionImpl.cc.

149  {
150  if (!transaction.get())
151  throwException("The transaction is not active.", "SessionImpl::openGTDb");
152  if (!transaction->gtDbOpen) {
153  transaction->gtDbExists = gtSchemaHandle->exists();
154  transaction->gtDbOpen = true;
155  }
156  if (!transaction->gtDbExists) {
157  if (policy == CREATE) {
158  gtSchemaHandle->create();
159  transaction->gtDbExists = true;
160  } else {
161  if (policy == THROW)
162  throwException("GT Database does not exist.", "SessionImpl::openGTDb");
163  }
164  }
165  }

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

◆ openIovDb()

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

Definition at line 131 of file SessionImpl.cc.

131  {
132  if (!transaction.get())
133  throwException("The transaction is not active.", "SessionImpl::openIovDb");
134  if (!transaction->iovDbOpen) {
135  transaction->iovDbExists = iovSchemaHandle->exists();
136  transaction->iovDbOpen = true;
137  }
138  if (!transaction->iovDbExists) {
139  if (policy == CREATE) {
140  iovSchemaHandle->create();
141  transaction->iovDbExists = true;
142  } else {
143  if (policy == THROW)
144  throwException("IOV Database does not exist.", "SessionImpl::openIovDb");
145  }
146  }
147  }

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

◆ openRunInfoDb()

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

Definition at line 167 of file SessionImpl.cc.

167  {
168  if (!transaction.get())
169  throwException("The transaction is not active.", "SessionImpl::openRunInfoDb");
170  if (!transaction->runInfoDbOpen) {
171  transaction->runInfoDbExists = runInfoSchemaHandle->exists();
172  transaction->runInfoDbOpen = true;
173  }
174  if (!transaction->runInfoDbExists) {
175  throwException("RunInfo Database does not exist.", "SessionImpl::openRunInfoDb");
176  }
177  }

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

◆ releaseTagLocks()

void cond::persistency::SessionImpl::releaseTagLocks ( )
private

◆ rollbackTransaction()

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

Definition at line 93 of file SessionImpl.cc.

93  {
94  std::unique_lock<std::recursive_mutex> lock;
95  lock.swap(transactionLock);
96  if (transaction) {
97  transaction->rollback();
98  transaction.reset();
99  iovSchemaHandle.reset();
100  gtSchemaHandle.reset();
101  runInfoSchemaHandle.reset();
102  }
103  }

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

Referenced by close(), and cond::persistency::Transaction::rollback().

◆ runInfoSchema()

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

Definition at line 204 of file SessionImpl.cc.

204 { return *runInfoSchemaHandle; }

References runInfoSchemaHandle.

◆ startTransaction()

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

Definition at line 62 of file SessionImpl.cc.

62  {
63  std::unique_lock<std::recursive_mutex> lock(transactionMutex);
64  if (!transaction.get()) {
65  coralSession->transaction().start(readOnly);
66  iovSchemaHandle = std::make_unique<IOVSchema>(coralSession->nominalSchema());
67  gtSchemaHandle = std::make_unique<GTSchema>(coralSession->nominalSchema());
68  runInfoSchemaHandle = std::make_unique<RunInfoSchema>(coralSession->nominalSchema());
69  transaction = std::make_unique<CondDBTransaction>(coralSession);
70  } else {
71  if (!readOnly)
72  throwException("An update transaction is already active.", "SessionImpl::startTransaction");
73  }
74  transaction->clients++;
75  transactionLock.swap(lock);
76  }

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

Referenced by close(), and cond::persistency::Transaction::start().

Member Data Documentation

◆ connectionString

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

Definition at line 71 of file SessionImpl.h.

◆ coralSession

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

Definition at line 69 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

◆ lockedTags

std::set<std::string> cond::persistency::SessionImpl::lockedTags

Definition at line 73 of file SessionImpl.h.

Referenced by close(), and releaseTagLocks().

◆ principalName

std::string cond::persistency::SessionImpl::principalName

Definition at line 72 of file SessionImpl.h.

◆ runInfoSchemaHandle

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

◆ sessionHash

std::string cond::persistency::SessionImpl::sessionHash

Definition at line 70 of file SessionImpl.h.

Referenced by releaseTagLocks(), and SessionImpl().

◆ transaction

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

◆ transactionLock

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

Definition at line 82 of file SessionImpl.h.

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

◆ transactionMutex

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

Definition at line 81 of file SessionImpl.h.

Referenced by startTransaction().

cond::persistency::SessionImpl::isActive
bool isActive() const
Definition: SessionImpl.cc:60
cond::persistency::SessionImpl::connectionString
std::string connectionString
Definition: SessionImpl.h:71
cond::auth::COND_DBTAG_LOCK_ACCESS_CODE
static constexpr int COND_DBTAG_LOCK_ACCESS_CODE
Definition: Auth.h:45
cond::persistency::SessionImpl::releaseTagLocks
void releaseTagLocks()
Definition: SessionImpl.cc:113
cond::persistency::SessionImpl::lockedTags
std::set< std::string > lockedTags
Definition: SessionImpl.h:73
cond::persistency::SessionImpl::transactionLock
std::unique_lock< std::recursive_mutex > transactionLock
Definition: SessionImpl.h:82
cond::auth::KeyGenerator::make
std::string make(size_t keySize)
Definition: DecodingKey.cc:75
cond::persistency::IIOVSchema::tagAccessPermissionTable
virtual ITagAccessPermissionTable & tagAccessPermissionTable()=0
cond::persistency::SessionImpl::close
void close()
Definition: SessionImpl.cc:45
cond::persistency::SessionImpl::rollbackTransaction
void rollbackTransaction()
Definition: SessionImpl.cc:93
cond::persistency::SessionImpl::sessionHash
std::string sessionHash
Definition: SessionImpl.h:70
cond::persistency::ITagTable::unsetProtectionCode
virtual void unsetProtectionCode(const std::string &name, int code)=0
cond::auth::COND_SESSION_HASH_CODE
static constexpr int COND_SESSION_HASH_CODE
Definition: Auth.h:42
cond::persistency::SessionImpl::DO_NOT_THROW
Definition: SessionImpl.h:42
cond::persistency::IIOVSchema::tagTable
virtual ITagTable & tagTable()=0
cond::persistency::SessionImpl::iovSchema
IIOVSchema & iovSchema()
Definition: SessionImpl.cc:200
CommonMethods.lock
def lock()
Definition: CommonMethods.py:81
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
cond::persistency::SessionImpl::startTransaction
void startTransaction(bool readOnly=true)
Definition: SessionImpl.cc:62
writedatasetfile.action
action
Definition: writedatasetfile.py:8
cond::persistency::SessionImpl::iovSchemaHandle
std::unique_ptr< IIOVSchema > iovSchemaHandle
Definition: SessionImpl.h:75
cond::persistency::ITagLogTable::insert
virtual void insert(const std::string &tag, const boost::posix_time::ptime &eventTime, const std::string &userName, const std::string &hostName, const std::string &command, const std::string &action, const std::string &userText)=0
cond::persistency::IIOVSchema::tagLogTable
virtual ITagLogTable & tagLogTable()=0
cond::auth::KeyGenerator
Definition: DecodingKey.h:20
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::SessionImpl::runInfoSchemaHandle
std::unique_ptr< IRunInfoSchema > runInfoSchemaHandle
Definition: SessionImpl.h:77
cond::auth::COND_SESSION_HASH_SIZE
static constexpr size_t COND_SESSION_HASH_SIZE
Definition: Auth.h:40
cond::persistency::ITagAccessPermissionTable::removeEntriesForCredential
virtual void removeEntriesForCredential(const std::string &credential, int credentialType)=0
cond::persistency::SessionImpl::principalName
std::string principalName
Definition: SessionImpl.h:72
cond::persistency::SessionImpl::transactionMutex
std::recursive_mutex transactionMutex
Definition: SessionImpl.h:81
cond::persistency::SessionImpl::coralSession
std::shared_ptr< coral::ISessionProxy > coralSession
Definition: SessionImpl.h:69
cond::persistency::SessionImpl::gtSchemaHandle
std::unique_ptr< IGTSchema > gtSchemaHandle
Definition: SessionImpl.h:76
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::commitTransaction
void commitTransaction()
Definition: SessionImpl.cc:78
cond::persistency::SessionImpl::FailureOnOpeningPolicy
FailureOnOpeningPolicy
Definition: SessionImpl.h:42
cond::persistency::SessionImpl::transaction
std::unique_ptr< ITransaction > transaction
Definition: SessionImpl.h:74