|
Isis 3.0 Developer's Reference (API) |
Home |
00001 #ifndef DatabaseFactory_h 00002 #define DatabaseFactory_h 00003 00026 #include <string> 00027 #include <vector> 00028 #include <iostream> 00029 00030 #include <QSqlDatabase> 00031 00032 #include "CollectorMap.h" 00033 #include "IException.h" 00034 00035 namespace Isis { 00036 00037 class DbAccess; 00038 class DbProfile; 00039 00258 class DatabaseFactory { 00259 public: 00260 static DatabaseFactory *getInstance(); 00261 00272 void setDefault(const QString &name) { 00273 _defDatabase = name; 00274 } 00275 00285 QString getDefault() const { 00286 return (_defDatabase); 00287 } 00288 00289 bool addAccessProfile(const QString &profileFile); 00290 void addProfile(const DbProfile &profile); 00291 std::vector<QString> getProfileList() const; 00292 DbProfile getProfile(const QString &name = "") const; 00293 00303 QString getDefaultProfileName() const { 00304 return (_defProfName); 00305 } 00306 00318 bool setDefaultProfileName(const QString &name) { 00319 _defProfName = name; 00320 return (_profiles.exists(name)); 00321 } 00322 00323 std::vector<QString> available() const; 00324 bool isDriverAvailable(const QString &driver) const; 00325 bool isAvailable(const QString &dbname = "") const; 00326 bool isConnected(const QString &dbname) const; 00327 bool isPersistant(const QString &name) const; 00328 00329 QSqlDatabase create(const QString &driver, const QString &dbname); 00330 QSqlDatabase create(const QString &name); 00331 void add(const QSqlDatabase &db, const QString &name, 00332 bool setAsDefault = false); 00333 void remove(const QString &dbname); 00334 void destroy(const QString &dbname); 00335 00336 private: 00337 // Gain access through Singleton interface 00338 DatabaseFactory(); 00339 ~DatabaseFactory(); 00340 00341 static void DieAtExit(); 00342 00343 static DatabaseFactory *_factory; 00344 00346 typedef CollectorMap<IString, QString, NoCaseStringCompare> Drivers; 00348 typedef CollectorMap<IString, DbProfile, NoCaseStringCompare> Profiles; 00350 typedef CollectorMap<IString, QSqlDatabase, NoCaseStringCompare> Databases; 00351 00352 QString _defProfName; 00353 Profiles _profiles; 00354 QString _defDatabase; 00355 Databases _dbList; 00356 00357 void init(); 00358 void initPreferences(); 00359 void loadDrivers(); 00360 Drivers getResourceList(bool drivers, bool connections) const; 00361 void selfDestruct(); 00362 00363 }; 00364 } 00365 #endif 00366 00367 00368