Isis 3 Developer Reference
|
A DbProfile is a container for access parameters to a database. More...
#include <DbProfile.h>
Public Member Functions | |
DbProfile () | |
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... | |
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.
|
protected |
|
inline |
Referenced by Isis::DbAccess::getProfile().
|
inline |
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 |
References 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.
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), loadkeys(), and value().
|
inlinevirtual |
Destructor ensures everything is cleaned up properly.
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 |
References 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 |
References 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(), and Isis::ConfKey().
|
inline |
Checks for the existance of a keyword.
key | Name of keyword to check |
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), and key().
Referenced by Isis::DatabaseFactory::addAccessProfile(), Isis::Database::configureAccess(), Isis::PhotometricFunction::ConfKey(), Isis::ConfKey(), Isis::DbAccess::getDefaultProfileName(), Isis::IsTrueValue(), Isis::LoadCSV::load(), 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.
|
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.
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 |
References 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 |
References 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.
Referenced by Isis::DatabaseFactory::addAccessProfile(), Isis::DbAccess::addProfile(), Isis::DatabaseFactory::addProfile(), Isis::DbAccess::getProfile(), Isis::Database::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 |
void Isis::DbProfile::remove | ( | const QString & | key | ) |
Removes a keyword from the profile.
key | Keyword to remove |
References 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 |
References 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 |
|
inline |
Reports the number of keywords in this user profile.
References 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 |
References _FILEINFO_, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and Isis::IException::Programmer.
Referenced by add(), Isis::DatabaseFactory::addAccessProfile(), Isis::PhotometricFunction::ConfKey(), Isis::ConfKey(), DbProfile(), Isis::DbAccess::getDefaultProfileName(), operator()(), and replace().