SessionMgr.h 3.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

#ifndef TrigConf_SessionMgr
#define TrigConf_SessionMgr

#include <string>
#include <iostream>
#include <stdexcept>
#include <memory>
#include "RelationalAccess/IRelationalService.h"
#include "RelationalAccess/IRelationalDomain.h"
14
#include "TrigConfBase/TrigConfMessaging.h"
15

16
17
18
19
namespace coral {
   class ISessionProxy;
}

20

21
namespace TrigConf {
22
23

   class ReplicaSorter;
24
  
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
   /**@brief Manager of the database session
    * 
    * it uses CORAL to connect to the different DB technologies
    */
   class SessionMgr : public TrigConfMessaging
   {
   public:

      /**@brief constructor */
      SessionMgr();

      /**@brief destructor*/
      ~SessionMgr();

      /**@brief close open sessions*/
      void closeSession();
41
    
42
43
44
45
46
47
48
49
50
      /**@brief instantiates the session*/
      coral::ISessionProxy& createSession();

      /**@brief SQL -> C++ type conversion mapping for Oracle database to match MySQL*/
      void setTypeConversionRules();

      // setters
      void setConnectionString(const std::string & connStr) { m_connectionString = connStr; }
      void setUseFrontier(bool useFrontier) { m_useFrontier = useFrontier; }
51
      void setUseSQLite(bool useSQLite) { m_useSQLite = useSQLite; }
52
53
54
55
56
57
58
59
60
61
62
63
64
      void setRetrialPeriod(int retrialPeriod) { m_retrialPeriod = retrialPeriod; }
      void setRetrialTimeout(int retrialTimeout) { m_retrialTimeout = retrialTimeout; }
      void setConnectionTimeout(int connectionTimeout) { m_connectionTimeout = connectionTimeout; }

      void setDbType(const std::string & s);
      void setDbServer(const std::string & s);
      void setDbName(const std::string & s);
      void setDbUser(const std::string & s);
      void setDbPassword(const std::string & s);

      // accessors
      const std::string& connection() const { return m_connectionString; }
      bool useFrontier() const { return m_useFrontier; }
65
      bool useSQLite() const { return m_useSQLite; }
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
      int retrialPeriod() const { return m_retrialPeriod; }
      int retrialTimeout() const { return m_retrialTimeout; }
      int connectionTimeout() const { return m_connectionTimeout; }
      const std::string & dbType() const { return m_dbtype; }
      const std::string & dbServer() const { return m_dbserver; }
      const std::string & dbName() const { return m_dbname; }
      const std::string & dbUser() const { return m_user; }
      const std::string & dbPassword() const { return m_password; }

   private:

      void buildConnectionString();

      /**@brief SQL -> C++ type conversion interface to CORAL*/
      void setCppTypeForSqlType(const std::string& cpp_type, 
                                const std::string& sql_type);

      coral::ISessionProxy * m_sessionproxy { nullptr };     ///< the coral database session

      std::string            m_connectionString { "" };   ///< connection string
      std::string            m_dbtype { "" };      ///< db type
      std::string            m_dbserver { "" };    ///< db server
      std::string            m_dbname { "" };      ///< db name
      std::string            m_user { "" };        ///< user name
      std::string            m_password { "" };    ///< password
      bool                   m_useFrontier { false }; ///< uses frontier instead of oracle
92
      bool                   m_useSQLite { true }; ///< resolve sqlite in the replicaSorter
93
94
95
      int                    m_retrialPeriod {0};
      int                    m_retrialTimeout {0};
      int                    m_connectionTimeout {0};
96
97
98

      ReplicaSorter *        m_replicaSorter { nullptr }; // private replica sorter in case of standalone usage of SessionMgr

99
   };
100
101
102
}

#endif