UpdateObject: IMetabaseObject;
The UpdateObject property determines repository object to that update is performed.
This property is assigned automatically on executing the Prepare method if updated object is found in repository. The user can change value of this property in the custom OnBeforeApplyUpdate event used in update module. If use of update module is not foreseen, the ForceUpdateObject property must be used to change repository object to that update is performed.
NOTE. An object that has the same class as an object in update has must be specified as updated object.
Public Class CUpdateEvents: UpdateEvents
Public Sub OnBeginUpdate(Update: IMetabaseUpdate);
Begin
Debug.WriteLine("Beginning of update of repository objects");
End Sub OnBeginUpdate;
Public Sub OnBeforeApplyUpdate(Update: IMetabaseUpdate);
Var
Root: IMetabaseUpdateFolderNode;
Node: IMetabaseUpdateNode;
ObjectNode: IMetabaseUpdateObjectNode;
State: IMetabaseUpdateObjectApplyState;
MB: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
i: Integer;
Begin
MB := MetabaseClass.Active;
Root := Update.RootFolder;
For i := 0 To Root.Count - 1 Do
Node := Root.Item(i);
If Node.NodeType = MetabaseUpdateNodeType.Object Then
ObjectNode := Node As IMetabaseUpdateObjectNode;
State := ObjectNode.ApplyState;
Select Case State.State
Case MetabaseUpdateObjectApplyState.Conflict Or MetabaseUpdateObjectApplyState.ConflictObjectNotFound:
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := ObjectNode.Object.ClassId;
CrInfo.Id := MB.GenerateId(ObjectNode.Object.Id);
CrInfo.Name := ObjectNode.Object.Name;
CrInfo.Parent := MB.Root;
CrInfo.SkipIdFormatCheck := True;
MObj := MB.CreateObject(CrInfo).Edit;
MObj.Save;
State.UpdateObject := MObj;
State.State := MetabaseUpdateObjectApplyState.EditExisting;
End Select;
End If;
End For;
End Sub OnBeforeApplyUpdate;
Public Sub OnEndUpdate(Update: IMetabaseUpdate);
Begin
Debug.WriteLine("Update of objects is completed");
End Sub OnEndUpdate;
End Class CUpdateEvents;
This example is a template for update module. On applying the update that contains this module readiness of objects that correspond with repository objects is checked. Particularly, a conflict will be solved if in repository there is not an object for that the type - Only Update was assigned in update.
A new empty object the same class is created in repository to solve a conflict. This object is assigned as updated object. The state of readiness of updated object will be changed on Update of a current object (MetabaseUpdateObjectApplyState.EditExisting).
NOTE. It is necessary to remember that not all conflicts can be solved. In this example a condition of update of the object by key is ignored. If an object does not exist in repository it will be created. Keys of the object in repository and in update are different.
See also: