rssguard/src/core/databasefactory.h
2014-01-13 13:56:10 +01:00

61 lines
1.6 KiB
C++

#ifndef DATABASEFACTORY_H
#define DATABASEFACTORY_H
#include <QObject>
#include <QPointer>
#include <QSqlDatabase>
class DatabaseFactory : public QObject {
Q_OBJECT
public:
// Destructor.
virtual ~DatabaseFactory();
// Returns absolute file path to database file.
inline QString getDatabasePath() {
return m_databasePath;
}
// If in-memory is true, then :memory: database is returned
// In-memory database is DEFAULT database.
// NOTE: This always returns OPENED database.
QSqlDatabase connection(const QString &connection_name = QString(),
bool in_memory = true);
// Removes connection.
void removeConnection(const QString &connection_name = QString());
// Performs saving of items from in-memory database
// to file-based database.
void saveMemoryDatabase();
// Singleton getter.
static DatabaseFactory *instance();
private:
// Conctructor.
explicit DatabaseFactory(QObject *parent = 0);
// Assemblies database file path.
void assemblyDatabaseFilePath();
// Creates new connection, initializes database and
// returns opened connections.
QSqlDatabase initializeInMemoryDatabase();
QSqlDatabase initializeFileBasedDatabase(const QString &connection_name);
// Path to database file.
QString m_databasePath;
// Is database file initialized?
bool m_fileBasedinitialized;
bool m_inMemoryInitialized;
// Private singleton value.
static QPointer<DatabaseFactory> s_instance;
};
#endif // DATABASEFACTORY_H