Isis 3 Programmer Reference
Isis::DbProfile Class Reference

A DbProfile is a container for access parameters to a database. More...

#include <DbProfile.h>

Inheritance diagram for Isis::DbProfile:
Inheritance graph
Collaboration diagram for Isis::DbProfile:
Collaboration graph

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, NoCaseStringCompareKeyList
 

Protected Member Functions

void loadkeys (PvlContainer &pvl)
 Loads DbProfile keys from the given Pvl construct. More...
 
const KeyListgetKeyList () 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...
 

Detailed Description

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.

Author
2006-11-09 Kris Becker
History:
2007-02-15 Kris Becker - Added key() method so one can iterate through all keys in the profile
History:
2007-12-19 Kris Becker - Added getKeyList method for additional flexibility to class developers
History:
2008-03-11 Kris Becker - Added more information to exception caught when attempting to get values from non-existant keys
History:
2008-09-05 Kris Becker - Added the replace and remove methods to the class.

Definition at line 51 of file DbProfile.h.

Constructor & Destructor Documentation

◆ DbProfile() [1/2]

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.

Parameters
nameName of new profile
prof1First profile to merge
prof2Second profile to merge

Definition at line 60 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().

◆ DbProfile() [2/2]

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.

Parameters
pvlPvl container of keywords to make a DbProfile from

Definition at line 31 of file DbProfile.cpp.

References _keys, _name, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), loadkeys(), and value().

◆ ~DbProfile()

virtual Isis::DbProfile::~DbProfile ( )
inlinevirtual

Destructor ensures everything is cleaned up properly.

Definition at line 67 of file DbProfile.h.

Member Function Documentation

◆ add()

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.

Parameters
keyKeyword to add or ammend
valueValue to add to the keyword

Definition at line 82 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().

◆ count()

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.

Parameters
keyName of key to get value count for
Returns
int Number values in key, or 0 if the key does not exist

Definition at line 127 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::Gruen::ConfKey(), Isis::ConfKey(), and Isis::PhotometricFunction::ConfKey().

◆ exists()

bool Isis::DbProfile::exists ( const QString &  key) const
inline

◆ getKeyList()

const KeyList& Isis::DbProfile::getKeyList ( ) const
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.

Returns
const KeyList& Reference to keyword list

Definition at line 159 of file DbProfile.h.

References _keys.

◆ isValid()

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.

Returns
bool True if the profile is valid, therefore containing keys

Definition at line 77 of file DbProfile.h.

References size().

Referenced by Isis::Database::init().

◆ key()

QString 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.

Parameters
nthSpecifies the nth key in the profile
Returns
QString Name of nth keyword in the profile.
Exceptions
Out-of-rangeexception if the nth keyword does not exist

Definition at line 141 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().

◆ 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.

Parameters
pvlContainer of keywords that will be loaded

Definition at line 184 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().

◆ Name()

◆ operator()()

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.

Parameters
keyName of keyword to return value for.
nthSpecifies the nth value in the keyword
Returns
QString The requested value in the keyword

Definition at line 172 of file DbProfile.cpp.

References key(), and value().

◆ remove()

void Isis::DbProfile::remove ( const QString &  key)

Removes a keyword from the profile.

Parameters
keyKeyword to remove

Definition at line 113 of file DbProfile.cpp.

References _keys, key(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::remove().

◆ replace()

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.

Parameters
keyKeyword to replace
valueValue to add to the keyword

Definition at line 103 of file DbProfile.cpp.

References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), key(), and value().

◆ setName()

void Isis::DbProfile::setName ( const QString &  name)
inline

Set the name of this profile.

Parameters
nameQString used to set the name of this profile

Definition at line 95 of file DbProfile.h.

References _name.

Referenced by Isis::Gruen::init().

◆ size()

int Isis::DbProfile::size ( ) const
inline

Reports the number of keywords in this user profile.

Returns
int Number keywords found in profile

Definition at line 86 of file DbProfile.h.

References _keys, and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().

Referenced by isValid().

◆ value()

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.

Parameters
keyName of keyword to return value for.
nthSpecifies the nth value in the keyword
Returns
QString The requested value in the keyword

Definition at line 146 of file DbProfile.cpp.

References _keys, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and Isis::IException::Programmer.

Referenced by add(), Isis::DatabaseFactory::addAccessProfile(), Isis::Gruen::ConfKey(), Isis::ConfKey(), Isis::PhotometricFunction::ConfKey(), DbProfile(), Isis::DbAccess::getDefaultProfileName(), operator()(), and replace().

Member Data Documentation

◆ _keys

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().

◆ _name

QString Isis::DbProfile::_name
private

Name of this profile.

Definition at line 164 of file DbProfile.h.

Referenced by DbProfile(), Name(), and setName().


The documentation for this class was generated from the following files: