Kea  1.5.0
isc::db::DatabaseConnection Class Reference

Common database connection class. More...

#include <database_connection.h>

+ Inheritance diagram for isc::db::DatabaseConnection:

Public Types

typedef boost::function< bool(ReconnectCtlPtr db_retry)> DbLostCallback
 Defines a callback prototype for propogating events upward. More...
 
typedef std::map< std::string, std::string > ParameterMap
 Database configuration parameter map. More...
 

Public Member Functions

 DatabaseConnection (const ParameterMap &parameters)
 Constructor. More...
 
virtual ~DatabaseConnection ()
 Destructor. More...
 
bool configuredReadOnly () const
 Convenience method checking if database should be opened with read only access. More...
 
std::string getParameter (const std::string &name) const
 Returns value of a connection parameter. More...
 
bool invokeDbLostCallback () const
 Invokes the connection's lost connectivity callback. More...
 
virtual ReconnectCtlPtr makeReconnectCtl () const
 Instantiates a ReconnectCtl based on the connection's reconnect parameters. More...
 

Static Public Member Functions

static ParameterMap parse (const std::string &dbaccess)
 Parse database access string. More...
 
static std::string redactedAccessString (const ParameterMap &parameters)
 Redact database access string. More...
 
static isc::data::ElementPtr toElement (const ParameterMap &params)
 Unparse a parameter map. More...
 
static isc::data::ElementPtr toElementDbAccessString (const std::string &dbaccess)
 Unparse an access string. More...
 

Static Public Attributes

static DbLostCallback db_lost_callback = 0
 Optional call back function to invoke if a successfully open connection subsequently fails. More...
 
static const time_t MAX_DB_TIME = 2147483647
 Defines maximum value for time that can be reliably stored. More...
 

Detailed Description

Common database connection class.

This class provides functions that are common for establishing connection with different types of databases; enables operations on access parameters strings. In particular, it provides a way to parse parameters in key=value format. This class is expected to be a base class for all isc::dhcp::LeaseMgr and possibly isc::dhcp::BaseHostDataSource derived classes.

Definition at line 140 of file database_connection.h.

Member Typedef Documentation

◆ DbLostCallback

typedef boost::function<bool (ReconnectCtlPtr db_retry)> isc::db::DatabaseConnection::DbLostCallback

Defines a callback prototype for propogating events upward.

Definition at line 206 of file database_connection.h.

◆ ParameterMap

typedef std::map<std::string, std::string> isc::db::DatabaseConnection::ParameterMap

Database configuration parameter map.

Definition at line 152 of file database_connection.h.

Constructor & Destructor Documentation

◆ DatabaseConnection()

isc::db::DatabaseConnection::DatabaseConnection ( const ParameterMap parameters)
inline

Constructor.

Parameters
parametersA data structure relating keywords and values concerned with the database.

Definition at line 158 of file database_connection.h.

◆ ~DatabaseConnection()

virtual isc::db::DatabaseConnection::~DatabaseConnection ( )
inlinevirtual

Destructor.

Definition at line 163 of file database_connection.h.

Member Function Documentation

◆ configuredReadOnly()

bool isc::db::DatabaseConnection::configuredReadOnly ( ) const

Convenience method checking if database should be opened with read only access.

Returns
true if "readonly" parameter is specified and set to true; false if "readonly" parameter is not specified or it is specified and set to false.

Definition at line 95 of file database_connection.cc.

References isc_throw.

Referenced by isc::dhcp::MySqlHostDataSourceImpl::MySqlHostDataSourceImpl(), and isc::dhcp::PgSqlHostDataSourceImpl::PgSqlHostDataSourceImpl().

◆ getParameter()

std::string isc::db::DatabaseConnection::getParameter ( const std::string &  name) const

◆ invokeDbLostCallback()

bool isc::db::DatabaseConnection::invokeDbLostCallback ( ) const

Invokes the connection's lost connectivity callback.

This function may be called by derivations when the connectivity to their data server is lost. If connectivity callback was specified, this function will instantiate a ReconnectCtl and pass it to the callback.

Returns
Returns the result of the callback or false if there is no callback.

Definition at line 147 of file database_connection.cc.

Referenced by isc::db::MySqlConnection::checkError(), and isc::db::PgSqlConnection::checkStatementError().

◆ makeReconnectCtl()

ReconnectCtlPtr isc::db::DatabaseConnection::makeReconnectCtl ( ) const
virtual

Instantiates a ReconnectCtl based on the connection's reconnect parameters.

Returns
pointer to the new ReconnectCtl object

Definition at line 114 of file database_connection.cc.

◆ parse()

DatabaseConnection::ParameterMap isc::db::DatabaseConnection::parse ( const std::string &  dbaccess)
static

Parse database access string.

Parses the string of "keyword=value" pairs and separates them out into the map.

Parameters
dbaccessDatabase access string.
Returns
ParameterMap of keyword/value pairs.

Definition at line 37 of file database_connection.cc.

References isc::db::DB_INVALID_ACCESS, DB_LOG_ERROR, isc_throw, and isc::util::str::tokens().

Referenced by isc::dhcp::HostDataSourceFactory::add(), isc::cb::BaseConfigBackendMgr< ConfigBackendPoolDHCPv4 >::addBackend(), isc::dhcp::LeaseMgrFactory::create(), and isc::process::ConfigDbInfo::setAccessString().

+ Here is the call graph for this function:

◆ redactedAccessString()

std::string isc::db::DatabaseConnection::redactedAccessString ( const ParameterMap parameters)
static

Redact database access string.

Takes the database parameters and returns a database access string passwords replaced by asterisks. This string is used in log messages.

Parameters
parametersDatabase access parameters (output of "parse").
Returns
Redacted database access string.

Definition at line 66 of file database_connection.cc.

Referenced by isc::dhcp::LeaseMgrFactory::create(), and isc::process::ConfigDbInfo::redactedAccessString().

◆ toElement()

isc::data::ElementPtr isc::db::DatabaseConnection::toElement ( const ParameterMap params)
static

Unparse a parameter map.

Parameters
paramsthe parameter map to unparse
Returns
a pointer to configuration

Definition at line 157 of file database_connection.cc.

References isc::data::Element::create(), isc::data::Element::createMap(), isc::db::database_logger, and LOG_ERROR.

+ Here is the call graph for this function:

◆ toElementDbAccessString()

isc::data::ElementPtr isc::db::DatabaseConnection::toElementDbAccessString ( const std::string &  dbaccess)
static

Unparse an access string.

Parameters
dbaccessthe database access string
Returns
a pointer to configuration

Definition at line 211 of file database_connection.cc.

Referenced by isc::process::ConfigDbInfo::toElement(), isc::dhcp::CfgLeaseDbAccess::toElement(), and isc::dhcp::CfgHostDbAccess::toElement().

Member Data Documentation

◆ db_lost_callback

DatabaseConnection::DbLostCallback isc::db::DatabaseConnection::db_lost_callback = 0
static

Optional call back function to invoke if a successfully open connection subsequently fails.

Definition at line 233 of file database_connection.h.

◆ MAX_DB_TIME

const time_t isc::db::DatabaseConnection::MAX_DB_TIME = 2147483647
static

Defines maximum value for time that can be reliably stored.

Todo:
: Is this common for MySQL and Postgres? Maybe we should have specific values for each backend?

If I'm still alive I'll be too old to care. You fix it.

Definition at line 149 of file database_connection.h.

Referenced by isc::db::CqlExchange::convertToDatabaseTime(), and isc::db::PgSqlExchange::convertToDatabaseTime().


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