mirror of https://github.com/Icinga/icinga2.git
parent
a727913aa0
commit
11dfcd76a3
|
@ -26,14 +26,13 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
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)
|
||||
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)
|
||||
{ }
|
||||
|
||||
std::vector<String> DbType::GetNames(void) const
|
||||
String DbType::GetName(void) const
|
||||
{
|
||||
boost::mutex::scoped_lock lock(GetStaticMutex());
|
||||
return m_Names;
|
||||
return m_Name;
|
||||
}
|
||||
|
||||
String DbType::GetTable(void) const
|
||||
|
@ -51,11 +50,10 @@ String DbType::GetIDColumn(void) const
|
|||
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());
|
||||
type->m_Names.push_back(name);
|
||||
GetTypes()[name] = type;
|
||||
GetTypes()[type->GetName()] = type;
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,14 +45,14 @@ public:
|
|||
typedef std::map<String, DbType::Ptr> TypeMap;
|
||||
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;
|
||||
long GetTypeID(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 GetByID(long tid);
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
static std::set<DbType::Ptr> GetAllTypes(void);
|
||||
|
||||
private:
|
||||
std::vector<String> m_Names;
|
||||
String m_Name;
|
||||
String m_Table;
|
||||
long m_TypeID;
|
||||
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 { \
|
||||
void RegisterDbType(void) \
|
||||
{ \
|
||||
DbType::Ptr dbtype = new DbType(table, tid, idcolumn, DbObjectFactory<type>); \
|
||||
DbType::RegisterType(#name, dbtype); \
|
||||
DbType::Ptr dbtype = new DbType(#name, table, tid, idcolumn, DbObjectFactory<type>); \
|
||||
DbType::RegisterType(dbtype); \
|
||||
} \
|
||||
INITIALIZE_ONCE(RegisterDbType); \
|
||||
} } }
|
||||
|
|
Loading…
Reference in New Issue