Isis Developer Reference
|
DbAccess manages programatic access to a database through profiles. More...
#include <DbAccess.h>
Public Member Functions | |
DbAccess () | |
DbAccess (const QString &dbaccFile, const QString &defProfileName="") | |
Construct with a given database access configuration file. | |
DbAccess (PvlObject &pvl, const QString &defProfileName="") | |
Constructor that accepts a Database Pvl Object. | |
virtual | ~DbAccess () |
Destructor ensures everything is cleaned up properly. | |
int | profileCount () const |
Reports the number of user profiles to access this database. | |
bool | profileExists (const QString &profile) const |
Checks existance of a database user profile. | |
const DbProfile | getProfile (const QString &name="") const |
Retrieves the specified access profile. | |
const DbProfile | getProfile (int nth) const |
Returns the nth specified DbProfile in the list. | |
void | addProfile (const DbProfile &profile) |
Adds a profile to the database profile. | |
void | load (const QString &filename) |
Loads a Database access configuration file. | |
void | load (PvlObject &pvl) |
Load a database access profile configuration from a PvlObject. | |
QString | getDefaultProfileName () const |
Determine the name of the default profile. | |
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 QString &name) |
Set the name of this profile. | |
QString | Name () const |
Returns the name of this property. | |
bool | exists (const QString &key) const |
Checks for the existance of a keyword. | |
void | add (const QString &key, const QString &value="") |
Adds a keyword and value pair to the profile. | |
void | replace (const QString &key, const QString &value="") |
Adds a keyword and value pair to the profile. | |
void | remove (const QString &key) |
Removes a keyword from the profile. | |
int | count (const QString &key) const |
Report number of values in keyword. | |
QString | key (int nth) const |
Returns the nth key in the profile. | |
QString | value (const QString &key, int nth=0) const |
Returns the specified value for the given keyword. | |
QString | operator() (const QString &key, int nth=0) const |
Returns the specified value for the given keyword. | |
Protected Types | |
typedef CollectorMap< IString, 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. | |
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.
|
protectedinherited |
|
inline |
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 |
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 |
References load().
|
inlinevirtual |
Destructor ensures everything is cleaned up properly.
|
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 |
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(), Isis::DbProfile::key(), and Isis::DbProfile::value().
Referenced by Isis::DatabaseFactory::addAccessProfile().
|
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 |
References 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 |
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), Isis::DbProfile::key(), and Isis::PvlKeyword::size().
|
inlineinherited |
Checks for the existance of a keyword.
key | Name of keyword to check |
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), and Isis::DbProfile::key().
Referenced by Isis::Database::configureAccess(), getDefaultProfileName(), and Isis::LoadCSV::load().
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.
References 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.
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 |
References Isis::DbProfile::DbProfile(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), and getDefaultProfileName().
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 |
References Isis::DbProfile::DbProfile(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::getNth().
|
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.
References Isis::DbProfile::size().
Referenced by Isis::Database::init(), and 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 |
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::key().
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. |
References Isis::PvlObject::findObject(), and load().
Referenced by DbAccess(), DbAccess(), and load().
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. |
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), and Isis::DbProfile::loadkeys().
|
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 |
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), and Isis::DbProfile::key().
Referenced by Isis::DbProfile::DbProfile(), and load().
|
inlineinherited |
Returns the name of this property.
Referenced by Isis::DatabaseFactory::addProfile(), addProfile(), and Isis::Database::init().
|
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 |
References Isis::DbProfile::key(), and Isis::DbProfile::value().
|
inline |
Reports the number of user profiles to access this database.
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().
|
inline |
Checks existance of a database user profile.
profile | Name of profile to check for existance |
References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists().
|
inherited |
Removes a keyword from the profile.
key | Keyword to remove |
References 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 |
References 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 |
|
inlineinherited |
Reports the number of keywords in this user profile.
References 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 |
References _FILEINFO_, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), Isis::DbProfile::key(), and Isis::IException::Programmer.
Referenced by Isis::DbProfile::add(), Isis::DbProfile::DbProfile(), getDefaultProfileName(), Isis::DbProfile::operator()(), and Isis::DbProfile::replace().