Kea  1.5.0
isc::dhcp::PgSqlHostDataSourceImpl Class Reference

Implementation of the PgSqlHostDataSource. More...

Public Types

enum  StatementIndex {
  GET_HOST_DHCPID, GET_HOST_ADDR, GET_HOST_SUBID4_DHCPID, GET_HOST_SUBID6_DHCPID,
  GET_HOST_SUBID_ADDR, GET_HOST_PREFIX, GET_HOST_SUBID6_ADDR, INSERT_HOST,
  INSERT_V6_RESRV, INSERT_V4_HOST_OPTION, INSERT_V6_HOST_OPTION, DEL_HOST_ADDR4,
  DEL_HOST_SUBID4_ID, DEL_HOST_SUBID6_ID, NUM_STATEMENTS
}
 Statement Tags. More...
 

Public Member Functions

 PgSqlHostDataSourceImpl (const PgSqlConnection::ParameterMap &parameters)
 Constructor. More...
 
 ~PgSqlHostDataSourceImpl ()
 Destructor. More...
 
void addOption (const PgSqlHostDataSourceImpl::StatementIndex &stindex, const OptionDescriptor &opt_desc, const std::string &opt_space, const OptionalValue< SubnetID > &subnet_id, const HostID &host_id)
 Inserts a single DHCP option into the database. More...
 
void addOptions (const StatementIndex &stindex, const ConstCfgOptionPtr &options_cfg, const uint64_t host_id)
 Inserts multiple options into the database. More...
 
void addResv (const IPv6Resrv &resv, const HostID &id)
 Inserts IPv6 Reservation into ipv6_reservation table. More...
 
uint64_t addStatement (PgSqlHostDataSourceImpl::StatementIndex stindex, PsqlBindArrayPtr &bind, const bool return_last_id=false)
 Executes statements which insert a row into one of the tables. More...
 
void checkReadOnly () const
 Throws exception if database is read only. More...
 
bool delStatement (PgSqlHostDataSourceImpl::StatementIndex stindex, PsqlBindArrayPtr &bind)
 Executes statements that delete records. More...
 
ConstHostPtr getHost (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, StatementIndex stindex, boost::shared_ptr< PgSqlHostExchange > exchange) const
 Retrieves a host by subnet and client's unique identifier. More...
 
void getHostCollection (StatementIndex stindex, PsqlBindArrayPtr bind, boost::shared_ptr< PgSqlHostExchange > exchange, ConstHostCollection &result, bool single) const
 Creates collection of Host objects with associated information such as IPv6 reservations and/or DHCP options. More...
 
std::pair< uint32_t, uint32_t > getVersion () const
 Returns PostgreSQL schema version of the open database. More...
 

Public Attributes

PgSqlConnection conn_
 PgSQL connection. More...
 
boost::shared_ptr< PgSqlHostWithOptionsExchange > host_exchange_
 Pointer to the object representing an exchange which can be used to retrieve hosts and DHCPv4 options. More...
 
boost::shared_ptr< PgSqlHostIPv6Exchange > host_ipv46_exchange_
 Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv4 and DHCPv6 options, and IPv6 reservations using a single query. More...
 
boost::shared_ptr< PgSqlHostIPv6Exchange > host_ipv6_exchange_
 Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv6 options and IPv6 reservations. More...
 
boost::shared_ptr< PgSqlIPv6ReservationExchange > host_ipv6_reservation_exchange_
 Pointer to an object representing an exchange which can be used to insert new IPv6 reservation. More...
 
boost::shared_ptr< PgSqlOptionExchange > host_option_exchange_
 Pointer to an object representing an exchange which can be used to insert DHCPv4 or DHCPv6 option into dhcp4_options or dhcp6_options table. More...
 
bool is_readonly_
 Indicates if the database is opened in read only mode. More...
 

Static Public Attributes

static const StatementIndex WRITE_STMTS_BEGIN = INSERT_HOST
 Index of first statement performing write to the database. More...
 

Detailed Description

