MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
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() { }
19 };
20 
21 class MBASE_PUBLIC Storage
22 {
23  public:
24  Storage() { }
25  virtual ~Storage() { }
26 
27  virtual void Load(void) = 0;
28  virtual void Save(void) = 0;
29  virtual void Save(QString /*destination*/) { }
30  virtual bool IsSaveRequired(void) const { return true; };
31  virtual void SetSaveRequired(void) { };
32 };
33 
34 class MBASE_PUBLIC DBStorage : public Storage
35 {
36  public:
37  DBStorage(StorageUser *_user, QString _table, QString _column) :
38  user(_user), tablename(_table), columnname(_column) { }
39 
40  virtual ~DBStorage() { }
41 
42  protected:
43  QString GetColumnName(void) const { return columnname; }
44  QString GetTableName(void) const { return tablename; }
45 
47  QString tablename;
48  QString columnname;
49 };
50 
51 class MBASE_PUBLIC SimpleDBStorage : public DBStorage
52 {
53  public:
55  QString _table, QString _column) :
56  DBStorage(_user, _table, _column) { initval.clear(); }
57  virtual ~SimpleDBStorage() { }
58 
59  virtual void Load(void);
60  virtual void Save(void);
61  virtual void Save(QString destination);
62  virtual bool IsSaveRequired(void) const;
63  virtual void SetSaveRequired(void);
64 
65  protected:
66  virtual QString GetWhereClause(MSqlBindings &bindings) const = 0;
67  virtual QString GetSetClause(MSqlBindings &bindings) const;
68 
69  protected:
70  QString initval;
71 };
72 
73 class MBASE_PUBLIC GenericDBStorage : public SimpleDBStorage
74 {
75  public:
77  QString _table, QString _column,
78  QString _keycolumn, QString _keyvalue = QString::null) :
79  SimpleDBStorage(_user, _table, _column),
80  keycolumn(_keycolumn), keyvalue(_keyvalue) {}
81  virtual ~GenericDBStorage() { }
82 
83  void SetKeyValue(const QString val) { keyvalue = val; }
84  void SetKeyValue(long long val) { keyvalue = QString::number(val); }
85 
86  protected:
87  virtual QString GetWhereClause(MSqlBindings &bindings) const;
88  virtual QString GetSetClause(MSqlBindings &bindings) const;
89 
90  protected:
91  QString keycolumn;
92  QString keyvalue;
93 };
94 
95 class MBASE_PUBLIC TransientStorage : public Storage
96 {
97  public:
99  virtual ~TransientStorage() { }
100 
101  virtual void Load(void) { }
102  virtual void Save(void) { }
103  virtual void Save(QString /*destination*/) { }
104 };
105 
106 class MBASE_PUBLIC HostDBStorage : public SimpleDBStorage
107 {
108  public:
109  HostDBStorage(StorageUser *_user, const QString &name);
110 
111  protected:
112  virtual QString GetWhereClause(MSqlBindings &bindings) const;
113  virtual QString GetSetClause(MSqlBindings &bindings) const;
114 
115  protected:
116  QString settingname;
117 };
118 
119 class MBASE_PUBLIC GlobalDBStorage : public SimpleDBStorage
120 {
121  public:
122  GlobalDBStorage(StorageUser *_user, const QString &name);
123 
124  protected:
125  virtual QString GetWhereClause(MSqlBindings &bindings) const;
126  virtual QString GetSetClause(MSqlBindings &bindings) const;
127 
128  protected:
129  QString settingname;
130 };
131 
133 
134 #endif // MYTHSTORAGE_H