Belle II Software  release-05-02-19
DBInterface.h
1 #ifndef _Belle2_DBInterface_hh
2 #define _Belle2_DBInterface_hh
3 
4 #include "daq/slc/database/DBRecord.h"
5 #include "daq/slc/system/Mutex.h"
6 
7 #include <vector>
8 #include <map>
9 
10 namespace Belle2 {
16  typedef std::vector<DBRecord> DBRecordList;
17  typedef std::map<std::string, std::string> DBFieldTypeList;
18 
19  class DBInterface {
20 
21  public:
22  DBInterface(const std::string& host,
23  const std::string& database,
24  const std::string& user,
25  const std::string& password,
26  int port);
27  virtual ~DBInterface();
28 
29  public:
30  virtual void connect() = 0;
31  virtual bool isConnected() = 0;
32  virtual void execute_imp(const char* command) = 0;
33  void execute(const char* command, ...);
34  void execute(const std::string& command);
35  virtual void close() = 0;
36  virtual void clear() = 0;
37  virtual DBRecordList loadRecords() = 0;
38  virtual bool checkTable(const std::string& tablename) = 0;
39  virtual DBFieldTypeList getTableContents(const std::string& tablename) = 0;
40  void clearRecords() { m_record_v.resize(0); }
41  DBRecordList& getRecords() { return m_record_v; }
42  const std::string& getHostName() const { return m_host; }
43  const std::string& getDatabase() const { return m_database; }
44  const std::string& getUserName() const { return m_user; }
45  const std::string& getPassword() const { return m_password; }
46  int getPort() const { return m_port; }
47 
48  protected:
49  DBInterface() {}
50  void init(const std::string& host,
51  const std::string& database,
52  const std::string& user,
53  const std::string& password,
54  int port);
55 
56  protected:
57  DBRecordList m_record_v;
58  std::string m_host;
59  std::string m_database;
60  std::string m_user;
61  std::string m_password;
62  int m_port;
63 
64  private:
65  Mutex m_mutex;
66  static const int m_buf_size = 1024 * 1000;
67  char* m_buf;
68 
69  };
70 
72 }
73 
74 #endif
Belle2::Mutex
Definition: Mutex.h:12
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DBInterface
Definition: DBInterface.h:19