Isis 3 Programmer Reference
DatabaseFactory.h
Go to the documentation of this file.
1 #ifndef DatabaseFactory_h
2 #define DatabaseFactory_h
3 
26 #include <string>
27 #include <vector>
28 #include <iostream>
29 
30 #include <QSqlDatabase>
31 
32 #include "CollectorMap.h"
33 #include "IException.h"
34 
35 namespace Isis {
36 
37  class DbAccess;
38  class DbProfile;
39 
259  public:
260  static DatabaseFactory *getInstance();
261 
272  void setDefault(const QString &name) {
273  _defDatabase = name;
274  }
275 
285  QString getDefault() const {
286  return (_defDatabase);
287  }
288 
289  bool addAccessProfile(const QString &profileFile);
290  void addProfile(const DbProfile &profile);
291  std::vector<QString> getProfileList() const;
292  DbProfile getProfile(const QString &name = "") const;
293 
303  QString getDefaultProfileName() const {
304  return (_defProfName);
305  }
306 
318  bool setDefaultProfileName(const QString &name) {
319  _defProfName = name;
320  return (_profiles.exists(name));
321  }
322 
323  std::vector<QString> available() const;
324  bool isDriverAvailable(const QString &driver) const;
325  bool isAvailable(const QString &dbname = "") const;
326  bool isConnected(const QString &dbname) const;
327  bool isPersistant(const QString &name) const;
328 
329  QSqlDatabase create(const QString &driver, const QString &dbname);
330  QSqlDatabase create(const QString &name);
331  void add(const QSqlDatabase &db, const QString &name,
332  bool setAsDefault = false);
333  void remove(const QString &dbname);
334  void destroy(const QString &dbname);
335 
336  private:
337  // Gain access through Singleton interface
338  DatabaseFactory();
340 
341  static void DieAtExit();
342 
344 
351 
352  QString _defProfName;
354  QString _defDatabase;
356 
357  void init();
358  void initPreferences();
359  void loadDrivers();
360  Drivers getResourceList(bool drivers, bool connections) const;
361  void selfDestruct();
362 
363  };
364 }
365 #endif
366 
367 
368 
Drivers getResourceList(bool drivers, bool connections) const
Get a list of available database drivers and connections.
QString getDefault() const
Returns the name of the default database.
std::vector< QString > available() const
Determine what database drivers are available.
void setDefault(const QString &name)
Sets the default name of the database.
void addProfile(const DbProfile &profile)
Adds a database access profile to the list of profiles.
DbProfile getProfile(const QString &name="") const
Get the specified database access profile.
CollectorMap< IString, QSqlDatabase, NoCaseStringCompare > Databases
Define active database maintainer.
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
Create database interfaces using access profiles or generic drivers.
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:65
bool addAccessProfile(const QString &profileFile)
Establishes an access profile for subsequent database connections.
void initPreferences()
Initializes user database preferences.
bool setDefaultProfileName(const QString &name)
Sets the default profile to the name provided.
QString _defProfName
Default profile name.
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Definition: CollectorMap.h:567
DatabaseFactory()
Constructor establishing the startup state of this singleton.
CollectorMap< IString, DbProfile, NoCaseStringCompare > Profiles
Define list of Profiles.
bool isAvailable(const QString &dbname="") const
Check for availablity of a database connection resource.
bool isDriverAvailable(const QString &driver) const
Check for the existance of a specific database driver.
void loadDrivers()
Load any drivers explicity.
void selfDestruct()
Destroy all elements associated with this object.
QString getDefaultProfileName() const
Returns the name of the default profile.
Collector/container for arbitrary items.
Definition: CollectorMap.h:435
CollectorMap< IString, QString, NoCaseStringCompare > Drivers
Define list of drivers and/or databases.
void add(const QSqlDatabase &db, const QString &name, bool setAsDefault=false)
Adds the database to the connection pool making it persistant.
void init()
Initializes this object upon instantiation.
Profiles _profiles
Maintain list of profiles.
~DatabaseFactory()
Destructor implements self-destruction of this object.
Databases _dbList
Maintains active databases.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
static DatabaseFactory * _factory
Pointer to self (singleton)
bool isConnected(const QString &dbname) const
Determines if the database resource is connected.
static void DieAtExit()
Exit termination routine.
std::vector< QString > getProfileList() const
Return list of names of currently available profiles.
void destroy(const QString &dbname)
Removes the database from the connection pool and destroys it.
bool isPersistant(const QString &name) const
Checks if the database resource is persistant.
QSqlDatabase create(const QString &driver, const QString &dbname)
Create a database using the named driver.
QString _defDatabase
Name of default database.