Belle II Software  release-08-01-10
DBInterface.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #ifndef _Belle2_DBInterface_hh
9 #define _Belle2_DBInterface_hh
10 
11 #include "daq/slc/database/DBRecord.h"
12 #include "daq/slc/system/Mutex.h"
13 
14 #include <vector>
15 #include <map>
16 
17 namespace Belle2 {
23  typedef std::vector<DBRecord> DBRecordList;
24  typedef std::map<std::string, std::string> DBFieldTypeList;
25 
26  class DBInterface {
27 
28  public:
29  DBInterface(const std::string& host,
30  const std::string& database,
31  const std::string& user,
32  const std::string& password,
33  int port);
34  virtual ~DBInterface();
35 
36  public:
37  virtual void connect() = 0;
38  virtual bool isConnected() = 0;
39  virtual void execute_imp(const char* command) = 0;
40  void execute(const char* command, ...);
41  void execute(const std::string& command);
42  virtual void close() = 0;
43  virtual void clear() = 0;
44  virtual DBRecordList loadRecords() = 0;
45  virtual bool checkTable(const std::string& tablename) = 0;
46  virtual DBFieldTypeList getTableContents(const std::string& tablename) = 0;
47  void clearRecords() { m_record_v.resize(0); }
48  DBRecordList& getRecords() { return m_record_v; }
49  const std::string& getHostName() const { return m_host; }
50  const std::string& getDatabase() const { return m_database; }
51  const std::string& getUserName() const { return m_user; }
52  const std::string& getPassword() const { return m_password; }
53  int getPort() const { return m_port; }
54 
55  protected:
56  DBInterface() {}
57  void init(const std::string& host,
58  const std::string& database,
59  const std::string& user,
60  const std::string& password,
61  int port);
62 
63  protected:
64  DBRecordList m_record_v;
65  std::string m_host;
66  std::string m_database;
67  std::string m_user;
68  std::string m_password;
69  int m_port;
70 
71  private:
72  Mutex m_mutex;
73  static const int m_buf_size = 1024 * 1000;
74  char* m_buf;
75 
76  };
77 
79 }
80 
81 #endif
Abstract base class for different kinds of events.