FailureOnOpeningPolicy

ITransaction

SessionImpl

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#ifndef CondCore_CondDB_SessionImpl_h
#define CondCore_CondDB_SessionImpl_h

#include "CondCore/CondDB/interface/Types.h"
#include "IOVSchema.h"
#include "GTSchema.h"
#include "RunInfoSchema.h"
//
#include "RelationalAccess/ConnectionService.h"
#include "RelationalAccess/ISessionProxy.h"
//
#include <memory>
#include <mutex>
// temporarely

namespace coral {
  class ISessionProxy;
  class ISchema;
}  // namespace coral

namespace cond {

  namespace persistency {

    class ITransaction {
    public:
      virtual ~ITransaction() {}
      virtual void commit() = 0;
      virtual void rollback() = 0;
      virtual bool isActive() = 0;
      bool iovDbExists = false;
      bool iovDbOpen = false;
      bool gtDbExists = false;
      bool gtDbOpen = false;
      bool runInfoDbExists = false;
      bool runInfoDbOpen = false;
      size_t clients = 0;
    };

    class SessionImpl {
    public:
      typedef enum { THROW, DO_NOT_THROW, CREATE } FailureOnOpeningPolicy;

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

      ~SessionImpl();

      void close();
      bool isActive() const;
      void startTransaction(bool readOnly = true);
      void commitTransaction();
      void rollbackTransaction();
      bool isTransactionActive(bool deep = true) const;

      void openIovDb(FailureOnOpeningPolicy policy = THROW);
      void openGTDb(FailureOnOpeningPolicy policy = THROW);
      void openRunInfoDb();
      void openDb();
      IIOVSchema& iovSchema();
      IGTSchema& gtSchema();
      IRunInfoSchema& runInfoSchema();

    public:
      // allows for session shared among more services. To be changed to unique_ptr when we stop needing this feature.
      std::shared_ptr<coral::ISessionProxy> coralSession;
      std::string sessionHash;
      std::string connectionString;
      std::string principalName;
      std::set<std::string> lockedTags;
      std::unique_ptr<ITransaction> transaction;
      std::unique_ptr<IIOVSchema> iovSchemaHandle;
      std::unique_ptr<IGTSchema> gtSchemaHandle;
      std::unique_ptr<IRunInfoSchema> runInfoSchemaHandle;

    private:
      void releaseTagLocks();
      std::recursive_mutex transactionMutex;
      std::unique_lock<std::recursive_mutex> transactionLock;
    };

  }  // namespace persistency

}  // namespace cond

#endif