mirror of https://github.com/Icinga/icinga2.git
ido: Rename component with ido prefix.
This marks the configuration object as ido specific mysql db connection. refs #3307
This commit is contained in:
parent
0b892c123f
commit
7760c2c7bc
|
@ -12,8 +12,8 @@ EXTRA_DIST = \
|
||||||
|
|
||||||
libido_mysql_la_SOURCES = \
|
libido_mysql_la_SOURCES = \
|
||||||
ido_mysql-type.cpp \
|
ido_mysql-type.cpp \
|
||||||
mysqldbconnection.cpp \
|
idomysqldbconnection.cpp \
|
||||||
mysqldbconnection.h
|
idomysqldbconnection.h
|
||||||
|
|
||||||
libido_mysql_la_CPPFLAGS = \
|
libido_mysql_la_CPPFLAGS = \
|
||||||
$(LTDLINCL) \
|
$(LTDLINCL) \
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
type MysqlDbConnection inherits DbConnection {
|
type IdoMysqlDbConnection inherits DbConnection {
|
||||||
%attribute string "host",
|
%attribute string "host",
|
||||||
%attribute number "port",
|
%attribute number "port",
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,16 @@
|
||||||
#include "base/utility.h"
|
#include "base/utility.h"
|
||||||
#include "ido/dbtype.h"
|
#include "ido/dbtype.h"
|
||||||
#include "ido/dbvalue.h"
|
#include "ido/dbvalue.h"
|
||||||
#include "ido_mysql/mysqldbconnection.h"
|
#include "ido_mysql/idomysqldbconnection.h"
|
||||||
#include <boost/tuple/tuple.hpp>
|
#include <boost/tuple/tuple.hpp>
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(MysqlDbConnection);
|
REGISTER_TYPE(IdoMysqlDbConnection);
|
||||||
|
|
||||||
MysqlDbConnection::MysqlDbConnection(const Dictionary::Ptr& serializedUpdate)
|
IdoMysqlDbConnection::IdoMysqlDbConnection(const Dictionary::Ptr& serializedUpdate)
|
||||||
: DbConnection(serializedUpdate), m_Connected(false)
|
: DbConnection(serializedUpdate), m_Connected(false)
|
||||||
{
|
{
|
||||||
RegisterAttribute("host", Attribute_Config, &m_Host);
|
RegisterAttribute("host", Attribute_Config, &m_Host);
|
||||||
|
@ -46,18 +46,18 @@ MysqlDbConnection::MysqlDbConnection(const Dictionary::Ptr& serializedUpdate)
|
||||||
|
|
||||||
m_TxTimer = boost::make_shared<Timer>();
|
m_TxTimer = boost::make_shared<Timer>();
|
||||||
m_TxTimer->SetInterval(5);
|
m_TxTimer->SetInterval(5);
|
||||||
m_TxTimer->OnTimerExpired.connect(boost::bind(&MysqlDbConnection::TxTimerHandler, this));
|
m_TxTimer->OnTimerExpired.connect(boost::bind(&IdoMysqlDbConnection::TxTimerHandler, this));
|
||||||
m_TxTimer->Start();
|
m_TxTimer->Start();
|
||||||
|
|
||||||
m_ReconnectTimer = boost::make_shared<Timer>();
|
m_ReconnectTimer = boost::make_shared<Timer>();
|
||||||
m_ReconnectTimer->SetInterval(10);
|
m_ReconnectTimer->SetInterval(10);
|
||||||
m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&MysqlDbConnection::ReconnectTimerHandler, this));
|
m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&IdoMysqlDbConnection::ReconnectTimerHandler, this));
|
||||||
m_ReconnectTimer->Start();
|
m_ReconnectTimer->Start();
|
||||||
|
|
||||||
ASSERT(mysql_thread_safe());
|
ASSERT(mysql_thread_safe());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::Stop(void)
|
void IdoMysqlDbConnection::Stop(void)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ void MysqlDbConnection::Stop(void)
|
||||||
mysql_close(&m_Connection);
|
mysql_close(&m_Connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::TxTimerHandler(void)
|
void IdoMysqlDbConnection::TxTimerHandler(void)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ void MysqlDbConnection::TxTimerHandler(void)
|
||||||
Query("BEGIN");
|
Query("BEGIN");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::ReconnectTimerHandler(void)
|
void IdoMysqlDbConnection::ReconnectTimerHandler(void)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
||||||
|
@ -160,7 +160,7 @@ void MysqlDbConnection::ReconnectTimerHandler(void)
|
||||||
UpdateAllObjects();
|
UpdateAllObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::ClearConfigTables(void)
|
void IdoMysqlDbConnection::ClearConfigTables(void)
|
||||||
{
|
{
|
||||||
/* TODO make hardcoded table names modular */
|
/* TODO make hardcoded table names modular */
|
||||||
ClearConfigTable("commands");
|
ClearConfigTable("commands");
|
||||||
|
@ -187,12 +187,12 @@ void MysqlDbConnection::ClearConfigTables(void)
|
||||||
ClearConfigTable("timeperiods");
|
ClearConfigTable("timeperiods");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::ClearConfigTable(const String& table)
|
void IdoMysqlDbConnection::ClearConfigTable(const String& table)
|
||||||
{
|
{
|
||||||
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE instance_id = " + Convert::ToString(static_cast<long>(m_InstanceID)));
|
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE instance_id = " + Convert::ToString(static_cast<long>(m_InstanceID)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Ptr MysqlDbConnection::Query(const String& query)
|
Array::Ptr IdoMysqlDbConnection::Query(const String& query)
|
||||||
{
|
{
|
||||||
Log(LogDebug, "ido_mysql", "Query: " + query);
|
Log(LogDebug, "ido_mysql", "Query: " + query);
|
||||||
|
|
||||||
|
@ -224,12 +224,12 @@ Array::Ptr MysqlDbConnection::Query(const String& query)
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
DbReference MysqlDbConnection::GetLastInsertID(void)
|
DbReference IdoMysqlDbConnection::GetLastInsertID(void)
|
||||||
{
|
{
|
||||||
return DbReference(mysql_insert_id(&m_Connection));
|
return DbReference(mysql_insert_id(&m_Connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
String MysqlDbConnection::Escape(const String& s)
|
String IdoMysqlDbConnection::Escape(const String& s)
|
||||||
{
|
{
|
||||||
ssize_t length = s.GetLength();
|
ssize_t length = s.GetLength();
|
||||||
char *to = new char[s.GetLength() * 2 + 1];
|
char *to = new char[s.GetLength() * 2 + 1];
|
||||||
|
@ -243,7 +243,7 @@ String MysqlDbConnection::Escape(const String& s)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr MysqlDbConnection::FetchRow(MYSQL_RES *result)
|
Dictionary::Ptr IdoMysqlDbConnection::FetchRow(MYSQL_RES *result)
|
||||||
{
|
{
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
MYSQL_FIELD *field;
|
MYSQL_FIELD *field;
|
||||||
|
@ -274,13 +274,13 @@ Dictionary::Ptr MysqlDbConnection::FetchRow(MYSQL_RES *result)
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::ActivateObject(const DbObject::Ptr& dbobj)
|
void IdoMysqlDbConnection::ActivateObject(const DbObject::Ptr& dbobj)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
||||||
InternalActivateObject(dbobj);
|
InternalActivateObject(dbobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::InternalActivateObject(const DbObject::Ptr& dbobj)
|
void IdoMysqlDbConnection::InternalActivateObject(const DbObject::Ptr& dbobj)
|
||||||
{
|
{
|
||||||
if (!m_Connected)
|
if (!m_Connected)
|
||||||
return;
|
return;
|
||||||
|
@ -300,7 +300,7 @@ void MysqlDbConnection::InternalActivateObject(const DbObject::Ptr& dbobj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::DeactivateObject(const DbObject::Ptr& dbobj)
|
void IdoMysqlDbConnection::DeactivateObject(const DbObject::Ptr& dbobj)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ void MysqlDbConnection::DeactivateObject(const DbObject::Ptr& dbobj)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* caller must hold m_ConnectionMutex */
|
/* caller must hold m_ConnectionMutex */
|
||||||
bool MysqlDbConnection::FieldToEscapedString(const String& key, const Value& value, Value *result)
|
bool IdoMysqlDbConnection::FieldToEscapedString(const String& key, const Value& value, Value *result)
|
||||||
{
|
{
|
||||||
if (key == "instance_id") {
|
if (key == "instance_id") {
|
||||||
*result = static_cast<long>(m_InstanceID);
|
*result = static_cast<long>(m_InstanceID);
|
||||||
|
@ -372,7 +372,7 @@ bool MysqlDbConnection::FieldToEscapedString(const String& key, const Value& val
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MysqlDbConnection::ExecuteQuery(const DbQuery& query)
|
void IdoMysqlDbConnection::ExecuteQuery(const DbQuery& query)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef MYSQLDBCONNECTION_H
|
#ifndef IDOMYSQLDBCONNECTION_H
|
||||||
#define MYSQLDBCONNECTION_H
|
#define IDOMYSQLDBCONNECTION_H
|
||||||
|
|
||||||
#include "base/array.h"
|
#include "base/array.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
|
@ -30,17 +30,17 @@ namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A MySQL database connection.
|
* An IDO MySQL database connection.
|
||||||
*
|
*
|
||||||
* @ingroup ido
|
* @ingroup ido
|
||||||
*/
|
*/
|
||||||
class MysqlDbConnection : public DbConnection
|
class IdoMysqlDbConnection : public DbConnection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<MysqlDbConnection> Ptr;
|
typedef shared_ptr<IdoMysqlDbConnection> Ptr;
|
||||||
typedef weak_ptr<MysqlDbConnection> WeakPtr;
|
typedef weak_ptr<IdoMysqlDbConnection> WeakPtr;
|
||||||
|
|
||||||
MysqlDbConnection(const Dictionary::Ptr& serializedUpdate);
|
IdoMysqlDbConnection(const Dictionary::Ptr& serializedUpdate);
|
||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
|
||||||
//virtual void UpdateObject(const DbObject::Ptr& dbobj, DbUpdateType kind);
|
//virtual void UpdateObject(const DbObject::Ptr& dbobj, DbUpdateType kind);
|
||||||
|
@ -85,4 +85,4 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MYSQLDBCONNECTION_H */
|
#endif /* IDOMYSQLDBCONNECTION_H */
|
Loading…
Reference in New Issue