Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:29

0001 #ifndef CondCore_CondDB_SessionImpl_h
0002 #define CondCore_CondDB_SessionImpl_h
0003 
0004 #include "CondCore/CondDB/interface/Types.h"
0005 #include "IOVSchema.h"
0006 #include "GTSchema.h"
0007 #include "RunInfoSchema.h"
0008 //
0009 #include "RelationalAccess/ConnectionService.h"
0010 #include "RelationalAccess/ISessionProxy.h"
0011 //
0012 #include <memory>
0013 #include <mutex>
0014 // temporarely
0015 
0016 namespace coral {
0017   class ISessionProxy;
0018   class ISchema;
0019 }  // namespace coral
0020 
0021 namespace cond {
0022 
0023   namespace persistency {
0024 
0025     class ITransaction {
0026     public:
0027       virtual ~ITransaction() {}
0028       virtual void commit() = 0;
0029       virtual void rollback() = 0;
0030       virtual bool isActive() = 0;
0031       bool iovDbExists = false;
0032       bool iovDbOpen = false;
0033       bool gtDbExists = false;
0034       bool gtDbOpen = false;
0035       bool runInfoDbExists = false;
0036       bool runInfoDbOpen = false;
0037       size_t clients = 0;
0038     };
0039 
0040     class SessionImpl {
0041     public:
0042       typedef enum { THROW, DO_NOT_THROW, CREATE } FailureOnOpeningPolicy;
0043 
0044     public:
0045       SessionImpl();
0046       SessionImpl(std::shared_ptr<coral::ISessionProxy>& session,
0047                   const std::string& connectionString,
0048                   const std::string& principalName);
0049 
0050       ~SessionImpl();
0051 
0052       void close();
0053       bool isActive() const;
0054       void startTransaction(bool readOnly = true);
0055       void commitTransaction();
0056       void rollbackTransaction();
0057       bool isTransactionActive(bool deep = true) const;
0058 
0059       void openIovDb(FailureOnOpeningPolicy policy = THROW);
0060       void openGTDb(FailureOnOpeningPolicy policy = THROW);
0061       void openRunInfoDb();
0062       void openDb();
0063       IIOVSchema& iovSchema();
0064       IGTSchema& gtSchema();
0065       IRunInfoSchema& runInfoSchema();
0066 
0067     public:
0068       // allows for session shared among more services. To be changed to unique_ptr when we stop needing this feature.
0069       std::shared_ptr<coral::ISessionProxy> coralSession;
0070       std::string sessionHash;
0071       std::string connectionString;
0072       std::string principalName;
0073       std::set<std::string> lockedTags;
0074       std::unique_ptr<ITransaction> transaction;
0075       std::unique_ptr<IIOVSchema> iovSchemaHandle;
0076       std::unique_ptr<IGTSchema> gtSchemaHandle;
0077       std::unique_ptr<IRunInfoSchema> runInfoSchemaHandle;
0078 
0079     private:
0080       void releaseTagLocks();
0081       std::recursive_mutex transactionMutex;
0082       std::unique_lock<std::recursive_mutex> transactionLock;
0083     };
0084 
0085   }  // namespace persistency
0086 
0087 }  // namespace cond
0088 
0089 #endif