Implementation of the PgSqlHostDataSource.

Definition at line 1272 of file pgsql_host_data_source.cc.

Member Enumeration Documentation

◆ StatementIndex

Statement Tags.

The contents of the enum are indexes into the list of SQL statements. It is assumed that the order is such that the indices of statements reading the database are less than those of statements modifying the database.

Enumerator
GET_HOST_DHCPID 
GET_HOST_ADDR 
GET_HOST_SUBID4_DHCPID 
GET_HOST_SUBID6_DHCPID 
GET_HOST_SUBID_ADDR 
GET_HOST_PREFIX 
GET_HOST_SUBID6_ADDR 
INSERT_HOST 
INSERT_V6_RESRV 
INSERT_V4_HOST_OPTION 
INSERT_V6_HOST_OPTION 
DEL_HOST_ADDR4 
DEL_HOST_SUBID4_ID 
DEL_HOST_SUBID6_ID 
NUM_STATEMENTS 

Definition at line 1281 of file pgsql_host_data_source.cc.

Constructor & Destructor Documentation

◆ PgSqlHostDataSourceImpl()

isc::dhcp::PgSqlHostDataSourceImpl::PgSqlHostDataSourceImpl ( const PgSqlConnection::ParameterMap &  parameters)

◆ ~PgSqlHostDataSourceImpl()

isc::dhcp::PgSqlHostDataSourceImpl::~PgSqlHostDataSourceImpl ( )

Destructor.

Definition at line 1768 of file pgsql_host_data_source.cc.

Member Function Documentation

◆ addOption()

void isc::dhcp::PgSqlHostDataSourceImpl::addOption ( const PgSqlHostDataSourceImpl::StatementIndex stindex,
const OptionDescriptor opt_desc,
const std::string &  opt_space,
const OptionalValue< SubnetID > &  subnet_id,
const HostID host_id 
)

Inserts a single DHCP option into the database.

Parameters
stindexIndex of a statement being executed.
opt_descOption descriptor holding information about an option to be inserted into the database.
opt_spaceOption space name.
subnet_idSubnet identifier.
host_idHost identifier.

Definition at line 1838 of file pgsql_host_data_source.cc.

References addStatement(), and host_option_exchange_.

Referenced by addOptions().

+ Here is the call graph for this function:

◆ addOptions()

void isc::dhcp::PgSqlHostDataSourceImpl::addOptions ( const StatementIndex stindex,
const ConstCfgOptionPtr options_cfg,
const uint64_t  host_id 
)

Inserts multiple options into the database.

Parameters
stindexIndex of a statement being executed.
options_cfgAn object holding a collection of options to be inserted into the database.
host_idHost identifier retrieved using getColumnValue in addStatement method

Definition at line 1850 of file pgsql_host_data_source.cc.

References addOption().

Referenced by isc::dhcp::PgSqlHostDataSource::add().

+ Here is the call graph for this function:

◆ addResv()

void isc::dhcp::PgSqlHostDataSourceImpl::addResv ( const IPv6Resrv resv,
const HostID id 
)

Inserts IPv6 Reservation into ipv6_reservation table.

Parameters
resvIPv6 Reservation to be added
idID of a host owning this reservation

Definition at line 1830 of file pgsql_host_data_source.cc.

References addStatement(), host_ipv6_reservation_exchange_, and INSERT_V6_RESRV.

Referenced by isc::dhcp::PgSqlHostDataSource::add().

+ Here is the call graph for this function:

◆ addStatement()

uint64_t isc::dhcp::PgSqlHostDataSourceImpl::addStatement ( PgSqlHostDataSourceImpl::StatementIndex  stindex,
PsqlBindArrayPtr bind,
const bool  return_last_id = false 
)

Executes statements which insert a row into one of the tables.

