pgsql_lease_mgr.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. // Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef PGSQL_LEASE_MGR_H
  7. #define PGSQL_LEASE_MGR_H
  8. #include <dhcp/hwaddr.h>
  9. #include <dhcpsrv/lease_mgr.h>
  10. #include <dhcpsrv/pgsql_connection.h>
  11. #include <dhcpsrv/pgsql_exchange.h>
  12. #include <boost/scoped_ptr.hpp>
  13. #include <boost/utility.hpp>
  14. #include <vector>
  15. namespace isc {
  16. namespace dhcp {
  17. // Forward definitions (needed for shared_ptr definitions)
  18. // See pgsql_lease_mgr.cc file for actual class definitions
  19. class PgSqlLease4Exchange;
  20. class PgSqlLease6Exchange;
  21. /// @brief PostgreSQL Lease Manager
  22. ///
  23. /// This class provides the \ref isc::dhcp::LeaseMgr interface to the PostgreSQL
  24. /// database. Use of this backend presupposes that a PostgreSQL database is
  25. /// available and that the Kea schema has been created within it.
  26. class PgSqlLeaseMgr : public LeaseMgr {
  27. public:
  28. /// @brief Constructor
  29. ///
  30. /// Uses the following keywords in the parameters passed to it to
  31. /// connect to the database:
  32. /// - name - Name of the database to which to connect (mandatory)
  33. /// - host - Host to which to connect (optional, defaults to "localhost")
  34. /// - user - Username under which to connect (optional)
  35. /// - password - Password for "user" on the database (optional)
  36. ///
  37. /// If the database is successfully opened, the version number in the
  38. /// schema_version table will be checked against hard-coded value in
  39. /// the implementation file.
  40. ///
  41. /// Finally, all the SQL commands are pre-compiled.
  42. ///
  43. /// @param parameters A data structure relating keywords and values
  44. /// concerned with the database.
  45. ///
  46. /// @throw isc::dhcp::NoDatabaseName Mandatory database name not given
  47. /// @throw isc::dhcp::DbOpenError Error opening the database
  48. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  49. /// failed.
  50. PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters);
  51. /// @brief Destructor (closes database)
  52. virtual ~PgSqlLeaseMgr();
  53. /// @brief Local version of getDBVersion() class method
  54. static std::string getDBVersion();
  55. /// @brief Adds an IPv4 lease
  56. ///
  57. /// @param lease lease to be added
  58. ///
  59. /// @result true if the lease was added, false if not (because a lease
  60. /// with the same address was already there).
  61. ///
  62. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  63. /// failed.
  64. virtual bool addLease(const Lease4Ptr& lease);
  65. /// @brief Adds an IPv6 lease
  66. ///
  67. /// @param lease lease to be added
  68. ///
  69. /// @result true if the lease was added, false if not (because a lease
  70. /// with the same address was already there).
  71. ///
  72. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  73. /// failed.
  74. virtual bool addLease(const Lease6Ptr& lease);
  75. /// @brief Returns an IPv4 lease for specified IPv4 address
  76. ///
  77. /// This method return a lease that is associated with a given address.
  78. /// For other query types (by hardware addr, by Client ID) there can be
  79. /// several leases in different subnets (e.g. for mobile clients that
  80. /// got address in different subnets). However, for a single address
  81. /// there can be only one lease, so this method returns a pointer to
  82. /// a single lease, not a container of leases.
  83. ///
  84. /// @param addr address of the searched lease
  85. ///
  86. /// @return smart pointer to the lease (or NULL if a lease is not found)
  87. ///
  88. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  89. /// failed.
  90. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const;
  91. /// @brief Returns existing IPv4 leases for specified hardware address.
  92. ///
  93. /// Although in the usual case there will be only one lease, for mobile
  94. /// clients or clients with multiple static/fixed/reserved leases there
  95. /// can be more than one. Thus return type is a container, not a single
  96. /// pointer.
  97. ///
  98. /// @param hwaddr hardware address of the client
  99. ///
  100. /// @return lease collection
  101. ///
  102. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  103. /// failed.
  104. virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const;
  105. /// @brief Returns existing IPv4 leases for specified hardware address
  106. /// and a subnet
  107. ///
  108. /// There can be at most one lease for a given HW address in a single
  109. /// pool, so this method with either return a single lease or NULL.
  110. ///
  111. /// @param hwaddr hardware address of the client
  112. /// @param subnet_id identifier of the subnet that lease must belong to
  113. ///
  114. /// @return a pointer to the lease (or NULL if a lease is not found)
  115. ///
  116. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  117. /// failed.
  118. virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr,
  119. SubnetID subnet_id) const;
  120. /// @brief Returns existing IPv4 leases for specified client-id
  121. ///
  122. /// Although in the usual case there will be only one lease, for mobile
  123. /// clients or clients with multiple static/fixed/reserved leases there
  124. /// can be more than one. Thus return type is a container, not a single
  125. /// pointer.
  126. ///
  127. /// @param clientid client identifier
  128. ///
  129. /// @return lease collection
  130. ///
  131. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  132. /// failed.
  133. virtual Lease4Collection getLease4(const ClientId& clientid) const;
  134. /// @brief Returns IPv4 lease for the specified client identifier, HW
  135. /// address and subnet identifier.
  136. ///
  137. /// @param client_id A client identifier.
  138. /// @param hwaddr Hardware address.
  139. /// @param subnet_id A subnet identifier.
  140. ///
  141. /// @return A pointer to the lease or NULL if the lease is not found.
  142. /// @throw isc::NotImplemented On every call as this function is currently
  143. /// not implemented for the PostgreSQL backend.
  144. virtual Lease4Ptr getLease4(const ClientId& client_id, const HWAddr& hwaddr,
  145. SubnetID subnet_id) const;
  146. /// @brief Returns existing IPv4 lease for specified client-id
  147. ///
  148. /// There can be at most one lease for a given HW address in a single
  149. /// pool, so this method with either return a single lease or NULL.
  150. ///
  151. /// @param clientid client identifier
  152. /// @param subnet_id identifier of the subnet that lease must belong to
  153. ///
  154. /// @return a pointer to the lease (or NULL if a lease is not found)
  155. ///
  156. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  157. /// failed.
  158. virtual Lease4Ptr getLease4(const ClientId& clientid,
  159. SubnetID subnet_id) const;
  160. /// @brief Returns existing IPv6 lease for a given IPv6 address.
  161. ///
  162. /// For a given address, we assume that there will be only one lease.
  163. /// The assumption here is that there will not be site or link-local
  164. /// addresses used, so there is no way of having address duplication.
  165. ///
  166. /// @param type specifies lease type: (NA, TA or PD)
  167. /// @param addr address of the searched lease
  168. ///
  169. /// @return smart pointer to the lease (or NULL if a lease is not found)
  170. ///
  171. /// @throw isc::BadValue record retrieved from database had an invalid
  172. /// lease type field.
  173. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  174. /// failed.
  175. virtual Lease6Ptr getLease6(Lease::Type type,
  176. const isc::asiolink::IOAddress& addr) const;
  177. /// @brief Returns existing IPv6 leases for a given DUID+IA combination
  178. ///
  179. /// Although in the usual case there will be only one lease, for mobile
  180. /// clients or clients with multiple static/fixed/reserved leases there
  181. /// can be more than one. Thus return type is a container, not a single
  182. /// pointer.
  183. ///
  184. /// @param type specifies lease type: (NA, TA or PD)
  185. /// @param duid client DUID
  186. /// @param iaid IA identifier
  187. ///
  188. /// @return smart pointer to the lease (or NULL if a lease is not found)
  189. ///
  190. /// @throw isc::BadValue record retrieved from database had an invalid
  191. /// lease type field.
  192. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  193. /// failed.
  194. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
  195. uint32_t iaid) const;
  196. /// @brief Returns existing IPv6 lease for a given DUID+IA combination
  197. ///
  198. /// @param type specifies lease type: (NA, TA or PD)
  199. /// @param duid client DUID
  200. /// @param iaid IA identifier
  201. /// @param subnet_id subnet id of the subnet the lease belongs to
  202. ///
  203. /// @return lease collection (may be empty if no lease is found)
  204. ///
  205. /// @throw isc::BadValue record retrieved from database had an invalid
  206. /// lease type field.
  207. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  208. /// failed.
  209. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
  210. uint32_t iaid, SubnetID subnet_id) const;
  211. /// @brief Returns a collection of expired DHCPv6 leases.
  212. ///
  213. /// This method returns at most @c max_leases expired leases. The leases
  214. /// returned haven't been reclaimed, i.e. the database query must exclude
  215. /// reclaimed leases from the results returned.
  216. ///
  217. /// @param [out] expired_leases A container to which expired leases returned
  218. /// by the database backend are added.
  219. /// @param max_leases A maximum number of leases to be returned. If this
  220. /// value is set to 0, all expired (but not reclaimed) leases are returned.
  221. virtual void getExpiredLeases6(Lease6Collection& expired_leases,
  222. const size_t max_leases) const;
  223. /// @brief Returns a collection of expired DHCPv4 leases.
  224. ///
  225. /// This method returns at most @c max_leases expired leases. The leases
  226. /// returned haven't been reclaimed, i.e. the database query must exclude
  227. /// reclaimed leases from the results returned.
  228. ///
  229. /// @param [out] expired_leases A container to which expired leases returned
  230. /// by the database backend are added.
  231. /// @param max_leases A maximum number of leases to be returned. If this
  232. /// value is set to 0, all expired (but not reclaimed) leases are returned.
  233. virtual void getExpiredLeases4(Lease4Collection& expired_leases,
  234. const size_t max_leases) const;
  235. /// @brief Updates IPv4 lease.
  236. ///
  237. /// Updates the record of the lease in the database (as identified by the
  238. /// address) with the data in the passed lease object.
  239. ///
  240. /// @param lease4 The lease to be updated.
  241. ///
  242. /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
  243. /// exist.
  244. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  245. /// failed.
  246. virtual void updateLease4(const Lease4Ptr& lease4);
  247. /// @brief Updates IPv6 lease.
  248. ///
  249. /// Updates the record of the lease in the database (as identified by the
  250. /// address) with the data in the passed lease object.
  251. ///
  252. /// @param lease6 The lease to be updated.
  253. ///
  254. /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
  255. /// exist.
  256. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  257. /// failed.
  258. virtual void updateLease6(const Lease6Ptr& lease6);
  259. /// @brief Deletes a lease.
  260. ///
  261. /// @param addr Address of the lease to be deleted. This can be an IPv4
  262. /// address or an IPv6 address.
  263. ///
  264. /// @return true if deletion was successful, false if no such lease exists
  265. ///
  266. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  267. /// failed.
  268. virtual bool deleteLease(const isc::asiolink::IOAddress& addr);
  269. /// @brief Deletes all expired-reclaimed DHCPv4 leases.
  270. ///
  271. /// @param secs Number of seconds since expiration of leases before
  272. /// they can be removed. Leases which have expired later than this
  273. /// time will not be deleted.
  274. ///
  275. /// @return Number of leases deleted.
  276. virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs);
  277. /// @brief Deletes all expired-reclaimed DHCPv6 leases.
  278. ///
  279. /// @param secs Number of seconds since expiration of leases before
  280. /// they can be removed. Leases which have expired later than this
  281. /// time will not be deleted.
  282. ///
  283. /// @return Number of leases deleted.
  284. virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs);
  285. /// @brief Creates and runs the IPv4 lease stats query
  286. ///
  287. /// It creates an instance of a PgSqlLeaseStatsQuery4 and then
  288. /// invokes its start method, which fetches its statistical data
  289. /// result set by executing the RECOUNT_LEASE_STATS4 query.
  290. /// The query object is then returned.
  291. ///
  292. /// @return The populated query as a pointer to an LeaseStatsQuery
  293. virtual LeaseStatsQueryPtr startLeaseStatsQuery4();
  294. /// @brief Creates and runs the IPv6 lease stats query
  295. ///
  296. /// It creates an instance of a PgSqlLeaseStatsQuery and then
  297. /// invokes its start method, which fetches its statistical data
  298. /// result set by executing the RECOUNT_LEASE_STATS6 query.
  299. /// The query object is then returned.
  300. ///
  301. /// @return The populated query as a pointer to an LeaseStatsQuery
  302. virtual LeaseStatsQueryPtr startLeaseStatsQuery6();
  303. /// @brief Return backend type
  304. ///
  305. /// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
  306. ///
  307. /// @return Type of the backend.
  308. virtual std::string getType() const {
  309. return (std::string("postgresql"));
  310. }
  311. /// @brief Returns name of the database.
  312. ///
  313. /// @return database name
  314. virtual std::string getName() const;
  315. /// @brief Returns description of the backend.
  316. ///
  317. /// This description may be multiline text that describes the backend.
  318. ///
  319. /// @return Description of the backend.
  320. virtual std::string getDescription() const;
  321. /// @brief Returns backend version.
  322. ///
  323. /// @return Version number as a pair of unsigned integers. "first" is the
  324. /// major version number, "second" the minor number.
  325. ///
  326. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  327. /// failed.
  328. virtual std::pair<uint32_t, uint32_t> getVersion() const;
  329. /// @brief Commit Transactions
  330. ///
  331. /// Commits all pending database operations.
  332. ///
  333. /// @throw DbOperationError If the commit failed.
  334. virtual void commit();
  335. /// @brief Rollback Transactions
  336. ///
  337. /// Rolls back all pending database operations.
  338. ///
  339. /// @throw DbOperationError If the rollback failed.
  340. virtual void rollback();
  341. /// @brief Statement Tags
  342. ///
  343. /// The contents of the enum are indexes into the list of compiled SQL
  344. /// statements
  345. enum StatementIndex {
  346. DELETE_LEASE4, // Delete from lease4 by address
  347. DELETE_LEASE4_STATE_EXPIRED,// Delete expired lease4s in certain state.
  348. DELETE_LEASE6, // Delete from lease6 by address
  349. DELETE_LEASE6_STATE_EXPIRED,// Delete expired lease6s in certain state.
  350. GET_LEASE4_ADDR, // Get lease4 by address
  351. GET_LEASE4_CLIENTID, // Get lease4 by client ID
  352. GET_LEASE4_CLIENTID_SUBID, // Get lease4 by client ID & subnet ID
  353. GET_LEASE4_HWADDR, // Get lease4 by HW address
  354. GET_LEASE4_HWADDR_SUBID, // Get lease4 by HW address & subnet ID
  355. GET_LEASE4_EXPIRE, // Get expired lease4
  356. GET_LEASE6_ADDR, // Get lease6 by address
  357. GET_LEASE6_DUID_IAID, // Get lease6 by DUID and IAID
  358. GET_LEASE6_DUID_IAID_SUBID, // Get lease6 by DUID, IAID and subnet ID
  359. GET_LEASE6_EXPIRE, // Get expired lease6
  360. GET_VERSION, // Obtain version number
  361. INSERT_LEASE4, // Add entry to lease4 table
  362. INSERT_LEASE6, // Add entry to lease6 table
  363. UPDATE_LEASE4, // Update a Lease4 entry
  364. UPDATE_LEASE6, // Update a Lease6 entry
  365. RECOUNT_LEASE4_STATS, // Fetch IPv4 lease statistical data
  366. RECOUNT_LEASE6_STATS, // Fetch IPv4 lease statistical data
  367. NUM_STATEMENTS // Number of statements
  368. };
  369. private:
  370. /// @brief Add Lease Common Code
  371. ///
  372. /// This method performs the common actions for both flavours (V4 and V6)
  373. /// of the addLease method. It binds the contents of the lease object to
  374. /// the prepared statement and adds it to the database.
  375. ///
  376. /// @param stindex Index of statement being executed
  377. /// @param bind_array array that has been created for the type
  378. /// of lease in question.
  379. ///
  380. /// @return true if the lease was added, false if it was not added because
  381. /// a lease with that address already exists in the database.
  382. ///
  383. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  384. /// failed.
  385. bool addLeaseCommon(StatementIndex stindex, PsqlBindArray& bind_array);
  386. /// @brief Get Lease Collection Common Code
  387. ///
  388. /// This method performs the common actions for obtaining multiple leases
  389. /// from the database.
  390. ///
  391. /// @param stindex Index of statement being executed
  392. /// @param bind_array array containing the where clause input parameters
  393. /// @param exchange Exchange object to use
  394. /// @param result Returned collection of Leases Note that any leases in
  395. /// the collection when this method is called are not erased: the
  396. /// new data is appended to the end.
  397. /// @param single If true, only a single data item is to be retrieved.
  398. /// If more than one is present, a MultipleRecords exception will
  399. /// be thrown.
  400. ///
  401. /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
  402. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  403. /// failed.
  404. /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved
  405. /// from the database where only one was expected.
  406. template <typename Exchange, typename LeaseCollection>
  407. void getLeaseCollection(StatementIndex stindex, PsqlBindArray& bind_array,
  408. Exchange& exchange, LeaseCollection& result,
  409. bool single = false) const;
  410. /// @brief Gets Lease4 Collection
  411. ///
  412. /// Gets a collection of Lease4 objects. This is just an interface to
  413. /// the get lease collection common code.
  414. ///
  415. /// @param stindex Index of statement being executed
  416. /// @param bind_array array containing the where clause input parameters
  417. /// @param lease LeaseCollection object returned. Note that any leases in
  418. /// the collection when this method is called are not erased: the
  419. /// new data is appended to the end.
  420. ///
  421. /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
  422. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  423. /// failed.
  424. /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved
  425. /// from the database where only one was expected.
  426. void getLeaseCollection(StatementIndex stindex, PsqlBindArray& bind_array,
  427. Lease4Collection& result) const {
  428. getLeaseCollection(stindex, bind_array, exchange4_, result);
  429. }
  430. /// @brief Get Lease6 Collection
  431. ///
  432. /// Gets a collection of Lease6 objects. This is just an interface to
  433. /// the get lease collection common code.
  434. ///
  435. /// @param stindex Index of statement being executed
  436. /// @param bind_array array containing input parameters for the query
  437. /// @param lease LeaseCollection object returned. Note that any existing
  438. /// data in the collection is erased first.
  439. ///
  440. /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
  441. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  442. /// failed.
  443. /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved
  444. /// from the database where only one was expected.
  445. void getLeaseCollection(StatementIndex stindex, PsqlBindArray& bind_array,
  446. Lease6Collection& result) const {
  447. getLeaseCollection(stindex, bind_array, exchange6_, result);
  448. }
  449. /// @brief Get Lease4 Common Code
  450. ///
  451. /// This method performs the common actions for the various getLease4()
  452. /// methods. It acts as an interface to the getLeaseCollection() method,
  453. /// but retrieving only a single lease.
  454. ///
  455. /// @param stindex Index of statement being executed
  456. /// @param bind_array array containing input parameters for the query
  457. /// @param lease Lease4 object returned
  458. void getLease(StatementIndex stindex, PsqlBindArray& bind_array,
  459. Lease4Ptr& result) const;
  460. /// @brief Get Lease6 Common Code
  461. ///
  462. /// This method performs the common actions for the various getLease4()
  463. /// methods. It acts as an interface to the getLeaseCollection() method,
  464. /// but retrieving only a single lease.
  465. ///
  466. /// @param stindex Index of statement being executed
  467. /// @param bind_array array containing input parameters for the query
  468. /// @param lease Lease6 object returned
  469. void getLease(StatementIndex stindex, PsqlBindArray& bind_array,
  470. Lease6Ptr& result) const;
  471. /// @brief Get expired leases common code.
  472. ///
  473. /// This method retrieves expired and not reclaimed leases from the
  474. /// lease database. The returned leases are ordered by the expiration
  475. /// time. The maximum number of leases to be returned is specified
  476. /// as an argument.
  477. ///
  478. /// @param [out] expired_leases Reference to the container where the
  479. /// retrieved leases are put.
  480. /// @param max_leases Maximum number of leases to be returned.
  481. /// @param statement_index One of the @c GET_LEASE4_EXPIRE or
  482. /// @c GET_LEASE6_EXPIRE.
  483. ///
  484. /// @tparam One of the @c Lease4Collection or @c Lease6Collection.
  485. template<typename LeaseCollection>
  486. void getExpiredLeasesCommon(LeaseCollection& expired_leases,
  487. const size_t max_leases,
  488. StatementIndex statement_index) const;
  489. /// @brief Update lease common code
  490. ///
  491. /// Holds the common code for updating a lease. It binds the parameters
  492. /// to the prepared statement, executes it, then checks how many rows
  493. /// were affected.
  494. ///
  495. /// @param stindex Index of prepared statement to be executed
  496. /// @param bind_array array containing lease values and where clause
  497. /// parameters for the update.
  498. /// @param lease Pointer to the lease object whose record is being updated.
  499. ///
  500. /// @throw NoSuchLease Could not update a lease because no lease matches
  501. /// the address given.
  502. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  503. /// failed.
  504. template <typename LeasePtr>
  505. void updateLeaseCommon(StatementIndex stindex, PsqlBindArray& bind_array,
  506. const LeasePtr& lease);
  507. /// @brief Delete lease common code
  508. ///
  509. /// Holds the common code for deleting a lease. It binds the parameters
  510. /// to the prepared statement, executes the statement and checks to
  511. /// see how many rows were deleted.
  512. ///
  513. /// @param stindex Index of prepared statement to be executed
  514. /// @param bind_array array containing lease values and where clause
  515. /// parameters for the delete
  516. ///
  517. /// @return Number of deleted leases.
  518. ///
  519. /// @throw isc::dhcp::DbOperationError An operation on the open database has
  520. /// failed.
  521. uint64_t deleteLeaseCommon(StatementIndex stindex,
  522. PsqlBindArray& bind_array);
  523. /// @brief Delete expired-reclaimed leases.
  524. ///
  525. /// @param secs Number of seconds since expiration of leases before
  526. /// they can be removed. Leases which have expired later than this
  527. /// time will not be deleted.
  528. /// @param statement_index One of the @c DELETE_LEASE4_STATE_EXPIRED or
  529. /// @c DELETE_LEASE6_STATE_EXPIRED.
  530. ///
  531. /// @return Number of leases deleted.
  532. uint64_t deleteExpiredReclaimedLeasesCommon(const uint32_t secs,
  533. StatementIndex statement_index);
  534. /// The exchange objects are used for transfer of data to/from the database.
  535. /// They are pointed-to objects as the contents may change in "const" calls,
  536. /// while the rest of this object does not. (At alternative would be to
  537. /// declare them as "mutable".)
  538. boost::scoped_ptr<PgSqlLease4Exchange> exchange4_; ///< Exchange object
  539. boost::scoped_ptr<PgSqlLease6Exchange> exchange6_; ///< Exchange object
  540. /// PostgreSQL connection handle
  541. PgSqlConnection conn_;
  542. };
  543. }; // end of isc::dhcp namespace
  544. }; // end of isc namespace
  545. #endif // PGSQL_LEASE_MGR_H