00001 00002 #ifndef DBICONNECTION 00003 #define DBICONNECTION 00004 00005 00009 00031 #include <string> 00032 00033 #ifndef ROOT_Rtypes 00034 #if !defined(__CINT__) || defined(__MAKECINT__) 00035 #include "Rtypes.h" 00036 #endif 00037 #endif 00038 #include "TSQLServer.h" 00039 #include "TSQLStatement.h" 00040 #include "TUrl.h" 00041 00042 #include "DatabaseInterface/Dbi.h" 00043 #include "DatabaseInterface/DbiExceptionLog.h" 00044 #include "DatabaseInterface/DbiLog.h" 00045 00046 class DbiConnection 00047 { 00048 00049 public: 00050 00051 // Constructors and destructors. 00052 DbiConnection(const std::string& url = "", 00053 const std::string& user = "", 00054 const std::string& password = ""); 00055 virtual ~DbiConnection(); 00056 00057 // State testing member functions 00058 00059 // Standard getters. 00060 00061 const std::string& GetDbName() const { return fDbName; } 00062 Dbi::DbTypes GetDbType() const { return fDbType; } 00063 const std::string& GetPassword() const { return fPassword; } 00064 const std::string& GetUrl() const; 00065 const std::string& GetUser() const { return fUser; } 00066 Bool_t IsClosed() const { return ! fServer; } 00067 Bool_t IsTemporary() const { return fIsTemporary; } 00068 Int_t GetNumConnectedStatements() const { return fNumConnectedStatements ; } 00069 00070 // Exception log handling 00071 00072 const DbiExceptionLog& GetExceptionLog() const { return fExceptionLog; } 00073 void ClearExceptionLog() { fExceptionLog.Clear(); } 00074 00076 Bool_t PrintExceptionLog(Logging::Level level = 3) const; 00077 void RecordException(); 00078 00079 // State changing member functions 00080 00081 // Idle connnection management 00082 00084 void ConnectStatement() { ++fNumConnectedStatements; } 00086 void DisConnectStatement() { 00087 --fNumConnectedStatements; 00088 if ( ! fNumConnectedStatements ) this->CloseIdleConnection(); } 00090 void SetPermanent() { fIsTemporary = kFALSE; } 00091 00092 00093 Bool_t Close(Bool_t force = false); 00094 Bool_t Open(); 00095 00098 TSQLServer* GetServer(); 00099 00102 TSQLStatement* CreatePreparedStatement(const std::string& sql); 00103 00104 private: 00105 00106 void CloseIdleConnection(); 00107 00108 00109 // Data members 00110 00112 std::string fDbName; 00113 00115 TUrl fUrl; 00116 00118 std::string fUser; 00119 00121 std::string fPassword; 00122 00124 Bool_t fUrlValidated; 00125 00127 Int_t fNumConnectedStatements; 00128 00130 Bool_t fIsTemporary; 00131 00133 TSQLServer* fServer; 00134 00137 DbiExceptionLog fExceptionLog; 00138 00140 Dbi::DbTypes fDbType; 00141 00142 // Removed: ClassDef(DbiConnection,0) // Managed TSQLServer 00143 00144 }; 00145 00146 00147 #endif // DBICONNECTION 00148