Isis 3 Programmer Reference
|
DbAccess manages programatic access to a database through profiles. More...
#include <DbAccess.h>
Public Member Functions | |
DbAccess (const QString &dbaccFile, const QString &defProfileName="") | |
Construct with a given database access configuration file. More... | |
DbAccess (PvlObject &pvl, const QString &defProfileName="") | |
Constructor that accepts a Database Pvl Object. More... | |
virtual | ~DbAccess () |
Destructor ensures everything is cleaned up properly. More... | |
int | profileCount () const |
Reports the number of user profiles to access this database. More... | |
bool | profileExists (const QString &profile) const |
Checks existance of a database user profile. More... | |
const DbProfile | getProfile (const QString &name="") const |
Retrieves the specified access profile. More... | |
const DbProfile | getProfile (int nth) const |
Returns the nth specified DbProfile in the list. More... | |
void | addProfile (const DbProfile &profile) |
Adds a profile to the database profile. More... | |
void | load (const QString &filename) |
Loads a Database access configuration file. More... | |
void | load (PvlObject &pvl) |
Load a database access profile configuration from a PvlObject. More... | |
QString | getDefaultProfileName () const |
Determine the name of the default profile. 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 Types | |
typedef CollectorMap< IString, DbProfile, NoCaseStringCompare > | ProfileList |
Define the container for the DbAccess key word list. More... | |
Private Attributes | |
QString | _defProfileName |
Name of default profile. More... | |
ProfileList | _profiles |
List of profiles. More... | |
QString | _name |
Name of this profile. More... | |
KeyList | _keys |
List of keys in profile. More... | |
DbAccess manages programatic access to a database through profiles.
This class reads a Pvl formatted file and constructs access profiles on the fly from the contents. It is intended to specify any and all information sufficient to establish a database connection in software applications.
The input file to this class is typically created with an editor. It can contain any keyword = value combination. It must contain a Database object and may optionally contain Profile groups. The Database object can contain kewords such as User, Host, DbName, and so forth. Here is an example of what the file, named upc.conf, of this type would look like:
The code used to load and access this profile is:
Additionally, you can add specific profiles that alter some or all of the parameters contained in the Object section of the file. Simply add one or more Profile groups that grant or specify different access profiles for the given database. For example the example below names the Profile "upcread" and adds an additional user and password to the profile.
To access this profile, use:
It will look for the Name keyword as the specifed named profile. What actually happens when the above code is invoked is all the keywords contained in the Database object, such as Dbname, Type, as well as Name are copied to a new dynamic profile named "upcread". Then any keywords found in the actual Profile group with Name = "upcread" are copied to the newly created dynamic one replacing any existing keywords with the ones found in the requested Profile. This ensures precedence is given to requested profiles and common parameters in the Database object are retained.
Definition at line 106 of file DbAccess.h.
|
private |
Define the container for the DbAccess key word list.
Definition at line 110 of file DbAccess.h.
Isis::DbAccess::DbAccess | ( | const QString & | dbaccFile, |
const QString & | defProfileName = "" |
||
) |
Construct with a given database access configuration file.
This constructor accepts the name of a Pvl formatted file that must contain a object named Database. It loads keywords in the order they occur in the object. Keywords should be unique - if not, previous keywords are silently replaced by subsequent occuring keywords.
Then all groups named Profile are loaded and established as additional, distinct access profiles. They all should have unique names. Subsequent profiles with the same name are replaced.
The caller may additionally provide the name of the default profile to use when none is given. If one is not provided, then should a keyword called DefaultProfile is searched for and the value of this keyword serves as the default profile. See the getProfile() method for details on how this situation is resolved.
dbaccFile | Name of a Pvl formatted file containing the access specifications for a database |
defProfileName | Optional name of the default access profile |
Definition at line 46 of file DbAccess.cpp.
References load().
Isis::DbAccess::DbAccess | ( | PvlObject & | pvl, |
const QString & | defProfileName = "" |
||
) |
Constructor that accepts a Database Pvl Object.
The functionality of this constructor is exactly the same as file constructor except with a PvObject named "Database" as an argument.
pvl | A Database PvlObject containing access information |
defProfileName | Optional name of the default profile |
Definition at line 62 of file DbAccess.cpp.
References load().
|
inlinevirtual |
Destructor ensures everything is cleaned up properly.
Definition at line 120 of file DbAccess.h.
|
inherited |
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 82 of file DbProfile.cpp.
References Isis::DbProfile::_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(), Isis::DbProfile::key(), and Isis::DbProfile::value().
|
inline |
Adds a profile to the database profile.
Inheritors may add profiles to the user profile list. Note that duplicate profiles are not allowed, therefore existing profiles with the same name is replaced.
profile | Profile to add |
Definition at line 155 of file DbAccess.h.
References _profiles, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), and Isis::DbProfile::Name().
|
inherited |
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 127 of file DbProfile.cpp.
References Isis::DbProfile::_keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), Isis::DbProfile::key(), and Isis::PvlKeyword::size().
Referenced by Isis::Gruen::ConfKey(), Isis::ConfKey(), and Isis::PhotometricFunction::ConfKey().
|
inlineinherited |
Checks for the existance of a keyword.
key | Name of keyword to check |
Definition at line 115 of file DbProfile.h.
References Isis::DbProfile::_keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), and Isis::DbProfile::key().
Referenced by Isis::DatabaseFactory::addAccessProfile(), Isis::Database::configureAccess(), Isis::Gruen::ConfKey(), Isis::ConfKey(), Isis::PhotometricFunction::ConfKey(), getDefaultProfileName(), Isis::IsTrueValue(), Isis::Gruen::ParameterKey(), and Isis::ZeroBufferFit::ZeroBufferFit().
QString Isis::DbAccess::getDefaultProfileName | ( | ) | const |
Determine the name of the default profile.
This method is called to determine the real name of the default profile as predetermined at load time. This determination is made either through the default specified in the configuration Database object, the DefaultProfile keyword, or provided by the application progirammer in the constructor.
Definition at line 189 of file DbAccess.cpp.
References _defProfileName, Isis::DbProfile::exists(), and Isis::DbProfile::value().
Referenced by getProfile().
|
inlineprotectedinherited |
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 159 of file DbProfile.h.
References Isis::DbProfile::_keys.
const DbProfile Isis::DbAccess::getProfile | ( | const QString & | name = "" | ) | const |
Retrieves the specified access profile.
This method retrieves the named profile. If no name is provided, the default profile is returned.
There are two ways to specify the default. The first source of a named default comes from within the configuration file. A keyword specified in the Database object section named DefaultProfile can specify a named profile, the value of the Name keyword in a Profile group. The second source comes from the application programmer. In the constructor call to this object, the application programmer can provide a named profile as the default, which could ultimately come from the user (interface).
If no default is specified, then only the keywords contained in the Database object section of the configuration file is returned when requesting an unnamed profile.
name | Optional name of the profile to return |
Definition at line 92 of file DbAccess.cpp.
References _profiles, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), and getDefaultProfileName().
Referenced by Isis::DatabaseFactory::addAccessProfile(), and Isis::ZeroReverse::init().
const DbProfile Isis::DbAccess::getProfile | ( | int | nth | ) | const |
Returns the nth specified DbProfile in the list.
This method allows user to iterate through the list of DbProfiles in this access scheme. If the caller provides an index that exceeds the number contained, an exception is thrown. Use profileCount() to determine the number of profiles.
nth | Zero-based index of profile to return |
Definition at line 126 of file DbAccess.cpp.
References _profiles, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::getNth(), and Isis::DbProfile::Name().
|
inlineinherited |
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 77 of file DbProfile.h.
References Isis::DbProfile::size().
Referenced by Isis::Database::init().
|
inlineinherited |
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 141 of file DbProfile.h.
References Isis::DbProfile::_keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::key(), and Isis::IString::ToQt().
Referenced by Isis::DbProfile::add(), Isis::DbProfile::count(), Isis::DbProfile::exists(), Isis::DbProfile::loadkeys(), Isis::DbProfile::operator()(), Isis::DbProfile::remove(), Isis::DbProfile::replace(), and Isis::DbProfile::value().
void Isis::DbAccess::load | ( | const QString & | filename | ) |
Loads a Database access configuration file.
Given the name of a file, it will open the file using Isis Pvl classes. See the load(pvl) class for additonal information what takes place in this method.
Note the file may use environment variables.
filename | Name of Pvl file to open. |
Definition at line 142 of file DbAccess.cpp.
References Isis::PvlObject::findObject().
Referenced by DbAccess().
void Isis::DbAccess::load | ( | PvlObject & | pvl | ) |
Load a database access profile configuration from a PvlObject.
This method loads all keywords found in the Object section of the PvlObject and then searches for each Group named Profile. Profile groups contain augmentations to the object keywords to add to or replace object level access specifications. Each profile group must contain a Name keyword to uniquely identify the (group) access parameters.
Profiles are loaded and stored in this object for subsequent access.
pvl | A PvlObject that contains keywords and option Profile groups. |
Definition at line 161 of file DbAccess.cpp.
References _profiles, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::PvlObject::beginGroup(), Isis::PvlObject::endGroup(), Isis::PvlObject::findGroup(), Isis::DbProfile::loadkeys(), and Isis::DbProfile::Name().
|
protectedinherited |
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 184 of file DbProfile.cpp.
References Isis::DbProfile::_keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::PvlContainer::begin(), Isis::PvlContainer::end(), and Isis::DbProfile::key().
Referenced by Isis::DbProfile::DbProfile(), and load().
|
inlineinherited |
Returns the name of this property.
Definition at line 104 of file DbProfile.h.
References Isis::DbProfile::_name.
Referenced by Isis::DatabaseFactory::addAccessProfile(), Isis::DatabaseFactory::addProfile(), addProfile(), getProfile(), Isis::Database::init(), Isis::ZeroBufferSmooth::init(), Isis::ZeroReverse::init(), Isis::Gruen::init(), load(), and Isis::ZeroBufferFit::ZeroBufferFit().
|
inherited |
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 172 of file DbProfile.cpp.
References Isis::DbProfile::key(), and Isis::DbProfile::value().
|
inline |
Reports the number of user profiles to access this database.
Definition at line 127 of file DbAccess.h.
References _profiles, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().
Referenced by Isis::DatabaseFactory::addAccessProfile().
|
inline |
Checks existance of a database user profile.
profile | Name of profile to check for existance |
Definition at line 138 of file DbAccess.h.
References _profiles, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists().
Referenced by Isis::ZeroReverse::init().
|
inherited |
Removes a keyword from the profile.
key | Keyword to remove |
Definition at line 113 of file DbProfile.cpp.
References Isis::DbProfile::_keys, Isis::DbProfile::key(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::remove().
|
inherited |
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 103 of file DbProfile.cpp.
References Isis::DbProfile::_keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::DbProfile::key(), and Isis::DbProfile::value().
|
inlineinherited |
Set the name of this profile.
name | QString used to set the name of this profile |
Definition at line 95 of file DbProfile.h.
References Isis::DbProfile::_name.
Referenced by Isis::Gruen::init().
|
inlineinherited |
Reports the number of keywords in this user profile.
Definition at line 86 of file DbProfile.h.
References Isis::DbProfile::_keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().
Referenced by Isis::DbProfile::isValid().
|
inherited |
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 146 of file DbProfile.cpp.
References Isis::DbProfile::_keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), Isis::DbProfile::key(), and Isis::IException::Programmer.
Referenced by Isis::DbProfile::add(), Isis::DatabaseFactory::addAccessProfile(), Isis::Gruen::ConfKey(), Isis::ConfKey(), Isis::PhotometricFunction::ConfKey(), Isis::DbProfile::DbProfile(), getDefaultProfileName(), Isis::DbProfile::operator()(), and Isis::DbProfile::replace().
|
private |
Name of default profile.
Definition at line 165 of file DbAccess.h.
Referenced by getDefaultProfileName().
|
privateinherited |
List of keys in profile.
Definition at line 165 of file DbProfile.h.
Referenced by Isis::DbProfile::add(), Isis::DbProfile::count(), Isis::DbProfile::DbProfile(), Isis::DbProfile::exists(), Isis::DbProfile::getKeyList(), Isis::DbProfile::key(), Isis::DbProfile::loadkeys(), Isis::DbProfile::remove(), Isis::DbProfile::replace(), Isis::DbProfile::size(), and Isis::DbProfile::value().
|
privateinherited |
Name of this profile.
Definition at line 164 of file DbProfile.h.
Referenced by Isis::DbProfile::DbProfile(), Isis::DbProfile::Name(), and Isis::DbProfile::setName().
|
private |
List of profiles.
Definition at line 166 of file DbAccess.h.
Referenced by addProfile(), getProfile(), load(), profileCount(), and profileExists().