MythTV  master
mythstorage.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef MYTHSTORAGE_H
4 #define MYTHSTORAGE_H
5 
6 #include <utility>
7 
8 // Qt headers
9 #include <QString>
10 
11 // MythTV headers
12 #include "mythbaseexp.h"
13 #include "mythdbcon.h"
14 
16 {
17  public:
18  virtual void SetDBValue(const QString&) = 0;
19  virtual QString GetDBValue(void) const = 0;
20  virtual ~StorageUser() = default;
21 };
22 
24 {
25  public:
26  Storage() = default;
27  virtual ~Storage() = default;
28 
29  virtual void Load(void) = 0;
30  virtual void Save(void) = 0;
31  virtual void Save(const QString &/*destination*/) { }
32  virtual bool IsSaveRequired(void) const { return true; };
33  virtual void SetSaveRequired(void) { };
34 };
35 
37 {
38  public:
39  DBStorage(StorageUser *user, QString table, QString column) :
40  m_user(user),
41  m_tablename(std::move(table)),
42  m_columnname(std::move(column)) { }
43 
44  ~DBStorage() override = default;
45 
46  protected:
47  QString GetColumnName(void) const { return m_columnname; }
48  QString GetTableName(void) const { return m_tablename; }
49 
50  StorageUser *m_user {nullptr};
51  QString m_tablename;
52  QString m_columnname;
53 };
54 
56 {
57  public:
59  const QString &table, const QString &column) :
60  DBStorage(user, table, column) { m_initval.clear(); }
61  ~SimpleDBStorage() override = default;
62 
63  void Load(void) override; // Storage
64  void Save(void) override; // Storage
65  void Save(const QString &table) override; // Storage
66  bool IsSaveRequired(void) const override; // Storage
67  void SetSaveRequired(void) override; // Storage
68 
69  protected:
70  virtual QString GetWhereClause(MSqlBindings &bindings) const = 0;
71  virtual QString GetSetClause(MSqlBindings &bindings) const;
72 
73  protected:
74  QString m_initval;
75 };
76 
78 {
79  public:
81  const QString &table, const QString &column,
82  QString keycolumn, QString keyvalue = QString()) :
83  SimpleDBStorage(user, table, column),
84  m_keycolumn(std::move(keycolumn)),
85  m_keyvalue(std::move(keyvalue)) {}
86  ~GenericDBStorage() override = default;
87 
88  void SetKeyValue(const QString &val) { m_keyvalue = val; }
89  void SetKeyValue(long long val) { m_keyvalue = QString::number(val); }
90 
91  protected:
92  QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
93  QString GetSetClause(MSqlBindings &bindings) const override; // SimpleDBStorage
94 
95  protected:
96  QString m_keycolumn;
97  QString m_keyvalue;
98 };
99 
101 {
102  public:
103  TransientStorage() = default;
104  ~TransientStorage() override = default;
105 
106  void Load(void) override { } // Storage
107  void Save(void) override { } // Storage
108  void Save(const QString &/*destination*/) override { } // Storage
109 };
110 
112 {
113  public:
114  HostDBStorage(StorageUser *_user, QString name);
115  using SimpleDBStorage::Save; // prevent compiler warning
116  void Save(void) override; // SimpleDBStorage
117 
118  protected:
119  QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
120  QString GetSetClause(MSqlBindings &bindings) const override; // SimpleDBStorage
121 
122  protected:
123  QString m_settingname;
124 };
125 
127 {
128  public:
129  GlobalDBStorage(StorageUser *_user, QString name);
130  using SimpleDBStorage::Save; // prevent compiler warning
131  void Save(void) override; // SimpleDBStorage
132 
133  protected:
134  QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
135  QString GetSetClause(MSqlBindings &bindings) const override; // SimpleDBStorage
136 
137  protected:
138  QString m_settingname;
139 };
140 
142 
143 #endif // MYTHSTORAGE_H
virtual ~StorageUser()=default
QString GetColumnName(void) const
Definition: mythstorage.h:47
QString m_columnname
Definition: mythstorage.h:52
SimpleDBStorage(StorageUser *user, const QString &table, const QString &column)
Definition: mythstorage.h:58
QString m_settingname
Definition: mythstorage.h:123
QString m_settingname
Definition: mythstorage.h:138
void Save(void) override
Definition: mythstorage.h:107
void SetKeyValue(long long val)
Definition: mythstorage.h:89
QString GetTableName(void) const
Definition: mythstorage.h:48
QString m_tablename
Definition: mythstorage.h:51
virtual QString GetDBValue(void) const =0
virtual QString GetSetClause(MSqlBindings &bindings) const
Definition: mythstorage.cpp:86
void Save(const QString &) override
Definition: mythstorage.h:108
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:98
virtual bool IsSaveRequired(void) const
Definition: mythstorage.h:32
virtual QString GetWhereClause(MSqlBindings &bindings) const =0
void Save(void) override
Definition: mythstorage.cpp:81
DBStorage(StorageUser *user, QString table, QString column)
Definition: mythstorage.h:39
QString m_initval
Definition: mythstorage.h:74
virtual void Save(void)=0
virtual void Load(void)=0
GenericDBStorage(StorageUser *user, const QString &table, const QString &column, QString keycolumn, QString keyvalue=QString())
Definition: mythstorage.h:80
void SetKeyValue(const QString &val)
Definition: mythstorage.h:88
QString m_keycolumn
Definition: mythstorage.h:96
virtual void SetDBValue(const QString &)=0
virtual void Save(const QString &)
Definition: mythstorage.h:31
void Load(void) override
Definition: mythstorage.h:106
QString m_keyvalue
Definition: mythstorage.h:97
virtual void SetSaveRequired(void)
Definition: mythstorage.h:33