EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDbMultConnector.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDbMultConnector.h
1 #ifndef FAIRDBMULTCONNECTOR_H
2 #define FAIRDBMULTCONNECTOR_H
3 
4 #include <map>
5 #include <ostream>
6 using std::ostream;
7 #include <string>
8 using std::string;
9 #include <vector>
10 using std::vector;
11 
12 #if !defined(__CINT__) || defined(__MAKECINT__)
13 #include "Rtypes.h"
14 #endif
15 
16 #include "FairDbConnection.h"
17 #include "FairDbStatement.h"
18 
19 class TSQL_Statement;
20 
22 {
23  friend ostream& operator<<(ostream& s, const FairDbMultConnector& cascader);
24 
25  public:
26 
27 
29 
30  FairDbStatement* CreateStatement(UInt_t dbNo) const;
31 
33  const FairDbConnection*
34  GetConnection(UInt_t dbNo) const;
36  GetConnection(UInt_t dbNo) ;
37 
38  string GetDbName(UInt_t dbNo) const;
39  Int_t GetDbNo(const string& dbName) const;
40  Int_t GetStatus(UInt_t dbNo) const {
41  if ( dbNo >= GetNumDb() || ! fConnections[dbNo] ) { return kFailed; }
42  return fConnections[dbNo]->IsClosed() ? kClosed : kOpen;
43  }
44  string GetStatusAsString(UInt_t dbNo) const ;
45  string GetURL(UInt_t dbNo) const {
46  return ( dbNo < GetNumDb() ) ? fConnections[dbNo]-> GetUrl(): "";
47  }
48  Bool_t IsTemporaryTable(const string& tableName,
49  Int_t dbNo) const;
50 // Cascade-wide getters.
51 
52  Int_t AllocateSeqNo(const string& tableName,
53  Int_t requireGlobal = 0,
54  Int_t dbNo = 0) const;
55  Int_t GetAuthorisingDbNo() const { return fGlobalSeqNoDbNo; }
56  UInt_t GetNumDb() const {return fConnections.size();}
57  Int_t GetTableDbNo(const string& tableName, Int_t selectDbNo = -1) const;
58  Bool_t TableExists(const string& tableName, Int_t selectDbNo = -1) const {
59  return this->GetTableDbNo(tableName,selectDbNo) >= 0;
60  }
61 
62 
63  Int_t CreateTemporaryTable(const string& tableName,
64  const string& tableDescr);
65  void HoldConnections();
66  void ReleaseConnections();
67  void SetPermanent(UInt_t dbNo, Bool_t permanent = true);
68  // Constructors and destructors.
70  virtual ~FairDbMultConnector();
72 
73  void SetAuthorisingEntry(Int_t entry) {fGlobalSeqNoDbNo = entry;}
74 
75  protected:
76 
77  private:
78 
79  Int_t ReserveNextSeqNo(const string& tableName,
80  Bool_t isGlobal,
81  UInt_t dbNo) const;
82 
83 
85  vector<FairDbConnection*> fConnections;
86  std::map<string,Int_t> fTemporaryTables;
87 
88 
89 
90  class BLock
91  {
92 
93  public:
94  BLock(FairDbStatement* stmtDB, const string& seqnoTable, const string& dataTable);
95  ~BLock();
96 
97  Bool_t IsBLocked() const { return fLocked; }
98 
99  private:
100 
101  BLock(const BLock&);
102  BLock operator=(const BLock&);
103 
104  void SetBLock(Bool_t setting = kTRUE);
105 
106  FairDbStatement* fStmt; // Statement to be used to issue lock
107  string fSeqnoTableName; // The SEQNO table that is locked
108  string fDataTableName; // The data table that is locked
109  Bool_t fLocked; // Lock status
110 
111  };
112 
113 
114 
115  ClassDef(FairDbMultConnector,0) // A priority list of Db connections
116 
117 };
118 
119 #endif //