Fix incorrect is_active queries

fixes #10891
This commit is contained in:
Gunnar Beutner 2016-01-11 14:23:16 +01:00
parent a727913aa0
commit 11dfcd76a3
2 changed files with 19 additions and 14 deletions

View File

@ -26,14 +26,13 @@
using namespace icinga; using namespace icinga;
DbType::DbType(const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory) DbType::DbType(const String& name, const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory)
: m_Table(table), m_TypeID(tid), m_IDColumn(idcolumn), m_ObjectFactory(factory) : m_Name(name), m_Table(table), m_TypeID(tid), m_IDColumn(idcolumn), m_ObjectFactory(factory)
{ } { }
std::vector<String> DbType::GetNames(void) const String DbType::GetName(void) const
{ {
boost::mutex::scoped_lock lock(GetStaticMutex()); return m_Name;
return m_Names;
} }
String DbType::GetTable(void) const String DbType::GetTable(void) const
@ -51,11 +50,10 @@ String DbType::GetIDColumn(void) const
return m_IDColumn; return m_IDColumn;
} }
void DbType::RegisterType(const String& name, const DbType::Ptr& type) void DbType::RegisterType(const DbType::Ptr& type)
{ {
boost::mutex::scoped_lock lock(GetStaticMutex()); boost::mutex::scoped_lock lock(GetStaticMutex());
type->m_Names.push_back(name); GetTypes()[type->GetName()] = type;
GetTypes()[name] = type;
} }
DbType::Ptr DbType::GetByName(const String& name) DbType::Ptr DbType::GetByName(const String& name)
@ -93,6 +91,13 @@ DbObject::Ptr DbType::GetOrCreateObjectByName(const String& name1, const String&
DbObject::Ptr dbobj = m_ObjectFactory(this, name1, name2); DbObject::Ptr dbobj = m_ObjectFactory(this, name1, name2);
m_Objects[std::make_pair(name1, name2)] = dbobj; m_Objects[std::make_pair(name1, name2)] = dbobj;
String objName = name1;
if (!name2.IsEmpty())
objName += "!" + name2;
dbobj->SetObject(ConfigObject::GetObject(m_Name, objName));
return dbobj; return dbobj;
} }

View File

@ -45,14 +45,14 @@ public:
typedef std::map<String, DbType::Ptr> TypeMap; typedef std::map<String, DbType::Ptr> TypeMap;
typedef std::map<std::pair<String, String>, intrusive_ptr<DbObject> > ObjectMap; typedef std::map<std::pair<String, String>, intrusive_ptr<DbObject> > ObjectMap;
DbType(const String& table, long tid, const String& idcolumn, const ObjectFactory& factory); DbType(const String& name, const String& table, long tid, const String& idcolumn, const ObjectFactory& factory);
std::vector<String> GetNames(void) const; String GetName(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 String& name, const DbType::Ptr& type); static void RegisterType(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);
@ -62,7 +62,7 @@ public:
static std::set<DbType::Ptr> GetAllTypes(void); static std::set<DbType::Ptr> GetAllTypes(void);
private: private:
std::vector<String> m_Names; String m_Name;
String m_Table; String m_Table;
long m_TypeID; long m_TypeID;
String m_IDColumn; String m_IDColumn;
@ -100,8 +100,8 @@ intrusive_ptr<T> DbObjectFactory(const DbType::Ptr& type, const String& name1, c
namespace { namespace UNIQUE_NAME(ido) { namespace ido ## name { \ namespace { namespace UNIQUE_NAME(ido) { namespace ido ## name { \
void RegisterDbType(void) \ void RegisterDbType(void) \
{ \ { \
DbType::Ptr dbtype = new DbType(table, tid, idcolumn, DbObjectFactory<type>); \ DbType::Ptr dbtype = new DbType(#name, table, tid, idcolumn, DbObjectFactory<type>); \
DbType::RegisterType(#name, dbtype); \ DbType::RegisterType(dbtype); \
} \ } \
INITIALIZE_ONCE(RegisterDbType); \ INITIALIZE_ONCE(RegisterDbType); \
} } } } } }