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