Isis Developer Reference
DatabaseFactory.h
Go to the documentation of this file.
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 
21 namespace Isis {
22 
23  class DbAccess;
24  class DbProfile;
25 
245  public:
246  static DatabaseFactory *getInstance();
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
324  DatabaseFactory();
325  ~DatabaseFactory();
326 
327  static void DieAtExit();
328 
329  static DatabaseFactory *_factory;
330 
337 
338  QString _defProfName;
339  Profiles _profiles;
340  QString _defDatabase;
341  Databases _dbList;
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
Isis::DatabaseFactory::isConnected
bool isConnected(const QString &dbname) const
Determines if the database resource is connected.
Definition: DatabaseFactory.cpp:315
FileName.h
Isis::DatabaseFactory::create
QSqlDatabase create(const QString &driver, const QString &dbname)
Create a database using the named driver.
Definition: DatabaseFactory.cpp:358
Isis::DbProfile::Name
QString Name() const
Returns the name of this property.
Definition: DbProfile.h:104
Isis::DatabaseFactory::setDefault
void setDefault(const QString &name)
Sets the default name of the database.
Definition: DatabaseFactory.h:258
Isis::DbProfile::exists
bool exists(const QString &key) const
Checks for the existance of a keyword.
Definition: DbProfile.h:115
Isis::DatabaseFactory::getProfileList
std::vector< QString > getProfileList() const
Return list of names of currently available profiles.
Definition: DatabaseFactory.cpp:207
QSqlDatabase
Isis::DatabaseFactory::getProfile
DbProfile getProfile(const QString &name="") const
Get the specified database access profile.
Definition: DatabaseFactory.cpp:235
Isis::DbAccess
DbAccess manages programatic access to a database through profiles.
Definition: DbAccess.h:106
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::DatabaseFactory::remove
void remove(const QString &dbname)
Removes the database from the connection pool.
Definition: DatabaseFactory.cpp:450
Isis::FileName::fileExists
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:449
Isis::CollectorMap::get
T & get(const K &key)
Returns the value associated with the name provided.
Definition: CollectorMap.h:567
Isis::CollectorMap::size
int size() const
Returns the size of the collection.
Definition: CollectorMap.h:512
Isis::CollectorMap::remove
int remove(const K &key)
Removes and entry from the list.
Definition: CollectorMap.h:694
Isis::DatabaseFactory::setDefaultProfileName
bool setDefaultProfileName(const QString &name)
Sets the default profile to the name provided.
Definition: DatabaseFactory.h:304
Isis::DatabaseFactory::getDefaultProfileName
QString getDefaultProfileName() const
Returns the name of the default profile.
Definition: DatabaseFactory.h:289
DatabaseFactory.h
Isis::Database::init
QSqlDatabase init(const DbProfile &profile, Access dbConn=Connect)
Create and initialize a new database connection from a DbProfile.
Definition: Database.cpp:403
Isis::DatabaseFactory::available
std::vector< QString > available() const
Determine what database drivers are available.
Definition: DatabaseFactory.cpp:260
Isis::DatabaseFactory::isDriverAvailable
bool isDriverAvailable(const QString &driver) const
Check for the existance of a specific database driver.
Definition: DatabaseFactory.cpp:279
Isis::DatabaseFactory::addProfile
void addProfile(const DbProfile &profile)
Adds a database access profile to the list of profiles.
Definition: DatabaseFactory.cpp:194
Isis::DatabaseFactory::isPersistant
bool isPersistant(const QString &name) const
Checks if the database resource is persistant.
Definition: DatabaseFactory.cpp:335
QStringList
Preference.h
Isis::DatabaseFactory::destroy
void destroy(const QString &dbname)
Removes the database from the connection pool and destroys it.
Definition: DatabaseFactory.cpp:435
IString.h
Isis::DatabaseFactory::isAvailable
bool isAvailable(const QString &dbname="") const
Check for availablity of a database connection resource.
Definition: DatabaseFactory.cpp:297
Isis::DatabaseFactory::add
void add(const QSqlDatabase &db, const QString &name, bool setAsDefault=false)
Adds the database to the connection pool making it persistant.
Definition: DatabaseFactory.cpp:415
Isis::CollectorMap::exists
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Definition: CollectorMap.h:551
Isis::CollectorMap::key
const K & key(int nth) const
Returns the nth key in the collection.
Definition: CollectorMap.h:673
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::DatabaseFactory::addAccessProfile
bool addAccessProfile(const QString &profileFile)
Establishes an access profile for subsequent database connections.
Definition: DatabaseFactory.cpp:152
Isis::DbProfile
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:51
Isis::IException
Isis exception class.
Definition: IException.h:91
DbAccess.h
Isis::CollectorMap::add
void add(const K &key, const T &value)
Adds the element to the list.
Definition: CollectorMap.h:540
Isis::DatabaseFactory
Create database interfaces using access profiles or generic drivers.
Definition: DatabaseFactory.h:244
Isis::DatabaseFactory::getInstance
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
Definition: DatabaseFactory.cpp:124
IException.h
std
Namespace for the standard library.
CollectorMap.h
Isis::CollectorMap
Collector/container for arbitrary items.
Definition: CollectorMap.h:419
Isis::DbAccess::profileCount
int profileCount() const
Reports the number of user profiles to access this database.
Definition: DbAccess.h:127
Isis::IString::Equal
bool Equal(const std::string &str) const
Compare a string to the object IString.
Definition: IString.cpp:690
Isis::DbAccess::getProfile
const DbProfile getProfile(const QString &name="") const
Retrieves the specified access profile.
Definition: DbAccess.cpp:92
Isis::Preference::Preferences
static Preference & Preferences(bool unitTest=false)
Definition: Preference.cpp:86
Isis::DatabaseFactory::getDefault
QString getDefault() const
Returns the name of the default database.
Definition: DatabaseFactory.h:271
Isis::DbProfile::value
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
Definition: DbProfile.cpp:146
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IString::ToQt
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:869