mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[2821] Updated documentation related to MySqlHolder class.
This commit is contained in:
@@ -908,6 +908,9 @@ MySqlLeaseMgr::~MySqlLeaseMgr() {
|
|||||||
statements_[i] = NULL;
|
statements_[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There is no need to close the database in this destructor: it is
|
||||||
|
// closed in the destructor of the mysql_ member variable.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include <dhcpsrv/lease_mgr.h>
|
#include <dhcpsrv/lease_mgr.h>
|
||||||
|
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
#include <boost/utility.hpp>
|
||||||
#include <mysql/mysql.h>
|
#include <mysql/mysql.h>
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -26,28 +27,50 @@
|
|||||||
namespace isc {
|
namespace isc {
|
||||||
namespace dhcp {
|
namespace dhcp {
|
||||||
|
|
||||||
|
/// @brief MySQL Handle Holder
|
||||||
|
///
|
||||||
/// Small RAII object for safer initialization, will close the database
|
/// Small RAII object for safer initialization, will close the database
|
||||||
/// connection upon destruction
|
/// connection upon destruction. This means that if an exception is thrown
|
||||||
class MySqlHolder {
|
/// during database initialization, resources allocated to the database are
|
||||||
|
/// guaranteed to be freed.
|
||||||
|
///
|
||||||
|
/// It makes no sense to copy an object of this class. After the copy, both
|
||||||
|
/// objects would contain pointers to the same MySql context object. The
|
||||||
|
/// destruction of one would invalid the context in the remaining object.
|
||||||
|
/// For this reason, the class is declared noncopyable.
|
||||||
|
class MySqlHolder : public boost::noncopyable {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/// @brief Constructor
|
||||||
|
///
|
||||||
|
/// Initialize MySql and store the associated context object.
|
||||||
|
///
|
||||||
|
/// @throw DbOpenError Unable to initialize MySql handle.
|
||||||
MySqlHolder() : mysql_(mysql_init(NULL)) {
|
MySqlHolder() : mysql_(mysql_init(NULL)) {
|
||||||
if (mysql_ == NULL) {
|
if (mysql_ == NULL) {
|
||||||
isc_throw(DbOpenError, "unable to initialize MySQL");
|
isc_throw(DbOpenError, "unable to initialize MySQL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Destructor
|
||||||
|
///
|
||||||
|
/// Frees up resources allocated by the initialization of MySql.
|
||||||
~MySqlHolder() {
|
~MySqlHolder() {
|
||||||
if (mysql_) {
|
if (mysql_ != NULL) {
|
||||||
mysql_close(mysql_);
|
mysql_close(mysql_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Conversion Operator
|
||||||
|
///
|
||||||
|
/// Allows the MySqlHolder object to be passed as the context argument to
|
||||||
|
/// mysql_xxx functions.
|
||||||
operator MYSQL*() const {
|
operator MYSQL*() const {
|
||||||
return (mysql_);
|
return (mysql_);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MYSQL* mysql_;
|
MYSQL* mysql_; ///< Initialization context
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define the current database schema values
|
// Define the current database schema values
|
||||||
|
Reference in New Issue
Block a user