31 #include <QStringList> 
   32 #include <QCoreApplication> 
   43   DatabaseFactory *DatabaseFactory::_factory = 0;
 
   69   DatabaseFactory::DatabaseFactory() : _defProfName(
""),  _profiles(),
 
   70     _defDatabase(
""), _dbList() {
 
   74     QCoreApplication *cApp = QCoreApplication::instance();
 
   76       static char **argv = 0;
 
   80         argv[0] = 
new char[1024];
 
   81         strcpy(argv[0], 
"DatabaseFactory");
 
   86       new QCoreApplication(argc, argv);
 
  165       if(dbconf.fileExists()) {
 
  179         if(acp.
exists(
"DefaultProfile")) {
 
  218     std::vector<QString> plist;
 
  246     QString profName(name);
 
  272     std::vector<QString> dblist;
 
  273     for(
int i = 0 ; i < drivers.
size() ; i++) {
 
  274       dblist.push_back(drivers.
key(i).ToQt());
 
  291     if(!drivers.
exists(dbname)) {
 
  294     return (QSqlDatabase::isDriverAvailable(drivers.
get(dbname)));
 
  309     QString name(dbname);
 
  313     return (dbdrivers.
exists(name));
 
  326     QString name(dbname);
 
  330     return (QSqlDatabase::contains(name));
 
  369                                        const QString &dbname) {
 
  372       QString mess = 
"Driver [" + driver + 
"] for database [" + dbname
 
  373                      + 
"] does not exist";
 
  379     return (QSqlDatabase::addDatabase(drivers.
get(driver), dbname));
 
  401     QString mess = 
"Database [" + dbname + 
"] does not exist";
 
  445     QSqlDatabase::removeDatabase(name);
 
  495     Preference &userPref = Preference::Preferences();
 
  528     if(drivers)     dblist += QSqlDatabase::drivers();
 
  529     if(connections) dblist += QSqlDatabase::connectionNames();
 
  531     for(
int i = 0 ; i < dblist.size() ; i++) {
 
  532       QString dbname(dblist.at(i));
 
  533       dbDrivers.
add(dbname, dbname);
 
  539     if(dbDrivers.
exists(
"QPSQL")) {
 
  540       dbDrivers.
add(
"PostgreSQL", 
"QPSQL");
 
  544     if(dbDrivers.
exists(
"QMYSQL")) {
 
  545       dbDrivers.
add(
"MySQL", 
"QMYSQL");
 
  549     if(dbDrivers.
exists(
"QOCI")) {
 
  550       dbDrivers.
add(
"Oracle", 
"QOCI");
 
  554     if(dbDrivers.
exists(
"QSQLITE")) {
 
  555       dbDrivers.
add(
"SQLite", 
"QSQLITE");
 
  587     QStringList dblist = QSqlDatabase::connectionNames();
 
  588     for(
int i = 0 ; i < dblist.size() ; i++) {
 
  589       QSqlDatabase::removeDatabase(dblist[i]);
 
const K & key(int nth) const 
Returns the nth key in the collection. 
 
bool exists(const K &key) const 
Checks the existance of a particular key in the list. 
 
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes. 
 
T & get(const K &key)
Returns the value associated with the name provided. 
 
QString ToQt() const 
Retuns the object string as a QString. 
 
File name manipulation and expansion. 
 
bool Equal(const std::string &str) const 
Compare a string to the object IString. 
 
DbProfile getProfile(const QString &name="") const 
Get the specified database access profile. 
 
const DbProfile getProfile(const QString &name="") const 
Retrieves the specified access profile. 
 
void addProfile(const DbProfile &profile)
Adds a database access profile to the list of profiles. 
 
QString Name() const 
Returns the name of this property. 
 
bool isAvailable(const QString &dbname="") const 
Check for availablity of a database connection resource. 
 
int remove(const K &key)
Removes and entry from the list. 
 
std::vector< QString > available() const 
Determine what database drivers are available. 
 
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton. 
 
std::vector< QString > getProfileList() const 
Return list of names of currently available profiles. 
 
Create database interfaces using access profiles or generic drivers. 
 
QString value(const QString &key, int nth=0) const 
Returns the specified value for the given keyword. 
 
A DbProfile is a container for access parameters to a database. 
 
int profileCount() const 
Reports the number of user profiles to access this database. 
 
bool addAccessProfile(const QString &profileFile)
Establishes an access profile for subsequent database connections. 
 
void initPreferences()
Initializes user database preferences. 
 
QString _defProfName
Default profile name. 
 
Drivers getResourceList(bool drivers, bool connections) const 
Get a list of available database drivers and connections. 
 
Contains multiple PvlContainers. 
 
#define _FILEINFO_
Macro for the filename and line number. 
 
DatabaseFactory()
Constructor establishing the startup state of this singleton. 
 
void add(const K &key, const T &value)
Adds the element to the list. 
 
bool isDriverAvailable(const QString &driver) const 
Check for the existance of a specific database driver. 
 
A type of error that cannot be classified as any of the other error types. 
 
bool isConnected(const QString &dbname) const 
Determines if the database resource is connected. 
 
void loadDrivers()
Load any drivers explicity. 
 
void selfDestruct()
Destroy all elements associated with this object. 
 
Collector/container for arbitrary items. 
 
void add(const QSqlDatabase &db, const QString &name, bool setAsDefault=false)
Adds the database to the connection pool making it persistant. 
 
void remove(const QString &dbname)
Removes the database from the connection pool. 
 
bool exists(const QString &key) const 
Checks for the existance of a keyword. 
 
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. 
 
int size() const 
Returns the size of the collection. 
 
DbAccess manages programatic access to a database through profiles. 
 
bool hasGroup(const QString &name) const 
Returns a boolean value based on whether the object has the specified group or not. 
 
static DatabaseFactory * _factory
Pointer to self (singleton) 
 
static void DieAtExit()
Exit termination routine. 
 
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. 
 
bool hasKeyword(const QString &name) const 
Check to see if a keyword exists. 
 
QSqlDatabase create(const QString &driver, const QString &dbname)
Create a database using the named driver. 
 
Reads user preferences from a data file. 
 
QString _defDatabase
Name of default database.