EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDbConnection.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDbConnection.h
1 #ifndef FAIRDBCONNECTION
2 #define FAIRDBCONNECTION
3 
4 #include "TSQLServer.h"
5 #include "TSQLStatement.h"
6 #include "TUrl.h"
7 #include "TString.h"
8 
9 #ifndef ROOT_Rtypes
10 #if !defined(__CINT__) || defined(__MAKECINT__)
11 #include "Rtypes.h"
12 #endif
13 #endif
14 
15 #include <string>
16 #include "FairDb.h"
17 #include "FairDbExceptionLog.h"
18 
19 using namespace std;
20 
22 {
23  public:
24  FairDbConnection(const string& url = "",
25  const string& user = "",
26  const string& password = "");
27  virtual ~FairDbConnection();
28 
29 
30  // Standard connectivity functions
31  FairDb::DbTypes GetDbType() const { return fDbType; }
32  const string& GetDbName() const { return fDbName; }
33  const string& GetPassword() const { return fPassword; }
34  const string& GetUrl() const;
35  const string& GetUser() const { return fUser; }
36 
37 
38  // connection itself
39  Bool_t Close(Bool_t force = kFALSE);
40  Bool_t Open();
41  TSQLServer* GetServer();
42  TSQLStatement* CreatePreparedStatement(const string& sql);
43  Bool_t IsTemporary() const { return fIsTemporary; }
44  Bool_t TableExists(const string& tableName) const;
45  void SetTableExists(const string& tableName = "");
46  void Connect() { this->ConnectStatement();}
47  void DisConnect() { this->DisConnectStatement(); }
48  void ConnectStatement() { ++fNumConnectedStatements; }
50  --fNumConnectedStatements;
51  if ( ! fNumConnectedStatements ) { this->CloseIdleConnection(); }
52  }
53  void SetPermanent(Bool_t permanent = kTRUE) { fIsTemporary = ! permanent; }
54 
55 
56  Bool_t IsClosed() const { return ! (fServer); }
57  const FairDbExceptionLog& GetExceptionLog() const { return fExceptionLog; }
58  void ClearExceptionLog() { fExceptionLog.Clear(); }
60  Bool_t PrintExceptionLog(Int_t level = 3) const;
61  void RecordException();
62  protected:
63  string fDbName;
64  string fUser;
65  string fPassword;
68  TUrl fUrl;
69  Bool_t fUrlValidated;
70  Bool_t fIsTemporary;
72  TSQLServer* fServer;
74  void CloseIdleConnection();
75 
77  FairDbConnection operator=(const FairDbConnection&);
78 
79  ClassDef(FairDbConnection,0)
80 };
81 
82 #endif
83