Parameters
stindexIndex of a statement being executed.
bindVector of PgsqlBindArray objects to be used for the query
return_last_idflag indicating whether or not the insert returns the primary key of from the row inserted via " RETURNING <primary key> as pid" clause on the INSERT statement. The RETURNING clause causes the INSERT to return a result set that should consist of a single row with one column, the value of the primary key. Defaults to false.
Returns
0 if return_last_id is false, otherwise it returns the the value in the result set in the first col of the first row.
Exceptions
isc::db::DuplicateEntryDatabase throws duplicate entry error

Definition at line 1772 of file pgsql_host_data_source.cc.

References isc::db::PgSqlConnection::checkStatementError(), isc::db::PgSqlConnection::compareError(), conn_, isc_throw, and isc::dhcp::tagged_statements.

Referenced by isc::dhcp::PgSqlHostDataSource::add(), addOption(), and addResv().

+ Here is the call graph for this function:

◆ checkReadOnly()

void isc::dhcp::PgSqlHostDataSourceImpl::checkReadOnly ( ) const

Throws exception if database is read only.

This method should be called by the methods which write to the database. If the backend is operating in read-only mode this method will throw exception.

Exceptions
DbReadOnlyif backend is operating in read only mode.

Definition at line 1954 of file pgsql_host_data_source.cc.

References is_readonly_, and isc_throw.

Referenced by isc::dhcp::PgSqlHostDataSource::add(), isc::dhcp::PgSqlHostDataSource::commit(), isc::dhcp::PgSqlHostDataSource::del(), and isc::dhcp::PgSqlHostDataSource::rollback().

◆ delStatement()

bool isc::dhcp::PgSqlHostDataSourceImpl::delStatement ( PgSqlHostDataSourceImpl::StatementIndex  stindex,
PsqlBindArrayPtr bind 
)

Executes statements that delete records.

Parameters
stindexIndex of a statement being executed.
bindpointer to PsqlBindArray objects to be used for the query
Returns
true if any records were deleted, false otherwise

Definition at line 1803 of file pgsql_host_data_source.cc.

References isc::db::PgSqlConnection::checkStatementError(), conn_, isc_throw, and isc::dhcp::tagged_statements.

Referenced by isc::dhcp::PgSqlHostDataSource::del(), isc::dhcp::PgSqlHostDataSource::del4(), and isc::dhcp::PgSqlHostDataSource::del6().

+ Here is the call graph for this function:

◆ getHost()

ConstHostPtr isc::dhcp::PgSqlHostDataSourceImpl::getHost ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len,
StatementIndex  stindex,
boost::shared_ptr< PgSqlHostExchange >  exchange 
) const

Retrieves a host by subnet and client's unique identifier.

This method is used by both PgSqlHostDataSource::get4 and PgSqlHostDataSource::get6 methods.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
stindexStatement index.
exchangePointer to the exchange object used for the particular query.
Returns
Pointer to const instance of Host or null pointer if no host found.

Definition at line 1904 of file pgsql_host_data_source.cc.

References getHostCollection().

Referenced by isc::dhcp::PgSqlHostDataSource::get4(), and isc::dhcp::PgSqlHostDataSource::get6().

+ Here is the call graph for this function:

◆ getHostCollection()

void isc::dhcp::PgSqlHostDataSourceImpl::getHostCollection ( StatementIndex  stindex,
PsqlBindArrayPtr  bind,
boost::shared_ptr< PgSqlHostExchange >  exchange,
ConstHostCollection result,
bool  single 
) const

Creates collection of Host objects with associated information such as IPv6 reservations and/or DHCP options.

This method performs a query which returns host information from the 'hosts' table. The query may also use LEFT JOIN clause to retrieve information from other tables, e.g. ipv6_reservations, dhcp4_options and dhcp6_options. Whether IPv6 reservations and/or options are assigned to the Host objects depends on the type of the exchange object.

Parameters
stindexStatement index.
bindPointer to an array of PgSQL bindings.
exchangePointer to the exchange object used for the particular query.
[out]resultReference to the collection of hosts returned.
singleA boolean value indicating if a single host is expected to be returned, or multiple hosts.

Definition at line 1877 of file pgsql_host_data_source.cc.

