![]() |
Kea
1.5.0
|
Implementation of the PgSqlHostDataSource. More...
Public Member Functions | |
| PgSqlHostDataSourceImpl (const PgSqlConnection::ParameterMap ¶meters) | |
| 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... | |
Implementation of the PgSqlHostDataSource.
Definition at line 1272 of file pgsql_host_data_source.cc.
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.
Definition at line 1281 of file pgsql_host_data_source.cc.
| isc::dhcp::PgSqlHostDataSourceImpl::PgSqlHostDataSourceImpl | ( | const PgSqlConnection::ParameterMap & | parameters | ) |
Constructor.
This constructor opens database connection and initializes prepared statements used in the queries.
Definition at line 1724 of file pgsql_host_data_source.cc.
References isc::db::DatabaseConnection::configuredReadOnly(), conn_, isc::dhcp::dhcpsrv_logger, getVersion(), is_readonly_, isc_throw, LOG_INFO, isc::db::PgSqlConnection::openDatabase(), isc::db::PG_SCHEMA_VERSION_MAJOR, isc::db::PG_SCHEMA_VERSION_MINOR, isc::db::PgSqlConnection::prepareStatements(), isc::dhcp::tagged_statements, and WRITE_STMTS_BEGIN.
Here is the call graph for this function:| isc::dhcp::PgSqlHostDataSourceImpl::~PgSqlHostDataSourceImpl | ( | ) |
Destructor.
Definition at line 1768 of file pgsql_host_data_source.cc.
| 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.
| stindex | Index of a statement being executed. |
| opt_desc | Option descriptor holding information about an option to be inserted into the database. |
| opt_space | Option space name. |
| subnet_id | Subnet identifier. |
| host_id | Host 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:| void isc::dhcp::PgSqlHostDataSourceImpl::addOptions | ( | const StatementIndex & | stindex, |
| const ConstCfgOptionPtr & | options_cfg, | ||
| const uint64_t | host_id | ||
| ) |
Inserts multiple options into the database.
| stindex | Index of a statement being executed. |
| options_cfg | An object holding a collection of options to be inserted into the database. |
| host_id | Host 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:Inserts IPv6 Reservation into ipv6_reservation table.
| resv | IPv6 Reservation to be added |
| id | ID 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:| 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.
| stindex | Index of a statement being executed. |
| bind | Vector of PgsqlBindArray objects to be used for the query |
| return_last_id | flag 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. |
| isc::db::DuplicateEntry | Database 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:| 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.
| DbReadOnly | if 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().
| bool isc::dhcp::PgSqlHostDataSourceImpl::delStatement | ( | PgSqlHostDataSourceImpl::StatementIndex | stindex, |
| PsqlBindArrayPtr & | bind | ||
| ) |
Executes statements that delete records.
| stindex | Index of a statement being executed. |
| bind | pointer to PsqlBindArray objects to be used for the query |
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:| 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.
| subnet_id | Subnet identifier. |
| identifier_type | Identifier type. |
| identifier_begin | Pointer to a beginning of a buffer containing an identifier. |
| identifier_len | Identifier length. |
| stindex | Statement index. |
| exchange | Pointer to the exchange object used for the particular query. |
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:| 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.
| stindex | Statement index. | |
| bind | Pointer to an array of PgSQL bindings. | |
| exchange | Pointer to the exchange object used for the particular query. | |
| [out] | result | Reference to the collection of hosts returned. |
| single | A 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:| std::pair< uint32_t, uint32_t > isc::dhcp::PgSqlHostDataSourceImpl::getVersion | ( | ) | const |
Returns PostgreSQL schema version of the open database.
| isc::db::DbOperationError | An 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:| PgSqlConnection isc::dhcp::PgSqlHostDataSourceImpl::conn_ |
PgSQL connection.
Definition at line 1459 of file pgsql_host_data_source.cc.
Referenced by isc::dhcp::PgSqlHostDataSource::add(), addStatement(), isc::dhcp::PgSqlHostDataSource::commit(), delStatement(), getHostCollection(), isc::dhcp::PgSqlHostDataSource::getName(), getVersion(), PgSqlHostDataSourceImpl(), and isc::dhcp::PgSqlHostDataSource::rollback().
| 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().
| 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().
| 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().
| 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().
| 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().
| 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().
|
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().