Isis 3 Programmer Reference
DatabaseFactory.h
1#ifndef DatabaseFactory_h
2#define DatabaseFactory_h
3
10/* SPDX-License-Identifier: CC0-1.0 */
11
12#include <string>
13#include <vector>
14#include <iostream>
15
16#include <QSqlDatabase>
17
18#include "CollectorMap.h"
19#include "IException.h"
20
21namespace Isis {
22
23 class DbAccess;
24 class DbProfile;
25
245 public:
247
258 void setDefault(const QString &name) {
259 _defDatabase = name;
260 }
261
271 QString getDefault() const {
272 return (_defDatabase);
273 }
274
275 bool addAccessProfile(const QString &profileFile);
276 void addProfile(const DbProfile &profile);
277 std::vector<QString> getProfileList() const;
278 DbProfile getProfile(const QString &name = "") const;
279
289 QString getDefaultProfileName() const {
290 return (_defProfName);
291 }
292
304 bool setDefaultProfileName(const QString &name) {
305 _defProfName = name;
306 return (_profiles.exists(name));
307 }
308
309 std::vector<QString> available() const;
310 bool isDriverAvailable(const QString &driver) const;
311 bool isAvailable(const QString &dbname = "") const;
312 bool isConnected(const QString &dbname) const;
313 bool isPersistant(const QString &name) const;
314
315 QSqlDatabase create(const QString &driver, const QString &dbname);
316 QSqlDatabase create(const QString &name);
317 void add(const QSqlDatabase &db, const QString &name,
318 bool setAsDefault = false);
319 void remove(const QString &dbname);
320 void destroy(const QString &dbname);
321
322 private:
323 // Gain access through Singleton interface
326
327 static void DieAtExit();
328
330
332 typedef CollectorMap<IString, QString, NoCaseStringCompare> Drivers;
334 typedef CollectorMap<IString, DbProfile, NoCaseStringCompare> Profiles;
336 typedef CollectorMap<IString, QSqlDatabase, NoCaseStringCompare> Databases;
337
338 QString _defProfName;
340 QString _defDatabase;
342
343 void init();
344 void initPreferences();
345 void loadDrivers();
346 Drivers getResourceList(bool drivers, bool connections) const;
347 void selfDestruct();
348
349 };
350}
351#endif
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Create database interfaces using access profiles or generic drivers.
QSqlDatabase create(const QString &driver, const QString &dbname)
Create a database using the named driver.
CollectorMap< IString, DbProfile, NoCaseStringCompare > Profiles
Define list of Profiles.
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
void destroy(const QString &dbname)
Removes the database from the connection pool and destroys it.
void remove(const QString &dbname)
Removes the database from the connection pool.
DatabaseFactory()
Constructor establishing the startup state of this singleton.
DbProfile getProfile(const QString &name="") const
Get the specified database access profile.
static DatabaseFactory * _factory
Pointer to self (singleton)
void add(const QSqlDatabase &db, const QString &name, bool setAsDefault=false)
Adds the database to the connection pool making it persistant.
bool isDriverAvailable(const QString &driver) const
Check for the existance of a specific database driver.
CollectorMap< IString, QSqlDatabase, NoCaseStringCompare > Databases
Define active database maintainer.
bool isPersistant(const QString &name) const
Checks if the database resource is persistant.
std::vector< QString > available() const
Determine what database drivers are available.
bool addAccessProfile(const QString &profileFile)
Establishes an access profile for subsequent database connections.
void selfDestruct()
Destroy all elements associated with this object.
Drivers getResourceList(bool drivers, bool connections) const
Get a list of available database drivers and connections.
static void DieAtExit()
Exit termination routine.
bool isAvailable(const QString &dbname="") const
Check for availablity of a database connection resource.
void addProfile(const DbProfile &profile)
Adds a database access profile to the list of profiles.
Databases _dbList
Maintains active databases.
bool setDefaultProfileName(const QString &name)
Sets the default profile to the name provided.
QString getDefault() const
Returns the name of the default database.
void init()
Initializes this object upon instantiation.
void initPreferences()
Initializes user database preferences.
std::vector< QString > getProfileList() const
Return list of names of currently available profiles.
bool isConnected(const QString &dbname) const
Determines if the database resource is connected.
~DatabaseFactory()
Destructor implements self-destruction of this object.
void loadDrivers()
Load any drivers explicity.
QString _defDatabase
Name of default database.
Profiles _profiles
Maintain list of profiles.
void setDefault(const QString &name)
Sets the default name of the database.
QString getDefaultProfileName() const
Returns the name of the default profile.
CollectorMap< IString, QString, NoCaseStringCompare > Drivers
Define list of drivers and/or databases
QString _defProfName
Default profile name.
A DbProfile is a container for access parameters to a database.
Definition DbProfile.h:51
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16