References isc::db::PgSqlConnection::checkStatementError(), conn_, isc::db::PgSqlResult::getRows(), isc_throw, and isc::dhcp::tagged_statements.

Referenced by isc::dhcp::PgSqlHostDataSource::get4(), isc::dhcp::PgSqlHostDataSource::get6(), isc::dhcp::PgSqlHostDataSource::getAll(), isc::dhcp::PgSqlHostDataSource::getAll4(), and getHost().

+ Here is the call graph for this function:

◆ getVersion()

std::pair< uint32_t, uint32_t > isc::dhcp::PgSqlHostDataSourceImpl::getVersion ( ) const

Returns PostgreSQL schema version of the open database.

Returns
Version number stored in the database, as a pair of unsigned integers. "first" is the major version number, "second" the minor number.
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Definition at line 1934 of file pgsql_host_data_source.cc.

References conn_, isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc_throw, LOG_DEBUG, and version().

Referenced by isc::dhcp::PgSqlHostDataSource::getVersion(), and PgSqlHostDataSourceImpl().

+ Here is the call graph for this function:

Member Data Documentation

◆ conn_

◆ host_exchange_

boost::shared_ptr<PgSqlHostWithOptionsExchange> isc::dhcp::PgSqlHostDataSourceImpl::host_exchange_

Pointer to the object representing an exchange which can be used to retrieve hosts and DHCPv4 options.

Definition at line 1438 of file pgsql_host_data_source.cc.

Referenced by isc::dhcp::PgSqlHostDataSource::add(), isc::dhcp::PgSqlHostDataSource::get4(), and isc::dhcp::PgSqlHostDataSource::getAll4().

◆ host_ipv46_exchange_

boost::shared_ptr<PgSqlHostIPv6Exchange> isc::dhcp::PgSqlHostDataSourceImpl::host_ipv46_exchange_

Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv4 and DHCPv6 options, and IPv6 reservations using a single query.

Definition at line 1447 of file pgsql_host_data_source.cc.

Referenced by isc::dhcp::PgSqlHostDataSource::getAll().

◆ host_ipv6_exchange_

boost::shared_ptr<PgSqlHostIPv6Exchange> isc::dhcp::PgSqlHostDataSourceImpl::host_ipv6_exchange_

Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv6 options and IPv6 reservations.

Definition at line 1442 of file pgsql_host_data_source.cc.

Referenced by isc::dhcp::PgSqlHostDataSource::get6().

◆ host_ipv6_reservation_exchange_

boost::shared_ptr<PgSqlIPv6ReservationExchange> isc::dhcp::PgSqlHostDataSourceImpl::host_ipv6_reservation_exchange_

Pointer to an object representing an exchange which can be used to insert new IPv6 reservation.

Definition at line 1451 of file pgsql_host_data_source.cc.

Referenced by addResv().

◆ host_option_exchange_

boost::shared_ptr<PgSqlOptionExchange> isc::dhcp::PgSqlHostDataSourceImpl::host_option_exchange_

Pointer to an object representing an exchange which can be used to insert DHCPv4 or DHCPv6 option into dhcp4_options or dhcp6_options table.

Definition at line 1456 of file pgsql_host_data_source.cc.

Referenced by addOption().

◆ is_readonly_

bool isc::dhcp::PgSqlHostDataSourceImpl::is_readonly_

Indicates if the database is opened in read only mode.

Definition at line 1462 of file pgsql_host_data_source.cc.

Referenced by checkReadOnly(), and PgSqlHostDataSourceImpl().

◆ WRITE_STMTS_BEGIN

const StatementIndex isc::dhcp::PgSqlHostDataSourceImpl::WRITE_STMTS_BEGIN = INSERT_HOST
static

Index of first statement performing write to the database.

This value is used to mark border line between queries and other statements and statements performing write operation on the database, such as INSERT, DELETE, UPDATE.

Definition at line 1304 of file pgsql_host_data_source.cc.

Referenced by PgSqlHostDataSourceImpl().


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