ApplyState: IMetabaseUpdateObjectApplyState;
The ApplyState property returns parameters of object readiness to update.
A property value is filled after calling the IMetabaseUpdate.Prepare method of the whole update, or the IMetabaseUpdateNode.Prepare method of the particular object in the update.
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 unit. On applying the update that contains this unit, readiness of objects that correspond to repository objects is checked. Particularly, a conflict will be solved if the repository does not have an object, for which the Update Only type is set in update.
A new empty object of the same class is created in the repository to solve a conflict. This object is assigned as an updated object. The state of readiness of updated object will be changed to Update Existing Object (MetabaseUpdateObjectApplyState.EditExisting).
NOTE. 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: