TDbiCascader.hxx
Go to the documentation of this file.00001
00002 #ifndef DBICASCADER_H
00003 #define DBICASCADER_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <map>
00030 #include <ostream>
00031 using std::ostream;
00032 #include <string>
00033 using std::string;
00034 #include <vector>
00035 using std::vector;
00036
00037 #if !defined(__CINT__) || defined(__MAKECINT__)
00038 #include "Rtypes.h"
00039 #endif
00040
00041 #include "TDbiConnection.hxx"
00042 #include "TDbiStatement.hxx"
00043 class TDbiCascader;
00044 ostream& operator<<(ostream& os, const TDbiCascader& cascader) ;
00045 class TSQL_Statement;
00046
00047
00048 class TDbiCascader
00049 {
00050
00051 friend class TDbiDatabaseManager;
00052 friend ostream& operator<<(ostream& s, const TDbiCascader& cascader);
00053
00054 public:
00055
00056
00057
00058
00059 static bool canConnect();
00060 friend class TDbiValidate;
00061
00062 enum Status { kFailed, kClosed, kOpen };
00063
00064
00065
00066
00067
00068
00069 TDbiStatement* CreateStatement(UInt_t dbNo) const;
00070
00071
00072 const TDbiConnection*
00073 GetConnection(UInt_t dbNo) const;
00074 TDbiConnection*
00075 GetConnection(UInt_t dbNo) ;
00076
00077 string GetDbName(UInt_t dbNo) const;
00078 Int_t GetDbNo(const string& dbName) const;
00079 Int_t GetStatus(UInt_t dbNo) const {
00080 if ( dbNo >= GetNumDb() || ! fConnections[dbNo] ) return kFailed;
00081 return fConnections[dbNo]->IsClosed() ? kClosed : kOpen; }
00082 string GetStatusAsString(UInt_t dbNo) const ;
00083 string GetURL(UInt_t dbNo) const {
00084 return ( dbNo < GetNumDb() ) ? fConnections[dbNo]-> GetUrl(): ""; }
00085 Bool_t IsTemporaryTable(const string& tableName,
00086 Int_t dbNo) const;
00087
00088
00089 Int_t AllocateSeqNo(const string& tableName,
00090 Int_t requireGlobal = 0,
00091 Int_t dbNo = 0) const;
00092 Int_t GetAuthorisingDbNo() const { return fGlobalSeqNoDbNo; }
00093 UInt_t GetNumDb() const {return fConnections.size();}
00094 Int_t GetTableDbNo(const string& tableName, Int_t selectDbNo = -1) const;
00095 Bool_t TableExists(const string& tableName, Int_t selectDbNo = -1) const {
00096 return this->GetTableDbNo(tableName,selectDbNo) >= 0; }
00097
00098
00099
00100 Int_t CreateTemporaryTable(const string& tableName,
00101 const string& tableDescr);
00102 void HoldConnections();
00103 void ReleaseConnections();
00104 void SetPermanent(UInt_t dbNo, Bool_t permanent = true);
00105
00106 protected:
00107
00108 private:
00109
00110 Int_t ReserveNextSeqNo(const string& tableName,
00111 Bool_t isGlobal,
00112 UInt_t dbNo) const;
00113 void SetAuthorisingEntry(Int_t entry) {fGlobalSeqNoDbNo = entry;}
00114
00115
00116 TDbiCascader(bool beQuiet=false);
00117 virtual ~TDbiCascader();
00118 TDbiCascader(const TDbiCascader&);
00119
00120
00121
00122
00123 Int_t fGlobalSeqNoDbNo;
00124
00125
00126 vector<TDbiConnection*> fConnections;
00127
00128
00129 std::map<string,Int_t> fTemporaryTables;
00130
00131
00132
00133 class Lock {
00134
00135 public:
00136 Lock(TDbiStatement* stmtDB, const string& seqnoTable, const string& dataTable);
00137 ~Lock();
00138
00139 Bool_t IsLocked() const { return fLocked; }
00140
00141 private:
00142
00143 void SetLock(Bool_t setting = kTRUE);
00144
00145 TDbiStatement* fStmt;
00146 string fSeqnoTableName;
00147 string fDataTableName;
00148 Bool_t fLocked;
00149
00150 };
00151
00152 ClassDef(TDbiCascader,0)
00153
00154 };
00155
00156
00157 #endif // DBISKEL_H
00158