mirror of https://github.com/Icinga/icinga2.git
parent
238d90401c
commit
5ae20eb31a
|
@ -26,13 +26,14 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
DbType::DbType(const String& name, 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)
|
||||
DbType::DbType(const String& table, long tid, const String& idcolumn, const DbType::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
|
||||
|
@ -50,10 +51,11 @@ String DbType::GetIDColumn(void) const
|
|||
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());
|
||||
GetTypes()[type->GetName()] = type;
|
||||
type->m_Names.push_back(name);
|
||||
GetTypes()[name] = type;
|
||||
}
|
||||
|
||||
DbType::Ptr DbType::GetByName(const String& name)
|
||||
|
|
|
@ -44,14 +44,14 @@ public:
|
|||
typedef std::map<String, DbType::Ptr> TypeMap;
|
||||
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;
|
||||
long GetTypeID(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 GetByID(long tid);
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
shared_ptr<DbObject> GetOrCreateObjectByName(const String& name1, const String& name2);
|
||||
|
||||
private:
|
||||
String m_Name;
|
||||
std::vector<String> m_Names;
|
||||
String m_Table;
|
||||
long m_TypeID;
|
||||
String m_IDColumn;
|
||||
|
@ -95,8 +95,14 @@ class RegisterDbTypeHelper
|
|||
public:
|
||||
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::RegisterType(dbtype);
|
||||
DbType::Ptr dbtype;
|
||||
|
||||
dbtype = DbType::GetByID(tid);
|
||||
|
||||
if (!dbtype)
|
||||
dbtype = make_shared<DbType>(table, tid, idcolumn, factory);
|
||||
|
||||
DbType::RegisterType(name, dbtype);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue