Portability Libraries  2015.2.0.0
Common Methods and Objects for Platform Independance.
DatabaseConnection.hpp
Go to the documentation of this file.
1 #ifndef DATABASECONNECTION_HPP
2 #define DATABASECONNECTION_HPP
3 
4 #include <QString>
5 #include <QApplication>
6 #include <QMutex>
7 
8 #include <SaS/Sql/SQL.hpp>
9 #ifdef USE_POSTGRES
10 #include <SaS/Sql/SQL_postgres.hpp>
11 #endif
12 
13 #include <SaS/Sql/SqlDatabase.hpp>
14 #include <SaS/Secure/pem.hpp>
15 #include <SaS/Secure/PwSafe.hpp>
16 
17 #include <QSettings>
18 
19 #include <uuid/uuid.h>
20 
24 
25 namespace SoftwareAndServices
26 {
27  namespace Library
28  {
29  namespace Database
30  {
31  namespace Qt5
32  {
33  /**
34  * @class DatabaseConnection DatabaseConnection.hpp <SaS/Sql/Qt/Qt5/DatabaseConnection.hpp>
35  * One of these objects exist for each connected to database.
36  *
37  * Defaults to PostgreSQL.
38  */
40  {
41  public:
42 
43  /**
44  * DatabaseConnection - Default Constructor.
45  */
47 
48  /**
49  * DatabaseConnection - Destructor.
50  */
51  virtual ~DatabaseConnection();
52 
53  /**
54  * @brief DisplayName The name to display on the form.
55  */
56  QString DisplayName;
57 
58  /**
59  * @brief LoadSaved - Load all saved database connection
60  * settings.
61  *
62  * @param Config Initialzied configuration information
63  * to load the configuration information from.
64  *
65  * @param AppGuid When NON-NULL, this is the GUID
66  * that will be used to find this applications
67  * password safe. When NULL, the users default
68  * password safe will be used.
69  *
70  * @return true when loaded. When false, one or more
71  * settings failed to load. They will be in the list,
72  * and marked not working.
73  *
74  * @see Working()
75  */
76  static bool LoadSaved(QSettings * Config,
77  const char * AppGuid = NULL);
78 
79  /**
80  * @brief Save - Save this connection information.
81  *
82  * @param Config An initialzed QSettings object.
83  *
84  * @return true if saved.
85  */
86  static bool SaveAll(QSettings * Config);
87 
88  /**
89  * @brief Working - Determine if this objects data
90  * works, or if it is saved configuration that is not
91  * working.
92  *
93  * @return true when this objects data works.
94  */
95  bool Working();
96 
97  /**
98  * @brief Working - Set the working status of this object
99  *
100  * @param IsWorking When true, indicate that at least
101  * at one time, this entry worked.
102  *
103  * After testing, if it fails, set to false.
104  */
105  void Working(bool IsWorking);
106 
107  /**
108  * @brief All - Get a list of all known connections.
109  *
110  * @return The list of connections, or NULL when none.
111  */
112  static std::vector<DatabaseConnection*> * All();
113 
114  private:
115 
116  /**
117  * @brief _All - A vector of all known connections.
118  */
119  static std::vector<DatabaseConnection*> * _All;
120 
121  /**
122  * @brief _Once Used to do global initializations, once.
123  */
124  static QMutex _Once;
125 
126  /**
127  * @brief _Db This objects database.
128  */
129  SqlDatabase * _Db;
130 
131  /**
132  * @brief _Uuid - Each entry has a random, uniq ID.
133  */
134  uuid_t _Uuid;\
135 
136  /**
137  * @brief _Data When non-NULL, user defined data for
138  * this object.
139  */
140  void * _Data;
141 
142  public:
143 
144  /**
145  * @brief Item - Return a used defined data pointer
146  * for this object.
147  *
148  * @return The user defined data, or NULL when not set.
149  */
150  void * Data() const;
151 
152  /**
153  * @brief Data - Hold user defined data for this object.
154  *
155  * @param ItemData - The data pointer to store.
156  */
157  void Data(void * ItemData);
158 
159  /**
160  * @brief CDbType The index into the database type.
161  * That is designed to be the same as SQL::DatabaseType_e.
162  */
164 
165  /**
166  * @brief CDisplayName - Form value.
167  */
168  QString CDisplayName;
169 
170  /**
171  * @brief CHostName - Form value.
172  */
173  QString CHostName;
174 
175  /**
176  * @brief CDbName - Form value.
177  */
178  QString CDbName;
179 
180  /**
181  * @brief CUserName - Form value.
182  */
183  QString CUserName;
184 
185  /**
186  * @brief CPassword - Form value.
187  */
188  QString CPassword;
189 
190  /**
191  * @brief CHostAddress - Form value.
192  */
193  QString CHostAddress;
194 
195  /**
196  * @brief CPublicCert - Form value.
197  */
198  QString CPublicCert;
199 
200  /**
201  * @brief CPrivateCert - Form value.
202  */
203  QString CPrivateCert;
204 
205  /**
206  * @brief CWasWorking - true when the test DB button
207  * worked.
208  */
210 
211  /**
212  * @brief CPort - Form value.
213  */
215 
216  /**
217  * @brief CAuthType - Form value.
218  */
220 
221  /**
222  * @brief CSecType - Form value.
223  */
225 
226  /**
227  * @brief AppGuid - The calling applications GUID.
228  */
229  static const char * AppGuid;
230 
231  /**
232  * @brief PwSafe - The password safe, used to store
233  * the database user names, passswords, and certificates.
234  */
235  static PwSafe * Safe;
236 
237  };
238 
239  }
240  }
241  }
242 }
243 
244 #endif // DATABASECONNECTION_HPP
static const char * AppGuid
AppGuid - The calling applications GUID.
SQL::DatabaseType_e CDbType
CDbType The index into the database type. That is designed to be the same as SQL::DatabaseType_e.
QString DisplayName
DisplayName The name to display on the form.
bool CWasWorking
CWasWorking - true when the test DB button worked.
#define NULL
Definition: types.h:97
static PwSafe * Safe
PwSafe - The password safe, used to store the database user names, passswords, and certificates...
SQL * Database
SQL::AuthenticationType_e CAuthType
CAuthType - Form value.