31 #include <QStringList> 32 #include <QCoreApplication> 33 #include <QSqlDatabase> 44 DatabaseFactory *DatabaseFactory::_factory = 0;
70 DatabaseFactory::DatabaseFactory() : _defProfName(
""), _profiles(),
71 _defDatabase(
""), _dbList() {
77 QCoreApplication *cApp = QCoreApplication::instance();
79 static char **argv = 0;
83 argv[0] =
new char[1024];
84 strcpy(argv[0],
"DatabaseFactory");
89 new QCoreApplication(argc, argv);
182 if(acp.
exists(
"DefaultProfile")) {
221 std::vector<QString> plist;
249 QString profName(name);
275 std::vector<QString> dblist;
276 for(
int i = 0 ; i < drivers.
size() ; i++) {
277 dblist.push_back(drivers.
key(i).ToQt());
294 if(!drivers.
exists(dbname)) {
297 return (QSqlDatabase::isDriverAvailable(drivers.
get(dbname)));
312 QString name(dbname);
316 return (dbdrivers.
exists(name));
329 QString name(dbname);
333 return (QSqlDatabase::contains(name));
372 const QString &dbname) {
377 QString mess =
"Driver [" + driver +
"] for database [" + dbname
378 +
"] does not exist";
384 return (QSqlDatabase::addDatabase(drivers.
get(driver), dbname));
406 QString mess =
"Database [" + dbname +
"] does not exist";
450 QSqlDatabase::removeDatabase(name);
500 Preference &userPref = Preference::Preferences();
533 if(drivers) dblist += QSqlDatabase::drivers();
534 if(connections) dblist += QSqlDatabase::connectionNames();
536 for(
int i = 0 ; i < dblist.size() ; i++) {
537 QString dbname(dblist.at(i));
538 dbDrivers.
add(dbname, dbname);
544 if(dbDrivers.
exists(
"QPSQL")) {
545 dbDrivers.
add(
"PostgreSQL",
"QPSQL");
549 if(dbDrivers.
exists(
"QMYSQL")) {
550 dbDrivers.
add(
"MySQL",
"QMYSQL");
554 if(dbDrivers.
exists(
"QOCI")) {
555 dbDrivers.
add(
"Oracle",
"QOCI");
559 if(dbDrivers.
exists(
"QSQLITE")) {
560 dbDrivers.
add(
"SQLite",
"QSQLITE");
578 QSqlDatabase::drivers();
593 QStringList dblist = QSqlDatabase::connectionNames();
594 for(
int i = 0 ; i < dblist.size() ; i++) {
595 QSqlDatabase::removeDatabase(dblist[i]);
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Drivers getResourceList(bool drivers, bool connections) const
Get a list of available database drivers and connections.
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.
File name manipulation and expansion.
std::vector< QString > available() const
Determine what database drivers are available.
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.
int remove(const K &key)
Removes and entry from the list.
Namespace for the standard library.
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
bool exists(const QString &key) const
Checks for the existance of a keyword.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
int size() const
Returns the size of the collection.
Create database interfaces using access profiles or generic drivers.
A DbProfile is a container for access parameters to a 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.
const K & key(int nth) const
Returns the nth key in the collection.
const DbProfile getProfile(const QString &name="") const
Retrieves the specified access profile.
Contains multiple PvlContainers.
bool exists(const K &key) const
Checks the existance of a particular key in the list.
#define _FILEINFO_
Macro for the filename and line number.
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
DatabaseFactory()
Constructor establishing the startup state of this singleton.
void add(const K &key, const T &value)
Adds the element to the list.
A type of error that cannot be classified as any of the other error types.
bool isAvailable(const QString &dbname="") const
Check for availablity of a database connection resource.
QString ToQt() const
Retuns the object string as a QString.
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.
Collector/container for arbitrary items.
int profileCount() const
Reports the number of user profiles to access this database.
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.
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.
bool Equal(const std::string &str) const
Compare a string to the object IString.
DbAccess manages programatic access to a database through profiles.
Namespace for ISIS/Bullet specific routines.
QString Name() const
Returns the name of this property.
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 fileExists() const
Returns true if the file exists; false otherwise.
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.
Reads user preferences from a data file.
QString _defDatabase
Name of default database.