mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-10-31 19:24:25 +01:00 
			
		
		
		
	ido: Add host_parenthosts, use GetInsertID().
This commit is contained in:
		
							parent
							
								
									aa82ef7c06
								
							
						
					
					
						commit
						5977bdee2d
					
				| @ -291,15 +291,24 @@ bool MysqlDbConnection::FieldToEscapedString(const String& key, const Value& val | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (value.IsObjectType<DynamicObject>()) { | ||||
| 		DbObject::Ptr dbobjcol = DbObject::GetOrCreateByObject(value); | ||||
| 	Value rawvalue = DbValue::ExtractValue(value); | ||||
| 
 | ||||
| 	if (rawvalue.IsObjectType<DynamicObject>()) { | ||||
| 		DbObject::Ptr dbobjcol = DbObject::GetOrCreateByObject(rawvalue); | ||||
| 
 | ||||
| 		if (!dbobjcol) { | ||||
| 			*result = 0; | ||||
| 			return true; | ||||
| 		} | ||||
| 
 | ||||
| 		DbReference dbrefcol = GetObjectID(dbobjcol); | ||||
| 		DbReference dbrefcol; | ||||
| 
 | ||||
| 		if (DbValue::IsObjectInsertID(value)) { | ||||
| 			dbrefcol = GetInsertID(dbobjcol); | ||||
| 
 | ||||
| 			ASSERT(dbrefcol.IsValid()); | ||||
| 		} else { | ||||
| 			dbrefcol = GetObjectID(dbobjcol); | ||||
| 
 | ||||
| 			if (!dbrefcol.IsValid()) { | ||||
| 				InternalActivateObject(dbobjcol); | ||||
| @ -309,17 +318,18 @@ bool MysqlDbConnection::FieldToEscapedString(const String& key, const Value& val | ||||
| 				if (!dbrefcol.IsValid()) | ||||
| 					return false; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		*result = static_cast<long>(dbrefcol); | ||||
| 	} else if (DbValue::IsTimestamp(value)) { | ||||
| 		long ts = DbValue::ExtractValue(value); | ||||
| 		long ts = rawvalue;  | ||||
| 		std::ostringstream msgbuf; | ||||
| 		msgbuf << "FROM_UNIXTIME(" << ts << ")"; | ||||
| 		*result = Value(msgbuf.str()); | ||||
| 	} else if (DbValue::IsTimestampNow(value)) { | ||||
| 		*result = "NOW()"; | ||||
| 	} else { | ||||
| 		*result = "'" + Escape(DbValue::ExtractValue(value)) + "'"; | ||||
| 		*result = "'" + Escape(rawvalue) + "'"; | ||||
| 	} | ||||
| 
 | ||||
| 	return true; | ||||
|  | ||||
| @ -43,6 +43,11 @@ Value DbValue::FromValue(const Value& value) | ||||
| 	return value; | ||||
| } | ||||
| 
 | ||||
| Value DbValue::FromObjectInsertID(const Value& value) | ||||
| { | ||||
| 	return boost::make_shared<DbValue>(DbValueObjectInsertID, value); | ||||
| } | ||||
| 
 | ||||
| bool DbValue::IsTimestamp(const Value& value) | ||||
| { | ||||
| 	if (!value.IsObjectType<DbValue>()) | ||||
| @ -61,6 +66,15 @@ bool DbValue::IsTimestampNow(const Value& value) | ||||
| 	return dbv->GetType() == DbValueTimestampNow; | ||||
| } | ||||
| 
 | ||||
| bool DbValue::IsObjectInsertID(const Value& value) | ||||
| { | ||||
| 	if (!value.IsObjectType<DbValue>()) | ||||
| 		return false; | ||||
| 
 | ||||
| 	DbValue::Ptr dbv = value; | ||||
| 	return dbv->GetType() == DbValueObjectInsertID; | ||||
| } | ||||
| 
 | ||||
| Value DbValue::ExtractValue(const Value& value) | ||||
| { | ||||
| 	if (!value.IsObjectType<DbValue>()) | ||||
|  | ||||
| @ -31,6 +31,7 @@ enum DbValueType | ||||
| { | ||||
| 	DbValueTimestamp, | ||||
| 	DbValueTimestampNow, | ||||
| 	DbValueObjectInsertID, | ||||
| }; | ||||
| 
 | ||||
| /**
 | ||||
| @ -46,9 +47,11 @@ public: | ||||
| 	static Value FromTimestamp(const Value& ts); | ||||
| 	static Value FromTimestampNow(void); | ||||
| 	static Value FromValue(const Value& value); | ||||
| 	static Value FromObjectInsertID(const Value& value); | ||||
| 
 | ||||
| 	static bool IsTimestamp(const Value& value); | ||||
| 	static bool IsTimestampNow(const Value& value); | ||||
| 	static bool IsObjectInsertID(const Value& value); | ||||
| 	static Value ExtractValue(const Value& value); | ||||
| 
 | ||||
| 	DbValueType GetType(void) const; | ||||
|  | ||||
| @ -186,3 +186,37 @@ Dictionary::Ptr HostDbObject::GetStatusFields(void) const | ||||
| 
 | ||||
| 	return fields; | ||||
| } | ||||
| 
 | ||||
| void HostDbObject::OnConfigUpdate(void) | ||||
| { | ||||
| 	Host::Ptr host = static_pointer_cast<Host>(GetObject()); | ||||
| 
 | ||||
| 	/* parents: host_id, parent_host_object_id */ | ||||
| 
 | ||||
| 	/* delete possible definitions - TODO do that on startup */ | ||||
| 	DbQuery query1; | ||||
| 	query1.Table = GetType()->GetTable() + "_parenthosts"; | ||||
| 	query1.Type = DbQueryDelete; | ||||
| 	query1.WhereCriteria = boost::make_shared<Dictionary>(); | ||||
| 	query1.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject())); | ||||
| 	OnQuery(query1); | ||||
| 
 | ||||
| 	BOOST_FOREACH(const Host::Ptr& parent, host->GetParentHosts()) { | ||||
| 		Log(LogDebug, "ido", "host parents: " + parent->GetName()); | ||||
| 
 | ||||
| 		Dictionary::Ptr fields = boost::make_shared<Dictionary>(); | ||||
| 		fields->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject())); | ||||
| 		fields->Set("parent_host_object_id", parent); | ||||
| 		fields->Set("instance_id", 0); /* DbConnection class fills in real ID */ | ||||
| 
 | ||||
| 		DbQuery query2; | ||||
| 		query2.Table = GetType()->GetTable() + "_parenthosts"; | ||||
| 		query2.Type = DbQueryInsert; | ||||
| 		query2.Fields = fields; | ||||
| 		OnQuery(query2); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void HostDbObject::OnStatusUpdate(void) | ||||
| { | ||||
| } | ||||
|  | ||||
| @ -40,6 +40,10 @@ public: | ||||
| 
 | ||||
| 	virtual Dictionary::Ptr GetConfigFields(void) const; | ||||
| 	virtual Dictionary::Ptr GetStatusFields(void) const; | ||||
| 
 | ||||
| private: | ||||
| 	virtual void OnConfigUpdate(void); | ||||
| 	virtual void OnStatusUpdate(void); | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user