Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DbiConnection.h

Go to the documentation of this file.
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 
00045 class DbiConnection
00046 {
00047 
00048 public:
00049 
00050 // Constructors and destructors.
00051            DbiConnection(const std::string& url = "",
00052                          const std::string& user = "",
00053                          const std::string& password = "");
00054   virtual ~DbiConnection();
00055 
00056 // State testing member functions
00057 
00058 // Standard getters.
00059 
00060     const std::string& GetDbName() const { return fDbName; }
00061           Dbi::DbTypes GetDbType() const { return fDbType; }
00062     const std::string& GetPassword() const { return fPassword; }
00063     const std::string& GetUrl() const;
00064     const std::string& GetUser() const { return fUser; }
00065                 Bool_t IsClosed() const { return ! fServer; }
00066                 Bool_t IsTemporary() const { return fIsTemporary; }
00067                 Bool_t TableExists(const std::string& tableName) const;
00068 
00069 // Exception log handling
00070 
00071   const DbiExceptionLog& GetExceptionLog() const { return fExceptionLog; }
00072   void ClearExceptionLog() { fExceptionLog.Clear(); }
00073 
00075   Bool_t PrintExceptionLog(Int_t level = 3) const;
00076 
00077   void RecordException();
00078 
00079 // State changing member functions
00080 
00083   void SetTableExists(const std::string& tableName = ""); 
00084 
00085 // Idle connnection management
00086 
00088   void Connect()    { this->ConnectStatement(); }
00089   void DisConnect() { this->DisConnectStatement(); }
00090 
00092   void ConnectStatement() { ++fNumConnectedStatements; }
00094   void DisConnectStatement() {
00095        --fNumConnectedStatements;
00096       if ( ! fNumConnectedStatements ) this->CloseIdleConnection(); }
00098   void SetPermanent(Bool_t permanent = true) { fIsTemporary = ! permanent; }
00099 
00100 
00101   Bool_t Close(Bool_t force = false);
00102   Bool_t Open();
00103 
00106   TSQLServer* GetServer();
00107 
00110   TSQLStatement* CreatePreparedStatement(const std::string& sql);
00111 
00112 private:  
00113 
00114   void CloseIdleConnection();
00115 
00116 
00117 // Data members
00118 
00120   std::string fDbName;
00121 
00123     std::string fExistingTableList;
00124 
00126   TUrl fUrl;
00127 
00129   std::string fUser;
00130 
00132   std::string fPassword;
00133 
00135   Bool_t fUrlValidated;
00136 
00138   Int_t fNumConnectedStatements;
00139                                  
00141   Bool_t fIsTemporary;  
00142 
00144   TSQLServer* fServer;   
00145 
00148   DbiExceptionLog fExceptionLog;
00149 
00151   Dbi::DbTypes fDbType;
00152 
00153  ClassDef(DbiConnection,0)     // Managed TSQLServer
00154 
00155 };
00156 
00157 
00158 #endif // DBICONNECTION
00159 

Generated on Mon Feb 15 11:06:34 2010 for loon by  doxygen 1.3.9.1