Fix duplicate object IDs for command objects.

Fixes #5584
This commit is contained in:
Gunnar Beutner 2014-01-31 10:35:04 +01:00
parent 238d90401c
commit 5ae20eb31a
2 changed files with 20 additions and 12 deletions

View File

@ -26,13 +26,14 @@
using namespace icinga; using namespace icinga;
DbType::DbType(const String& name, const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory) DbType::DbType(const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory)
: m_Name(name), m_Table(table), m_TypeID(tid), m_IDColumn(idcolumn), m_ObjectFactory(factory) : m_Table(table), m_TypeID(tid), m_IDColumn(idcolumn), m_ObjectFactory(factory)
{ } { }
String DbType::GetName(void) const std::vector<String> DbType::GetNames(void) const
{ {
return m_Name; boost::mutex::scoped_lock lock(GetStaticMutex());
return m_Names;
} }
String DbType::GetTable(void) const String DbType::GetTable(void) const
@ -50,10 +51,11 @@ String DbType::GetIDColumn(void) const
return m_IDColumn; return m_IDColumn;
} }
void DbType::RegisterType(const DbType::Ptr& type) void DbType::RegisterType(const String& name, const DbType::Ptr& type)
{ {
boost::mutex::scoped_lock lock(GetStaticMutex()); boost::mutex::scoped_lock lock(GetStaticMutex());
GetTypes()[type->GetName()] = type; type->m_Names.push_back(name);
GetTypes()[name] = type;
} }
DbType::Ptr DbType::GetByName(const String& name) DbType::Ptr DbType::GetByName(const String& name)

View File

@ -44,14 +44,14 @@ public:
typedef std::map<String, DbType::Ptr> TypeMap; typedef std::map<String, DbType::Ptr> TypeMap;
typedef std::map<std::pair<String, String>, shared_ptr<DbObject> > ObjectMap; typedef std::map<std::pair<String, String>, shared_ptr<DbObject> > ObjectMap;
DbType(const String& name, const String& table, long tid, const String& idcolumn, const ObjectFactory& factory); DbType(const String& table, long tid, const String& idcolumn, const ObjectFactory& factory);
String GetName(void) const; std::vector<String> GetNames(void) const;
String GetTable(void) const; String GetTable(void) const;
long GetTypeID(void) const; long GetTypeID(void) const;
String GetIDColumn(void) const; String GetIDColumn(void) const;
static void RegisterType(const DbType::Ptr& type); static void RegisterType(const String& name, const DbType::Ptr& type);
static DbType::Ptr GetByName(const String& name); static DbType::Ptr GetByName(const String& name);
static DbType::Ptr GetByID(long tid); static DbType::Ptr GetByID(long tid);
@ -59,7 +59,7 @@ public:
shared_ptr<DbObject> GetOrCreateObjectByName(const String& name1, const String& name2); shared_ptr<DbObject> GetOrCreateObjectByName(const String& name1, const String& name2);
private: private:
String m_Name; std::vector<String> m_Names;
String m_Table; String m_Table;
long m_TypeID; long m_TypeID;
String m_IDColumn; String m_IDColumn;
@ -95,8 +95,14 @@ class RegisterDbTypeHelper
public: public:
RegisterDbTypeHelper(const String& name, const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory) RegisterDbTypeHelper(const String& name, const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory)
{ {
DbType::Ptr dbtype = make_shared<DbType>(name, table, tid, idcolumn, factory); DbType::Ptr dbtype;
DbType::RegisterType(dbtype);
dbtype = DbType::GetByID(tid);
if (!dbtype)
dbtype = make_shared<DbType>(table, tid, idcolumn, factory);
DbType::RegisterType(name, dbtype);
} }
}; };