|
Isis 3.0 Object Programmers' Reference |
Home |
#include <DbProfile.h>
Inheritance diagram for Isis::DbProfile:


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.
For internal use only.
Definition at line 65 of file DbProfile.h.
Public Member Functions | |
| DbProfile () | |
| DbProfile (const std::string &name) | |
| DbProfile (const DbProfile &prof1, const DbProfile &prof2, const std::string &name="") | |
| Creates a profile from the merging of two a DbProfiles. | |
| DbProfile (PvlContainer &pvl) | |
| Creates a DbProfile from a Pvl entity. | |
| virtual | ~DbProfile () |
| Destructor ensures everything is cleaned up properly. | |
| bool | isValid () const |
| Reports if this is a valid profile. | |
| int | size () const |
| Reports the number of keywords in this user profile. | |
| void | setName (const std::string &name) |
| Set the name of this profile. | |
| std::string | Name () const |
| Returns the name of this property. | |
| bool | exists (const std::string &key) const |
| Checks for the existance of a keyword. | |
| void | add (const std::string &key, const std::string &value="") |
| Adds a keyword and value pair to the profile. | |
| void | replace (const std::string &key, const std::string &value="") |
| Adds a keyword and value pair to the profile. | |
| void | remove (const std::string &key) |
| Removes a keyword from the profile. | |
| int | count (const std::string &key) const |
| Report number of values in keyword. | |
| std::string | key (int nth) const |
| Returns the nth key in the profile. | |
| std::string | value (const std::string &key, int nth=0) const |
| Returns the specified value for the given keyword. | |
| std::string | operator() (const std::string &key, int nth=0) const |
| Returns the specified value for the given keyword. | |
Protected Types | |
|
typedef CollectorMap< std::string, PvlKeyword, NoCaseStringCompare > | KeyList |
Protected Member Functions | |
| void | loadkeys (PvlContainer &pvl) |
| Loads DbProfile keys from the given Pvl construct. | |
| const KeyList & | getKeyList () const |
| Returns a reference to the key list. | |
Private Attributes | |
| std::string | _name |
| Name of this profile. | |
| KeyList | _keys |
| List of keys in profile. | |
| Isis::DbProfile::DbProfile | ( | const DbProfile & | prof1, | |
| const DbProfile & | prof2, | |||
| const std::string & | 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 75 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 46 of file DbProfile.cpp.
References _keys, _name, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), loadkeys(), pvl(), and value().
| virtual Isis::DbProfile::~DbProfile | ( | ) | [inline, virtual] |
| void Isis::DbProfile::add | ( | const std::string & | key, | |
| const std::string & | 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 95 of file DbProfile.cpp.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get().
| int Isis::DbProfile::count | ( | const std::string & | 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 140 of file DbProfile.cpp.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get().
Referenced by Isis::Gruen::ConfKey().
| bool Isis::DbProfile::exists | ( | const std::string & | key | ) | const [inline] |
Checks for the existance of a keyword.
| key | Name of keyword to check |
Definition at line 121 of file DbProfile.h.
References _keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists().
Referenced by Isis::Database::configureAccess(), Isis::Gruen::ConfKey(), Isis::DbAccess::getDefaultProfileName(), and Isis::Gruen::ParameterKey().
| const KeyList& Isis::DbProfile::getKeyList | ( | ) | const [inline, protected] |
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 161 of file DbProfile.h.
References _keys.
| bool Isis::DbProfile::isValid | ( | ) | const [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().
| std::string Isis::DbProfile::key | ( | int | nth | ) | const [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 145 of file DbProfile.h.
References _keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::key().
Referenced by loadkeys().
| void Isis::DbProfile::loadkeys | ( | PvlContainer & | pvl | ) | [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 197 of file DbProfile.cpp.
References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::PvlContainer::Begin(), Isis::PvlContainer::End(), key(), and pvl().
Referenced by DbProfile(), and Isis::DbAccess::load().
| std::string Isis::DbProfile::Name | ( | ) | const [inline] |
Returns the name of this property.
Definition at line 112 of file DbProfile.h.
References _name.
Referenced by Isis::DatabaseFactory::addAccessProfile(), Isis::DatabaseFactory::addProfile(), Isis::DbAccess::getProfile(), Isis::Database::init(), and Isis::Gruen::init().
| std::string Isis::DbProfile::operator() | ( | const std::string & | 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 185 of file DbProfile.cpp.
References value().
| void Isis::DbProfile::remove | ( | const std::string & | key | ) |
Removes a keyword from the profile.
| key | Keyword to remove |
Definition at line 126 of file DbProfile.cpp.
References _keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::remove().
| void Isis::DbProfile::replace | ( | const std::string & | key, | |
| const std::string & | 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 116 of file DbProfile.cpp.
References _keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add().
| void Isis::DbProfile::setName | ( | const std::string & | name | ) | [inline] |
Set the name of this profile.
| name | iString used to set the name of this profile |
Definition at line 105 of file DbProfile.h.
References _name.
Referenced by Isis::Gruen::init().
| int Isis::DbProfile::size | ( | ) | const [inline] |
Reports the number of keywords in this user profile.
Definition at line 98 of file DbProfile.h.
References _keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().
Referenced by isValid().
| std::string Isis::DbProfile::value | ( | const std::string & | 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 159 of file DbProfile.cpp.
References _FILEINFO_, _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), and Isis::iException::Message().
Referenced by Isis::Gruen::ConfKey(), DbProfile(), Isis::DbAccess::getDefaultProfileName(), and operator()().
KeyList Isis::DbProfile::_keys [private] |
List of keys in profile.
Definition at line 165 of file DbProfile.h.
Referenced by add(), count(), DbProfile(), exists(), getKeyList(), key(), loadkeys(), remove(), replace(), size(), and value().
std::string Isis::DbProfile::_name [private] |
Name of this profile.
Definition at line 164 of file DbProfile.h.
Referenced by DbProfile(), Name(), and setName().