Isis 3 Programmer Reference
|
A DbProfile is a container for access parameters to a database. More...
#include <DbProfile.h>
Public Member Functions | |
DbProfile (const QString &name) | |
DbProfile (const DbProfile &prof1, const DbProfile &prof2, const QString &name="") | |
Creates a profile from the merging of two a DbProfiles. More... | |
DbProfile (PvlContainer &pvl) | |
Creates a DbProfile from a Pvl entity. More... | |
virtual | ~DbProfile () |
Destructor ensures everything is cleaned up properly. More... | |
bool | isValid () const |
Reports if this is a valid profile. More... | |
int | size () const |
Reports the number of keywords in this user profile. More... | |
void | setName (const QString &name) |
Set the name of this profile. More... | |
QString | Name () const |
Returns the name of this property. More... | |
bool | exists (const QString &key) const |
Checks for the existance of a keyword. More... | |
void | add (const QString &key, const QString &value="") |
Adds a keyword and value pair to the profile. More... | |
void | replace (const QString &key, const QString &value="") |
Adds a keyword and value pair to the profile. More... | |
void | remove (const QString &key) |
Removes a keyword from the profile. More... | |
int | count (const QString &key) const |
Report number of values in keyword. More... | |
QString | key (int nth) const |
Returns the nth key in the profile. More... | |
QString | value (const QString &key, int nth=0) const |
Returns the specified value for the given keyword. More... | |
QString | operator() (const QString &key, int nth=0) const |
Returns the specified value for the given keyword. More... | |
Protected Types | |
typedef CollectorMap< IString, PvlKeyword, NoCaseStringCompare > | KeyList |
Protected Member Functions | |
void | loadkeys (PvlContainer &pvl) |
Loads DbProfile keys from the given Pvl construct. More... | |
const KeyList & | getKeyList () const |
Returns a reference to the key list. More... | |
Private Attributes | |
QString | _name |
Name of this profile. More... | |
KeyList | _keys |
List of keys in profile. More... | |
A DbProfile is a container for access parameters to a database.
This class provides a utility for (keyword) parameter management to access a database system. Profiles can be used to specify all parameters necessary to apply to programatic interfaces to database software such as Qt's SQL Module class, QSqlDatabase.
Using QSqlDatabase as an example, keywords such as User, Host, Port, and Dbname can be stored in this object and retrieved easily.
It can be easily adapted to any database software API by externally managing the contents of a configuration file. See DbAccess for additional details on how this scheme can be utilized.
2007-02-15 Kris Becker - Added key() method so one can iterate through all keys in the profile
2007-12-19 Kris Becker - Added getKeyList method for additional flexibility to class developers
2008-03-11 Kris Becker - Added more information to exception caught when attempting to get values from non-existant keys
2008-09-05 Kris Becker - Added the replace and remove methods to the class.
Definition at line 65 of file DbProfile.h.
Isis::DbProfile::DbProfile | ( | const DbProfile & | prof1, |
const DbProfile & | prof2, | ||
const QString & | name = "" |
||
) |
Creates a profile from the merging of two a DbProfiles.
This constructor will create a new DbProfile from two existing DbProfiles. Its intended use is for the merging of keys in an ordered fashion. It is useful when a higher level class inherits this class and a specific implementations calls for the keys to come from both the parent and the child DbProfile.
It should be noted that this is a convenient way to merge high level database access parameters with individual profile access where the last keys take precedence over the first. Thus, in the case where the same keys exist in both the first and second profiles, keys in the second profile take precedence. This is great for defining general database parameters in the top level database configure section and having individual profiles redefine certain access parameters.
name | Name of new profile |
prof1 | First profile to merge |
prof2 | Second profile to merge |
Definition at line 74 of file DbProfile.cpp.
References _keys, _name, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::getNth(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::key(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().
Isis::DbProfile::DbProfile | ( | PvlContainer & | pvl | ) |
Creates a DbProfile from a Pvl entity.
This constructor will create a DbProfile by reading keywords from a Pvl container. Pvl Containers can be an Object or a Group, or simply a list of keywords. This PvlContainer is expected to point to the appropriate keywords that the caller has pre-established by normal Isis Pvl methods.
Definition at line 45 of file DbProfile.cpp.
References _keys, _name, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), loadkeys(), and value().
|
inlinevirtual |
Destructor ensures everything is cleaned up properly.
Definition at line 81 of file DbProfile.h.
void Isis::DbProfile::add | ( | const QString & | key, |
const QString & | value = "" |
||
) |
Adds a keyword and value pair to the profile.
This method adds a keyword and value pair to the profile if it doesn't exist. If the keyword already exists,it appends the value to the existing keyword.
key | Keyword to add or ammend |
value | Value to add to the keyword |
Definition at line 96 of file DbProfile.cpp.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::PvlKeyword::addValue(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and value().
int Isis::DbProfile::count | ( | const QString & | key | ) | const |
Report number of values in keyword.
This method will return the number of values in the specified keyword. If the keyword does not exist, 0 is returned.
key | Name of key to get value count for |
Definition at line 141 of file DbProfile.cpp.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and Isis::PvlKeyword::size().
Referenced by Isis::PhotometricFunction::ConfKey(), Isis::ConfKey(), and Isis::Gruen::ConfKey().
|
inline |
Checks for the existance of a keyword.
key | Name of keyword to check |
Definition at line 129 of file DbProfile.h.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), and key().
Referenced by Isis::DatabaseFactory::addAccessProfile(), Isis::Database::configureAccess(), Isis::PhotometricFunction::ConfKey(), Isis::ConfKey(), Isis::Gruen::ConfKey(), Isis::DbAccess::getDefaultProfileName(), Isis::IsTrueValue(), Isis::Gruen::ParameterKey(), and Isis::ZeroBufferFit::ZeroBufferFit().
|
inlineprotected |
Returns a reference to the key list.
Direct access to the keyword container allows class developers some additional flexibility whilst maintaining integrity through the public interface.
Definition at line 173 of file DbProfile.h.
References _keys.
|
inline |
Reports if this is a valid profile.
A valid profile is simply defined to contain keys. If there are no keys defined for the profile, it is deemed invalid.
Definition at line 91 of file DbProfile.h.
References size().
Referenced by Isis::Database::init().
|
inline |
Returns the nth key in the profile.
This method returns the name of the nth keyword in the profile so one can iterate through all existing keys. Note that database passwords could be vulnerable to exposure via this method.
Keywords in the profile are sorted in alphabetical order and not in the order in which they are read.
nth | Specifies the nth key in the profile |
Out-of-range | exception if the nth keyword does not exist |
Definition at line 155 of file DbProfile.h.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::key(), and Isis::IString::ToQt().
Referenced by add(), count(), exists(), loadkeys(), operator()(), remove(), replace(), and value().
|
protected |
Loads DbProfile keys from the given Pvl construct.
This method iterates through all keywords in the Pvl container and loads them into this property.
pvl | Container of keywords that will be loaded |
Definition at line 198 of file DbProfile.cpp.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::PvlContainer::begin(), Isis::PvlContainer::end(), and key().
Referenced by DbProfile(), and Isis::DbAccess::load().
|
inline |
Returns the name of this property.
Definition at line 118 of file DbProfile.h.
References _name.
Referenced by Isis::DatabaseFactory::addAccessProfile(), Isis::DbAccess::addProfile(), Isis::DatabaseFactory::addProfile(), Isis::DbAccess::getProfile(), Isis::ZeroReverse::init(), Isis::ZeroBufferSmooth::init(), Isis::Database::init(), Isis::Gruen::init(), Isis::DbAccess::load(), and Isis::ZeroBufferFit::ZeroBufferFit().
QString Isis::DbProfile::operator() | ( | const QString & | key, |
int | nth = 0 |
||
) | const |
Returns the specified value for the given keyword.
This method returns a value from the specified keyword. If the keyword or the specified value does not exist, an exception is thrown.
key | Name of keyword to return value for. |
nth | Specifies the nth value in the keyword |
Definition at line 186 of file DbProfile.cpp.
void Isis::DbProfile::remove | ( | const QString & | key | ) |
Removes a keyword from the profile.
key | Keyword to remove |
Definition at line 127 of file DbProfile.cpp.
References _keys, key(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::remove().
void Isis::DbProfile::replace | ( | const QString & | key, |
const QString & | value = "" |
||
) |
Adds a keyword and value pair to the profile.
This method adds a keyword and value pair to the profile if it doesn't exist.
If the keyword already exists, it is deleted and replaced with this new keyword and value.
key | Keyword to replace |
value | Value to add to the keyword |
Definition at line 117 of file DbProfile.cpp.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), key(), and value().
|
inline |
Set the name of this profile.
name | QString used to set the name of this profile |
Definition at line 109 of file DbProfile.h.
References _name.
Referenced by Isis::Gruen::init().
|
inline |
Reports the number of keywords in this user profile.
Definition at line 100 of file DbProfile.h.
References _keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().
Referenced by isValid().
QString Isis::DbProfile::value | ( | const QString & | key, |
int | nth = 0 |
||
) | const |
Returns the specified value for the given keyword.
This method returns a value from the specified keyword. If the keyword or the specified value does not exist, an exception is thrown.
key | Name of keyword to return value for. |
nth | Specifies the nth value in the keyword |
Definition at line 160 of file DbProfile.cpp.
References _FILEINFO_, _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and Isis::IException::Programmer.
Referenced by add(), Isis::DatabaseFactory::addAccessProfile(), Isis::PhotometricFunction::ConfKey(), Isis::ConfKey(), Isis::Gruen::ConfKey(), DbProfile(), Isis::DbAccess::getDefaultProfileName(), operator()(), and replace().
|
private |
List of keys in profile.
Definition at line 179 of file DbProfile.h.
Referenced by add(), count(), DbProfile(), exists(), getKeyList(), key(), loadkeys(), remove(), replace(), size(), and value().
|
private |
Name of this profile.
Definition at line 178 of file DbProfile.h.
Referenced by DbProfile(), Name(), and setName().