00001 #ifndef DATABASESVC_H 00002 #define DATABASESVC_H 00003 00004 #ifndef BEAN 00005 #include "GaudiKernel/Service.h" 00006 #include "DatabaseSvc/IDatabaseSvc.h" 00007 00008 #include <mysql.h> 00009 00010 class DbInterface; 00011 00012 template <class TYPE> class SvcFactory; 00013 00014 class DatabaseSvc : virtual public IDatabaseSvc, 00015 virtual public Service 00016 { 00017 00018 // Allow SvcFactory to instantiate the service. 00019 friend class SvcFactory<DatabaseSvc>; 00020 00021 //maqm protected: 00022 public: 00023 // Constructor 00024 DatabaseSvc( const std::string& name, ISvcLocator* sl ); 00025 00026 // Destructor 00027 virtual ~DatabaseSvc(); 00028 00029 public: 00030 00031 // IInterface: query 00032 virtual StatusCode queryInterface( const InterfaceID& riid, void** ppvInterface ); 00033 00034 // Service: initialize 00035 virtual StatusCode initialize(); 00036 00037 // Service: finalize 00038 virtual StatusCode finalize(); 00039 00040 #else 00041 // -------------------------- BEAN ------------------------------------ 00042 #include "DatabaseSvc/DatabaseRecord.h" 00043 #include "DatabaseSvc/DbInterface.h" 00044 00045 class DatabaseSvc 00046 { 00047 public: 00048 static DatabaseSvc* instance() { 00049 return (m_db) ? m_db : (m_db = new DatabaseSvc()); 00050 } 00051 00052 private: 00053 DatabaseSvc(); 00054 virtual ~DatabaseSvc(); 00055 00056 bool initialize(); 00057 void finalize(); 00058 00059 public: 00060 void SetDBFilePath(std::string dbFilePath); 00061 std::string GetDBFilePath() const {return m_dbFilePath;} 00062 #endif 00063 00064 // make query 00065 int query(const std::string& dbName, const std::string& sql); 00066 int query(const std::string& dbName, const std::string& sql, 00067 DatabaseRecordVector& res); 00068 00069 private: 00070 00071 DbInterface * dbInterface; 00072 std::string m_dbName; 00073 00074 std::string m_dbHost; 00075 std::string m_dbUser; 00076 std::string m_dbPasswd; 00077 std::string m_dbFilePath; 00078 std::string m_dbType; 00079 bool m_dbReuseConnection; 00080 00081 #ifdef BEAN 00082 static DatabaseSvc* m_db; 00083 #endif 00084 }; 00085 00086 #endif